blob: f3de7d1229a2adc7fb7b479c9636c0b39c465d78 [file] [log] [blame]
[email protected]0850e842013-01-19 03:44:311// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d0027832013-01-14 12:43:562// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/command_line.h"
[email protected]a93cdd772013-01-18 14:11:146#include "base/utf_string_conversions.h"
[email protected]d0027832013-01-14 12:43:567#include "base/values.h"
8#include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
9#include "chrome/browser/infobars/infobar.h"
10#include "chrome/browser/infobars/infobar_tab_helper.h"
11#include "chrome/browser/managed_mode/managed_mode.h"
[email protected]0850e842013-01-19 03:44:3112#include "chrome/browser/managed_mode/managed_user_service.h"
13#include "chrome/browser/managed_mode/managed_user_service_factory.h"
[email protected]c753f142013-02-10 13:14:0414#include "chrome/browser/prefs/pref_registry_syncable.h"
15#include "chrome/browser/prefs/pref_service.h"
[email protected]a93cdd772013-01-18 14:11:1416#include "chrome/browser/profiles/profile.h"
[email protected]0850e842013-01-19 03:44:3117#include "chrome/browser/ui/browser.h"
[email protected]d0027832013-01-14 12:43:5618#include "chrome/browser/ui/browser_navigator.h"
[email protected]47ae23372013-01-29 01:50:4819#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]d0027832013-01-14 12:43:5620#include "chrome/common/chrome_notification_types.h"
21#include "chrome/common/chrome_switches.h"
[email protected]a93cdd772013-01-18 14:11:1422#include "chrome/common/pref_names.h"
[email protected]d0027832013-01-14 12:43:5623#include "chrome/test/base/in_process_browser_test.h"
24#include "chrome/test/base/ui_test_utils.h"
25#include "content/public/browser/interstitial_page.h"
26#include "content/public/browser/navigation_controller.h"
27#include "content/public/browser/navigation_entry.h"
28#include "content/public/browser/notification_service.h"
29#include "content/public/browser/web_contents.h"
30#include "content/public/browser/web_contents_observer.h"
31
32using content::InterstitialPage;
[email protected]d0027832013-01-14 12:43:5633using content::NavigationController;
34using content::NavigationEntry;
[email protected]a93cdd772013-01-18 14:11:1435using content::WebContents;
36
[email protected]d0027832013-01-14 12:43:5637// TODO(sergiu): Make the webkit error message disappear when navigating to an
38// interstitial page. The message states: "Not allowed to load local resource:
39// chrome://resources/css/widgets.css" followed by the compiled page.
40class ManagedModeBlockModeTest : public InProcessBrowserTest {
41 public:
42 // Indicates whether the interstitial should proceed or not.
43 enum InterstitialAction {
44 INTERSTITIAL_PROCEED,
45 INTERSTITIAL_DONTPROCEED,
46 };
47
48 // Indicates the infobar action or expected state. INFOBAR_ACCEPT and
49 // INFOBAR_CANCEL act on the infobar. INFOBAR_ALREADY_ADDED shows that
50 // the "Website was already added infobar" is expected (which expires
51 // automatically) and INFOBAR_NOT_USED shows that an infobar is not expected
52 // in this case.
53 enum InfobarAction {
54 INFOBAR_ACCEPT,
55 INFOBAR_CANCEL,
56 INFOBAR_ALREADY_ADDED,
57 INFOBAR_NOT_USED,
58 };
59
[email protected]0850e842013-01-19 03:44:3160 ManagedModeBlockModeTest() : managed_user_service_(NULL) {}
61 virtual ~ManagedModeBlockModeTest() {}
[email protected]d0027832013-01-14 12:43:5662
63 // Builds the redirect URL for the testserver from the hostnames and the
64 // final URL and returns it as a string.
65 std::string GetRedirectURL(std::vector<std::string> hostnames,
66 std::string final_url) {
67 // TODO(sergiu): Figure out how to make multiple successive redirects
68 // trigger multiple notfications to test more advanced scenarios.
69 std::string output;
70 for (std::vector<std::string>::const_iterator it = hostnames.begin();
71 it != hostnames.end(); ++it) {
72 output += "http://" + *it + "/server-redirect?";
73 }
74
75 output += "http://" + final_url;
76 return output;
77 }
78
79 void CheckShownPageIsInterstitial(WebContents* tab) {
80 CheckShownPage(tab, content::PAGE_TYPE_INTERSTITIAL);
81 }
82
83 void CheckShownPageIsNotInterstitial(WebContents* tab) {
84 CheckShownPage(tab, content::PAGE_TYPE_NORMAL);
85 }
86
87 // Checks to see if the type of the current page is |page_type|.
88 void CheckShownPage(WebContents* tab, content::PageType page_type) {
89 ASSERT_FALSE(tab->IsCrashed());
90 NavigationEntry* entry = tab->GetController().GetActiveEntry();
91 ASSERT_TRUE(entry);
92 ASSERT_EQ(page_type, entry->GetPageType());
93 }
94
95 // Checks if the current number of shown infobars is equal to |expected|.
96 void CheckNumberOfInfobars(unsigned int expected) {
97 EXPECT_EQ(expected,
[email protected]47ae23372013-01-29 01:50:4898 InfoBarService::FromWebContents(
99 browser()->tab_strip_model()->GetActiveWebContents())->
100 GetInfoBarCount());
[email protected]d0027832013-01-14 12:43:56101 }
102
103 // Acts on the interstitial and infobar according to the values set to
104 // |interstitial_action| and |infobar_action|.
105 void ActOnInterstitialAndInfobar(WebContents* tab,
106 InterstitialAction interstitial_action,
107 InfobarAction infobar_action) {
108 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
109 ASSERT_TRUE(interstitial_page);
110
111 content::WindowedNotificationObserver infobar_added(
112 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
113 content::NotificationService::AllSources());
114
115 if (interstitial_action == INTERSTITIAL_PROCEED) {
116 content::WindowedNotificationObserver observer(
117 content::NOTIFICATION_LOAD_STOP,
118 content::Source<NavigationController>(&tab->GetController()));
119 interstitial_page->Proceed();
120 observer.Wait();
121 infobar_added.Wait();
122 CheckNumberOfInfobars(1u);
123
124 InfoBarDelegate* info_bar_delegate =
125 content::Details<InfoBarAddedDetails>(infobar_added.details()).ptr();
126 ConfirmInfoBarDelegate* confirm_info_bar_delegate =
127 info_bar_delegate->AsConfirmInfoBarDelegate();
128 ASSERT_TRUE(confirm_info_bar_delegate);
129
130 content::WindowedNotificationObserver infobar_removed(
131 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
132 content::NotificationService::AllSources());
133 InfoBarService* infobar_service =
134 InfoBarService::FromWebContents(tab);
135
136 switch (infobar_action) {
137 case INFOBAR_ACCEPT:
138 confirm_info_bar_delegate->Accept();
139 break;
140 case INFOBAR_CANCEL:
141 confirm_info_bar_delegate->Cancel();
142 break;
143 case INFOBAR_ALREADY_ADDED:
144 confirm_info_bar_delegate->InfoBarDismissed();
145 infobar_service->RemoveInfoBar(confirm_info_bar_delegate);
146 break;
147 case INFOBAR_NOT_USED:
148 NOTREACHED();
149 break;
150 }
151
152 infobar_removed.Wait();
153 } else {
154 content::WindowedNotificationObserver observer(
155 content::NOTIFICATION_INTERSTITIAL_DETACHED,
156 content::Source<WebContents>(tab));
157 interstitial_page->DontProceed();
158 observer.Wait();
159 }
160 CheckNumberOfInfobars(0);
161 }
162
163 protected:
[email protected]0850e842013-01-19 03:44:31164 virtual void SetUpOnMainThread() OVERRIDE {
165 Profile* profile = browser()->profile();
166 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
167 profile->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true);
168 managed_user_service_->Init();
169 }
170
171 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
[email protected]d0027832013-01-14 12:43:56172 // Enable the test server and remap all URLs to it.
173 ASSERT_TRUE(test_server()->Start());
174 std::string host_port = test_server()->host_port_pair().ToString();
175 command_line->AppendSwitch(switches::kManaged);
176 command_line->AppendSwitchASCII(switches::kHostResolverRules,
177 "MAP *.example.com " + host_port + "," +
178 "MAP *.new-example.com " + host_port + "," +
179 "MAP *.a.com " + host_port);
180 }
181
[email protected]0850e842013-01-19 03:44:31182 ManagedUserService* managed_user_service_;
[email protected]d0027832013-01-14 12:43:56183};
184
185// Navigates to a URL which is not in a manual list, clicks preview on the
186// interstitial and then allows the website. The website should now be in the
187// manual whitelist.
188IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLNotInAnyLists) {
189 GURL test_url("http://www.example.com/files/simple.html");
190 ui_test_utils::NavigateToURL(browser(), test_url);
191
[email protected]47ae23372013-01-29 01:50:48192 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56193
194 CheckShownPageIsInterstitial(tab);
195 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
196
[email protected]5e022292013-02-06 16:42:17197 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
198 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56199}
200
201// Same as above just that the URL redirects to a second URL first. The initial
202// exact URL should be in the whitelist as well as the second hostname.
203IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, RedirectedURLsNotInAnyLists) {
204 std::vector<std::string> url_list;
205 url_list.push_back("www.a.com");
206 std::string last_url("www.example.com/files/simple.html");
207 GURL test_url(GetRedirectURL(url_list, last_url));
208
209 ui_test_utils::NavigateToURL(browser(), test_url);
210
[email protected]47ae23372013-01-29 01:50:48211 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56212
213 CheckShownPageIsInterstitial(tab);
214 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
215
[email protected]5e022292013-02-06 16:42:17216 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
217 managed_user_service_->GetManualBehaviorForURL(
218 GURL("http://www.a.com/server-redirect")));
219 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
220 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56221}
222
223// Navigates to a URL in the whitelist. No interstitial should be shown and
224// the browser should navigate to the page.
225IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLInWhitelist) {
226 GURL test_url("http://www.example.com/files/simple.html");
[email protected]5e022292013-02-06 16:42:17227 std::vector<std::string> hosts;
228 hosts.push_back(test_url.host());
229 managed_user_service_->SetManualBehaviorForHosts(
230 hosts, ManagedUserService::MANUAL_ALLOW);
231 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
232 managed_user_service_->GetManualBehaviorForHost(test_url.host()));
[email protected]d0027832013-01-14 12:43:56233
234 ui_test_utils::NavigateToURL(browser(), test_url);
235
[email protected]47ae23372013-01-29 01:50:48236 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56237
238 CheckShownPageIsNotInterstitial(tab);
[email protected]d0027832013-01-14 12:43:56239}
240
241// Navigates to a URL which redirects to another URL, both in the whitelist.
242// No interstitial should be shown and the browser should navigate to the page.
243IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
244 RedirectedURLsBothInWhitelist) {
[email protected]5e022292013-02-06 16:42:17245 std::string a_domain = "www.a.com";
[email protected]d0027832013-01-14 12:43:56246 std::vector<std::string> url_list;
[email protected]5e022292013-02-06 16:42:17247 url_list.push_back(a_domain);
248 std::string example_domain = "www.example.com";
249 std::string last_url = example_domain + "/files/simple.html";
[email protected]d0027832013-01-14 12:43:56250 GURL test_url(GetRedirectURL(url_list, last_url));
251
252 // Add both hostnames to the whitelist, should navigate without interstitial.
[email protected]5e022292013-02-06 16:42:17253 std::vector<std::string> hosts;
254 hosts.push_back(a_domain);
255 hosts.push_back(example_domain);
256 managed_user_service_->SetManualBehaviorForHosts(
257 hosts, ManagedUserService::MANUAL_ALLOW);
[email protected]d0027832013-01-14 12:43:56258
259 ui_test_utils::NavigateToURL(browser(), test_url);
260
[email protected]47ae23372013-01-29 01:50:48261 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56262
263 CheckShownPageIsNotInterstitial(tab);
264
[email protected]5e022292013-02-06 16:42:17265 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
266 managed_user_service_->GetManualBehaviorForHost(a_domain));
267 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
268 managed_user_service_->GetManualBehaviorForHost(example_domain));
[email protected]d0027832013-01-14 12:43:56269}
270
271// Only one URL is in the whitelist and the second not, so it should redirect,
272// show an interstitial, then after clicking preview and clicking accept both
273// websites should be in the whitelist.
274IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
275 RedirectedURLFirstInWhitelist) {
[email protected]5e022292013-02-06 16:42:17276 std::string a_domain = "www.a.com";
[email protected]d0027832013-01-14 12:43:56277 std::vector<std::string> url_list;
[email protected]5e022292013-02-06 16:42:17278 url_list.push_back(a_domain);
279 std::string example_domain = "www.example.com";
280 std::string last_url = example_domain + "/files/simple.html";
[email protected]d0027832013-01-14 12:43:56281 GURL test_url(GetRedirectURL(url_list, last_url));
282
283 // Add the first URL to the whitelist.
[email protected]5e022292013-02-06 16:42:17284 std::vector<std::string> hosts;
285 hosts.push_back(a_domain);
286 managed_user_service_->SetManualBehaviorForHosts(
287 hosts, ManagedUserService::MANUAL_ALLOW);
[email protected]d0027832013-01-14 12:43:56288
289 ui_test_utils::NavigateToURL(browser(), test_url);
290
[email protected]47ae23372013-01-29 01:50:48291 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56292
293 EXPECT_EQ(tab->GetURL().spec(), "http://" + last_url);
294 CheckShownPageIsInterstitial(tab);
295 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
296
[email protected]5e022292013-02-06 16:42:17297 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
298 managed_user_service_->GetManualBehaviorForHost(a_domain));
299 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
300 managed_user_service_->GetManualBehaviorForHost(example_domain));
[email protected]d0027832013-01-14 12:43:56301}
302
303// This test navigates to a URL which is not in the whitelist but redirects to
304// one that is. The expected behavior is that the user will get an interstitial
305// and after clicking preview the user will see an infobar stating that the URL
306// was already in the whitelist (and the first URL gets added as well).
307IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
308 RedirectedURLLastInWhitelist) {
309 std::vector<std::string> url_list;
310 url_list.push_back("www.a.com");
311 std::string last_url("www.example.com/files/simple.html");
312 GURL test_url(GetRedirectURL(url_list, last_url));
313
314 // Add the last URL to the whitelist.
[email protected]5e022292013-02-06 16:42:17315 std::vector<std::string> hosts;
316 hosts.push_back("www.example.com");
317 managed_user_service_->SetManualBehaviorForHosts(
318 hosts, ManagedUserService::MANUAL_ALLOW);
[email protected]d0027832013-01-14 12:43:56319
320 ui_test_utils::NavigateToURL(browser(), test_url);
321
[email protected]47ae23372013-01-29 01:50:48322 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56323
324 EXPECT_EQ(tab->GetURL().host(), "www.a.com");
325 CheckShownPageIsInterstitial(tab);
326 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED,
327 INFOBAR_ALREADY_ADDED);
328
[email protected]5e022292013-02-06 16:42:17329 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
330 managed_user_service_->GetManualBehaviorForURL(
331 GURL("http://www.a.com/server-redirect")));
332 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
333 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56334}
335
336// Tests whether going back after being shown an interstitial works. No
337// websites should be added to the whitelist.
338IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
339 SimpleURLNotInAnyListsGoBack) {
340 GURL test_url("http://www.example.com/files/simple.html");
341 ui_test_utils::NavigateToURL(browser(), test_url);
342
[email protected]47ae23372013-01-29 01:50:48343 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56344
345 CheckShownPageIsInterstitial(tab);
346 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_DONTPROCEED,
347 INFOBAR_NOT_USED);
348
349 EXPECT_EQ(tab->GetURL().spec(), "about:blank");
350
[email protected]5e022292013-02-06 16:42:17351 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
352 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56353}
354
355// Like SimpleURLNotInAnyLists just that it navigates to a page on the allowed
356// domain after clicking allow on the infobar. The navigation should complete
357// and no interstitial should be shown the second time.
358IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
359 SimpleURLNotInAnyListsNavigateAgain) {
360 GURL test_url("http://www.example.com/files/simple.html");
361 ui_test_utils::NavigateToURL(browser(), test_url);
362
[email protected]47ae23372013-01-29 01:50:48363 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56364
365 CheckShownPageIsInterstitial(tab);
366 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
367
[email protected]5e022292013-02-06 16:42:17368 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
369 managed_user_service_->GetManualBehaviorForHost(
370 "www.example.com"));
[email protected]d0027832013-01-14 12:43:56371
372 // Navigate to a different page on the same host.
373 test_url = GURL("http://www.example.com/files/english_page.html");
374 ui_test_utils::NavigateToURL(browser(), test_url);
375
376 // An interstitial should not show up.
377 CheckShownPageIsNotInterstitial(tab);
378 CheckNumberOfInfobars(0);
379}
380
381// Same as above just that it reloads the page instead of navigating to another
382// page on the website. Same expected behavior.
383IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
384 SimpleURLNotInAnyListsReloadPageAfterAdd) {
385 GURL test_url("http://www.example.com/files/simple.html");
386 ui_test_utils::NavigateToURL(browser(), test_url);
387
[email protected]47ae23372013-01-29 01:50:48388 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56389
390 CheckShownPageIsInterstitial(tab);
391 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
392
[email protected]5e022292013-02-06 16:42:17393 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
394 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56395
396 // Reload the page
397 tab->GetController().Reload(false);
398
399 // Expect that the page shows up and not an interstitial.
400 CheckShownPageIsNotInterstitial(tab);
401 CheckNumberOfInfobars(0);
402 EXPECT_EQ(tab->GetURL().spec(), test_url.spec());
403}
404
[email protected]d0027832013-01-14 12:43:56405// The test navigates to a page, the interstitial is shown and preview is
406// clicked but then the test navigates to other pages on the same domain before
407// clicking allow on the page. The "allow" infobar should still be there during
408// this time and the navigation should be allowed. When the test finally clicks
409// accept the webpage should be whitelisted.
410IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
411 SimpleURLNotInAnyListNavigateAround) {
412 GURL test_url("http://www.example.com/files/simple.html");
413 ui_test_utils::NavigateToURL(browser(), test_url);
414
[email protected]47ae23372013-01-29 01:50:48415 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56416
417 CheckShownPageIsInterstitial(tab);
418
419 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
420 ASSERT_TRUE(interstitial_page);
421
422 content::WindowedNotificationObserver infobar_added(
423 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
424 content::NotificationService::AllSources());
425
426 // Proceed with the interstitial.
427 content::WindowedNotificationObserver observer(
428 content::NOTIFICATION_LOAD_STOP,
429 content::Source<NavigationController>(&tab->GetController()));
430 interstitial_page->Proceed();
431 observer.Wait();
432
433 // Wait for the infobar and check that it is there.
434 infobar_added.Wait();
435 CheckNumberOfInfobars(1u);
436
437 // Navigate to a URL on the same host.
438 test_url = GURL("http://www.example.com/files/english_page.html");
439 ui_test_utils::NavigateToURL(browser(), test_url);
440
441 // Check that the infobar is still there.
442 CheckNumberOfInfobars(1u);
443
444 // Navigate to another URL on the same host.
445 test_url = GURL("http://www.example.com/files/french_page.html");
446 ui_test_utils::NavigateToURL(browser(), test_url);
447
448 // Check that the infobar is still there.
449 CheckNumberOfInfobars(1u);
450
451 InfoBarDelegate* info_bar_delegate =
452 content::Details<InfoBarAddedDetails>(infobar_added.details()).ptr();
453 ConfirmInfoBarDelegate* confirm_info_bar_delegate =
454 info_bar_delegate->AsConfirmInfoBarDelegate();
455 ASSERT_TRUE(confirm_info_bar_delegate);
456
457 content::WindowedNotificationObserver infobar_removed(
458 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
459 content::NotificationService::AllSources());
460
461 // Finally accept the infobar and see that it is gone.
462 confirm_info_bar_delegate->Accept();
463 infobar_removed.Wait();
464
465 CheckNumberOfInfobars(0);
466
[email protected]5e022292013-02-06 16:42:17467 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
468 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
[email protected]d0027832013-01-14 12:43:56469}
470
471// The test navigates to a page, the interstitial is shown and preview is
472// clicked but then the test navigates to a page on a different host, which
473// should trigger an interstitial again. Clicking preview on this interstitial
474// and accepting it should add the second website to the whitelist and not the
475// first one.
476IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest,
477 NavigateDifferentHostAfterPreview) {
478 GURL test_url("http://www.example.com/files/simple.html");
479 ui_test_utils::NavigateToURL(browser(), test_url);
480
[email protected]47ae23372013-01-29 01:50:48481 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
[email protected]d0027832013-01-14 12:43:56482
483 CheckShownPageIsInterstitial(tab);
484
485 InterstitialPage* interstitial_page = tab->GetInterstitialPage();
486 ASSERT_TRUE(interstitial_page);
487
488 content::WindowedNotificationObserver infobar_added(
489 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
490 content::NotificationService::AllSources());
491
492 // Proceed with the interstitial.
493 content::WindowedNotificationObserver observer(
494 content::NOTIFICATION_LOAD_STOP,
495 content::Source<NavigationController>(&tab->GetController()));
496 interstitial_page->Proceed();
497 observer.Wait();
498
499 // Wait for the infobar and check that it is there.
500 infobar_added.Wait();
501 CheckNumberOfInfobars(1u);
502 CheckShownPageIsNotInterstitial(tab);
503
504 // Navigate to another URL on a different host.
505 test_url = GURL("http://www.new-example.com/files/simple.html");
506 ui_test_utils::NavigateToURL(browser(), test_url);
507
508 CheckShownPageIsInterstitial(tab);
509 CheckNumberOfInfobars(0);
510
511 ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT);
512
[email protected]5e022292013-02-06 16:42:17513 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
514 managed_user_service_->GetManualBehaviorForHost("www.example.com"));
515 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
516 managed_user_service_->GetManualBehaviorForHost(
517 "www.new-example.com"));
[email protected]d0027832013-01-14 12:43:56518}