Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / services / proxy_resolver / mojo_proxy_resolver_v8_tracing_bindings_unittest.cc
1 // Copyright 2015 The Chromium Authors
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/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace proxy_resolver {
15
16 class MojoProxyResolverV8TracingBindingsTest : public testing::Test {
17  public:
18   MojoProxyResolverV8TracingBindingsTest() = default;
19
20   MojoProxyResolverV8TracingBindingsTest(
21       const MojoProxyResolverV8TracingBindingsTest&) = delete;
22   MojoProxyResolverV8TracingBindingsTest& operator=(
23       const MojoProxyResolverV8TracingBindingsTest&) = delete;
24
25   void Alert(const std::string& message) { alerts_.push_back(message); }
26
27   void OnError(int32_t line_number, const std::string& message) {
28     errors_.push_back(std::make_pair(line_number, message));
29   }
30
31   void ResolveDns(
32       const std::string& hostname,
33       net::ProxyResolveDnsOperation operation,
34       const net::NetworkAnonymizationKey& network_anonymization_key,
35       mojo::PendingRemote<mojom::HostResolverRequestClient> client) {}
36
37  protected:
38   MojoProxyResolverV8TracingBindings<MojoProxyResolverV8TracingBindingsTest>
39       bindings_{this};
40
41   std::vector<std::string> alerts_;
42   std::vector<std::pair<int, std::string>> errors_;
43 };
44
45 TEST_F(MojoProxyResolverV8TracingBindingsTest, Basic) {
46   bindings_.Alert(u"alert");
47   bindings_.OnError(-1, u"error");
48
49   EXPECT_TRUE(bindings_.GetHostResolver());
50   EXPECT_FALSE(bindings_.GetNetLogWithSource().net_log());
51
52   ASSERT_EQ(1u, alerts_.size());
53   EXPECT_EQ("alert", alerts_[0]);
54   ASSERT_EQ(1u, errors_.size());
55   EXPECT_EQ(-1, errors_[0].first);
56   EXPECT_EQ("error", errors_[0].second);
57 }
58
59 }  // namespace proxy_resolver