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

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 1056003003: Policy: Ignore ForceSafeSearch if ForceGoogleSafeSearch or ForceYoutubeSafetyMode are enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Android Created 5 years, 8 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 click_event.type = blink::WebInputEvent::MouseDown; 787 click_event.type = blink::WebInputEvent::MouseDown;
788 click_event.button = blink::WebMouseEvent::ButtonLeft; 788 click_event.button = blink::WebMouseEvent::ButtonLeft;
789 click_event.clickCount = 1; 789 click_event.clickCount = 1;
790 click_event.x = x; 790 click_event.x = x;
791 click_event.y = y; 791 click_event.y = y;
792 contents->GetRenderViewHost()->ForwardMouseEvent(click_event); 792 contents->GetRenderViewHost()->ForwardMouseEvent(click_event);
793 click_event.type = blink::WebInputEvent::MouseUp; 793 click_event.type = blink::WebInputEvent::MouseUp;
794 contents->GetRenderViewHost()->ForwardMouseEvent(click_event); 794 contents->GetRenderViewHost()->ForwardMouseEvent(click_event);
795 } 795 }
796 796
797 void SetPolicy(PolicyMap* policies, const char* key, base::Value* value) {
798 if (value) {
799 policies->Set(key,
800 POLICY_LEVEL_MANDATORY,
801 POLICY_SCOPE_USER,
802 value,
803 nullptr);
804 } else {
805 policies->Erase(key);
806 }
807 }
808
809 void ApplySafeSearchPolicy(base::FundamentalValue* legacy_safe_search,
810 base::FundamentalValue* google_safe_search,
811 base::FundamentalValue* youtube_safety_mode) {
812 PolicyMap policies;
813 SetPolicy(&policies, key::kForceSafeSearch, legacy_safe_search);
814 SetPolicy(&policies, key::kForceGoogleSafeSearch, google_safe_search);
815 SetPolicy(&policies, key::kForceYouTubeSafetyMode, youtube_safety_mode);
816 UpdateProviderPolicy(policies);
817 }
818
819 void CheckSafeSearch(bool expect_safe_search) {
820 content::WebContents* web_contents =
821 browser()->tab_strip_model()->GetActiveWebContents();
822 content::TestNavigationObserver observer(web_contents);
823 chrome::FocusLocationBar(browser());
824 LocationBar* location_bar = browser()->window()->GetLocationBar();
825 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
826 OmniboxEditModel* model = location_bar->GetOmniboxView()->model();
827 observer.Wait();
828 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid());
829
830 std::string expected_url("http://google.com/");
831 if (expect_safe_search) {
832 expected_url += "?" + std::string(chrome::kSafeSearchSafeParameter) +
833 "&" + chrome::kSafeSearchSsuiParameter;
834 }
835 EXPECT_EQ(GURL(expected_url), web_contents->GetURL());
836 }
837
797 MockConfigurationPolicyProvider provider_; 838 MockConfigurationPolicyProvider provider_;
798 scoped_ptr<extensions::ExtensionCacheFake> test_extension_cache_; 839 scoped_ptr<extensions::ExtensionCacheFake> test_extension_cache_;
799 #if defined(OS_CHROMEOS) 840 #if defined(OS_CHROMEOS)
800 QuitMessageLoopAfterScreenshot observer_; 841 QuitMessageLoopAfterScreenshot observer_;
801 #endif 842 #endif
802 }; 843 };
803 844
804 #if defined(OS_WIN) 845 #if defined(OS_WIN)
805 // This policy only exists on Windows. 846 // This policy only exists on Windows.
806 847
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 EXPECT_TRUE(expected.Equals(actual_from_profile)); 1117 EXPECT_TRUE(expected.Equals(actual_from_profile));
1077 } 1118 }
1078 1119
1079 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) { 1120 IN_PROC_BROWSER_TEST_F(PolicyTest, ForceSafeSearch) {
1080 // Makes the requests fail since all we want to check is that the redirection 1121 // Makes the requests fail since all we want to check is that the redirection
1081 // is done properly. 1122 // is done properly.
1082 MakeRequestFail make_request_fail("google.com"); 1123 MakeRequestFail make_request_fail("google.com");
1083 1124
1084 // Verifies that requests to Google Search engine with the SafeSearch 1125 // Verifies that requests to Google Search engine with the SafeSearch
1085 // enabled set the safe=active&ssui=on parameters at the end of the query. 1126 // enabled set the safe=active&ssui=on parameters at the end of the query.
1086 TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( 1127 // First check that nothing happens.
1087 browser()->profile()); 1128 CheckSafeSearch(false);
1088 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
1089 1129
1090 // First check that nothing happens. 1130 // Go over all combinations of (undefined,true,false) for the three policies.
1091 content::TestNavigationObserver no_safesearch_observer( 1131 for (int i = 0; i < 3 * 3 * 3; i++) {
1092 browser()->tab_strip_model()->GetActiveWebContents()); 1132 int legacy = i % 3;
1093 chrome::FocusLocationBar(browser()); 1133 int google = (i / 3) % 3;
1094 LocationBar* location_bar = browser()->window()->GetLocationBar(); 1134 int youtube = i / (3 * 3);
1095 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
1096 OmniboxEditModel* model = location_bar->GetOmniboxView()->model();
1097 no_safesearch_observer.Wait();
1098 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid());
1099 content::WebContents* web_contents =
1100 browser()->tab_strip_model()->GetActiveWebContents();
1101 GURL expected_without("http://google.com/");
1102 EXPECT_EQ(expected_without, web_contents->GetURL());
1103 1135
1104 PrefService* prefs = browser()->profile()->GetPrefs(); 1136 // Override the default SafeSearch setting using policies.
1105 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); 1137 ApplySafeSearchPolicy(
1106 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); 1138 legacy == 0 ? nullptr : new base::FundamentalValue(legacy == 1),
1139 google == 0 ? nullptr : new base::FundamentalValue(google == 1),
1140 youtube == 0 ? nullptr : new base::FundamentalValue(youtube == 1));
1107 1141
1108 // Override the default SafeSearch setting using policies. 1142 // The legacy policy should only have an effect if both google and youtube
1109 PolicyMap policies; 1143 // are undefined.
1110 policies.Set(key::kForceSafeSearch, 1144 bool legacy_in_effect = (google == 0 && youtube == 0 && legacy != 0);
1111 POLICY_LEVEL_MANDATORY, 1145 bool legacy_enabled = legacy_in_effect && legacy == 1;
1112 POLICY_SCOPE_USER,
1113 new base::FundamentalValue(true),
1114 NULL);
1115 UpdateProviderPolicy(policies);
1116 1146
1117 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); 1147 PrefService* prefs = browser()->profile()->GetPrefs();
1118 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); 1148 EXPECT_EQ(google != 0 || legacy_in_effect,
1149 prefs->IsManagedPreference(prefs::kForceGoogleSafeSearch));
1150 EXPECT_EQ(google == 1 || legacy_enabled,
1151 prefs->GetBoolean(prefs::kForceGoogleSafeSearch));
1119 1152
1120 content::TestNavigationObserver safesearch_observer( 1153 EXPECT_EQ(youtube != 0 || legacy_in_effect,
1121 browser()->tab_strip_model()->GetActiveWebContents()); 1154 prefs->IsManagedPreference(prefs::kForceYouTubeSafetyMode));
1155 EXPECT_EQ(youtube == 1 || legacy_enabled,
1156 prefs->GetBoolean(prefs::kForceYouTubeSafetyMode));
1122 1157
1123 // Verify that searching from google.com works. 1158 CheckSafeSearch(google == 1 || legacy_enabled);
1124 chrome::FocusLocationBar(browser()); 1159 }
1125 ui_test_utils::SendToOmniboxAndSubmit(location_bar, "http://google.com/");
1126 safesearch_observer.Wait();
1127 EXPECT_TRUE(model->CurrentMatch(NULL).destination_url.is_valid());
1128 web_contents = browser()->tab_strip_model()->GetActiveWebContents();
1129 std::string expected_url("http://google.com/?");
1130 expected_url += std::string(chrome::kSafeSearchSafeParameter) + "&" +
1131 chrome::kSafeSearchSsuiParameter;
1132 GURL expected_with_parameters(expected_url);
1133 EXPECT_EQ(expected_with_parameters, web_contents->GetURL());
1134 } 1160 }
1135 1161
1136 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) { 1162 IN_PROC_BROWSER_TEST_F(PolicyTest, ReplaceSearchTerms) {
1137 MakeRequestFail make_request_fail("search.example"); 1163 MakeRequestFail make_request_fail("search.example");
1138 1164
1139 chrome::EnableQueryExtractionForTesting(); 1165 chrome::EnableQueryExtractionForTesting();
1140 1166
1141 // Verifies that a default search is made using the provider configured via 1167 // Verifies that a default search is made using the provider configured via
1142 // policy. Also checks that default search can be completely disabled. 1168 // policy. Also checks that default search can be completely disabled.
1143 const base::string16 kKeyword(base::ASCIIToUTF16("testsearch")); 1169 const base::string16 kKeyword(base::ASCIIToUTF16("testsearch"));
(...skipping 2526 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 PrefService* prefs = browser()->profile()->GetPrefs(); 3696 PrefService* prefs = browser()->profile()->GetPrefs();
3671 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed( 3697 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed(
3672 prefs, "host.name")); 3698 prefs, "host.name"));
3673 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( 3699 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed(
3674 prefs, "other.host.name")); 3700 prefs, "other.host.name"));
3675 } 3701 }
3676 3702
3677 #endif // !defined(CHROME_OS) 3703 #endif // !defined(CHROME_OS)
3678 3704
3679 } // namespace policy 3705 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/configuration_policy_handler_list_factory.cc ('k') | chrome/browser/profiles/profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698