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

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

Issue 2401743003: Recommit and fix of "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyM… (Closed)
Patch Set: Rebase Created 4 years, 2 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 | « chrome/browser/net/chrome_network_delegate.cc ('k') | chrome/browser/net/safe_search_util.h » ('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) 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 }; 395 };
396 396
397 class ChromeNetworkDelegateSafeSearchTest : 397 class ChromeNetworkDelegateSafeSearchTest :
398 public ChromeNetworkDelegatePolicyTest { 398 public ChromeNetworkDelegatePolicyTest {
399 public: 399 public:
400 void SetUp() override { 400 void SetUp() override {
401 ChromeNetworkDelegate::InitializePrefsOnUIThread( 401 ChromeNetworkDelegate::InitializePrefsOnUIThread(
402 &enable_referrers_, 402 &enable_referrers_,
403 nullptr, 403 nullptr,
404 &force_google_safe_search_, 404 &force_google_safe_search_,
405 &force_youtube_safety_mode_, 405 &force_youtube_restrict_,
406 nullptr, 406 nullptr,
407 profile_.GetTestingPrefService()); 407 profile_.GetTestingPrefService());
408 } 408 }
409 409
410 protected: 410 protected:
411 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { 411 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() {
412 std::unique_ptr<ChromeNetworkDelegate> network_delegate( 412 std::unique_ptr<ChromeNetworkDelegate> network_delegate(
413 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, 413 new ChromeNetworkDelegate(forwarder(), &enable_referrers_,
414 metrics::UpdateUsagePrefCallbackType())); 414 metrics::UpdateUsagePrefCallbackType()));
415 network_delegate->set_force_google_safe_search(&force_google_safe_search_); 415 network_delegate->set_force_google_safe_search(&force_google_safe_search_);
416 network_delegate->set_force_youtube_safety_mode( 416 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_);
417 &force_youtube_safety_mode_);
418 return std::move(network_delegate); 417 return std::move(network_delegate);
419 } 418 }
420 419
421 void SetSafeSearch(bool google_safe_search, 420 void SetSafeSearch(bool google_safe_search, int youtube_restrict) {
422 bool youtube_safety_mode) {
423 force_google_safe_search_.SetValue(google_safe_search); 421 force_google_safe_search_.SetValue(google_safe_search);
424 force_youtube_safety_mode_.SetValue(youtube_safety_mode); 422 force_youtube_restrict_.SetValue(youtube_restrict);
425 } 423 }
426 424
427 // Does a request to an arbitrary URL and verifies that the SafeSearch 425 // Does a request to an arbitrary URL and verifies that the SafeSearch
428 // enforcement utility functions were called/not called as expected. 426 // enforcement utility functions were called/not called as expected.
429 void QueryURL(bool expect_google_safe_search, 427 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) {
430 bool expect_youtube_safety_mode) {
431 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 428 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
432 safe_search_util::ClearForceYouTubeSafetyModeCountForTesting(); 429 safe_search_util::ClearForceYouTubeRestrictCountForTesting();
433 430
434 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 431 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
435 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 432 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_));
436 433
437 request->Start(); 434 request->Start();
438 base::RunLoop().RunUntilIdle(); 435 base::RunLoop().RunUntilIdle();
439 436
440 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 437 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
441 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 438 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
442 EXPECT_EQ(expect_youtube_safety_mode ? 1 : 0, 439 EXPECT_EQ(expect_youtube_restrict ? 1 : 0,
443 safe_search_util::GetForceYouTubeSafetyModeCountForTesting()); 440 safe_search_util::GetForceYouTubeRestrictCountForTesting());
444 } 441 }
445 442
446 private: 443 private:
447 BooleanPrefMember force_google_safe_search_; 444 BooleanPrefMember force_google_safe_search_;
448 BooleanPrefMember force_youtube_safety_mode_; 445 IntegerPrefMember force_youtube_restrict_;
449 }; 446 };
450 447
451 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { 448 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) {
452 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); 449 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate());
453 SetDelegate(delegate.get()); 450 SetDelegate(delegate.get());
454 451
452 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 &&
453 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 &&
454 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2 &&
455 safe_search_util::YOUTUBE_RESTRICT_COUNT == 3,
456 "This test relies on mapping ints to enum values.");
457
455 // Loop over all combinations of the two policies. 458 // Loop over all combinations of the two policies.
456 for (int i = 0; i < 4; i++) { 459 for (int i = 0; i < 6; i++) {
457 bool google_safe_search = i % 2; 460 bool google_safe_search = (i / 3) != 0;
458 bool youtube_safety_mode = i / 2; 461 int youtube_restrict = i % 3;
459 SetSafeSearch(google_safe_search, youtube_safety_mode); 462 SetSafeSearch(google_safe_search, youtube_restrict);
460 463
461 QueryURL(google_safe_search, youtube_safety_mode); 464 QueryURL(google_safe_search, youtube_restrict != 0);
462 } 465 }
463 } 466 }
464 467
465 class ChromeNetworkDelegateAllowedDomainsTest : 468 class ChromeNetworkDelegateAllowedDomainsTest :
466 public ChromeNetworkDelegatePolicyTest { 469 public ChromeNetworkDelegatePolicyTest {
467 public: 470 public:
468 471
469 void SetUp() override { 472 void SetUp() override {
470 ChromeNetworkDelegate::InitializePrefsOnUIThread( 473 ChromeNetworkDelegate::InitializePrefsOnUIThread(
471 &enable_referrers_, 474 &enable_referrers_,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 658
656 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 659 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
657 kBlockedFirstPartySite)); 660 kBlockedFirstPartySite));
658 661
659 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, 662 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite,
660 CONTENT_SETTING_BLOCK); 663 CONTENT_SETTING_BLOCK);
661 // Privacy mode is disabled as kAllowedSite is still getting cookies 664 // Privacy mode is disabled as kAllowedSite is still getting cookies
662 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 665 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
663 kBlockedFirstPartySite)); 666 kBlockedFirstPartySite));
664 } 667 }
OLDNEW
« no previous file with comments | « chrome/browser/net/chrome_network_delegate.cc ('k') | chrome/browser/net/safe_search_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698