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

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: Inc'ed id of new policy to 346 Created 4 years, 3 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 }; 363 };
364 364
365 class ChromeNetworkDelegateSafeSearchTest : 365 class ChromeNetworkDelegateSafeSearchTest :
366 public ChromeNetworkDelegatePolicyTest { 366 public ChromeNetworkDelegatePolicyTest {
367 public: 367 public:
368 void SetUp() override { 368 void SetUp() override {
369 ChromeNetworkDelegate::InitializePrefsOnUIThread( 369 ChromeNetworkDelegate::InitializePrefsOnUIThread(
370 &enable_referrers_, 370 &enable_referrers_,
371 nullptr, 371 nullptr,
372 &force_google_safe_search_, 372 &force_google_safe_search_,
373 &force_youtube_safety_mode_, 373 &force_youtube_restrict_,
374 nullptr, 374 nullptr,
375 profile_.GetTestingPrefService()); 375 profile_.GetTestingPrefService());
376 } 376 }
377 377
378 protected: 378 protected:
379 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() { 379 std::unique_ptr<net::NetworkDelegate> CreateNetworkDelegate() {
380 std::unique_ptr<ChromeNetworkDelegate> network_delegate( 380 std::unique_ptr<ChromeNetworkDelegate> network_delegate(
381 new ChromeNetworkDelegate(forwarder(), &enable_referrers_, 381 new ChromeNetworkDelegate(forwarder(), &enable_referrers_,
382 metrics::UpdateUsagePrefCallbackType())); 382 metrics::UpdateUsagePrefCallbackType()));
383 network_delegate->set_force_google_safe_search(&force_google_safe_search_); 383 network_delegate->set_force_google_safe_search(&force_google_safe_search_);
384 network_delegate->set_force_youtube_safety_mode( 384 network_delegate->set_force_youtube_restrict(&force_youtube_restrict_);
385 &force_youtube_safety_mode_);
386 return std::move(network_delegate); 385 return std::move(network_delegate);
387 } 386 }
388 387
389 void SetSafeSearch(bool google_safe_search, 388 void SetSafeSearch(bool google_safe_search, int youtube_restrict) {
390 bool youtube_safety_mode) {
391 force_google_safe_search_.SetValue(google_safe_search); 389 force_google_safe_search_.SetValue(google_safe_search);
392 force_youtube_safety_mode_.SetValue(youtube_safety_mode); 390 force_youtube_restrict_.SetValue(youtube_restrict);
393 } 391 }
394 392
395 // Does a request to an arbitrary URL and verifies that the SafeSearch 393 // Does a request to an arbitrary URL and verifies that the SafeSearch
396 // enforcement utility functions were called/not called as expected. 394 // enforcement utility functions were called/not called as expected.
397 void QueryURL(bool expect_google_safe_search, 395 void QueryURL(bool expect_google_safe_search, bool expect_youtube_restrict) {
398 bool expect_youtube_safety_mode) {
399 safe_search_util::ClearForceGoogleSafeSearchCountForTesting(); 396 safe_search_util::ClearForceGoogleSafeSearchCountForTesting();
400 safe_search_util::ClearForceYouTubeSafetyModeCountForTesting(); 397 safe_search_util::ClearForceYouTubeRestrictCountForTesting();
401 398
402 std::unique_ptr<net::URLRequest> request(context_.CreateRequest( 399 std::unique_ptr<net::URLRequest> request(context_.CreateRequest(
403 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_)); 400 GURL("http://anyurl.com"), net::DEFAULT_PRIORITY, &delegate_));
404 401
405 request->Start(); 402 request->Start();
406 base::RunLoop().RunUntilIdle(); 403 base::RunLoop().RunUntilIdle();
407 404
408 EXPECT_EQ(expect_google_safe_search ? 1 : 0, 405 EXPECT_EQ(expect_google_safe_search ? 1 : 0,
409 safe_search_util::GetForceGoogleSafeSearchCountForTesting()); 406 safe_search_util::GetForceGoogleSafeSearchCountForTesting());
410 EXPECT_EQ(expect_youtube_safety_mode ? 1 : 0, 407 EXPECT_EQ(expect_youtube_restrict ? 1 : 0,
411 safe_search_util::GetForceYouTubeSafetyModeCountForTesting()); 408 safe_search_util::GetForceYouTubeRestrictCountForTesting());
412 } 409 }
413 410
414 private: 411 private:
415 BooleanPrefMember force_google_safe_search_; 412 BooleanPrefMember force_google_safe_search_;
416 BooleanPrefMember force_youtube_safety_mode_; 413 IntegerPrefMember force_youtube_restrict_;
417 }; 414 };
418 415
419 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) { 416 TEST_F(ChromeNetworkDelegateSafeSearchTest, SafeSearch) {
420 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate()); 417 std::unique_ptr<net::NetworkDelegate> delegate(CreateNetworkDelegate());
421 SetDelegate(delegate.get()); 418 SetDelegate(delegate.get());
422 419
423 // Loop over all combinations of the two policies. 420 // Loop over all combinations of the two policies.
424 for (int i = 0; i < 4; i++) { 421 for (int i = 0; i < 6; i++) {
425 bool google_safe_search = i % 2; 422 static_assert(safe_search_util::YOUTUBE_OFF == 0 &&
426 bool youtube_safety_mode = i / 2; 423 safe_search_util::YOUTUBE_MODERATE == 1 &&
427 SetSafeSearch(google_safe_search, youtube_safety_mode); 424 safe_search_util::YOUTUBE_STRICT == 2,
425 "Adjust youtube_restrict to match YouTubeRestrictMode enum");
426 bool google_safe_search = (i / 3) != 0;
427 int youtube_restrict = i % 3;
428 SetSafeSearch(google_safe_search, youtube_restrict);
428 429
429 QueryURL(google_safe_search, youtube_safety_mode); 430 QueryURL(google_safe_search, youtube_restrict != 0);
430 } 431 }
431 } 432 }
432 433
433 class ChromeNetworkDelegateAllowedDomainsTest : 434 class ChromeNetworkDelegateAllowedDomainsTest :
434 public ChromeNetworkDelegatePolicyTest { 435 public ChromeNetworkDelegatePolicyTest {
435 public: 436 public:
436 437
437 void SetUp() override { 438 void SetUp() override {
438 ChromeNetworkDelegate::InitializePrefsOnUIThread( 439 ChromeNetworkDelegate::InitializePrefsOnUIThread(
439 &enable_referrers_, 440 &enable_referrers_,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 624
624 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 625 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
625 kBlockedFirstPartySite)); 626 kBlockedFirstPartySite));
626 627
627 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite, 628 cookie_settings_->SetCookieSetting(kBlockedFirstPartySite,
628 CONTENT_SETTING_BLOCK); 629 CONTENT_SETTING_BLOCK);
629 // Privacy mode is disabled as kAllowedSite is still getting cookies 630 // Privacy mode is disabled as kAllowedSite is still getting cookies
630 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite, 631 EXPECT_FALSE(network_delegate_->CanEnablePrivacyMode(kAllowedSite,
631 kBlockedFirstPartySite)); 632 kBlockedFirstPartySite));
632 } 633 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698