Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / supervised_user / supervised_user_browsertest.cc
index 3400638..213e0b5 100644 (file)
@@ -7,7 +7,6 @@
 #include "base/strings/utf_string_conversions.h"
 #include "base/values.h"
 #include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/common/cancelable_request.h"
 #include "chrome/browser/history/history_service_factory.h"
 #include "chrome/browser/infobars/infobar_service.h"
 #include "chrome/browser/profiles/profile.h"
@@ -23,7 +22,6 @@
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
 #include "chrome/common/chrome_switches.h"
-#include "chrome/common/pref_names.h"
 #include "chrome/test/base/in_process_browser_test.h"
 #include "chrome/test/base/ui_test_utils.h"
 #include "components/infobars/core/confirm_infobar_delegate.h"
@@ -36,9 +34,7 @@
 #include "content/public/browser/web_contents.h"
 #include "content/public/browser/web_contents_observer.h"
 #include "content/public/test/browser_test_utils.h"
-#include "grit/generated_resources.h"
 #include "testing/gmock/include/gmock/gmock.h"
-#include "ui/base/l10n/l10n_util.h"
 
 using content::InterstitialPage;
 using content::NavigationController;
@@ -57,7 +53,7 @@ class SupervisedUserBlockModeTest : public InProcessBrowserTest {
   };
 
   SupervisedUserBlockModeTest() : supervised_user_service_(NULL) {}
-  virtual ~SupervisedUserBlockModeTest() {}
+  ~SupervisedUserBlockModeTest() override {}
 
   void CheckShownPageIsInterstitial(WebContents* tab) {
     CheckShownPage(tab, content::PAGE_TYPE_INTERSTITIAL);
@@ -100,7 +96,7 @@ class SupervisedUserBlockModeTest : public InProcessBrowserTest {
   }
 
  protected:
-  virtual void SetUpOnMainThread() OVERRIDE {
+  void SetUpOnMainThread() override {
     // Set up the SupervisedUserNavigationObserver manually since the profile
     // was not supervised when the browser was created.
     content::WebContents* web_contents =
@@ -118,7 +114,7 @@ class SupervisedUserBlockModeTest : public InProcessBrowserTest {
             new base::FundamentalValue(SupervisedUserURLFilter::BLOCK)));
   }
 
-  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
+  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();
@@ -136,22 +132,21 @@ class SupervisedUserBlockModeTest : public InProcessBrowserTest {
                     const std::string& text_query,
                     const history::QueryOptions& options,
                     history::QueryResults* results) {
-    CancelableRequestConsumer history_request_consumer;
     base::RunLoop run_loop;
+    base::CancelableTaskTracker history_task_tracker;
     history_service->QueryHistory(
         base::UTF8ToUTF16(text_query),
         options,
-        &history_request_consumer,
         base::Bind(&SupervisedUserBlockModeTest::QueryHistoryComplete,
                    base::Unretained(this),
                    results,
-                   &run_loop));
+                   &run_loop),
+        &history_task_tracker);
     run_loop.Run();  // Will go until ...Complete calls Quit.
   }
 
   void QueryHistoryComplete(history::QueryResults* new_results,
                             base::RunLoop* run_loop,
-                            HistoryService::Handle /* handle */,
                             history::QueryResults* results) {
     results->Swap(new_results);
     run_loop->Quit();  // Will return out to QueryHistory.
@@ -218,9 +213,12 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, OpenBlockedURLInNewTab) {
   // On pressing the "back" button, the new tab should be closed, and we should
   // get back to the previous active tab.
   MockTabStripModelObserver observer(tab_strip);
+  base::RunLoop run_loop;
   EXPECT_CALL(observer,
-              TabClosingAt(tab_strip, tab, tab_strip->active_index()));
+              TabClosingAt(tab_strip, tab, tab_strip->active_index()))
+      .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
   GoBack(tab);
+  run_loop.Run();
   EXPECT_EQ(prev_tab, tab_strip->GetActiveWebContents());
 }
 
@@ -229,6 +227,9 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
                        HistoryVisitRecorded) {
   GURL allowed_url("http://www.example.com/files/simple.html");
 
+  scoped_refptr<SupervisedUserURLFilter> filter =
+      supervised_user_service_->GetURLFilterForUIThread();
+
   // Set the host as allowed.
   scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
   dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
@@ -236,11 +237,11 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
       SupervisedUserSettingsServiceFactory::GetForProfile(
           browser()->profile());
   supervised_user_settings_service->SetLocalSettingForTesting(
-      supervised_users::kContentPackManualBehaviorHosts,
-      dict.PassAs<base::Value>());
-  EXPECT_EQ(
-      SupervisedUserService::MANUAL_ALLOW,
-      supervised_user_service_->GetManualBehaviorForHost(allowed_url.host()));
+      supervised_users::kContentPackManualBehaviorHosts, dict.Pass());
+  EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
+            filter->GetFilteringBehaviorForURL(allowed_url));
+  EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
+            filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath()));
 
   ui_test_utils::NavigateToURL(browser(), allowed_url);
 
@@ -260,13 +261,10 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
   // Check that we went back to the first URL and that the manual behaviors
   // have not changed.
   EXPECT_EQ(allowed_url.spec(), tab->GetURL().spec());
-  EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
-            supervised_user_service_->GetManualBehaviorForHost(
-                "www.example.com"));
-  EXPECT_EQ(
-      SupervisedUserService::MANUAL_NONE,
-      supervised_user_service_->GetManualBehaviorForHost(
-          "www.new-example.com"));
+  EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
+            filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath()));
+  EXPECT_EQ(SupervisedUserURLFilter::BLOCK,
+            filter->GetFilteringBehaviorForURL(blocked_url.GetWithEmptyPath()));
 
   // Query the history entry.
   HistoryService* history_service = HistoryServiceFactory::GetForProfile(
@@ -303,11 +301,12 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, Unblock) {
       SupervisedUserSettingsServiceFactory::GetForProfile(
           browser()->profile());
   supervised_user_settings_service->SetLocalSettingForTesting(
-      supervised_users::kContentPackManualBehaviorHosts,
-      dict.PassAs<base::Value>());
-  EXPECT_EQ(
-      SupervisedUserService::MANUAL_ALLOW,
-      supervised_user_service_->GetManualBehaviorForHost(test_url.host()));
+      supervised_users::kContentPackManualBehaviorHosts, dict.Pass());
+
+  scoped_refptr<SupervisedUserURLFilter> filter =
+      supervised_user_service_->GetURLFilterForUIThread();
+  EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
+            filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath()));
 
   observer.Wait();
   EXPECT_EQ(test_url, web_contents->GetURL());