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