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

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

Issue 2401733002: 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 }; 380 };
381 381
382 class ChromeNetworkDelegateSafeSearchTest : 382 class ChromeNetworkDelegateSafeSearchTest :
383 public ChromeNetworkDelegatePolicyTest { 383 public ChromeNetworkDelegatePolicyTest {
384 public: 384 public:
385 void SetUp() override { 385 void SetUp() override {
386 ChromeNetworkDelegate::InitializePrefsOnUIThread( 386 ChromeNetworkDelegate::InitializePrefsOnUIThread(
387 &enable_referrers_, 387 &enable_referrers_,
388 nullptr, 388 nullptr,
389 &force_google_safe_search_, 389 &force_google_safe_search_,
390 &force_youtube_restrict_, 390 &force_youtube_safety_mode_,
391 nullptr, 391 nullptr,
392 profile_.GetTestingPrefService()); 392 profile_.GetTestingPrefService());
393 } 393 }
394 394
395 protected: 395 protected:
396 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { 396 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() {
397 std::unique_ptr<ChromeNetworkDelegate> network_delegate( 397 std::unique_ptr<ChromeNetworkDelegate> network_delegate(
398 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, 398 new ChromeNetworkDelegate(forwarder(), &enable_referrers_,
399 metrics::UpdateUsagePrefCallbackType())); 399 metrics::UpdateUsagePrefCallbackType()));
400 network_delegate->set_force_google_safe_search(&force_google_safe_search_); 400 network_delegate->set_force_google_safe_search(&force_google_safe_search_);
401 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_); 401 network_delegate->set_force_youtube_safety_mode(
402 &force_youtube_safety_mode_);
402 return std::move(network_delegate); 403 return std::move(network_delegate);
403 } 404 }
404 405
405 void SetSafeSearch(bool google_safe_search, int youtube_restrict) { 406 void SetSafeSearch(bool google_safe_search,
407 bool youtube_safety_mode) {
406 force_google_safe_search_.SetValue(google_safe_search); 408 force_google_safe_search_.SetValue(google_safe_search);
407 force_youtube_restrict_.SetValue(youtube_restrict); 409 force_youtube_safety_mode_.SetValue(youtube_safety_mode);
408 } 410 }
409 411
410 // Does a request to an arbitrary URL and verifies that the SafeSearch 412 // Does a request to an arbitrary URL and verifies that the SafeSearch
411 // enforcement utility functions were called/not called as expected. 413 // enforcement utility functions were called/not called as expected.
412 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) { 414 void QueryURL(bool expect_google_safe_search,
415 bool expect_youtube_safety_mode) {
413 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 416 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
414 safe_search_util::ClearForceYouTubeRestrictCountForTesting(); 417 safe_search_util::ClearForceYouTubeSafetyModeCountForTesting();
415 418
416 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 419 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
417 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 420 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_));
418 421
419 request->Start(); 422 request->Start();
420 base::RunLoop().RunUntilIdle(); 423 base::RunLoop().RunUntilIdle();
421 424
422 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 425 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
423 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 426 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
424 EXPECT_EQ(expect_youtube_restrict ? 1 : 0, 427 EXPECT_EQ(expect_youtube_safety_mode ? 1 : 0,
425 safe_search_util::GetForceYouTubeRestrictCountForTesting()); 428 safe_search_util::GetForceYouTubeSafetyModeCountForTesting());
426 } 429 }
427 430
428 private: 431 private:
429 BooleanPrefMember force_google_safe_search_; 432 BooleanPrefMember force_google_safe_search_;
430 IntegerPrefMember force_youtube_restrict_; 433 BooleanPrefMember force_youtube_safety_mode_;
431 }; 434 };
432 435
433 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { 436 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) {
434 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); 437 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate());
435 SetDelegate(delegate.get()); 438 SetDelegate(delegate.get());
436 439
437 // Loop over all combinations of the two policies. 440 // Loop over all combinations of the two policies.
438 for (int i = 0; i < 6; i++) { 441 for (int i = 0; i < 4; i++) {
439 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 && 442 bool google_safe_search = i % 2;
440 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 && 443 bool youtube_safety_mode = i / 2;
441 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2, 444 SetSafeSearch(google_safe_search, youtube_safety_mode);
442 "Adjust youtube_restrict to match YouTubeRestrictMode enum");
443 bool google_safe_search = (i / 3) != 0;
444 int youtube_restrict = i % 3;
445 SetSafeSearch(google_safe_search, youtube_restrict);
446 445
447 QueryURL(google_safe_search, youtube_restrict != 0); 446 QueryURL(google_safe_search, youtube_safety_mode);
448 } 447 }
449 } 448 }
450 449
451 class ChromeNetworkDelegateAllowedDomainsTest : 450 class ChromeNetworkDelegateAllowedDomainsTest :
452 public ChromeNetworkDelegatePolicyTest { 451 public ChromeNetworkDelegatePolicyTest {
453 public: 452 public:
454 453
455 void SetUp() override { 454 void SetUp() override {
456 ChromeNetworkDelegate::InitializePrefsOnUIThread( 455 ChromeNetworkDelegate::InitializePrefsOnUIThread(
457 &enable_referrers_, 456 &enable_referrers_,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 640
642 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 641 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
643 kBlockedFirstPartySite)); 642 kBlockedFirstPartySite));
644 643
645 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, 644 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite,
646 CONTENT_SETTING_BLOCK); 645 CONTENT_SETTING_BLOCK);
647 // Privacy mode is disabled as kAllowedSite is still getting cookies 646 // Privacy mode is disabled as kAllowedSite is still getting cookies
648 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 647 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
649 kBlockedFirstPartySite)); 648 kBlockedFirstPartySite));
650 } 649 }
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