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

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

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 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
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing_wrapper.cc ('k') | net/proxy/proxy_script_decider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "net/proxy/proxy_resolver_v8_tracing_wrapper.h" 5 #include "net/proxy/proxy_resolver_v8_tracing_wrapper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/threading/platform_thread.h" 19 #include "base/threading/platform_thread.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
23 #include "net/dns/host_cache.h" 23 #include "net/dns/host_cache.h"
24 #include "net/dns/mock_host_resolver.h" 24 #include "net/dns/mock_host_resolver.h"
25 #include "net/log/net_log.h" 25 #include "net/log/net_log.h"
26 #include "net/log/net_log_event_type.h"
26 #include "net/log/test_net_log.h" 27 #include "net/log/test_net_log.h"
27 #include "net/log/test_net_log_entry.h" 28 #include "net/log/test_net_log_entry.h"
28 #include "net/log/test_net_log_util.h" 29 #include "net/log/test_net_log_util.h"
29 #include "net/proxy/proxy_info.h" 30 #include "net/proxy/proxy_info.h"
30 #include "net/proxy/proxy_resolver_error_observer.h" 31 #include "net/proxy/proxy_resolver_error_observer.h"
31 #include "net/test/event_waiter.h" 32 #include "net/test/event_waiter.h"
32 #include "net/test/gtest_util.h" 33 #include "net/test/gtest_util.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/gurl.h" 36 #include "url/gurl.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 183
183 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they 184 // Check the NetLogs -- there was 1 alert and 1 javascript error, and they
184 // were output to both the global log, and per-request log. 185 // were output to both the global log, and per-request log.
185 TestNetLogEntry::List entries_list[2]; 186 TestNetLogEntry::List entries_list[2];
186 log.GetEntries(&entries_list[0]); 187 log.GetEntries(&entries_list[0]);
187 request_log.GetEntries(&entries_list[1]); 188 request_log.GetEntries(&entries_list[1]);
188 189
189 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { 190 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
190 const TestNetLogEntry::List& entries = entries_list[list_i]; 191 const TestNetLogEntry::List& entries = entries_list[list_i];
191 EXPECT_EQ(2u, entries.size()); 192 EXPECT_EQ(2u, entries.size());
192 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 193 EXPECT_TRUE(LogContainsEvent(entries, 0,
193 NetLog::PHASE_NONE)); 194 NetLogEventType::PAC_JAVASCRIPT_ALERT,
194 EXPECT_TRUE(LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ERROR, 195 NetLogEventPhase::NONE));
195 NetLog::PHASE_NONE)); 196 EXPECT_TRUE(LogContainsEvent(entries, 1,
197 NetLogEventType::PAC_JAVASCRIPT_ERROR,
198 NetLogEventPhase::NONE));
196 199
197 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson()); 200 EXPECT_EQ("{\"message\":\"Prepare to DIE!\"}", entries[0].GetParamsJson());
198 EXPECT_EQ( 201 EXPECT_EQ(
199 "{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot " 202 "{\"line_number\":5,\"message\":\"Uncaught TypeError: Cannot "
200 "read property 'split' of null\"}", 203 "read property 'split' of null\"}",
201 entries[1].GetParamsJson()); 204 entries[1].GetParamsJson());
202 } 205 }
203 } 206 }
204 207
205 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyAlerts) { 208 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyAlerts) {
(...skipping 29 matching lines...) Expand all
235 // Check the NetLogs -- the script generated 50 alerts, which were mirrored 238 // Check the NetLogs -- the script generated 50 alerts, which were mirrored
236 // to both the global and per-request logs. 239 // to both the global and per-request logs.
237 TestNetLogEntry::List entries_list[2]; 240 TestNetLogEntry::List entries_list[2];
238 log.GetEntries(&entries_list[0]); 241 log.GetEntries(&entries_list[0]);
239 request_log.GetEntries(&entries_list[1]); 242 request_log.GetEntries(&entries_list[1]);
240 243
241 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { 244 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
242 const TestNetLogEntry::List& entries = entries_list[list_i]; 245 const TestNetLogEntry::List& entries = entries_list[list_i];
243 EXPECT_EQ(50u, entries.size()); 246 EXPECT_EQ(50u, entries.size());
244 for (size_t i = 0; i < entries.size(); ++i) { 247 for (size_t i = 0; i < entries.size(); ++i) {
245 ASSERT_TRUE(LogContainsEvent( 248 ASSERT_TRUE(LogContainsEvent(entries, i,
246 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); 249 NetLogEventType::PAC_JAVASCRIPT_ALERT,
250 NetLogEventPhase::NONE));
247 } 251 }
248 } 252 }
249 } 253 }
250 254
251 // Verify that buffered alerts cannot grow unboundedly, even when the message is 255 // Verify that buffered alerts cannot grow unboundedly, even when the message is
252 // empty string. 256 // empty string.
253 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyEmptyAlerts) { 257 TEST_F(ProxyResolverV8TracingWrapperTest, TooManyEmptyAlerts) {
254 TestNetLog log; 258 TestNetLog log;
255 BoundTestNetLog request_log; 259 BoundTestNetLog request_log;
256 MockCachingHostResolver host_resolver; 260 MockCachingHostResolver host_resolver;
(...skipping 23 matching lines...) Expand all
280 // Check the NetLogs -- the script generated 50 alerts, which were mirrored 284 // Check the NetLogs -- the script generated 50 alerts, which were mirrored
281 // to both the global and per-request logs. 285 // to both the global and per-request logs.
282 TestNetLogEntry::List entries_list[2]; 286 TestNetLogEntry::List entries_list[2];
283 log.GetEntries(&entries_list[0]); 287 log.GetEntries(&entries_list[0]);
284 request_log.GetEntries(&entries_list[1]); 288 request_log.GetEntries(&entries_list[1]);
285 289
286 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { 290 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
287 const TestNetLogEntry::List& entries = entries_list[list_i]; 291 const TestNetLogEntry::List& entries = entries_list[list_i];
288 EXPECT_EQ(1000u, entries.size()); 292 EXPECT_EQ(1000u, entries.size());
289 for (size_t i = 0; i < entries.size(); ++i) { 293 for (size_t i = 0; i < entries.size(); ++i) {
290 ASSERT_TRUE(LogContainsEvent( 294 ASSERT_TRUE(LogContainsEvent(entries, i,
291 entries, i, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, NetLog::PHASE_NONE)); 295 NetLogEventType::PAC_JAVASCRIPT_ALERT,
296 NetLogEventPhase::NONE));
292 } 297 }
293 } 298 }
294 } 299 }
295 300
296 // This test runs a PAC script that issues a sequence of DNS resolves. The test 301 // This test runs a PAC script that issues a sequence of DNS resolves. The test
297 // verifies the final result, and that the underlying DNS resolver received 302 // verifies the final result, and that the underlying DNS resolver received
298 // the correct set of queries. 303 // the correct set of queries.
299 TEST_F(ProxyResolverV8TracingWrapperTest, Dns) { 304 TEST_F(ProxyResolverV8TracingWrapperTest, Dns) {
300 TestNetLog log; 305 TestNetLog log;
301 BoundTestNetLog request_log; 306 BoundTestNetLog request_log;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 358
354 // Check the NetLogs -- the script generated 1 alert, mirrored to both 359 // Check the NetLogs -- the script generated 1 alert, mirrored to both
355 // the per-request and global logs. 360 // the per-request and global logs.
356 TestNetLogEntry::List entries_list[2]; 361 TestNetLogEntry::List entries_list[2];
357 log.GetEntries(&entries_list[0]); 362 log.GetEntries(&entries_list[0]);
358 request_log.GetEntries(&entries_list[1]); 363 request_log.GetEntries(&entries_list[1]);
359 364
360 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { 365 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
361 const TestNetLogEntry::List& entries = entries_list[list_i]; 366 const TestNetLogEntry::List& entries = entries_list[list_i];
362 EXPECT_EQ(1u, entries.size()); 367 EXPECT_EQ(1u, entries.size());
363 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 368 EXPECT_TRUE(LogContainsEvent(entries, 0,
364 NetLog::PHASE_NONE)); 369 NetLogEventType::PAC_JAVASCRIPT_ALERT,
370 NetLogEventPhase::NONE));
365 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson()); 371 EXPECT_EQ("{\"message\":\"iteration: 7\"}", entries[0].GetParamsJson());
366 } 372 }
367 } 373 }
368 374
369 // This test runs a PAC script that does "myIpAddress()" followed by 375 // This test runs a PAC script that does "myIpAddress()" followed by
370 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's 376 // "dnsResolve()". This requires 2 restarts. However once the HostResolver's
371 // cache is warmed, subsequent calls should take 0 restarts. 377 // cache is warmed, subsequent calls should take 0 restarts.
372 TEST_F(ProxyResolverV8TracingWrapperTest, DnsChecksCache) { 378 TEST_F(ProxyResolverV8TracingWrapperTest, DnsChecksCache) {
373 TestNetLog log; 379 TestNetLog log;
374 BoundTestNetLog request_log; 380 BoundTestNetLog request_log;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 462
457 // Check the NetLogs -- the script generated 1 alert, mirrored to both 463 // Check the NetLogs -- the script generated 1 alert, mirrored to both
458 // the per-request and global logs. 464 // the per-request and global logs.
459 TestNetLogEntry::List entries_list[2]; 465 TestNetLogEntry::List entries_list[2];
460 log.GetEntries(&entries_list[0]); 466 log.GetEntries(&entries_list[0]);
461 request_log.GetEntries(&entries_list[1]); 467 request_log.GetEntries(&entries_list[1]);
462 468
463 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) { 469 for (size_t list_i = 0; list_i < arraysize(entries_list); list_i++) {
464 const TestNetLogEntry::List& entries = entries_list[list_i]; 470 const TestNetLogEntry::List& entries = entries_list[list_i];
465 EXPECT_EQ(1u, entries.size()); 471 EXPECT_EQ(1u, entries.size());
466 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 472 EXPECT_TRUE(LogContainsEvent(entries, 0,
467 NetLog::PHASE_NONE)); 473 NetLogEventType::PAC_JAVASCRIPT_ALERT,
474 NetLogEventPhase::NONE));
468 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson()); 475 EXPECT_EQ("{\"message\":\"iteration: 4\"}", entries[0].GetParamsJson());
469 } 476 }
470 } 477 }
471 478
472 // This test runs a weird PAC script that was designed to defeat the DNS tracing 479 // This test runs a weird PAC script that was designed to defeat the DNS tracing
473 // optimization. The proxy resolver should detect the inconsistency and 480 // optimization. The proxy resolver should detect the inconsistency and
474 // fall-back to synchronous mode execution. 481 // fall-back to synchronous mode execution.
475 TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous2) { 482 TEST_F(ProxyResolverV8TracingWrapperTest, FallBackToSynchronous2) {
476 TestNetLog log; 483 TestNetLog log;
477 BoundTestNetLog request_log; 484 BoundTestNetLog request_log;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 637
631 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99", 638 EXPECT_EQ("91.13.12.1-91.13.12.2-145.88.13.3-137.89.8.45:99",
632 proxy_info.proxy_server().ToURI()); 639 proxy_info.proxy_server().ToURI());
633 640
634 // Check the NetLogs -- the script generated 2 alerts during initialization. 641 // Check the NetLogs -- the script generated 2 alerts during initialization.
635 EXPECT_EQ(0u, request_log.GetSize()); 642 EXPECT_EQ(0u, request_log.GetSize());
636 TestNetLogEntry::List entries; 643 TestNetLogEntry::List entries;
637 log.GetEntries(&entries); 644 log.GetEntries(&entries);
638 645
639 ASSERT_EQ(2u, entries.size()); 646 ASSERT_EQ(2u, entries.size());
640 EXPECT_TRUE(LogContainsEvent(entries, 0, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 647 EXPECT_TRUE(LogContainsEvent(entries, 0,
641 NetLog::PHASE_NONE)); 648 NetLogEventType::PAC_JAVASCRIPT_ALERT,
642 EXPECT_TRUE(LogContainsEvent(entries, 1, NetLog::TYPE_PAC_JAVASCRIPT_ALERT, 649 NetLogEventPhase::NONE));
643 NetLog::PHASE_NONE)); 650 EXPECT_TRUE(LogContainsEvent(entries, 1,
651 NetLogEventType::PAC_JAVASCRIPT_ALERT,
652 NetLogEventPhase::NONE));
644 653
645 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson()); 654 EXPECT_EQ("{\"message\":\"Watsup\"}", entries[0].GetParamsJson());
646 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson()); 655 EXPECT_EQ("{\"message\":\"Watsup2\"}", entries[1].GetParamsJson());
647 } 656 }
648 657
649 // Tests a PAC script which does DNS resolves during initialization. 658 // Tests a PAC script which does DNS resolves during initialization.
650 TEST_F(ProxyResolverV8TracingWrapperTest, DnsDuringInit) { 659 TEST_F(ProxyResolverV8TracingWrapperTest, DnsDuringInit) {
651 // Test with both both a host resolver that always completes asynchronously, 660 // Test with both both a host resolver that always completes asynchronously,
652 // and then again with one that completes synchronously. 661 // and then again with one that completes synchronously.
653 DnsDuringInitHelper(false); 662 DnsDuringInitHelper(false);
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 proxy_uri.substr(0, proxy_uri.find(':') + 1)); 1155 proxy_uri.substr(0, proxy_uri.find(':') + 1));
1147 } else { 1156 } else {
1148 NOTREACHED(); 1157 NOTREACHED();
1149 } 1158 }
1150 } 1159 }
1151 } 1160 }
1152 1161
1153 } // namespace 1162 } // namespace
1154 1163
1155 } // namespace net 1164 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_v8_tracing_wrapper.cc ('k') | net/proxy/proxy_script_decider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698