mojo_proxy_resolver_v8_tracing_bindings_unittest.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "services/proxy_resolver/mojo_proxy_resolver_v8_tracing_bindings.h"
  5. #include <string>
  6. #include <utility>
  7. #include <vector>
  8. #include "base/strings/utf_string_conversions.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace proxy_resolver {
  11. class MojoProxyResolverV8TracingBindingsTest : public testing::Test {
  12. public:
  13. MojoProxyResolverV8TracingBindingsTest() = default;
  14. MojoProxyResolverV8TracingBindingsTest(
  15. const MojoProxyResolverV8TracingBindingsTest&) = delete;
  16. MojoProxyResolverV8TracingBindingsTest& operator=(
  17. const MojoProxyResolverV8TracingBindingsTest&) = delete;
  18. void Alert(const std::string& message) { alerts_.push_back(message); }
  19. void OnError(int32_t line_number, const std::string& message) {
  20. errors_.push_back(std::make_pair(line_number, message));
  21. }
  22. void ResolveDns(
  23. const std::string& hostname,
  24. net::ProxyResolveDnsOperation operation,
  25. const net::NetworkIsolationKey& network_isolation_key,
  26. mojo::PendingRemote<mojom::HostResolverRequestClient> client) {}
  27. protected:
  28. MojoProxyResolverV8TracingBindings<MojoProxyResolverV8TracingBindingsTest>
  29. bindings_{this};
  30. std::vector<std::string> alerts_;
  31. std::vector<std::pair<int, std::string>> errors_;
  32. };
  33. TEST_F(MojoProxyResolverV8TracingBindingsTest, Basic) {
  34. bindings_.Alert(u"alert");
  35. bindings_.OnError(-1, u"error");
  36. EXPECT_TRUE(bindings_.GetHostResolver());
  37. EXPECT_FALSE(bindings_.GetNetLogWithSource().net_log());
  38. ASSERT_EQ(1u, alerts_.size());
  39. EXPECT_EQ("alert", alerts_[0]);
  40. ASSERT_EQ(1u, errors_.size());
  41. EXPECT_EQ(-1, errors_[0].first);
  42. EXPECT_EQ("error", errors_[0].second);
  43. }
  44. } // namespace proxy_resolver