[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 1 | // Copyright (c) 2009 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 "base/file_util.h" |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 6 | #include "base/path_service.h" |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 7 | #include "base/string_util.h" |
| 8 | #include "base/utf_string_conversions.h" |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 9 | #include "googleurl/src/gurl.h" |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 10 | #include "net/base/net_errors.h" |
[email protected] | 72b4a77 | 2010-07-14 01:29:30 | [diff] [blame] | 11 | #include "net/base/net_log_unittest.h" |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 12 | #include "net/proxy/proxy_info.h" |
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 13 | #include "net/proxy/proxy_resolver_js_bindings.h" |
| 14 | #include "net/proxy/proxy_resolver_v8.h" |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
| 16 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 17 | namespace net { |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 18 | namespace { |
| 19 | |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 20 | // Javascript bindings for ProxyResolverV8, which returns mock values. |
| 21 | // Each time one of the bindings is called into, we push the input into a |
| 22 | // list, for later verification. |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 23 | class MockJSBindings : public ProxyResolverJSBindings { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 24 | public: |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 25 | MockJSBindings() : my_ip_address_count(0), my_ip_address_ex_count(0) {} |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 26 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 27 | virtual void Alert(const string16& message) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 28 | LOG(INFO) << "PAC-alert: " << message; // Helpful when debugging. |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 29 | alerts.push_back(UTF16ToUTF8(message)); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 30 | } |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 31 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 32 | virtual bool MyIpAddress(std::string* ip_address) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 33 | my_ip_address_count++; |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 34 | *ip_address = my_ip_address_result; |
| 35 | return !my_ip_address_result.empty(); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 36 | } |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 37 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 38 | virtual bool MyIpAddressEx(std::string* ip_address_list) { |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 39 | my_ip_address_ex_count++; |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 40 | *ip_address_list = my_ip_address_ex_result; |
| 41 | return !my_ip_address_ex_result.empty(); |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 42 | } |
| 43 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 44 | virtual bool DnsResolve(const std::string& host, std::string* ip_address) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 45 | dns_resolves.push_back(host); |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 46 | *ip_address = dns_resolve_result; |
| 47 | return !dns_resolve_result.empty(); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 50 | virtual bool DnsResolveEx(const std::string& host, |
| 51 | std::string* ip_address_list) { |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 52 | dns_resolves_ex.push_back(host); |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 53 | *ip_address_list = dns_resolve_ex_result; |
| 54 | return !dns_resolve_ex_result.empty(); |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 55 | } |
| 56 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 57 | virtual void OnError(int line_number, const string16& message) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 58 | // Helpful when debugging. |
| 59 | LOG(INFO) << "PAC-error: [" << line_number << "] " << message; |
| 60 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 61 | errors.push_back(UTF16ToUTF8(message)); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 62 | errors_line_number.push_back(line_number); |
| 63 | } |
| 64 | |
[email protected] | 61b84d5 | 2010-07-09 03:32:00 | [diff] [blame] | 65 | virtual void Shutdown() {} |
| 66 | |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 67 | // Mock values to return. |
| 68 | std::string my_ip_address_result; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 69 | std::string my_ip_address_ex_result; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 70 | std::string dns_resolve_result; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 71 | std::string dns_resolve_ex_result; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 72 | |
| 73 | // Inputs we got called with. |
| 74 | std::vector<std::string> alerts; |
| 75 | std::vector<std::string> errors; |
| 76 | std::vector<int> errors_line_number; |
| 77 | std::vector<std::string> dns_resolves; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 78 | std::vector<std::string> dns_resolves_ex; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 79 | int my_ip_address_count; |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 80 | int my_ip_address_ex_count; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | // This is the same as ProxyResolverV8, but it uses mock bindings in place of |
| 84 | // the default bindings, and has a helper function to load PAC scripts from |
| 85 | // disk. |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 86 | class ProxyResolverV8WithMockBindings : public ProxyResolverV8 { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 87 | public: |
| 88 | ProxyResolverV8WithMockBindings() : ProxyResolverV8(new MockJSBindings()) {} |
| 89 | |
| 90 | MockJSBindings* mock_js_bindings() const { |
| 91 | return reinterpret_cast<MockJSBindings*>(js_bindings()); |
| 92 | } |
| 93 | |
| 94 | // Initialize with the PAC script data at |filename|. |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 95 | int SetPacScriptFromDisk(const char* filename) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 96 | FilePath path; |
| 97 | PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 98 | path = path.AppendASCII("net"); |
| 99 | path = path.AppendASCII("data"); |
| 100 | path = path.AppendASCII("proxy_resolver_v8_unittest"); |
| 101 | path = path.AppendASCII(filename); |
| 102 | |
| 103 | // Try to read the file from disk. |
| 104 | std::string file_contents; |
| 105 | bool ok = file_util::ReadFileToString(path, &file_contents); |
| 106 | |
| 107 | // If we can't load the file from disk, something is misconfigured. |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 108 | if (!ok) { |
| 109 | LOG(ERROR) << "Failed to read file: " << path.value(); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 110 | return ERR_UNEXPECTED; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 111 | } |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 112 | |
| 113 | // Load the PAC script into the ProxyResolver. |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 114 | return SetPacScript(ProxyResolverScriptData::FromUTF8(file_contents), |
| 115 | NULL); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 116 | } |
| 117 | }; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 118 | |
| 119 | // Doesn't really matter what these values are for many of the tests. |
| 120 | const GURL kQueryUrl("http://www.google.com"); |
| 121 | const GURL kPacUrl; |
| 122 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 123 | |
| 124 | TEST(ProxyResolverV8Test, Direct) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 125 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 126 | int result = resolver.SetPacScriptFromDisk("direct.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 127 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 128 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 129 | ProxyInfo proxy_info; |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 130 | CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 131 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 132 | log.bound()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 133 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 134 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 135 | EXPECT_TRUE(proxy_info.is_direct()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 136 | |
| 137 | EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
| 138 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 139 | |
| 140 | // No bindings were called, so no log entries. |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 141 | EXPECT_EQ(0u, log.entries().size()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | TEST(ProxyResolverV8Test, ReturnEmptyString) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 145 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 146 | int result = resolver.SetPacScriptFromDisk("return_empty_string.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 147 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 148 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 149 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 150 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 151 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 152 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 153 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 154 | EXPECT_TRUE(proxy_info.is_direct()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 155 | |
| 156 | EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
| 157 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | TEST(ProxyResolverV8Test, Basic) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 161 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 162 | int result = resolver.SetPacScriptFromDisk("passthrough.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 163 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 164 | |
| 165 | // The "FindProxyForURL" of this PAC script simply concatenates all of the |
| 166 | // arguments into a pseudo-host. The purpose of this test is to verify that |
| 167 | // the correct arguments are being passed to FindProxyForURL(). |
| 168 | { |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 169 | ProxyInfo proxy_info; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 170 | result = resolver.GetProxyForURL(GURL("http://query.com/path"), |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 171 | &proxy_info, NULL, NULL, BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 172 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 173 | EXPECT_EQ("http.query.com.path.query.com:80", |
| 174 | proxy_info.proxy_server().ToURI()); |
| 175 | } |
| 176 | { |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 177 | ProxyInfo proxy_info; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 178 | int result = resolver.GetProxyForURL(GURL("ftp://query.com:90/path"), |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 179 | &proxy_info, NULL, NULL, |
| 180 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 181 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 182 | // Note that FindProxyForURL(url, host) does not expect |host| to contain |
| 183 | // the port number. |
| 184 | EXPECT_EQ("ftp.query.com.90.path.query.com:80", |
| 185 | proxy_info.proxy_server().ToURI()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 186 | |
| 187 | EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
| 188 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 189 | } |
[email protected] | 0cf348be | 2009-10-13 01:39:58 | [diff] [blame] | 190 | |
| 191 | // We call this so we'll have code coverage of the function and valgrind will |
| 192 | // make sure nothing bad happens. |
| 193 | // |
| 194 | // NOTE: This is here instead of in its own test so that we'll be calling it |
| 195 | // after having done something, in hopes it won't be a no-op. |
| 196 | resolver.PurgeMemory(); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | TEST(ProxyResolverV8Test, BadReturnType) { |
| 200 | // These are the filenames of PAC scripts which each return a non-string |
| 201 | // types for FindProxyForURL(). They should all fail with |
| 202 | // ERR_PAC_SCRIPT_FAILED. |
| 203 | static const char* const filenames[] = { |
| 204 | "return_undefined.js", |
| 205 | "return_integer.js", |
| 206 | "return_function.js", |
| 207 | "return_object.js", |
| 208 | // TODO(eroman): Should 'null' be considered equivalent to "DIRECT" ? |
| 209 | "return_null.js" |
| 210 | }; |
| 211 | |
| 212 | for (size_t i = 0; i < arraysize(filenames); ++i) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 213 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 214 | int result = resolver.SetPacScriptFromDisk(filenames[i]); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 215 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 216 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 217 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 218 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 219 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 220 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 221 | EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 222 | |
| 223 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 224 | EXPECT_EQ(0U, bindings->alerts.size()); |
| 225 | ASSERT_EQ(1U, bindings->errors.size()); |
| 226 | EXPECT_EQ("FindProxyForURL() did not return a string.", |
| 227 | bindings->errors[0]); |
| 228 | EXPECT_EQ(-1, bindings->errors_line_number[0]); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
| 232 | // Try using a PAC script which defines no "FindProxyForURL" function. |
| 233 | TEST(ProxyResolverV8Test, NoEntryPoint) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 234 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 235 | int result = resolver.SetPacScriptFromDisk("no_entrypoint.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 236 | EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 237 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 238 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 239 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 240 | BoundNetLog()); |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 241 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 242 | EXPECT_EQ(ERR_FAILED, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | // Try loading a malformed PAC script. |
| 246 | TEST(ProxyResolverV8Test, ParseError) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 247 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 248 | int result = resolver.SetPacScriptFromDisk("missing_close_brace.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 249 | EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 250 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 251 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 252 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 253 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 254 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 255 | EXPECT_EQ(ERR_FAILED, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 256 | |
| 257 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 258 | EXPECT_EQ(0U, bindings->alerts.size()); |
| 259 | |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 260 | // We get one error during compilation. |
| 261 | ASSERT_EQ(1U, bindings->errors.size()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 262 | |
| 263 | EXPECT_EQ("Uncaught SyntaxError: Unexpected end of input", |
| 264 | bindings->errors[0]); |
[email protected] | b72bdc1 | 2010-05-11 08:12:36 | [diff] [blame] | 265 | EXPECT_EQ(0, bindings->errors_line_number[0]); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | // Run a PAC script several times, which has side-effects. |
| 269 | TEST(ProxyResolverV8Test, SideEffects) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 270 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 271 | int result = resolver.SetPacScriptFromDisk("side_effects.js"); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 272 | |
| 273 | // The PAC script increments a counter each time we invoke it. |
| 274 | for (int i = 0; i < 3; ++i) { |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 275 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 276 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 277 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 278 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 279 | EXPECT_EQ(StringPrintf("sideffect_%d:80", i), |
| 280 | proxy_info.proxy_server().ToURI()); |
| 281 | } |
| 282 | |
| 283 | // Reload the script -- the javascript environment should be reset, hence |
| 284 | // the counter starts over. |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 285 | result = resolver.SetPacScriptFromDisk("side_effects.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 286 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 287 | |
| 288 | for (int i = 0; i < 3; ++i) { |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 289 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 290 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 291 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 292 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 293 | EXPECT_EQ(StringPrintf("sideffect_%d:80", i), |
| 294 | proxy_info.proxy_server().ToURI()); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // Execute a PAC script which throws an exception in FindProxyForURL. |
| 299 | TEST(ProxyResolverV8Test, UnhandledException) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 300 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 301 | int result = resolver.SetPacScriptFromDisk("unhandled_exception.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 302 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 303 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 304 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 305 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 306 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 307 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 308 | EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 309 | |
| 310 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 311 | EXPECT_EQ(0U, bindings->alerts.size()); |
| 312 | ASSERT_EQ(1U, bindings->errors.size()); |
| 313 | EXPECT_EQ("Uncaught ReferenceError: undefined_variable is not defined", |
| 314 | bindings->errors[0]); |
| 315 | EXPECT_EQ(3, bindings->errors_line_number[0]); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 316 | } |
| 317 | |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 318 | TEST(ProxyResolverV8Test, ReturnUnicode) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 319 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 320 | int result = resolver.SetPacScriptFromDisk("return_unicode.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 321 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 322 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 323 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 324 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 325 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 326 | |
| 327 | // The result from this resolve was unparseable, because it |
[email protected] | 51e413c | 2010-06-23 00:15:58 | [diff] [blame] | 328 | // wasn't ASCII. |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 329 | EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Test the PAC library functions that we expose in the JS environmnet. |
| 333 | TEST(ProxyResolverV8Test, JavascriptLibrary) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 334 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 335 | int result = resolver.SetPacScriptFromDisk("pac_library_unittest.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 336 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 337 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 338 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 339 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 340 | BoundNetLog()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 341 | |
| 342 | // If the javascript side of this unit-test fails, it will throw a javascript |
| 343 | // exception. Otherwise it will return "PROXY success:80". |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 344 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 345 | EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 346 | |
| 347 | EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
| 348 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 349 | } |
| 350 | |
[email protected] | 775fd9e | 2009-07-26 21:12:20 | [diff] [blame] | 351 | // Try resolving when SetPacScriptByData() has not been called. |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 352 | TEST(ProxyResolverV8Test, NoSetPacScript) { |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 353 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 354 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 355 | ProxyInfo proxy_info; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 356 | |
| 357 | // Resolve should fail, as we are not yet initialized with a script. |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 358 | int result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 359 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 360 | EXPECT_EQ(ERR_FAILED, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 361 | |
| 362 | // Initialize it. |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 363 | result = resolver.SetPacScriptFromDisk("direct.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 364 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 365 | |
| 366 | // Resolve should now succeed. |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 367 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 368 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 369 | EXPECT_EQ(OK, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 370 | |
| 371 | // Clear it, by initializing with an empty string. |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 372 | resolver.SetPacScript( |
| 373 | ProxyResolverScriptData::FromUTF16(string16()), NULL); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 374 | |
| 375 | // Resolve should fail again now. |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 376 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 377 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 378 | EXPECT_EQ(ERR_FAILED, result); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 379 | |
| 380 | // Load a good script once more. |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 381 | result = resolver.SetPacScriptFromDisk("direct.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 382 | EXPECT_EQ(OK, result); |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 383 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 384 | BoundNetLog()); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 385 | EXPECT_EQ(OK, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 386 | |
| 387 | EXPECT_EQ(0U, resolver.mock_js_bindings()->alerts.size()); |
| 388 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
| 389 | } |
| 390 | |
| 391 | // Test marshalling/un-marshalling of values between C++/V8. |
| 392 | TEST(ProxyResolverV8Test, V8Bindings) { |
| 393 | ProxyResolverV8WithMockBindings resolver; |
[email protected] | d35c366 | 2010-05-05 20:04:34 | [diff] [blame] | 394 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 395 | bindings->dns_resolve_result = "127.0.0.1"; |
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 396 | int result = resolver.SetPacScriptFromDisk("bindings.js"); |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 397 | EXPECT_EQ(OK, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 398 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 399 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 400 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 401 | BoundNetLog()); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 402 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 403 | EXPECT_EQ(OK, result); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 404 | EXPECT_TRUE(proxy_info.is_direct()); |
| 405 | |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 406 | EXPECT_EQ(0U, resolver.mock_js_bindings()->errors.size()); |
| 407 | |
| 408 | // Alert was called 5 times. |
| 409 | ASSERT_EQ(5U, bindings->alerts.size()); |
| 410 | EXPECT_EQ("undefined", bindings->alerts[0]); |
| 411 | EXPECT_EQ("null", bindings->alerts[1]); |
| 412 | EXPECT_EQ("undefined", bindings->alerts[2]); |
| 413 | EXPECT_EQ("[object Object]", bindings->alerts[3]); |
| 414 | EXPECT_EQ("exception from calling toString()", bindings->alerts[4]); |
| 415 | |
[email protected] | d35c366 | 2010-05-05 20:04:34 | [diff] [blame] | 416 | // DnsResolve was called 8 times, however only 2 of those were string |
| 417 | // parameters. (so 6 of them failed immediately). |
| 418 | ASSERT_EQ(2U, bindings->dns_resolves.size()); |
| 419 | EXPECT_EQ("", bindings->dns_resolves[0]); |
| 420 | EXPECT_EQ("arg1", bindings->dns_resolves[1]); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 421 | |
| 422 | // MyIpAddress was called two times. |
| 423 | EXPECT_EQ(2, bindings->my_ip_address_count); |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 424 | |
| 425 | // MyIpAddressEx was called once. |
| 426 | EXPECT_EQ(1, bindings->my_ip_address_ex_count); |
| 427 | |
| 428 | // DnsResolveEx was called 2 times. |
| 429 | ASSERT_EQ(2U, bindings->dns_resolves_ex.size()); |
| 430 | EXPECT_EQ("is_resolvable", bindings->dns_resolves_ex[0]); |
| 431 | EXPECT_EQ("foobar", bindings->dns_resolves_ex[1]); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | a5e9f2c | 2010-03-31 22:10:11 | [diff] [blame] | 434 | // Test calling a binding (myIpAddress()) from the script's global scope. |
| 435 | // http://crbug.com/40026 |
| 436 | TEST(ProxyResolverV8Test, BindingCalledDuringInitialization) { |
| 437 | ProxyResolverV8WithMockBindings resolver; |
| 438 | |
| 439 | int result = resolver.SetPacScriptFromDisk("binding_from_global.js"); |
| 440 | EXPECT_EQ(OK, result); |
| 441 | |
| 442 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 443 | |
| 444 | // myIpAddress() got called during initialization of the script. |
| 445 | EXPECT_EQ(1, bindings->my_ip_address_count); |
| 446 | |
| 447 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 448 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 449 | BoundNetLog()); |
[email protected] | a5e9f2c | 2010-03-31 22:10:11 | [diff] [blame] | 450 | |
| 451 | EXPECT_EQ(OK, result); |
| 452 | EXPECT_FALSE(proxy_info.is_direct()); |
| 453 | EXPECT_EQ("127.0.0.1:80", proxy_info.proxy_server().ToURI()); |
| 454 | |
| 455 | // Check that no other bindings were called. |
| 456 | EXPECT_EQ(0U, bindings->errors.size()); |
| 457 | ASSERT_EQ(0U, bindings->alerts.size()); |
| 458 | ASSERT_EQ(0U, bindings->dns_resolves.size()); |
| 459 | EXPECT_EQ(0, bindings->my_ip_address_ex_count); |
| 460 | ASSERT_EQ(0U, bindings->dns_resolves_ex.size()); |
| 461 | } |
| 462 | |
[email protected] | cd88b0c | 2009-09-25 04:52:39 | [diff] [blame] | 463 | // Try loading a PAC script that ends with a comment and has no terminal |
| 464 | // newline. This should not cause problems with the PAC utility functions |
| 465 | // that we add to the script's environment. |
[email protected] | c945a46 | 2009-09-24 02:13:57 | [diff] [blame] | 466 | // http://crbug.com/22864 |
[email protected] | cd88b0c | 2009-09-25 04:52:39 | [diff] [blame] | 467 | TEST(ProxyResolverV8Test, EndsWithCommentNoNewline) { |
[email protected] | c945a46 | 2009-09-24 02:13:57 | [diff] [blame] | 468 | ProxyResolverV8WithMockBindings resolver; |
| 469 | int result = resolver.SetPacScriptFromDisk("ends_with_comment.js"); |
| 470 | EXPECT_EQ(OK, result); |
| 471 | |
| 472 | ProxyInfo proxy_info; |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 473 | CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 474 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 475 | log.bound()); |
[email protected] | c945a46 | 2009-09-24 02:13:57 | [diff] [blame] | 476 | |
| 477 | EXPECT_EQ(OK, result); |
| 478 | EXPECT_FALSE(proxy_info.is_direct()); |
| 479 | EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
| 480 | } |
| 481 | |
[email protected] | cd88b0c | 2009-09-25 04:52:39 | [diff] [blame] | 482 | // Try loading a PAC script that ends with a statement and has no terminal |
| 483 | // newline. This should not cause problems with the PAC utility functions |
| 484 | // that we add to the script's environment. |
| 485 | // http://crbug.com/22864 |
| 486 | TEST(ProxyResolverV8Test, EndsWithStatementNoNewline) { |
| 487 | ProxyResolverV8WithMockBindings resolver; |
| 488 | int result = resolver.SetPacScriptFromDisk( |
| 489 | "ends_with_statement_no_semicolon.js"); |
| 490 | EXPECT_EQ(OK, result); |
| 491 | |
| 492 | ProxyInfo proxy_info; |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 493 | CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 494 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 495 | log.bound()); |
[email protected] | cd88b0c | 2009-09-25 04:52:39 | [diff] [blame] | 496 | |
| 497 | EXPECT_EQ(OK, result); |
| 498 | EXPECT_FALSE(proxy_info.is_direct()); |
| 499 | EXPECT_EQ("success:3", proxy_info.proxy_server().ToURI()); |
| 500 | } |
| 501 | |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 502 | // Test the return values from myIpAddress(), myIpAddressEx(), dnsResolve(), |
| 503 | // dnsResolveEx(), isResolvable(), isResolvableEx(), when the the binding |
| 504 | // returns empty string (failure). This simulates the return values from |
| 505 | // those functions when the underlying DNS resolution fails. |
| 506 | TEST(ProxyResolverV8Test, DNSResolutionFailure) { |
| 507 | ProxyResolverV8WithMockBindings resolver; |
| 508 | int result = resolver.SetPacScriptFromDisk("dns_fail.js"); |
| 509 | EXPECT_EQ(OK, result); |
| 510 | |
| 511 | ProxyInfo proxy_info; |
[email protected] | 5a1d7ca | 2010-04-28 20:12:27 | [diff] [blame] | 512 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 513 | BoundNetLog()); |
[email protected] | 21f20c89 | 2009-10-26 23:51:28 | [diff] [blame] | 514 | |
| 515 | EXPECT_EQ(OK, result); |
| 516 | EXPECT_FALSE(proxy_info.is_direct()); |
| 517 | EXPECT_EQ("success:80", proxy_info.proxy_server().ToURI()); |
| 518 | } |
| 519 | |
[email protected] | 0238de4 | 2010-06-23 18:04:01 | [diff] [blame] | 520 | TEST(ProxyResolverV8Test, DNSResolutionOfInternationDomainName) { |
| 521 | ProxyResolverV8WithMockBindings resolver; |
| 522 | int result = resolver.SetPacScriptFromDisk("international_domain_names.js"); |
| 523 | EXPECT_EQ(OK, result); |
| 524 | |
| 525 | // Execute FindProxyForURL(). |
| 526 | ProxyInfo proxy_info; |
| 527 | result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, NULL, NULL, |
| 528 | BoundNetLog()); |
| 529 | |
| 530 | EXPECT_EQ(OK, result); |
| 531 | EXPECT_TRUE(proxy_info.is_direct()); |
| 532 | |
| 533 | // Check that the international domain name was converted to punycode |
| 534 | // before passing it onto the bindings layer. |
| 535 | MockJSBindings* bindings = resolver.mock_js_bindings(); |
| 536 | |
| 537 | ASSERT_EQ(1u, bindings->dns_resolves.size()); |
| 538 | EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves[0]); |
| 539 | |
| 540 | ASSERT_EQ(1u, bindings->dns_resolves_ex.size()); |
| 541 | EXPECT_EQ("xn--bcher-kva.ch", bindings->dns_resolves_ex[0]); |
| 542 | } |
| 543 | |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 544 | } // namespace |
| 545 | } // namespace net |