| OLD | NEW |
| 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 protected: | 607 protected: |
| 608 PolicyTest() {} | 608 PolicyTest() {} |
| 609 ~PolicyTest() override {} | 609 ~PolicyTest() override {} |
| 610 | 610 |
| 611 void SetUp() override { | 611 void SetUp() override { |
| 612 test_extension_cache_.reset(new extensions::ExtensionCacheFake()); | 612 test_extension_cache_.reset(new extensions::ExtensionCacheFake()); |
| 613 InProcessBrowserTest::SetUp(); | 613 InProcessBrowserTest::SetUp(); |
| 614 } | 614 } |
| 615 | 615 |
| 616 void SetUpInProcessBrowserTestFixture() override { | 616 void SetUpInProcessBrowserTestFixture() override { |
| 617 CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); | 617 base::CommandLine::ForCurrentProcess()->AppendSwitch("noerrdialogs"); |
| 618 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 618 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 619 .WillRepeatedly(Return(true)); | 619 .WillRepeatedly(Return(true)); |
| 620 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 620 BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 621 } | 621 } |
| 622 | 622 |
| 623 void SetUpOnMainThread() override { | 623 void SetUpOnMainThread() override { |
| 624 BrowserThread::PostTask( | 624 BrowserThread::PostTask( |
| 625 BrowserThread::IO, FROM_HERE, | 625 BrowserThread::IO, FROM_HERE, |
| 626 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 626 base::Bind(chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 627 if (extension_service()->updater()) { | 627 if (extension_service()->updater()) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); | 833 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("en-US"); |
| 834 EXPECT_EQ("en-US", loaded); | 834 EXPECT_EQ("en-US", loaded); |
| 835 base::string16 english_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 835 base::string16 english_title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 836 EXPECT_NE(french_title, english_title); | 836 EXPECT_NE(french_title, english_title); |
| 837 } | 837 } |
| 838 #endif | 838 #endif |
| 839 | 839 |
| 840 IN_PROC_BROWSER_TEST_F(PolicyTest, BookmarkBarEnabled) { | 840 IN_PROC_BROWSER_TEST_F(PolicyTest, BookmarkBarEnabled) { |
| 841 #if defined(OS_WIN) && defined(USE_ASH) | 841 #if defined(OS_WIN) && defined(USE_ASH) |
| 842 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 842 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 843 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 843 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 844 switches::kAshBrowserTests)) |
| 844 return; | 845 return; |
| 845 #endif | 846 #endif |
| 846 | 847 |
| 847 // Verifies that the bookmarks bar can be forced to always or never show up. | 848 // Verifies that the bookmarks bar can be forced to always or never show up. |
| 848 | 849 |
| 849 // Test starts in about:blank. | 850 // Test starts in about:blank. |
| 850 PrefService* prefs = browser()->profile()->GetPrefs(); | 851 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 851 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); | 852 EXPECT_FALSE(prefs->IsManagedPreference(bookmarks::prefs::kShowBookmarkBar)); |
| 852 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); | 853 EXPECT_FALSE(prefs->GetBoolean(bookmarks::prefs::kShowBookmarkBar)); |
| 853 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); | 854 EXPECT_EQ(BookmarkBar::HIDDEN, browser()->bookmark_bar_state()); |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); | 1492 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
| 1492 // And it's not possible to open it again. | 1493 // And it's not possible to open it again. |
| 1493 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1494 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
| 1494 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); | 1495 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
| 1495 } | 1496 } |
| 1496 | 1497 |
| 1497 // TODO(samarth): remove along with rest of NTP4 code. | 1498 // TODO(samarth): remove along with rest of NTP4 code. |
| 1498 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { | 1499 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { |
| 1499 #if defined(OS_WIN) && defined(USE_ASH) | 1500 #if defined(OS_WIN) && defined(USE_ASH) |
| 1500 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 1501 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 1501 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 1502 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1503 switches::kAshBrowserTests)) |
| 1502 return; | 1504 return; |
| 1503 #endif | 1505 #endif |
| 1504 | 1506 |
| 1505 // Verifies that the web store icons can be hidden from the new tab page. | 1507 // Verifies that the web store icons can be hidden from the new tab page. |
| 1506 | 1508 |
| 1507 // Open new tab page and look for the web store icons. | 1509 // Open new tab page and look for the web store icons. |
| 1508 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 1510 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
| 1509 content::WebContents* contents = | 1511 content::WebContents* contents = |
| 1510 browser()->tab_strip_model()->GetActiveWebContents(); | 1512 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1511 | 1513 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 ExtensionService* service = extension_service(); | 1636 ExtensionService* service = extension_service(); |
| 1635 ASSERT_FALSE(service->GetExtensionById(kImporterId, true)); | 1637 ASSERT_FALSE(service->GetExtensionById(kImporterId, true)); |
| 1636 ASSERT_FALSE(service->GetExtensionById(kSharedModuleId, true)); | 1638 ASSERT_FALSE(service->GetExtensionById(kSharedModuleId, true)); |
| 1637 | 1639 |
| 1638 // Mock the webstore update URL. This is where the shared module extension | 1640 // Mock the webstore update URL. This is where the shared module extension |
| 1639 // will be installed from. | 1641 // will be installed from. |
| 1640 base::FilePath update_xml_path = base::FilePath(kTestExtensionsDir) | 1642 base::FilePath update_xml_path = base::FilePath(kTestExtensionsDir) |
| 1641 .AppendASCII("policy_shared_module") | 1643 .AppendASCII("policy_shared_module") |
| 1642 .AppendASCII("update.xml"); | 1644 .AppendASCII("update.xml"); |
| 1643 GURL update_xml_url(URLRequestMockHTTPJob::GetMockUrl(update_xml_path)); | 1645 GURL update_xml_url(URLRequestMockHTTPJob::GetMockUrl(update_xml_path)); |
| 1644 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1646 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 1645 switches::kAppsGalleryUpdateURL, update_xml_url.spec()); | 1647 switches::kAppsGalleryUpdateURL, update_xml_url.spec()); |
| 1646 ui_test_utils::NavigateToURL(browser(), update_xml_url); | 1648 ui_test_utils::NavigateToURL(browser(), update_xml_url); |
| 1647 | 1649 |
| 1648 // Blacklist "*" but force-install the importer extension. The shared module | 1650 // Blacklist "*" but force-install the importer extension. The shared module |
| 1649 // should be automatically installed too. | 1651 // should be automatically installed too. |
| 1650 base::ListValue blacklist; | 1652 base::ListValue blacklist; |
| 1651 blacklist.AppendString("*"); | 1653 blacklist.AppendString("*"); |
| 1652 base::ListValue forcelist; | 1654 base::ListValue forcelist; |
| 1653 forcelist.AppendString( | 1655 forcelist.AppendString( |
| 1654 base::StringPrintf("%s;%s", kImporterId, update_xml_url.spec().c_str())); | 1656 base::StringPrintf("%s;%s", kImporterId, update_xml_url.spec().c_str())); |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 base::RunLoop().RunUntilIdle(); | 2149 base::RunLoop().RunUntilIdle(); |
| 2148 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); | 2150 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
| 2149 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); | 2151 EXPECT_TRUE(registry->disabled_extensions().Contains(kGoodCrxId)); |
| 2150 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, | 2152 EXPECT_EQ(extensions::Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY, |
| 2151 extension_prefs->GetDisableReasons(kGoodCrxId)); | 2153 extension_prefs->GetDisableReasons(kGoodCrxId)); |
| 2152 } | 2154 } |
| 2153 | 2155 |
| 2154 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { | 2156 IN_PROC_BROWSER_TEST_F(PolicyTest, HomepageLocation) { |
| 2155 #if defined(OS_WIN) && defined(USE_ASH) | 2157 #if defined(OS_WIN) && defined(USE_ASH) |
| 2156 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 2158 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 2157 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 2159 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2160 switches::kAshBrowserTests)) |
| 2158 return; | 2161 return; |
| 2159 #endif | 2162 #endif |
| 2160 | 2163 |
| 2161 // Verifies that the homepage can be configured with policies. | 2164 // Verifies that the homepage can be configured with policies. |
| 2162 // Set a default, and check that the home button navigates there. | 2165 // Set a default, and check that the home button navigates there. |
| 2163 browser()->profile()->GetPrefs()->SetString( | 2166 browser()->profile()->GetPrefs()->SetString( |
| 2164 prefs::kHomePage, chrome::kChromeUIPolicyURL); | 2167 prefs::kHomePage, chrome::kChromeUIPolicyURL); |
| 2165 browser()->profile()->GetPrefs()->SetBoolean( | 2168 browser()->profile()->GetPrefs()->SetBoolean( |
| 2166 prefs::kHomePageIsNewTabPage, false); | 2169 prefs::kHomePageIsNewTabPage, false); |
| 2167 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), | 2170 EXPECT_EQ(GURL(chrome::kChromeUIPolicyURL), |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3040 | 3043 |
| 3041 #endif | 3044 #endif |
| 3042 | 3045 |
| 3043 namespace { | 3046 namespace { |
| 3044 | 3047 |
| 3045 static const char* kRestoredURLs[] = { | 3048 static const char* kRestoredURLs[] = { |
| 3046 "http://aaa.com/empty.html", | 3049 "http://aaa.com/empty.html", |
| 3047 "http://bbb.com/empty.html", | 3050 "http://bbb.com/empty.html", |
| 3048 }; | 3051 }; |
| 3049 | 3052 |
| 3050 bool IsNonSwitchArgument(const CommandLine::StringType& s) { | 3053 bool IsNonSwitchArgument(const base::CommandLine::StringType& s) { |
| 3051 return s.empty() || s[0] != '-'; | 3054 return s.empty() || s[0] != '-'; |
| 3052 } | 3055 } |
| 3053 | 3056 |
| 3054 } // namespace | 3057 } // namespace |
| 3055 | 3058 |
| 3056 // Similar to PolicyTest but allows setting policies before the browser is | 3059 // Similar to PolicyTest but allows setting policies before the browser is |
| 3057 // created. Each test parameter is a method that sets up the early policies | 3060 // created. Each test parameter is a method that sets up the early policies |
| 3058 // and stores the expected startup URLs in |expected_urls_|. | 3061 // and stores the expected startup URLs in |expected_urls_|. |
| 3059 class RestoreOnStartupPolicyTest | 3062 class RestoreOnStartupPolicyTest |
| 3060 : public PolicyTest, | 3063 : public PolicyTest, |
| 3061 public testing::WithParamInterface< | 3064 public testing::WithParamInterface< |
| 3062 void (RestoreOnStartupPolicyTest::*)(void)> { | 3065 void (RestoreOnStartupPolicyTest::*)(void)> { |
| 3063 public: | 3066 public: |
| 3064 RestoreOnStartupPolicyTest() {} | 3067 RestoreOnStartupPolicyTest() {} |
| 3065 virtual ~RestoreOnStartupPolicyTest() {} | 3068 virtual ~RestoreOnStartupPolicyTest() {} |
| 3066 | 3069 |
| 3067 #if defined(OS_CHROMEOS) | 3070 #if defined(OS_CHROMEOS) |
| 3068 virtual void SetUpCommandLine(CommandLine* command_line) override { | 3071 virtual void SetUpCommandLine(base::CommandLine* command_line) override { |
| 3069 // TODO(nkostylev): Investigate if we can remove this switch. | 3072 // TODO(nkostylev): Investigate if we can remove this switch. |
| 3070 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); | 3073 command_line->AppendSwitch(switches::kCreateBrowserOnStartupForTests); |
| 3071 PolicyTest::SetUpCommandLine(command_line); | 3074 PolicyTest::SetUpCommandLine(command_line); |
| 3072 } | 3075 } |
| 3073 #endif | 3076 #endif |
| 3074 | 3077 |
| 3075 void SetUpInProcessBrowserTestFixture() override { | 3078 void SetUpInProcessBrowserTestFixture() override { |
| 3076 PolicyTest::SetUpInProcessBrowserTestFixture(); | 3079 PolicyTest::SetUpInProcessBrowserTestFixture(); |
| 3077 // Set early policies now, before the browser is created. | 3080 // Set early policies now, before the browser is created. |
| 3078 (this->*(GetParam()))(); | 3081 (this->*(GetParam()))(); |
| 3079 | 3082 |
| 3080 // Remove the non-switch arguments, so that session restore kicks in for | 3083 // Remove the non-switch arguments, so that session restore kicks in for |
| 3081 // these tests. | 3084 // these tests. |
| 3082 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 3085 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 3083 CommandLine::StringVector argv = command_line->argv(); | 3086 base::CommandLine::StringVector argv = command_line->argv(); |
| 3084 argv.erase(std::remove_if(++argv.begin(), argv.end(), IsNonSwitchArgument), | 3087 argv.erase(std::remove_if(++argv.begin(), argv.end(), IsNonSwitchArgument), |
| 3085 argv.end()); | 3088 argv.end()); |
| 3086 command_line->InitFromArgv(argv); | 3089 command_line->InitFromArgv(argv); |
| 3087 ASSERT_TRUE(std::equal(argv.begin(), argv.end(), | 3090 ASSERT_TRUE(std::equal(argv.begin(), argv.end(), |
| 3088 command_line->argv().begin())); | 3091 command_line->argv().begin())); |
| 3089 } | 3092 } |
| 3090 | 3093 |
| 3091 void SetUpOnMainThread() override { | 3094 void SetUpOnMainThread() override { |
| 3092 BrowserThread::PostTask( | 3095 BrowserThread::PostTask( |
| 3093 BrowserThread::IO, | 3096 BrowserThread::IO, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3201 content::NotificationService::AllSources()); | 3204 content::NotificationService::AllSources()); |
| 3202 chrome::AddSelectedTabWithURL(browser(), GURL(kRestoredURLs[i]), | 3205 chrome::AddSelectedTabWithURL(browser(), GURL(kRestoredURLs[i]), |
| 3203 ui::PAGE_TRANSITION_LINK); | 3206 ui::PAGE_TRANSITION_LINK); |
| 3204 observer.Wait(); | 3207 observer.Wait(); |
| 3205 } | 3208 } |
| 3206 } | 3209 } |
| 3207 | 3210 |
| 3208 IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, RunTest) { | 3211 IN_PROC_BROWSER_TEST_P(RestoreOnStartupPolicyTest, RunTest) { |
| 3209 #if defined(OS_WIN) && defined(USE_ASH) | 3212 #if defined(OS_WIN) && defined(USE_ASH) |
| 3210 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 3213 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 3211 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 3214 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3215 switches::kAshBrowserTests)) |
| 3212 return; | 3216 return; |
| 3213 #endif | 3217 #endif |
| 3214 | 3218 |
| 3215 TabStripModel* model = browser()->tab_strip_model(); | 3219 TabStripModel* model = browser()->tab_strip_model(); |
| 3216 int size = static_cast<int>(expected_urls_.size()); | 3220 int size = static_cast<int>(expected_urls_.size()); |
| 3217 EXPECT_EQ(size, model->count()); | 3221 EXPECT_EQ(size, model->count()); |
| 3218 for (int i = 0; i < size && i < model->count(); ++i) { | 3222 for (int i = 0; i < size && i < model->count(); ++i) { |
| 3219 EXPECT_EQ(expected_urls_[i], model->GetWebContentsAt(i)->GetURL()); | 3223 EXPECT_EQ(expected_urls_[i], model->GetWebContentsAt(i)->GetURL()); |
| 3220 } | 3224 } |
| 3221 } | 3225 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 policies->Set(policy_name, | 3324 policies->Set(policy_name, |
| 3321 POLICY_LEVEL_MANDATORY, | 3325 POLICY_LEVEL_MANDATORY, |
| 3322 POLICY_SCOPE_USER, | 3326 POLICY_SCOPE_USER, |
| 3323 new base::FundamentalValue(policy_value_), | 3327 new base::FundamentalValue(policy_value_), |
| 3324 NULL); | 3328 NULL); |
| 3325 | 3329 |
| 3326 if (whitelist_policy) { | 3330 if (whitelist_policy) { |
| 3327 // TODO(tommi): Remove the kiosk mode flag when the whitelist is visible | 3331 // TODO(tommi): Remove the kiosk mode flag when the whitelist is visible |
| 3328 // in the media exceptions UI. | 3332 // in the media exceptions UI. |
| 3329 // See discussion here: https://codereview.chromium.org/15738004/ | 3333 // See discussion here: https://codereview.chromium.org/15738004/ |
| 3330 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kKioskMode); | 3334 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3335 switches::kKioskMode); |
| 3331 | 3336 |
| 3332 // Add an entry to the whitelist that allows the specified URL regardless | 3337 // Add an entry to the whitelist that allows the specified URL regardless |
| 3333 // of the setting of kAudioCapturedAllowed. | 3338 // of the setting of kAudioCapturedAllowed. |
| 3334 request_url_ = GURL("http://www.example.com/foo"); | 3339 request_url_ = GURL("http://www.example.com/foo"); |
| 3335 base::ListValue* list = new base::ListValue(); | 3340 base::ListValue* list = new base::ListValue(); |
| 3336 if (allow_rule) { | 3341 if (allow_rule) { |
| 3337 list->AppendString(allow_rule); | 3342 list->AppendString(allow_rule); |
| 3338 request_url_allowed_via_whitelist_ = true; | 3343 request_url_allowed_via_whitelist_ = true; |
| 3339 } else { | 3344 } else { |
| 3340 list->AppendString(ContentSettingsPattern::Wildcard().ToString()); | 3345 list->AppendString(ContentSettingsPattern::Wildcard().ToString()); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3622 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 3627 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 3623 browser2->tab_strip_model()->GetActiveWebContents(), | 3628 browser2->tab_strip_model()->GetActiveWebContents(), |
| 3624 "domAutomationController.send(window.showModalDialog !== undefined);", | 3629 "domAutomationController.send(window.showModalDialog !== undefined);", |
| 3625 &result)); | 3630 &result)); |
| 3626 EXPECT_TRUE(result); | 3631 EXPECT_TRUE(result); |
| 3627 } | 3632 } |
| 3628 | 3633 |
| 3629 #endif // !defined(CHROME_OS) | 3634 #endif // !defined(CHROME_OS) |
| 3630 | 3635 |
| 3631 } // namespace policy | 3636 } // namespace policy |
| OLD | NEW |