Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: net/proxy/proxy_resolver_v8_unittest.cc

Issue 11959029: Make the v8 Isolate used in the proxy resolver explicit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed component build Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "googleurl/src/gurl.h" 11 #include "googleurl/src/gurl.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/net_log_unittest.h" 13 #include "net/base/net_log_unittest.h"
14 #include "net/proxy/proxy_info.h" 14 #include "net/proxy/proxy_info.h"
15 #include "net/proxy/proxy_resolver_js_bindings.h" 15 #include "net/proxy/proxy_resolver_js_bindings.h"
16 #include "net/proxy/proxy_resolver_v8.h" 16 #include "net/proxy/proxy_resolver_v8.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "v8/include/v8.h"
18 19
19 namespace net { 20 namespace net {
20 namespace { 21 namespace {
21 22
22 // Javascript bindings for ProxyResolverV8, which returns mock values. 23 // Javascript bindings for ProxyResolverV8, which returns mock values.
23 // Each time one of the bindings is called into, we push the input into a 24 // Each time one of the bindings is called into, we push the input into a
24 // list, for later verification. 25 // list, for later verification.
25 class MockJSBindings : public ProxyResolverJSBindings { 26 class MockJSBindings : public ProxyResolverJSBindings {
26 public: 27 public:
27 MockJSBindings() : my_ip_address_count(0), my_ip_address_ex_count(0) {} 28 MockJSBindings() : my_ip_address_count(0), my_ip_address_ex_count(0) {}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 std::vector<std::string> dns_resolves_ex; 82 std::vector<std::string> dns_resolves_ex;
82 int my_ip_address_count; 83 int my_ip_address_count;
83 int my_ip_address_ex_count; 84 int my_ip_address_ex_count;
84 }; 85 };
85 86
86 // This is the same as ProxyResolverV8, but it uses mock bindings in place of 87 // This is the same as ProxyResolverV8, but it uses mock bindings in place of
87 // the default bindings, and has a helper function to load PAC scripts from 88 // the default bindings, and has a helper function to load PAC scripts from
88 // disk. 89 // disk.
89 class ProxyResolverV8WithMockBindings : public ProxyResolverV8 { 90 class ProxyResolverV8WithMockBindings : public ProxyResolverV8 {
90 public: 91 public:
91 ProxyResolverV8WithMockBindings() : ProxyResolverV8(new MockJSBindings()) {} 92 ProxyResolverV8WithMockBindings()
93 : ProxyResolverV8(new MockJSBindings(), v8::Isolate::GetCurrent()) {}
92 94
93 MockJSBindings* mock_js_bindings() const { 95 MockJSBindings* mock_js_bindings() const {
94 return reinterpret_cast<MockJSBindings*>(js_bindings()); 96 return reinterpret_cast<MockJSBindings*>(js_bindings());
95 } 97 }
96 98
97 // Initialize with the PAC script data at |filename|. 99 // Initialize with the PAC script data at |filename|.
98 int SetPacScriptFromDisk(const char* filename) { 100 int SetPacScriptFromDisk(const char* filename) {
99 FilePath path; 101 FilePath path;
100 PathService::Get(base::DIR_SOURCE_ROOT, &path); 102 PathService::Get(base::DIR_SOURCE_ROOT, &path);
101 path = path.AppendASCII("net"); 103 path = path.AppendASCII("net");
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 EXPECT_TRUE(proxy_info.is_direct()); 564 EXPECT_TRUE(proxy_info.is_direct());
563 565
564 // We called dnsResolveEx() exactly once, by passing through the "host" 566 // We called dnsResolveEx() exactly once, by passing through the "host"
565 // argument to FindProxyForURL(). The brackets should have been stripped. 567 // argument to FindProxyForURL(). The brackets should have been stripped.
566 ASSERT_EQ(1U, resolver.mock_js_bindings()->dns_resolves_ex.size()); 568 ASSERT_EQ(1U, resolver.mock_js_bindings()->dns_resolves_ex.size());
567 EXPECT_EQ("abcd::efff", resolver.mock_js_bindings()->dns_resolves_ex[0]); 569 EXPECT_EQ("abcd::efff", resolver.mock_js_bindings()->dns_resolves_ex[0]);
568 } 570 }
569 571
570 } // namespace 572 } // namespace
571 } // namespace net 573 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698