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

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

Issue 2239753002: Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyMode policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and inc'ed policy ID to 348 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
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_safety_mode_, 390 &force_youtube_restrict_,
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_safety_mode( 401 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_);
402 &force_youtube_safety_mode_);
403 return std::move(network_delegate); 402 return std::move(network_delegate);
404 } 403 }
405 404
406 void SetSafeSearch(bool google_safe_search, 405 void SetSafeSearch(bool google_safe_search, int youtube_restrict) {
407 bool youtube_safety_mode) {
408 force_google_safe_search_.SetValue(google_safe_search); 406 force_google_safe_search_.SetValue(google_safe_search);
409 force_youtube_safety_mode_.SetValue(youtube_safety_mode); 407 force_youtube_restrict_.SetValue(youtube_restrict);
410 } 408 }
411 409
412 // Does a request to an arbitrary URL and verifies that the SafeSearch 410 // Does a request to an arbitrary URL and verifies that the SafeSearch
413 // enforcement utility functions were called/not called as expected. 411 // enforcement utility functions were called/not called as expected.
414 void QueryURL(bool expect_google_safe_search, 412 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) {
415 bool expect_youtube_safety_mode) {
416 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 413 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
417 safe_search_util::ClearForceYouTubeSafetyModeCountForTesting(); 414 safe_search_util::ClearForceYouTubeRestrictCountForTesting();
418 415
419 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 416 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
420 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 417 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_));
421 418
422 request->Start(); 419 request->Start();
423 base::RunLoop().RunUntilIdle(); 420 base::RunLoop().RunUntilIdle();
424 421
425 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 422 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
426 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 423 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
427 EXPECT_EQ(expect_youtube_safety_mode ? 1 : 0, 424 EXPECT_EQ(expect_youtube_restrict ? 1 : 0,
428 safe_search_util::GetForceYouTubeSafetyModeCountForTesting()); 425 safe_search_util::GetForceYouTubeRestrictCountForTesting());
429 } 426 }
430 427
431 private: 428 private:
432 BooleanPrefMember force_google_safe_search_; 429 BooleanPrefMember force_google_safe_search_;
433 BooleanPrefMember force_youtube_safety_mode_; 430 IntegerPrefMember force_youtube_restrict_;
434 }; 431 };
435 432
436 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { 433 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) {
437 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); 434 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate());
438 SetDelegate(delegate.get()); 435 SetDelegate(delegate.get());
439 436
440 // Loop over all combinations of the two policies. 437 // Loop over all combinations of the two policies.
441 for (int i = 0; i < 4; i++) { 438 for (int i = 0; i < 6; i++) {
442 bool google_safe_search = i % 2; 439 static_assert(safe_search_util::YOUTUBE_RESTRICT_OFF == 0 &&
Thiemo Nagel 2016/10/06 14:05:58 Nit: I think it would be more readable to move the
443 bool youtube_safety_mode = i / 2; 440 safe_search_util::YOUTUBE_RESTRICT_MODERATE == 1 &&
444 SetSafeSearch(google_safe_search, youtube_safety_mode); 441 safe_search_util::YOUTUBE_RESTRICT_STRICT == 2,
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);
445 446
446 QueryURL(google_safe_search, youtube_safety_mode); 447 QueryURL(google_safe_search, youtube_restrict != 0);
447 } 448 }
448 } 449 }
449 450
450 class ChromeNetworkDelegateAllowedDomainsTest : 451 class ChromeNetworkDelegateAllowedDomainsTest :
451 public ChromeNetworkDelegatePolicyTest { 452 public ChromeNetworkDelegatePolicyTest {
452 public: 453 public:
453 454
454 void SetUp() override { 455 void SetUp() override {
455 ChromeNetworkDelegate::InitializePrefsOnUIThread( 456 ChromeNetworkDelegate::InitializePrefsOnUIThread(
456 &enable_referrers_, 457 &enable_referrers_,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 641
641 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 642 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
642 kBlockedFirstPartySite)); 643 kBlockedFirstPartySite));
643 644
644 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, 645 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite,
645 CONTENT_SETTING_BLOCK); 646 CONTENT_SETTING_BLOCK);
646 // Privacy mode is disabled as kAllowedSite is still getting cookies 647 // Privacy mode is disabled as kAllowedSite is still getting cookies
647 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 648 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
648 kBlockedFirstPartySite)); 649 kBlockedFirstPartySite));
649 } 650 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698