Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / proxy / mojo_proxy_resolver_v8_tracing_bindings_unittest.cc
blobce11b7108d7e592327345587eeef3788a9ecb6c9
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.
5 #include "net/proxy/mojo_proxy_resolver_v8_tracing_bindings.h"
7 #include <string>
8 #include <utility>
9 #include <vector>
11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace net {
16 class MojoProxyResolverV8TracingBindingsTest : public testing::Test {
17 public:
18 MojoProxyResolverV8TracingBindingsTest() = default;
20 void SetUp() override {
21 bindings_.reset(new MojoProxyResolverV8TracingBindings<
22 MojoProxyResolverV8TracingBindingsTest>(this));
25 void Alert(const mojo::String& message) {
26 alerts_.push_back(message.To<std::string>());
29 void OnError(int32_t line_number, const mojo::String& message) {
30 errors_.push_back(std::make_pair(line_number, message.To<std::string>()));
33 void ResolveDns(interfaces::HostResolverRequestInfoPtr request_info,
34 interfaces::HostResolverRequestClientPtr client) {}
36 protected:
37 scoped_ptr<MojoProxyResolverV8TracingBindings<
38 MojoProxyResolverV8TracingBindingsTest>> bindings_;
40 std::vector<std::string> alerts_;
41 std::vector<std::pair<int, std::string>> errors_;
43 private:
44 DISALLOW_COPY_AND_ASSIGN(MojoProxyResolverV8TracingBindingsTest);
47 TEST_F(MojoProxyResolverV8TracingBindingsTest, Basic) {
48 bindings_->Alert(base::ASCIIToUTF16("alert"));
49 bindings_->OnError(-1, base::ASCIIToUTF16("error"));
51 EXPECT_TRUE(bindings_->GetHostResolver());
52 EXPECT_FALSE(bindings_->GetBoundNetLog().net_log());
54 ASSERT_EQ(1u, alerts_.size());
55 EXPECT_EQ("alert", alerts_[0]);
56 ASSERT_EQ(1u, errors_.size());
57 EXPECT_EQ(-1, errors_[0].first);
58 EXPECT_EQ("error", errors_[0].second);
61 } // namespace net