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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_browsertest.cc

Issue 23376002: Move ManagedModePolicyProvider functionality to ManagedUserSettingsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/prefs/pref_service.h" 6 #include "base/prefs/pref_service.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/common/cancelable_request.h" 10 #include "chrome/browser/common/cancelable_request.h"
11 #include "chrome/browser/history/history_service_factory.h" 11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
13 #include "chrome/browser/infobars/infobar.h" 13 #include "chrome/browser/infobars/infobar.h"
14 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" 15 #include "chrome/browser/managed_mode/managed_mode_interstitial.h"
16 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 16 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
17 #include "chrome/browser/managed_mode/managed_user_constants.h"
17 #include "chrome/browser/managed_mode/managed_user_service.h" 18 #include "chrome/browser/managed_mode/managed_user_service.h"
18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 19 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
19 #include "chrome/browser/policy/managed_mode_policy_provider.h" 20 #include "chrome/browser/managed_mode/managed_user_settings_service.h"
20 #include "chrome/browser/policy/profile_policy_connector.h" 21 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
21 #include "chrome/browser/policy/profile_policy_connector_factory.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_navigator.h" 24 #include "chrome/browser/ui/browser_navigator.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "chrome/test/base/in_process_browser_test.h" 28 #include "chrome/test/base/in_process_browser_test.h"
29 #include "chrome/test/base/ui_test_utils.h" 29 #include "chrome/test/base/ui_test_utils.h"
30 #include "components/user_prefs/pref_registry_syncable.h" 30 #include "components/user_prefs/pref_registry_syncable.h"
31 #include "content/public/browser/interstitial_page.h" 31 #include "content/public/browser/interstitial_page.h"
32 #include "content/public/browser/navigation_controller.h" 32 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
34 #include "content/public/browser/notification_service.h" 34 #include "content/public/browser/notification_service.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/web_contents_observer.h" 36 #include "content/public/browser/web_contents_observer.h"
37 #include "content/public/test/browser_test_utils.h" 37 #include "content/public/test/browser_test_utils.h"
38 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
39 #include "policy/policy_constants.h"
40 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
41 40
42 using content::InterstitialPage; 41 using content::InterstitialPage;
43 using content::NavigationController; 42 using content::NavigationController;
44 using content::NavigationEntry; 43 using content::NavigationEntry;
45 using content::WebContents; 44 using content::WebContents;
46 45
47 namespace { 46 namespace {
48 47
49 // Tests the filter mode in which all sites are blocked by default. 48 // Tests the filter mode in which all sites are blocked by default.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 virtual void SetUpOnMainThread() OVERRIDE { 101 virtual void SetUpOnMainThread() OVERRIDE {
103 // Set up the ManagedModeNavigationObserver manually since the profile was 102 // Set up the ManagedModeNavigationObserver manually since the profile was
104 // not managed when the browser was created. 103 // not managed when the browser was created.
105 content::WebContents* web_contents = 104 content::WebContents* web_contents =
106 browser()->tab_strip_model()->GetActiveWebContents(); 105 browser()->tab_strip_model()->GetActiveWebContents();
107 ManagedModeNavigationObserver::CreateForWebContents(web_contents); 106 ManagedModeNavigationObserver::CreateForWebContents(web_contents);
108 107
109 Profile* profile = browser()->profile(); 108 Profile* profile = browser()->profile();
110 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); 109 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
111 managed_user_service_->InitForTesting(); 110 managed_user_service_->InitForTesting();
112 policy::ProfilePolicyConnector* connector = 111 ManagedUserSettingsService* managed_user_settings_service =
113 policy::ProfilePolicyConnectorFactory::GetForProfile(profile); 112 ManagedUserSettingsServiceFactory::GetForProfile(profile);
114 policy::ManagedModePolicyProvider* policy_provider = 113 managed_user_settings_service->SetLocalSettingForTesting(
115 connector->managed_mode_policy_provider(); 114 managed_users::kContentPackDefaultFilteringBehavior,
116 policy_provider->SetLocalPolicyForTesting(
117 policy::key::kContentPackDefaultFilteringBehavior,
118 scoped_ptr<base::Value>( 115 scoped_ptr<base::Value>(
119 new base::FundamentalValue(ManagedModeURLFilter::BLOCK))); 116 new base::FundamentalValue(ManagedModeURLFilter::BLOCK)));
120 base::RunLoop().RunUntilIdle();
121 } 117 }
122 118
123 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 119 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
124 // Enable the test server and remap all URLs to it. 120 // Enable the test server and remap all URLs to it.
125 ASSERT_TRUE(test_server()->Start()); 121 ASSERT_TRUE(test_server()->Start());
126 std::string host_port = test_server()->host_port_pair().ToString(); 122 std::string host_port = test_server()->host_port_pair().ToString();
127 command_line->AppendSwitchASCII(switches::kHostResolverRules, 123 command_line->AppendSwitchASCII(switches::kHostResolverRules,
128 "MAP *.example.com " + host_port + "," + 124 "MAP *.example.com " + host_port + "," +
129 "MAP *.new-example.com " + host_port + "," + 125 "MAP *.new-example.com " + host_port + "," +
130 "MAP *.a.com " + host_port); 126 "MAP *.a.com " + host_port);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 176 }
181 177
182 // Tests whether a visit attempt adds a special history entry. 178 // Tests whether a visit attempt adds a special history entry.
183 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 179 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
184 HistoryVisitRecorded) { 180 HistoryVisitRecorded) {
185 GURL allowed_url("http://www.example.com/files/simple.html"); 181 GURL allowed_url("http://www.example.com/files/simple.html");
186 182
187 // Set the host as allowed. 183 // Set the host as allowed.
188 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 184 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
189 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true); 185 dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
190 policy::ProfilePolicyConnector* connector = 186 ManagedUserSettingsService* managed_user_settings_service =
191 policy::ProfilePolicyConnectorFactory::GetForProfile( 187 ManagedUserSettingsServiceFactory::GetForProfile(
192 browser()->profile()); 188 browser()->profile());
193 policy::ManagedModePolicyProvider* policy_provider = 189 managed_user_settings_service->SetLocalSettingForTesting(
194 connector->managed_mode_policy_provider(); 190 managed_users::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
195 policy_provider->SetLocalPolicyForTesting(
196 policy::key::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
197 base::RunLoop().RunUntilIdle();
198 EXPECT_EQ( 191 EXPECT_EQ(
199 ManagedUserService::MANUAL_ALLOW, 192 ManagedUserService::MANUAL_ALLOW,
200 managed_user_service_->GetManualBehaviorForHost(allowed_url.host())); 193 managed_user_service_->GetManualBehaviorForHost(allowed_url.host()));
201 194
202 ui_test_utils::NavigateToURL(browser(), allowed_url); 195 ui_test_utils::NavigateToURL(browser(), allowed_url);
203 196
204 // Navigate to it and check that we don't get an interstitial. 197 // Navigate to it and check that we don't get an interstitial.
205 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 198 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
206 CheckShownPageIsNotInterstitial(tab); 199 CheckShownPageIsNotInterstitial(tab);
207 200
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 240
248 CheckShownPageIsInterstitial(web_contents); 241 CheckShownPageIsInterstitial(web_contents);
249 242
250 content::WindowedNotificationObserver observer( 243 content::WindowedNotificationObserver observer(
251 content::NOTIFICATION_LOAD_STOP, 244 content::NOTIFICATION_LOAD_STOP,
252 content::NotificationService::AllSources()); 245 content::NotificationService::AllSources());
253 246
254 // Set the host as allowed. 247 // Set the host as allowed.
255 scoped_ptr<DictionaryValue> dict(new DictionaryValue); 248 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
256 dict->SetBooleanWithoutPathExpansion(test_url.host(), true); 249 dict->SetBooleanWithoutPathExpansion(test_url.host(), true);
257 policy::ProfilePolicyConnector* connector = 250 ManagedUserSettingsService* managed_user_settings_service =
258 policy::ProfilePolicyConnectorFactory::GetForProfile( 251 ManagedUserSettingsServiceFactory::GetForProfile(
259 browser()->profile()); 252 browser()->profile());
260 policy::ManagedModePolicyProvider* policy_provider = 253 managed_user_settings_service->SetLocalSettingForTesting(
261 connector->managed_mode_policy_provider(); 254 managed_users::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
262 policy_provider->SetLocalPolicyForTesting(
263 policy::key::kContentPackManualBehaviorHosts, dict.PassAs<Value>());
264 base::RunLoop().RunUntilIdle();
265 EXPECT_EQ( 255 EXPECT_EQ(
266 ManagedUserService::MANUAL_ALLOW, 256 ManagedUserService::MANUAL_ALLOW,
267 managed_user_service_->GetManualBehaviorForHost(test_url.host())); 257 managed_user_service_->GetManualBehaviorForHost(test_url.host()));
268 258
269 observer.Wait(); 259 observer.Wait();
270 EXPECT_EQ(test_url, web_contents->GetURL()); 260 EXPECT_EQ(test_url, web_contents->GetURL());
271 } 261 }
272 262
273 } // namespace 263 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698