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

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

Issue 11826059: Add ManagedUserService for profile-specific managed user data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 11 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) 2013 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/values.h" 6 #include "base/values.h"
7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" 7 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/infobars/infobar.h" 8 #include "chrome/browser/infobars/infobar.h"
10 #include "chrome/browser/infobars/infobar_tab_helper.h" 9 #include "chrome/browser/infobars/infobar_tab_helper.h"
11 #include "chrome/browser/managed_mode/managed_mode.h" 10 #include "chrome/browser/managed_mode/managed_mode.h"
12 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser_navigator.h" 11 #include "chrome/browser/ui/browser_navigator.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 12 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h"
20 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/interstitial_page.h" 17 #include "content/public/browser/interstitial_page.h"
23 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
28 #include "content/public/test/test_utils.h"
29 #include "googleurl/src/gurl.h"
30 23
31 using content::InterstitialPage; 24 using content::InterstitialPage;
32 using content::MessageLoopRunner;
33 using content::NavigationController; 25 using content::NavigationController;
34 using content::NavigationEntry; 26 using content::NavigationEntry;
35 using content::WebContents; 27 using content::WebContents;
36 28
37 namespace {
38
39 class ManagedModeURLFilterObserver : public ManagedModeURLFilter::Observer {
40 public:
41 explicit ManagedModeURLFilterObserver(ManagedModeURLFilter* url_filter)
42 : url_filter_(url_filter) {
43 Reset();
44 url_filter_->AddObserver(this);
45 }
46
47 ~ManagedModeURLFilterObserver() {
48 url_filter_->RemoveObserver(this);
49 }
50
51 void Wait() {
52 message_loop_runner_->Run();
53 Reset();
54 }
55
56 // ManagedModeURLFilter::Observer
57 virtual void OnSiteListUpdated() OVERRIDE {
58 message_loop_runner_->Quit();
59 }
60
61 private:
62 void Reset() {
63 message_loop_runner_ = new MessageLoopRunner;
64 }
65
66 ManagedModeURLFilter* url_filter_;
67 scoped_refptr<MessageLoopRunner> message_loop_runner_;
68 };
69
70 } // namespace
71
72 class ManagedModeContentPackTest : public ExtensionBrowserTest {
73 public:
74 ManagedModeContentPackTest() {}
75 virtual ~ManagedModeContentPackTest() {}
76
77 virtual void SetUpOnMainThread() OVERRIDE {
78 PrefService* prefs = browser()->profile()->GetPrefs();
79 prefs->SetInteger(prefs::kDefaultManagedModeFilteringBehavior,
80 ManagedModeURLFilter::WARN);
81 }
82 };
83
84 IN_PROC_BROWSER_TEST_F(ManagedModeContentPackTest, InstallContentPacks) {
85 ManagedMode* managed_mode = ManagedMode::GetInstance();
86 ManagedModeURLFilter* url_filter =
87 managed_mode->GetURLFilterForUIThreadImpl();
88 ManagedModeURLFilterObserver observer(url_filter);
89
90 GURL url("http://example.com");
91 EXPECT_EQ(ManagedModeURLFilter::ALLOW,
92 url_filter->GetFilteringBehaviorForURL(url));
93
94 managed_mode->SetInManagedMode(browser()->profile());
95 observer.Wait();
96
97 EXPECT_EQ(ManagedModeURLFilter::WARN,
98 url_filter->GetFilteringBehaviorForURL(url));
99
100 const extensions::Extension* extension = LoadExtension(
101 test_data_dir_.AppendASCII("managed_mode/content_pack"));
102 ASSERT_TRUE(extension) << "Failed to load extension.";
103 observer.Wait();
104
105 ScopedVector<ManagedModeSiteList> site_lists =
106 GetActiveSiteLists(&managed_user_service);
107 ASSERT_EQ(1u, site_lists.size());
108 std::vector<ManagedModeSiteList::Site> sites;
109 site_lists[0]->GetSites(&sites);
110 ASSERT_EQ(3u, sites.size());
111 EXPECT_EQ(ASCIIToUTF16("YouTube"), sites[0].name);
112 EXPECT_EQ(ASCIIToUTF16("Homestar Runner"), sites[1].name);
113 EXPECT_EQ(string16(), sites[2].name);
114
115 EXPECT_EQ(ManagedModeURLFilter::ALLOW,
116 url_filter->GetFilteringBehaviorForURL(url));
117 EXPECT_EQ(ManagedModeURLFilter::WARN,
118 url_filter->GetFilteringBehaviorForURL(GURL("http://moose.org")));
119 }
120
121 // TODO(sergiu): Make the webkit error message disappear when navigating to an 29 // TODO(sergiu): Make the webkit error message disappear when navigating to an
122 // interstitial page. The message states: "Not allowed to load local resource: 30 // interstitial page. The message states: "Not allowed to load local resource:
123 // chrome://resources/css/widgets.css" followed by the compiled page. 31 // chrome://resources/css/widgets.css" followed by the compiled page.
124 class ManagedModeBlockModeTest : public InProcessBrowserTest { 32 class ManagedModeBlockModeTest : public InProcessBrowserTest {
125 public: 33 public:
126 // Indicates whether the interstitial should proceed or not. 34 // Indicates whether the interstitial should proceed or not.
127 enum InterstitialAction { 35 enum InterstitialAction {
128 INTERSTITIAL_PROCEED, 36 INTERSTITIAL_PROCEED,
129 INTERSTITIAL_DONTPROCEED, 37 INTERSTITIAL_DONTPROCEED,
130 }; 38 };
131 39
132 // Indicates the infobar action or expected state. INFOBAR_ACCEPT and 40 // Indicates the infobar action or expected state. INFOBAR_ACCEPT and
133 // INFOBAR_CANCEL act on the infobar. INFOBAR_ALREADY_ADDED shows that 41 // INFOBAR_CANCEL act on the infobar. INFOBAR_ALREADY_ADDED shows that
134 // the "Website was already added infobar" is expected (which expires 42 // the "Website was already added infobar" is expected (which expires
135 // automatically) and INFOBAR_NOT_USED shows that an infobar is not expected 43 // automatically) and INFOBAR_NOT_USED shows that an infobar is not expected
136 // in this case. 44 // in this case.
137 enum InfobarAction { 45 enum InfobarAction {
138 INFOBAR_ACCEPT, 46 INFOBAR_ACCEPT,
139 INFOBAR_CANCEL, 47 INFOBAR_CANCEL,
140 INFOBAR_ALREADY_ADDED, 48 INFOBAR_ALREADY_ADDED,
141 INFOBAR_NOT_USED, 49 INFOBAR_NOT_USED,
142 }; 50 };
143 51
144 ManagedModeBlockModeTest() {} 52 ManagedModeBlockModeTest() : managed_user_service_(NULL) {}
53 virtual ~ManagedModeBlockModeTest() {}
145 54
146 // Builds the redirect URL for the testserver from the hostnames and the 55 // Builds the redirect URL for the testserver from the hostnames and the
147 // final URL and returns it as a string. 56 // final URL and returns it as a string.
148 std::string GetRedirectURL(std::vector<std::string> hostnames, 57 std::string GetRedirectURL(std::vector<std::string> hostnames,
149 std::string final_url) { 58 std::string final_url) {
150 // TODO(sergiu): Figure out how to make multiple successive redirects 59 // TODO(sergiu): Figure out how to make multiple successive redirects
151 // trigger multiple notfications to test more advanced scenarios. 60 // trigger multiple notfications to test more advanced scenarios.
152 std::string output; 61 std::string output;
153 for (std::vector<std::string>::const_iterator it = hostnames.begin(); 62 for (std::vector<std::string>::const_iterator it = hostnames.begin();
154 it != hostnames.end(); ++it) { 63 it != hostnames.end(); ++it) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 content::WindowedNotificationObserver observer( 145 content::WindowedNotificationObserver observer(
237 content::NOTIFICATION_INTERSTITIAL_DETACHED, 146 content::NOTIFICATION_INTERSTITIAL_DETACHED,
238 content::Source<WebContents>(tab)); 147 content::Source<WebContents>(tab));
239 interstitial_page->DontProceed(); 148 interstitial_page->DontProceed();
240 observer.Wait(); 149 observer.Wait();
241 } 150 }
242 CheckNumberOfInfobars(0); 151 CheckNumberOfInfobars(0);
243 } 152 }
244 153
245 protected: 154 protected:
246 virtual void SetUpCommandLine(CommandLine* command_line) { 155 virtual void SetUpOnMainThread() OVERRIDE {
156 managed_user_service_ =
157 ManagedUserServiceFactory::GetForProfile(browser()->profile());
158 }
159
160 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
247 // Enable the test server and remap all URLs to it. 161 // Enable the test server and remap all URLs to it.
248 ASSERT_TRUE(test_server()->Start()); 162 ASSERT_TRUE(test_server()->Start());
249 std::string host_port = test_server()->host_port_pair().ToString(); 163 std::string host_port = test_server()->host_port_pair().ToString();
250 command_line->AppendSwitch(switches::kManaged); 164 command_line->AppendSwitch(switches::kManaged);
251 command_line->AppendSwitchASCII(switches::kHostResolverRules, 165 command_line->AppendSwitchASCII(switches::kHostResolverRules,
252 "MAP *.example.com " + host_port + "," + 166 "MAP *.example.com " + host_port + "," +
253 "MAP *.new-example.com " + host_port + "," + 167 "MAP *.new-example.com " + host_port + "," +
254 "MAP *.a.com " + host_port); 168 "MAP *.a.com " + host_port);
255 } 169 }
256 170
257 private: 171 ManagedUserService* managed_user_service_;
258 DISALLOW_COPY_AND_ASSIGN(ManagedModeBlockModeTest);
259 }; 172 };
260 173
261 // Navigates to a URL which is not in a manual list, clicks preview on the 174 // Navigates to a URL which is not in a manual list, clicks preview on the
262 // interstitial and then allows the website. The website should now be in the 175 // interstitial and then allows the website. The website should now be in the
263 // manual whitelist. 176 // manual whitelist.
264 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLNotInAnyLists) { 177 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLNotInAnyLists) {
265 GURL test_url("http://www.example.com/files/simple.html"); 178 GURL test_url("http://www.example.com/files/simple.html");
266 ui_test_utils::NavigateToURL(browser(), test_url); 179 ui_test_utils::NavigateToURL(browser(), test_url);
267 180
268 WebContents* tab = chrome::GetActiveWebContents(browser()); 181 WebContents* tab = chrome::GetActiveWebContents(browser());
269 182
270 CheckShownPageIsInterstitial(tab); 183 CheckShownPageIsInterstitial(tab);
271 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 184 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
272 185
273 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 186 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
274 } 187 }
275 188
276 // Same as above just that the URL redirects to a second URL first. The initial 189 // Same as above just that the URL redirects to a second URL first. The initial
277 // exact URL should be in the whitelist as well as the second hostname. 190 // exact URL should be in the whitelist as well as the second hostname.
278 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, RedirectedURLsNotInAnyLists) { 191 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, RedirectedURLsNotInAnyLists) {
279 std::vector<std::string> url_list; 192 std::vector<std::string> url_list;
280 url_list.push_back("www.a.com"); 193 url_list.push_back("www.a.com");
281 std::string last_url("www.example.com/files/simple.html"); 194 std::string last_url("www.example.com/files/simple.html");
282 GURL test_url(GetRedirectURL(url_list, last_url)); 195 GURL test_url(GetRedirectURL(url_list, last_url));
283 196
284 ui_test_utils::NavigateToURL(browser(), test_url); 197 ui_test_utils::NavigateToURL(browser(), test_url);
285 198
286 WebContents* tab = chrome::GetActiveWebContents(browser()); 199 WebContents* tab = chrome::GetActiveWebContents(browser());
287 200
288 CheckShownPageIsInterstitial(tab); 201 CheckShownPageIsInterstitial(tab);
289 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 202 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
290 203
291 EXPECT_TRUE(ManagedMode::IsInManualList(true, 204 EXPECT_TRUE(managed_user_service_->IsInManualList(
292 "http://.www.a.com/server-redirect")); 205 true, "http://.www.a.com/server-redirect"));
293 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 206 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
294 } 207 }
295 208
296 // Navigates to a URL in the whitelist. No interstitial should be shown and 209 // Navigates to a URL in the whitelist. No interstitial should be shown and
297 // the browser should navigate to the page. 210 // the browser should navigate to the page.
298 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLInWhitelist) { 211 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLInWhitelist) {
299 GURL test_url("http://www.example.com/files/simple.html"); 212 GURL test_url("http://www.example.com/files/simple.html");
300 ListValue whitelist; 213 ListValue whitelist;
301 whitelist.AppendString(test_url.host()); 214 whitelist.AppendString(test_url.host());
302 ManagedMode::AddToManualList(true, whitelist); 215 managed_user_service_->AddToManualList(true, whitelist);
303 216
304 ui_test_utils::NavigateToURL(browser(), test_url); 217 ui_test_utils::NavigateToURL(browser(), test_url);
305 218
306 WebContents* tab = chrome::GetActiveWebContents(browser()); 219 WebContents* tab = chrome::GetActiveWebContents(browser());
307 220
308 CheckShownPageIsNotInterstitial(tab); 221 CheckShownPageIsNotInterstitial(tab);
309 222
310 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 223 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
311 } 224 }
312 225
313 // Navigates to a URL which redirects to another URL, both in the whitelist. 226 // Navigates to a URL which redirects to another URL, both in the whitelist.
314 // No interstitial should be shown and the browser should navigate to the page. 227 // No interstitial should be shown and the browser should navigate to the page.
315 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 228 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
316 RedirectedURLsBothInWhitelist) { 229 RedirectedURLsBothInWhitelist) {
317 std::vector<std::string> url_list; 230 std::vector<std::string> url_list;
318 url_list.push_back("www.a.com"); 231 url_list.push_back("www.a.com");
319 std::string last_url("www.example.com/files/simple.html"); 232 std::string last_url("www.example.com/files/simple.html");
320 GURL test_url(GetRedirectURL(url_list, last_url)); 233 GURL test_url(GetRedirectURL(url_list, last_url));
321 234
322 // Add both hostnames to the whitelist, should navigate without interstitial. 235 // Add both hostnames to the whitelist, should navigate without interstitial.
323 ListValue whitelist; 236 ListValue whitelist;
324 whitelist.AppendString("www.a.com"); 237 whitelist.AppendString("www.a.com");
325 whitelist.AppendString("www.example.com"); 238 whitelist.AppendString("www.example.com");
326 ManagedMode::AddToManualList(true, whitelist); 239 managed_user_service_->AddToManualList(true, whitelist);
327 240
328 ui_test_utils::NavigateToURL(browser(), test_url); 241 ui_test_utils::NavigateToURL(browser(), test_url);
329 242
330 WebContents* tab = chrome::GetActiveWebContents(browser()); 243 WebContents* tab = chrome::GetActiveWebContents(browser());
331 244
332 CheckShownPageIsNotInterstitial(tab); 245 CheckShownPageIsNotInterstitial(tab);
333 246
334 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.a.com")); 247 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.a.com"));
335 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 248 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
336 } 249 }
337 250
338 // Only one URL is in the whitelist and the second not, so it should redirect, 251 // Only one URL is in the whitelist and the second not, so it should redirect,
339 // show an interstitial, then after clicking preview and clicking accept both 252 // show an interstitial, then after clicking preview and clicking accept both
340 // websites should be in the whitelist. 253 // websites should be in the whitelist.
341 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 254 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
342 RedirectedURLFirstInWhitelist) { 255 RedirectedURLFirstInWhitelist) {
343 std::vector<std::string> url_list; 256 std::vector<std::string> url_list;
344 url_list.push_back("www.a.com"); 257 url_list.push_back("www.a.com");
345 std::string last_url("www.example.com/files/simple.html"); 258 std::string last_url("www.example.com/files/simple.html");
346 GURL test_url(GetRedirectURL(url_list, last_url)); 259 GURL test_url(GetRedirectURL(url_list, last_url));
347 260
348 // Add the first URL to the whitelist. 261 // Add the first URL to the whitelist.
349 ListValue whitelist; 262 ListValue whitelist;
350 whitelist.AppendString("www.a.com"); 263 whitelist.AppendString("www.a.com");
351 ManagedMode::AddToManualList(true, whitelist); 264 managed_user_service_->AddToManualList(true, whitelist);
352 265
353 ui_test_utils::NavigateToURL(browser(), test_url); 266 ui_test_utils::NavigateToURL(browser(), test_url);
354 267
355 WebContents* tab = chrome::GetActiveWebContents(browser()); 268 WebContents* tab = chrome::GetActiveWebContents(browser());
356 269
357 EXPECT_EQ(tab->GetURL().spec(), "http://" + last_url); 270 EXPECT_EQ(tab->GetURL().spec(), "http://" + last_url);
358 CheckShownPageIsInterstitial(tab); 271 CheckShownPageIsInterstitial(tab);
359 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 272 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
360 273
361 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.a.com")); 274 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.a.com"));
362 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 275 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
363 } 276 }
364 277
365 // This test navigates to a URL which is not in the whitelist but redirects to 278 // This test navigates to a URL which is not in the whitelist but redirects to
366 // one that is. The expected behavior is that the user will get an interstitial 279 // one that is. The expected behavior is that the user will get an interstitial
367 // and after clicking preview the user will see an infobar stating that the URL 280 // and after clicking preview the user will see an infobar stating that the URL
368 // was already in the whitelist (and the first URL gets added as well). 281 // was already in the whitelist (and the first URL gets added as well).
369 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 282 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
370 RedirectedURLLastInWhitelist) { 283 RedirectedURLLastInWhitelist) {
371 std::vector<std::string> url_list; 284 std::vector<std::string> url_list;
372 url_list.push_back("www.a.com"); 285 url_list.push_back("www.a.com");
373 std::string last_url("www.example.com/files/simple.html"); 286 std::string last_url("www.example.com/files/simple.html");
374 GURL test_url(GetRedirectURL(url_list, last_url)); 287 GURL test_url(GetRedirectURL(url_list, last_url));
375 288
376 // Add the last URL to the whitelist. 289 // Add the last URL to the whitelist.
377 ListValue whitelist; 290 ListValue whitelist;
378 whitelist.AppendString("www.example.com"); 291 whitelist.AppendString("www.example.com");
379 ManagedMode::AddToManualList(true, whitelist); 292 managed_user_service_->AddToManualList(true, whitelist);
380 293
381 ui_test_utils::NavigateToURL(browser(), test_url); 294 ui_test_utils::NavigateToURL(browser(), test_url);
382 295
383 WebContents* tab = chrome::GetActiveWebContents(browser()); 296 WebContents* tab = chrome::GetActiveWebContents(browser());
384 297
385 EXPECT_EQ(tab->GetURL().host(), "www.a.com"); 298 EXPECT_EQ(tab->GetURL().host(), "www.a.com");
386 CheckShownPageIsInterstitial(tab); 299 CheckShownPageIsInterstitial(tab);
387 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, 300 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED,
388 INFOBAR_ALREADY_ADDED); 301 INFOBAR_ALREADY_ADDED);
389 302
390 EXPECT_TRUE(ManagedMode::IsInManualList(true, 303 EXPECT_TRUE(managed_user_service_->IsInManualList(
391 "http://.www.a.com/server-redirect")); 304 true, "http://.www.a.com/server-redirect"));
392 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 305 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
393 } 306 }
394 307
395 // Tests whether going back after being shown an interstitial works. No 308 // Tests whether going back after being shown an interstitial works. No
396 // websites should be added to the whitelist. 309 // websites should be added to the whitelist.
397 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 310 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
398 SimpleURLNotInAnyListsGoBack) { 311 SimpleURLNotInAnyListsGoBack) {
399 GURL test_url("http://www.example.com/files/simple.html"); 312 GURL test_url("http://www.example.com/files/simple.html");
400 ui_test_utils::NavigateToURL(browser(), test_url); 313 ui_test_utils::NavigateToURL(browser(), test_url);
401 314
402 WebContents* tab = chrome::GetActiveWebContents(browser()); 315 WebContents* tab = chrome::GetActiveWebContents(browser());
403 316
404 CheckShownPageIsInterstitial(tab); 317 CheckShownPageIsInterstitial(tab);
405 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_DONTPROCEED, 318 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_DONTPROCEED,
406 INFOBAR_NOT_USED); 319 INFOBAR_NOT_USED);
407 320
408 EXPECT_EQ(tab->GetURL().spec(), "about:blank"); 321 EXPECT_EQ(tab->GetURL().spec(), "about:blank");
409 322
410 EXPECT_FALSE(ManagedMode::IsInManualList(true, "www.example.com")); 323 EXPECT_FALSE(managed_user_service_->IsInManualList(true, "www.example.com"));
411 } 324 }
412 325
413 // Like SimpleURLNotInAnyLists just that it navigates to a page on the allowed 326 // Like SimpleURLNotInAnyLists just that it navigates to a page on the allowed
414 // domain after clicking allow on the infobar. The navigation should complete 327 // domain after clicking allow on the infobar. The navigation should complete
415 // and no interstitial should be shown the second time. 328 // and no interstitial should be shown the second time.
416 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 329 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
417 SimpleURLNotInAnyListsNavigateAgain) { 330 SimpleURLNotInAnyListsNavigateAgain) {
418 GURL test_url("http://www.example.com/files/simple.html"); 331 GURL test_url("http://www.example.com/files/simple.html");
419 ui_test_utils::NavigateToURL(browser(), test_url); 332 ui_test_utils::NavigateToURL(browser(), test_url);
420 333
421 WebContents* tab = chrome::GetActiveWebContents(browser()); 334 WebContents* tab = chrome::GetActiveWebContents(browser());
422 335
423 CheckShownPageIsInterstitial(tab); 336 CheckShownPageIsInterstitial(tab);
424 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 337 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
425 338
426 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 339 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
427 340
428 // Navigate to a different page on the same host. 341 // Navigate to a different page on the same host.
429 test_url = GURL("http://www.example.com/files/english_page.html"); 342 test_url = GURL("http://www.example.com/files/english_page.html");
430 ui_test_utils::NavigateToURL(browser(), test_url); 343 ui_test_utils::NavigateToURL(browser(), test_url);
431 344
432 // An interstitial should not show up. 345 // An interstitial should not show up.
433 CheckShownPageIsNotInterstitial(tab); 346 CheckShownPageIsNotInterstitial(tab);
434 CheckNumberOfInfobars(0); 347 CheckNumberOfInfobars(0);
435 } 348 }
436 349
437 // Same as above just that it reloads the page instead of navigating to another 350 // Same as above just that it reloads the page instead of navigating to another
438 // page on the website. Same expected behavior. 351 // page on the website. Same expected behavior.
439 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 352 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
440 SimpleURLNotInAnyListsReloadPageAfterAdd) { 353 SimpleURLNotInAnyListsReloadPageAfterAdd) {
441 GURL test_url("http://www.example.com/files/simple.html"); 354 GURL test_url("http://www.example.com/files/simple.html");
442 ui_test_utils::NavigateToURL(browser(), test_url); 355 ui_test_utils::NavigateToURL(browser(), test_url);
443 356
444 WebContents* tab = chrome::GetActiveWebContents(browser()); 357 WebContents* tab = chrome::GetActiveWebContents(browser());
445 358
446 CheckShownPageIsInterstitial(tab); 359 CheckShownPageIsInterstitial(tab);
447 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 360 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
448 361
449 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 362 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
450 363
451 // Reload the page 364 // Reload the page
452 tab->GetController().Reload(false); 365 tab->GetController().Reload(false);
453 366
454 // Expect that the page shows up and not an interstitial. 367 // Expect that the page shows up and not an interstitial.
455 CheckShownPageIsNotInterstitial(tab); 368 CheckShownPageIsNotInterstitial(tab);
456 CheckNumberOfInfobars(0); 369 CheckNumberOfInfobars(0);
457 EXPECT_EQ(tab->GetURL().spec(), test_url.spec()); 370 EXPECT_EQ(tab->GetURL().spec(), test_url.spec());
458 } 371 }
459 372
460 // Navigates to an HTTPS page not in any lists, similar to the simple test but 373 // Navigates to an HTTPS page not in any lists, similar to the simple test but
461 // over HTTPS (expected behavior is that only the HTTPS version of the site 374 // over HTTPS (expected behavior is that only the HTTPS version of the site
462 // gets whitelisted, compared to the simple case where all protocols get 375 // gets whitelisted, compared to the simple case where all protocols get
463 // whitelisted). 376 // whitelisted).
464 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 377 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
465 SimpleHTTPSURLNotInAnyLists) { 378 SimpleHTTPSURLNotInAnyLists) {
466 // Navigate to an HTTPS URL. 379 // Navigate to an HTTPS URL.
467 GURL test_url("https://www.example.com/files/simple.html"); 380 GURL test_url("https://www.example.com/files/simple.html");
468 ui_test_utils::NavigateToURL(browser(), test_url); 381 ui_test_utils::NavigateToURL(browser(), test_url);
469 382
470 WebContents* tab = chrome::GetActiveWebContents(browser()); 383 WebContents* tab = chrome::GetActiveWebContents(browser());
471 384
472 CheckShownPageIsInterstitial(tab); 385 CheckShownPageIsInterstitial(tab);
473 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 386 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
474 387
475 // Check that the https:// version is added in the whitelist. 388 // Check that the https:// version is added in the whitelist.
476 EXPECT_TRUE(ManagedMode::IsInManualList(true, "https://www.example.com")); 389 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "https://www.example.c om"));
477 } 390 }
478 391
479 // The test navigates to a page, the interstitial is shown and preview is 392 // The test navigates to a page, the interstitial is shown and preview is
480 // clicked but then the test navigates to other pages on the same domain before 393 // clicked but then the test navigates to other pages on the same domain before
481 // clicking allow on the page. The "allow" infobar should still be there during 394 // clicking allow on the page. The "allow" infobar should still be there during
482 // this time and the navigation should be allowed. When the test finally clicks 395 // this time and the navigation should be allowed. When the test finally clicks
483 // accept the webpage should be whitelisted. 396 // accept the webpage should be whitelisted.
484 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 397 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
485 SimpleURLNotInAnyListNavigateAround) { 398 SimpleURLNotInAnyListNavigateAround) {
486 GURL test_url("http://www.example.com/files/simple.html"); 399 GURL test_url("http://www.example.com/files/simple.html");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 content::WindowedNotificationObserver infobar_removed( 444 content::WindowedNotificationObserver infobar_removed(
532 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, 445 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
533 content::NotificationService::AllSources()); 446 content::NotificationService::AllSources());
534 447
535 // Finally accept the infobar and see that it is gone. 448 // Finally accept the infobar and see that it is gone.
536 confirm_info_bar_delegate->Accept(); 449 confirm_info_bar_delegate->Accept();
537 infobar_removed.Wait(); 450 infobar_removed.Wait();
538 451
539 CheckNumberOfInfobars(0); 452 CheckNumberOfInfobars(0);
540 453
541 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); 454 EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com"));
542 } 455 }
543 456
544 // The test navigates to a page, the interstitial is shown and preview is 457 // The test navigates to a page, the interstitial is shown and preview is
545 // clicked but then the test navigates to a page on a different host, which 458 // clicked but then the test navigates to a page on a different host, which
546 // should trigger an interstitial again. Clicking preview on this interstitial 459 // should trigger an interstitial again. Clicking preview on this interstitial
547 // and accepting it should add the second website to the whitelist and not the 460 // and accepting it should add the second website to the whitelist and not the
548 // first one. 461 // first one.
549 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, 462 IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
550 NavigateDifferentHostAfterPreview) { 463 NavigateDifferentHostAfterPreview) {
551 GURL test_url("http://www.example.com/files/simple.html"); 464 GURL test_url("http://www.example.com/files/simple.html");
(...skipping 24 matching lines...) Expand all
576 489
577 // Navigate to another URL on a different host. 490 // Navigate to another URL on a different host.
578 test_url = GURL("http://www.new-example.com/files/simple.html"); 491 test_url = GURL("http://www.new-example.com/files/simple.html");
579 ui_test_utils::NavigateToURL(browser(), test_url); 492 ui_test_utils::NavigateToURL(browser(), test_url);
580 493
581 CheckShownPageIsInterstitial(tab); 494 CheckShownPageIsInterstitial(tab);
582 CheckNumberOfInfobars(0); 495 CheckNumberOfInfobars(0);
583 496
584 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); 497 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
585 498
586 EXPECT_FALSE(ManagedMode::IsInManualList(true, "www.example.com")); 499 EXPECT_FALSE(managed_user_service_->IsInManualList(true, "www.example.com"));
587 EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.new-example.com")); 500 EXPECT_TRUE(managed_user_service_->IsInManualList(true,
501 "www.new-example.com"));
588 } 502 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698