Index: chrome/browser/managed_mode/managed_mode_browsertest.cc |
diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc |
index 1aef679d08f4072e1e353f1f806fae789ecdc0a2..9b0db77a4d663c7e972d68046a95eac3f1808166 100644 |
--- a/chrome/browser/managed_mode/managed_mode_browsertest.cc |
+++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -6,13 +6,14 @@ |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
-#include "chrome/browser/extensions/extension_browsertest.h" |
#include "chrome/browser/infobars/infobar.h" |
#include "chrome/browser/infobars/infobar_tab_helper.h" |
#include "chrome/browser/managed_mode/managed_mode.h" |
-#include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
-#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/managed_mode/managed_user_service.h" |
+#include "chrome/browser/managed_mode/managed_user_service_factory.h" |
+#include "chrome/browser/prefs/pref_service_syncable.h" |
#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_navigator.h" |
#include "chrome/browser/ui/browser_tabstrip.h" |
#include "chrome/common/chrome_notification_types.h" |
@@ -26,129 +27,12 @@ |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/browser/web_contents_observer.h" |
-#include "content/public/test/test_utils.h" |
-#include "googleurl/src/gurl.h" |
using content::InterstitialPage; |
-using content::MessageLoopRunner; |
using content::NavigationController; |
using content::NavigationEntry; |
using content::WebContents; |
-namespace { |
- |
-class ManagedModeURLFilterObserver : public ManagedModeURLFilter::Observer { |
- public: |
- explicit ManagedModeURLFilterObserver(ManagedModeURLFilter* url_filter) |
- : url_filter_(url_filter) { |
- Reset(); |
- url_filter_->AddObserver(this); |
- } |
- |
- ~ManagedModeURLFilterObserver() { |
- url_filter_->RemoveObserver(this); |
- } |
- |
- void Wait() { |
- message_loop_runner_->Run(); |
- Reset(); |
- } |
- |
- // ManagedModeURLFilter::Observer |
- virtual void OnSiteListUpdated() OVERRIDE { |
- message_loop_runner_->Quit(); |
- } |
- |
- private: |
- void Reset() { |
- message_loop_runner_ = new MessageLoopRunner; |
- } |
- |
- ManagedModeURLFilter* url_filter_; |
- scoped_refptr<MessageLoopRunner> message_loop_runner_; |
-}; |
- |
-} // namespace |
- |
-class ManagedModeContentPackTest : public ExtensionBrowserTest { |
- public: |
- ManagedModeContentPackTest() {} |
- virtual ~ManagedModeContentPackTest() {} |
- |
- virtual void SetUpOnMainThread() OVERRIDE { |
- PrefService* prefs = browser()->profile()->GetPrefs(); |
- prefs->SetInteger(prefs::kDefaultManagedModeFilteringBehavior, |
- ManagedModeURLFilter::WARN); |
- } |
-}; |
- |
-IN_PROC_BROWSER_TEST_F(ManagedModeContentPackTest, InstallContentPacks) { |
- ManagedMode* managed_mode = ManagedMode::GetInstance(); |
- ManagedModeURLFilter* url_filter = |
- managed_mode->GetURLFilterForUIThreadImpl(); |
- ManagedModeURLFilterObserver observer(url_filter); |
- |
- GURL example_url("http://example.com"); |
- GURL moose_url("http://moose.org"); |
- EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
- url_filter->GetFilteringBehaviorForURL(example_url)); |
- |
- managed_mode->SetInManagedMode(browser()->profile()); |
- observer.Wait(); |
- |
- EXPECT_EQ(ManagedModeURLFilter::WARN, |
- url_filter->GetFilteringBehaviorForURL(example_url)); |
- |
- // Load a content pack. |
- const extensions::Extension* extension = LoadExtension( |
- test_data_dir_.AppendASCII("managed_mode/content_pack")); |
- ASSERT_TRUE(extension) << "Failed to load extension."; |
- observer.Wait(); |
- |
- ScopedVector<ManagedModeSiteList> site_lists = |
- managed_mode->GetActiveSiteLists(); |
- ASSERT_EQ(1u, site_lists.size()); |
- std::vector<ManagedModeSiteList::Site> sites; |
- site_lists[0]->GetSites(&sites); |
- ASSERT_EQ(3u, sites.size()); |
- EXPECT_EQ(ASCIIToUTF16("YouTube"), sites[0].name); |
- EXPECT_EQ(ASCIIToUTF16("Homestar Runner"), sites[1].name); |
- EXPECT_EQ(string16(), sites[2].name); |
- |
- EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
- url_filter->GetFilteringBehaviorForURL(example_url)); |
- EXPECT_EQ(ManagedModeURLFilter::WARN, |
- url_filter->GetFilteringBehaviorForURL(moose_url)); |
- |
- // Load a second content pack. |
- extension = LoadExtension( |
- test_data_dir_.AppendASCII("managed_mode/content_pack_2")); |
- ASSERT_TRUE(extension) << "Failed to load extension."; |
- observer.Wait(); |
- |
- site_lists = managed_mode->GetActiveSiteLists(); |
- ASSERT_EQ(2u, site_lists.size()); |
- sites.clear(); |
- site_lists[0]->GetSites(&sites); |
- site_lists[1]->GetSites(&sites); |
- ASSERT_EQ(4u, sites.size()); |
- // The site lists might be returned in any order, so we put them into a set. |
- std::set<std::string> site_names; |
- for (std::vector<ManagedModeSiteList::Site>::const_iterator it = |
- sites.begin(); it != sites.end(); ++it) { |
- site_names.insert(UTF16ToUTF8(it->name)); |
- } |
- EXPECT_TRUE(site_names.count("YouTube") == 1u); |
- EXPECT_TRUE(site_names.count("Homestar Runner") == 1u); |
- EXPECT_TRUE(site_names.count(std::string()) == 1u); |
- EXPECT_TRUE(site_names.count("Moose") == 1u); |
- |
- EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
- url_filter->GetFilteringBehaviorForURL(example_url)); |
- EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
- url_filter->GetFilteringBehaviorForURL(moose_url)); |
-} |
- |
// TODO(sergiu): Make the webkit error message disappear when navigating to an |
// interstitial page. The message states: "Not allowed to load local resource: |
// chrome://resources/css/widgets.css" followed by the compiled page. |
@@ -172,7 +56,8 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { |
INFOBAR_NOT_USED, |
}; |
- ManagedModeBlockModeTest() {} |
+ ManagedModeBlockModeTest() : managed_user_service_(NULL) {} |
+ virtual ~ManagedModeBlockModeTest() {} |
// Builds the redirect URL for the testserver from the hostnames and the |
// final URL and returns it as a string. |
@@ -274,7 +159,14 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { |
} |
protected: |
- virtual void SetUpCommandLine(CommandLine* command_line) { |
+ virtual void SetUpOnMainThread() OVERRIDE { |
+ Profile* profile = browser()->profile(); |
+ managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
+ profile->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); |
+ managed_user_service_->Init(); |
+ } |
+ |
+ virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
// Enable the test server and remap all URLs to it. |
ASSERT_TRUE(test_server()->Start()); |
std::string host_port = test_server()->host_port_pair().ToString(); |
@@ -285,8 +177,7 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { |
"MAP *.a.com " + host_port); |
} |
- private: |
- DISALLOW_COPY_AND_ASSIGN(ManagedModeBlockModeTest); |
+ ManagedUserService* managed_user_service_; |
}; |
// Navigates to a URL which is not in a manual list, clicks preview on the |
@@ -301,7 +192,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLNotInAnyLists) { |
CheckShownPageIsInterstitial(tab); |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Same as above just that the URL redirects to a second URL first. The initial |
@@ -319,9 +210,9 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, RedirectedURLsNotInAnyLists) { |
CheckShownPageIsInterstitial(tab); |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, |
- "http://.www.a.com/server-redirect")); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList( |
+ true, "http://.www.a.com/server-redirect")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Navigates to a URL in the whitelist. No interstitial should be shown and |
@@ -330,7 +221,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLInWhitelist) { |
GURL test_url("http://www.example.com/files/simple.html"); |
ListValue whitelist; |
whitelist.AppendString(test_url.host()); |
- ManagedMode::AddToManualList(true, whitelist); |
+ managed_user_service_->AddToManualList(true, whitelist); |
ui_test_utils::NavigateToURL(browser(), test_url); |
@@ -338,7 +229,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, SimpleURLInWhitelist) { |
CheckShownPageIsNotInterstitial(tab); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Navigates to a URL which redirects to another URL, both in the whitelist. |
@@ -354,7 +245,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
ListValue whitelist; |
whitelist.AppendString("www.a.com"); |
whitelist.AppendString("www.example.com"); |
- ManagedMode::AddToManualList(true, whitelist); |
+ managed_user_service_->AddToManualList(true, whitelist); |
ui_test_utils::NavigateToURL(browser(), test_url); |
@@ -362,8 +253,8 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
CheckShownPageIsNotInterstitial(tab); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.a.com")); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.a.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Only one URL is in the whitelist and the second not, so it should redirect, |
@@ -379,7 +270,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
// Add the first URL to the whitelist. |
ListValue whitelist; |
whitelist.AppendString("www.a.com"); |
- ManagedMode::AddToManualList(true, whitelist); |
+ managed_user_service_->AddToManualList(true, whitelist); |
ui_test_utils::NavigateToURL(browser(), test_url); |
@@ -389,8 +280,8 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
CheckShownPageIsInterstitial(tab); |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.a.com")); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.a.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// This test navigates to a URL which is not in the whitelist but redirects to |
@@ -407,7 +298,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
// Add the last URL to the whitelist. |
ListValue whitelist; |
whitelist.AppendString("www.example.com"); |
- ManagedMode::AddToManualList(true, whitelist); |
+ managed_user_service_->AddToManualList(true, whitelist); |
ui_test_utils::NavigateToURL(browser(), test_url); |
@@ -418,9 +309,9 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, |
INFOBAR_ALREADY_ADDED); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, |
- "http://.www.a.com/server-redirect")); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList( |
+ true, "http://.www.a.com/server-redirect")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Tests whether going back after being shown an interstitial works. No |
@@ -438,7 +329,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
EXPECT_EQ(tab->GetURL().spec(), "about:blank"); |
- EXPECT_FALSE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_FALSE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// Like SimpleURLNotInAnyLists just that it navigates to a page on the allowed |
@@ -454,7 +345,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
CheckShownPageIsInterstitial(tab); |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
// Navigate to a different page on the same host. |
test_url = GURL("http://www.example.com/files/english_page.html"); |
@@ -477,7 +368,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
CheckShownPageIsInterstitial(tab); |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
// Reload the page |
tab->GetController().Reload(false); |
@@ -504,7 +395,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
// Check that the https:// version is added in the whitelist. |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "https://www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "https://www.example.com")); |
} |
// The test navigates to a page, the interstitial is shown and preview is |
@@ -569,7 +460,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
CheckNumberOfInfobars(0); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, "www.example.com")); |
} |
// The test navigates to a page, the interstitial is shown and preview is |
@@ -614,6 +505,7 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBlockModeTest, |
ActOnInterstitialAndInfobar(tab, INTERSTITIAL_PROCEED, INFOBAR_ACCEPT); |
- EXPECT_FALSE(ManagedMode::IsInManualList(true, "www.example.com")); |
- EXPECT_TRUE(ManagedMode::IsInManualList(true, "www.new-example.com")); |
+ EXPECT_FALSE(managed_user_service_->IsInManualList(true, "www.example.com")); |
+ EXPECT_TRUE(managed_user_service_->IsInManualList(true, |
+ "www.new-example.com")); |
} |