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

Side by Side Diff: chrome/browser/net/chrome_network_delegate_unittest.cc

Issue 2804023003: Network traffic annotation added to chrome/browser/ unittests. (Closed)
Patch Set: Another missing header added. Created 3 years, 8 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
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 "chrome/browser/net/chrome_network_delegate.h" 5 #include "chrome/browser/net/chrome_network_delegate.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 21 matching lines...) Expand all
32 #include "components/sync_preferences/testing_pref_service_syncable.h" 32 #include "components/sync_preferences/testing_pref_service_syncable.h"
33 #include "content/public/browser/resource_request_info.h" 33 #include "content/public/browser/resource_request_info.h"
34 #include "content/public/common/content_switches.h" 34 #include "content/public/common/content_switches.h"
35 #include "content/public/common/previews_state.h" 35 #include "content/public/common/previews_state.h"
36 #include "content/public/common/resource_type.h" 36 #include "content/public/common/resource_type.h"
37 #include "content/public/test/test_browser_thread_bundle.h" 37 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "extensions/features/features.h" 38 #include "extensions/features/features.h"
39 #include "net/base/request_priority.h" 39 #include "net/base/request_priority.h"
40 #include "net/http/http_request_headers.h" 40 #include "net/http/http_request_headers.h"
41 #include "net/socket/socket_test_util.h" 41 #include "net/socket/socket_test_util.h"
42 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
42 #include "net/url_request/url_request.h" 43 #include "net/url_request/url_request.h"
43 #include "net/url_request/url_request_test_util.h" 44 #include "net/url_request/url_request_test_util.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
45 #include "url/gurl.h" 46 #include "url/gurl.h"
46 47
47 #if BUILDFLAG(ENABLE_EXTENSIONS) 48 #if BUILDFLAG(ENABLE_EXTENSIONS)
48 #include "chrome/browser/extensions/event_router_forwarder.h" 49 #include "chrome/browser/extensions/event_router_forwarder.h"
49 #endif 50 #endif
50 51
51 namespace { 52 namespace {
(...skipping 14 matching lines...) Expand all
66 67
67 net::MockRead response_mock_reads[] = { 68 net::MockRead response_mock_reads[] = {
68 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"), 69 net::MockRead("HTTP/1.1 200 OK\r\n\r\n"), net::MockRead("response body"),
69 net::MockRead(net::SYNCHRONOUS, net::OK), 70 net::MockRead(net::SYNCHRONOUS, net::OK),
70 }; 71 };
71 net::StaticSocketDataProvider response_socket_data_provider( 72 net::StaticSocketDataProvider response_socket_data_provider(
72 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); 73 response_mock_reads, arraysize(response_mock_reads), nullptr, 0);
73 socket_factory->AddSocketDataProvider(&response_socket_data_provider); 74 socket_factory->AddSocketDataProvider(&response_socket_data_provider);
74 net::TestDelegate test_delegate; 75 net::TestDelegate test_delegate;
75 test_delegate.set_quit_on_complete(true); 76 test_delegate.set_quit_on_complete(true);
76 std::unique_ptr<net::URLRequest> request(context->CreateRequest( 77 std::unique_ptr<net::URLRequest> request(
77 GURL("http://example.com"), net::DEFAULT_PRIORITY, &test_delegate)); 78 context->CreateRequest(GURL("http://example.com"), net::DEFAULT_PRIORITY,
79 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
78 80
79 content::ResourceRequestInfo::AllocateForTesting( 81 content::ResourceRequestInfo::AllocateForTesting(
80 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2, 82 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, nullptr, -2, -2, -2,
81 true, false, true, true, content::PREVIEWS_OFF); 83 true, false, true, true, content::PREVIEWS_OFF);
82 84
83 request->Start(); 85 request->Start();
84 base::RunLoop().RunUntilIdle(); 86 base::RunLoop().RunUntilIdle();
85 return request; 87 return request;
86 } 88 }
87 89
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 257
256 const char kHttpRequestCompletionErrorCode[] = 258 const char kHttpRequestCompletionErrorCode[] =
257 "Net.HttpRequestCompletionErrorCodes"; 259 "Net.HttpRequestCompletionErrorCodes";
258 const char kHttpRequestCompletionErrorCodeMainFrame[] = 260 const char kHttpRequestCompletionErrorCodeMainFrame[] =
259 "Net.HttpRequestCompletionErrorCodes.MainFrame"; 261 "Net.HttpRequestCompletionErrorCodes.MainFrame";
260 262
261 for (const auto& test : kTests) { 263 for (const auto& test : kTests) {
262 base::HistogramTester histograms; 264 base::HistogramTester histograms;
263 265
264 net::TestDelegate test_delegate; 266 net::TestDelegate test_delegate;
265 std::unique_ptr<net::URLRequest> request(context()->CreateRequest( 267 std::unique_ptr<net::URLRequest> request(
266 test.url, net::DEFAULT_PRIORITY, &test_delegate)); 268 context()->CreateRequest(test.url, net::DEFAULT_PRIORITY,
269 &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
267 if (test.is_main_frame) { 270 if (test.is_main_frame) {
268 request->SetLoadFlags(request->load_flags() | 271 request->SetLoadFlags(request->load_flags() |
269 net::LOAD_MAIN_FRAME_DEPRECATED); 272 net::LOAD_MAIN_FRAME_DEPRECATED);
270 } 273 }
271 network_delegate()->NotifyCompleted(request.get(), false, test.net_error); 274 network_delegate()->NotifyCompleted(request.get(), false, test.net_error);
272 275
273 histograms.ExpectTotalCount(kHttpRequestCompletionErrorCode, 276 histograms.ExpectTotalCount(kHttpRequestCompletionErrorCode,
274 test.expected_request_completion_count); 277 test.expected_request_completion_count);
275 histograms.ExpectUniqueSample(kHttpRequestCompletionErrorCode, 278 histograms.ExpectUniqueSample(kHttpRequestCompletionErrorCode,
276 test.expected_sample_bucket, 279 test.expected_sample_bucket,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 force_google_safe_search_.SetValue(google_safe_search); 346 force_google_safe_search_.SetValue(google_safe_search);
344 force_youtube_restrict_.SetValue(youtube_restrict); 347 force_youtube_restrict_.SetValue(youtube_restrict);
345 } 348 }
346 349
347 // Does a request to an arbitrary URL and verifies that the SafeSearch 350 // Does a request to an arbitrary URL and verifies that the SafeSearch
348 // enforcement utility functions were called/not called as expected. 351 // enforcement utility functions were called/not called as expected.
349 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) { 352 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) {
350 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 353 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
351 safe_search_util::ClearForceYouTubeRestrictCountForTesting(); 354 safe_search_util::ClearForceYouTubeRestrictCountForTesting();
352 355
353 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 356 std::unique_ptr<net::URLRequest> request(
354 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 357 context_.CreateRequest(GURL("http://anyurl.com"), net::DEFAULT_PRIORITY,
358 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS));
355 359
356 request->Start(); 360 request->Start();
357 base::RunLoop().RunUntilIdle(); 361 base::RunLoop().RunUntilIdle();
358 362
359 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 363 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
360 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 364 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
361 EXPECT_EQ(expect_youtube_restrict ? 1 : 0, 365 EXPECT_EQ(expect_youtube_restrict ? 1 : 0,
362 safe_search_util::GetForceYouTubeRestrictCountForTesting()); 366 safe_search_util::GetForceYouTubeRestrictCountForTesting());
363 } 367 }
364 368
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // If |expected| is passed as false, this routine verifies that no 418 // If |expected| is passed as false, this routine verifies that no
415 // X-GoogApps-Allowed-Domains header is set. If |expected| is passed as true, 419 // X-GoogApps-Allowed-Domains header is set. If |expected| is passed as true,
416 // this routine verifies that the X-GoogApps-Allowed-Domains header is set and 420 // this routine verifies that the X-GoogApps-Allowed-Domains header is set and
417 // the value is identical to |allowed|. 421 // the value is identical to |allowed|.
418 void CheckAllowedDomainsHeaders(const std::string& allowed, 422 void CheckAllowedDomainsHeaders(const std::string& allowed,
419 const GURL& url, 423 const GURL& url,
420 bool expected) { 424 bool expected) {
421 allowed_domains_for_apps_.SetValue(allowed); 425 allowed_domains_for_apps_.SetValue(allowed);
422 426
423 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 427 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
424 url, net::DEFAULT_PRIORITY, &delegate_)); 428 url, net::DEFAULT_PRIORITY, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS));
425 429
426 request->Start(); 430 request->Start();
427 base::RunLoop().RunUntilIdle(); 431 base::RunLoop().RunUntilIdle();
428 432
429 net::HttpRequestHeaders request_headers = request->extra_request_headers(); 433 net::HttpRequestHeaders request_headers = request->extra_request_headers();
430 434
431 const char allowed_domains_header_name[] = "X-GoogApps-Allowed-Domains"; 435 const char allowed_domains_header_name[] = "X-GoogApps-Allowed-Domains";
432 EXPECT_EQ(expected, request_headers.HasHeader(allowed_domains_header_name)); 436 EXPECT_EQ(expected, request_headers.HasHeader(allowed_domains_header_name));
433 437
434 if (expected) { 438 if (expected) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 636
633 // Files in external storage are allowed. 637 // Files in external storage are allowed.
634 base::FilePath external_storage_path; 638 base::FilePath external_storage_path;
635 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path); 639 PathService::Get(base::DIR_ANDROID_EXTERNAL_STORAGE, &external_storage_path);
636 EXPECT_TRUE(IsAccessAllowed( 640 EXPECT_TRUE(IsAccessAllowed(
637 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), "")); 641 external_storage_path.AppendASCII("foo.txt").AsUTF8Unsafe(), ""));
638 // The external storage root itself is not allowed. 642 // The external storage root itself is not allowed.
639 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), "")); 643 EXPECT_FALSE(IsAccessAllowed(external_storage_path.AsUTF8Unsafe(), ""));
640 #endif 644 #endif
641 } 645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698