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

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

Issue 2419383004: Revert "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy" (Closed)
Patch Set: 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_restrict_, 405 &force_youtube_safety_mode_,
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_restrict(&force_youtube_restrict_); 416 network_delegate->set_force_youtube_safety_mode(
417 &force_youtube_safety_mode_);
417 return std::move(network_delegate); 418 return std::move(network_delegate);
418 } 419 }
419 420
420 void SetSafeSearch(bool google_safe_search, int youtube_restrict) { 421 void SetSafeSearch(bool google_safe_search,
422 bool youtube_safety_mode) {
421 force_google_safe_search_.SetValue(google_safe_search); 423 force_google_safe_search_.SetValue(google_safe_search);
422 force_youtube_restrict_.SetValue(youtube_restrict); 424 force_youtube_safety_mode_.SetValue(youtube_safety_mode);
423 } 425 }
424 426
425 // Does a request to an arbitrary URL and verifies that the SafeSearch 427 // Does a request to an arbitrary URL and verifies that the SafeSearch
426 // enforcement utility functions were called/not called as expected. 428 // enforcement utility functions were called/not called as expected.
427 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) { 429 void QueryURL(bool expect_google_safe_search,
430 bool expect_youtube_safety_mode) {
428 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 431 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
429 safe_search_util::ClearForceYouTubeRestrictCountForTesting(); 432 safe_search_util::ClearForceYouTubeSafetyModeCountForTesting();
430 433
431 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 434 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
432 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 435 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_));
433 436
434 request->Start(); 437 request->Start();
435 base::RunLoop().RunUntilIdle(); 438 base::RunLoop().RunUntilIdle();
436 439
437 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 440 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
438 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 441 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
439 EXPECT_EQ(expect_youtube_restrict ? 1 : 0, 442 EXPECT_EQ(expect_youtube_safety_mode ? 1 : 0,
440 safe_search_util::GetForceYouTubeRestrictCountForTesting()); 443 safe_search_util::GetForceYouTubeSafetyModeCountForTesting());
441 } 444 }
442 445
443 private: 446 private:
444 BooleanPrefMember force_google_safe_search_; 447 BooleanPrefMember force_google_safe_search_;
445 IntegerPrefMember force_youtube_restrict_; 448 BooleanPrefMember force_youtube_safety_mode_;
446 }; 449 };
447 450
448 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { 451 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) {
449 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); 452 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate());
450 SetDelegate(delegate.get()); 453 SetDelegate(delegate.get());
451 454
452 // Loop over all combinations of the two policies. 455 // Loop over all combinations of the two policies.
453 for (int i = 0; i < 6; i++) { 456 for (int i = 0; i < 4; i++) {
454 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && 457 bool google_safe_search = i % 2;
455 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && 458 bool youtube_safety_mode = i / 2;
456 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2, 459 SetSafeSearch(google_safe_search, youtube_safety_mode);
457 "Adjust youtube_restrict to match YouTubeRestrictMode enum");
458 bool google_safe_search = (i / 3) != 0;
459 int youtube_restrict = i % 3;
460 SetSafeSearch(google_safe_search, youtube_restrict);
461 460
462 QueryURL(google_safe_search, youtube_restrict != 0); 461 QueryURL(google_safe_search, youtube_safety_mode);
463 } 462 }
464 } 463 }
465 464
466 class ChromeNetworkDelegateAllowedDomainsTest : 465 class ChromeNetworkDelegateAllowedDomainsTest :
467 public ChromeNetworkDelegatePolicyTest { 466 public ChromeNetworkDelegatePolicyTest {
468 public: 467 public:
469 468
470 void SetUp() override { 469 void SetUp() override {
471 ChromeNetworkDelegate::InitializePrefsOnUIThread( 470 ChromeNetworkDelegate::InitializePrefsOnUIThread(
472 &enable_referrers_, 471 &enable_referrers_,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 655
657 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 656 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
658 kBlockedFirstPartySite)); 657 kBlockedFirstPartySite));
659 658
660 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, 659 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite,
661 CONTENT_SETTING_BLOCK); 660 CONTENT_SETTING_BLOCK);
662 // Privacy mode is disabled as kAllowedSite is still getting cookies 661 // Privacy mode is disabled as kAllowedSite is still getting cookies
663 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 662 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
664 kBlockedFirstPartySite)); 663 kBlockedFirstPartySite));
665 } 664 }
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