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
5 #include "services/proxy_resolver/mojo_proxy_resolver_v8_tracing_bindings.h"
6
7 #include <string>
8 #include <utility>
9 #include <vector>
10
11 #include "base/macros.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace proxy_resolver {
16
17 class MojoProxyResolverV8TracingBindingsTest : public testing::Test {
18 public:
19 MojoProxyResolverV8TracingBindingsTest() = default;
20
Alert(const std::string & message)21 void Alert(const std::string& message) { alerts_.push_back(message); }
22
OnError(int32_t line_number,const std::string & message)23 void OnError(int32_t line_number, const std::string& message) {
24 errors_.push_back(std::make_pair(line_number, message));
25 }
26
ResolveDns(const std::string & hostname,net::ProxyResolveDnsOperation operation,const net::NetworkIsolationKey & network_isolation_key,mojo::PendingRemote<mojom::HostResolverRequestClient> client)27 void ResolveDns(
28 const std::string& hostname,
29 net::ProxyResolveDnsOperation operation,
30 const net::NetworkIsolationKey& network_isolation_key,
31 mojo::PendingRemote<mojom::HostResolverRequestClient> client) {}
32
33 protected:
34 MojoProxyResolverV8TracingBindings<MojoProxyResolverV8TracingBindingsTest>
35 bindings_{this};
36
37 std::vector<std::string> alerts_;
38 std::vector<std::pair<int, std::string>> errors_;
39
40 private:
41 DISALLOW_COPY_AND_ASSIGN(MojoProxyResolverV8TracingBindingsTest);
42 };
43
TEST_F(MojoProxyResolverV8TracingBindingsTest,Basic)44 TEST_F(MojoProxyResolverV8TracingBindingsTest, Basic) {
45 bindings_.Alert(base::ASCIIToUTF16("alert"));
46 bindings_.OnError(-1, base::ASCIIToUTF16("error"));
47
48 EXPECT_TRUE(bindings_.GetHostResolver());
49 EXPECT_FALSE(bindings_.GetNetLogWithSource().net_log());
50
51 ASSERT_EQ(1u, alerts_.size());
52 EXPECT_EQ("alert", alerts_[0]);
53 ASSERT_EQ(1u, errors_.size());
54 EXPECT_EQ(-1, errors_[0].first);
55 EXPECT_EQ("error", errors_[0].second);
56 }
57
58 } // namespace proxy_resolver
59