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 "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 371 |
372 // Downloads a file named |file| and expects it to be saved to |dir|, which | 372 // Downloads a file named |file| and expects it to be saved to |dir|, which |
373 // must be empty. | 373 // must be empty. |
374 void DownloadAndVerifyFile( | 374 void DownloadAndVerifyFile( |
375 Browser* browser, const base::FilePath& dir, const base::FilePath& file) { | 375 Browser* browser, const base::FilePath& dir, const base::FilePath& file) { |
376 content::DownloadManager* download_manager = | 376 content::DownloadManager* download_manager = |
377 content::BrowserContext::GetDownloadManager(browser->profile()); | 377 content::BrowserContext::GetDownloadManager(browser->profile()); |
378 content::DownloadTestObserverTerminal observer( | 378 content::DownloadTestObserverTerminal observer( |
379 download_manager, 1, | 379 download_manager, 1, |
380 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 380 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
381 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 381 GURL url(URLRequestMockHTTPJob::GetMockUrl(file.MaybeAsASCII())); |
382 base::FilePath downloaded = dir.Append(file); | 382 base::FilePath downloaded = dir.Append(file); |
383 EXPECT_FALSE(base::PathExists(downloaded)); | 383 EXPECT_FALSE(base::PathExists(downloaded)); |
384 ui_test_utils::NavigateToURL(browser, url); | 384 ui_test_utils::NavigateToURL(browser, url); |
385 observer.WaitForFinished(); | 385 observer.WaitForFinished(); |
386 EXPECT_EQ( | 386 EXPECT_EQ( |
387 1u, observer.NumDownloadsSeenInState(content::DownloadItem::COMPLETE)); | 387 1u, observer.NumDownloadsSeenInState(content::DownloadItem::COMPLETE)); |
388 EXPECT_TRUE(base::PathExists(downloaded)); | 388 EXPECT_TRUE(base::PathExists(downloaded)); |
389 base::FileEnumerator enumerator(dir, false, base::FileEnumerator::FILES); | 389 base::FileEnumerator enumerator(dir, false, base::FileEnumerator::FILES); |
390 EXPECT_EQ(file, enumerator.Next().BaseName()); | 390 EXPECT_EQ(file, enumerator.Next().BaseName()); |
391 EXPECT_EQ(base::FilePath(), enumerator.Next()); | 391 EXPECT_EQ(base::FilePath(), enumerator.Next()); |
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 // No plugins at startup. | 1518 // No plugins at startup. |
1519 EXPECT_EQ(0, CountPlugins()); | 1519 EXPECT_EQ(0, CountPlugins()); |
1520 | 1520 |
1521 content::WebContents* contents = | 1521 content::WebContents* contents = |
1522 browser()->tab_strip_model()->GetActiveWebContents(); | 1522 browser()->tab_strip_model()->GetActiveWebContents(); |
1523 ASSERT_TRUE(contents); | 1523 ASSERT_TRUE(contents); |
1524 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | 1524 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
1525 ASSERT_TRUE(infobar_service); | 1525 ASSERT_TRUE(infobar_service); |
1526 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1526 EXPECT_EQ(0u, infobar_service->infobar_count()); |
1527 | 1527 |
1528 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); | 1528 GURL url(URLRequestMockHTTPJob::GetMockUrl("plugin/quicktime.html")); |
1529 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | |
1530 ui_test_utils::NavigateToURL(browser(), url); | 1529 ui_test_utils::NavigateToURL(browser(), url); |
1531 // This should have triggered the dangerous plugin infobar. | 1530 // This should have triggered the dangerous plugin infobar. |
1532 ASSERT_EQ(1u, infobar_service->infobar_count()); | 1531 ASSERT_EQ(1u, infobar_service->infobar_count()); |
1533 EXPECT_TRUE( | 1532 EXPECT_TRUE( |
1534 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); | 1533 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); |
1535 // And the plugin isn't running. | 1534 // And the plugin isn't running. |
1536 EXPECT_EQ(0, CountPlugins()); | 1535 EXPECT_EQ(0, CountPlugins()); |
1537 | 1536 |
1538 // Now set a policy to always authorize this. | 1537 // Now set a policy to always authorize this. |
1539 PolicyMap policies; | 1538 PolicyMap policies; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 // Verify that the extensions are not installed initially. | 1727 // Verify that the extensions are not installed initially. |
1729 ExtensionService* service = extension_service(); | 1728 ExtensionService* service = extension_service(); |
1730 ASSERT_FALSE(service->GetExtensionById(kImporterId, true)); | 1729 ASSERT_FALSE(service->GetExtensionById(kImporterId, true)); |
1731 ASSERT_FALSE(service->GetExtensionById(kSharedModuleId, true)); | 1730 ASSERT_FALSE(service->GetExtensionById(kSharedModuleId, true)); |
1732 | 1731 |
1733 // Mock the webstore update URL. This is where the shared module extension | 1732 // Mock the webstore update URL. This is where the shared module extension |
1734 // will be installed from. | 1733 // will be installed from. |
1735 base::FilePath update_xml_path = base::FilePath(kTestExtensionsDir) | 1734 base::FilePath update_xml_path = base::FilePath(kTestExtensionsDir) |
1736 .AppendASCII("policy_shared_module") | 1735 .AppendASCII("policy_shared_module") |
1737 .AppendASCII("update.xml"); | 1736 .AppendASCII("update.xml"); |
1738 GURL update_xml_url(URLRequestMockHTTPJob::GetMockUrl(update_xml_path)); | 1737 GURL update_xml_url( |
| 1738 URLRequestMockHTTPJob::GetMockUrl(update_xml_path.MaybeAsASCII())); |
1739 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1739 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
1740 switches::kAppsGalleryUpdateURL, update_xml_url.spec()); | 1740 switches::kAppsGalleryUpdateURL, update_xml_url.spec()); |
1741 ui_test_utils::NavigateToURL(browser(), update_xml_url); | 1741 ui_test_utils::NavigateToURL(browser(), update_xml_url); |
1742 | 1742 |
1743 // Blacklist "*" but force-install the importer extension. The shared module | 1743 // Blacklist "*" but force-install the importer extension. The shared module |
1744 // should be automatically installed too. | 1744 // should be automatically installed too. |
1745 base::ListValue blacklist; | 1745 base::ListValue blacklist; |
1746 blacklist.AppendString("*"); | 1746 blacklist.AppendString("*"); |
1747 base::ListValue forcelist; | 1747 base::ListValue forcelist; |
1748 forcelist.AppendString( | 1748 forcelist.AppendString( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 // Verifies that extensions that are force-installed by policies are | 1822 // Verifies that extensions that are force-installed by policies are |
1823 // installed and can't be uninstalled. | 1823 // installed and can't be uninstalled. |
1824 ExtensionService* service = extension_service(); | 1824 ExtensionService* service = extension_service(); |
1825 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1825 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1826 | 1826 |
1827 // Extensions that are force-installed come from an update URL, which defaults | 1827 // Extensions that are force-installed come from an update URL, which defaults |
1828 // to the webstore. Use a mock URL for this test with an update manifest | 1828 // to the webstore. Use a mock URL for this test with an update manifest |
1829 // that includes "good_v1.crx". | 1829 // that includes "good_v1.crx". |
1830 base::FilePath path = | 1830 base::FilePath path = |
1831 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); | 1831 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
1832 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1832 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); |
1833 | 1833 |
1834 // Setting the forcelist extension should install "good_v1.crx". | 1834 // Setting the forcelist extension should install "good_v1.crx". |
1835 base::ListValue forcelist; | 1835 base::ListValue forcelist; |
1836 forcelist.Append(new base::StringValue( | 1836 forcelist.Append(new base::StringValue( |
1837 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); | 1837 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); |
1838 PolicyMap policies; | 1838 PolicyMap policies; |
1839 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1839 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
1840 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), | 1840 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, forcelist.DeepCopy(), |
1841 nullptr); | 1841 nullptr); |
1842 extensions::TestExtensionRegistryObserver observer( | 1842 extensions::TestExtensionRegistryObserver observer( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1934 } | 1934 } |
1935 | 1935 |
1936 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) { | 1936 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) { |
1937 // Verifies that extensions that are recommended-installed by policies are | 1937 // Verifies that extensions that are recommended-installed by policies are |
1938 // installed, can be disabled but not uninstalled. | 1938 // installed, can be disabled but not uninstalled. |
1939 ExtensionService* service = extension_service(); | 1939 ExtensionService* service = extension_service(); |
1940 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1940 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1941 | 1941 |
1942 base::FilePath path = | 1942 base::FilePath path = |
1943 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); | 1943 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
1944 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1944 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); |
1945 | 1945 |
1946 // Setting the forcelist extension should install "good_v1.crx". | 1946 // Setting the forcelist extension should install "good_v1.crx". |
1947 base::DictionaryValue dict_value; | 1947 base::DictionaryValue dict_value; |
1948 dict_value.SetString(std::string(kGoodCrxId) + "." + | 1948 dict_value.SetString(std::string(kGoodCrxId) + "." + |
1949 extensions::schema_constants::kInstallationMode, | 1949 extensions::schema_constants::kInstallationMode, |
1950 extensions::schema_constants::kNormalInstalled); | 1950 extensions::schema_constants::kNormalInstalled); |
1951 dict_value.SetString( | 1951 dict_value.SetString( |
1952 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, | 1952 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, |
1953 url.spec()); | 1953 url.spec()); |
1954 PolicyMap policies; | 1954 PolicyMap policies; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 // Flaky on windows; http://crbug.com/295729 . | 2012 // Flaky on windows; http://crbug.com/295729 . |
2013 #if defined(OS_WIN) | 2013 #if defined(OS_WIN) |
2014 #define MAYBE_ExtensionInstallSources DISABLED_ExtensionInstallSources | 2014 #define MAYBE_ExtensionInstallSources DISABLED_ExtensionInstallSources |
2015 #else | 2015 #else |
2016 #define MAYBE_ExtensionInstallSources ExtensionInstallSources | 2016 #define MAYBE_ExtensionInstallSources ExtensionInstallSources |
2017 #endif | 2017 #endif |
2018 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) { | 2018 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) { |
2019 extensions::ScopedTestDialogAutoConfirm auto_confirm( | 2019 extensions::ScopedTestDialogAutoConfirm auto_confirm( |
2020 extensions::ScopedTestDialogAutoConfirm::ACCEPT); | 2020 extensions::ScopedTestDialogAutoConfirm::ACCEPT); |
2021 | 2021 |
2022 const GURL install_source_url(URLRequestMockHTTPJob::GetMockUrl( | 2022 const GURL install_source_url( |
2023 base::FilePath(FILE_PATH_LITERAL("extensions/*")))); | 2023 URLRequestMockHTTPJob::GetMockUrl("extensions/*")); |
2024 const GURL referrer_url(URLRequestMockHTTPJob::GetMockUrl( | 2024 const GURL referrer_url(URLRequestMockHTTPJob::GetMockUrl("policy/*")); |
2025 base::FilePath(FILE_PATH_LITERAL("policy/*")))); | |
2026 | 2025 |
2027 base::ScopedTempDir download_directory; | 2026 base::ScopedTempDir download_directory; |
2028 ASSERT_TRUE(download_directory.CreateUniqueTempDir()); | 2027 ASSERT_TRUE(download_directory.CreateUniqueTempDir()); |
2029 DownloadPrefs* download_prefs = | 2028 DownloadPrefs* download_prefs = |
2030 DownloadPrefs::FromBrowserContext(browser()->profile()); | 2029 DownloadPrefs::FromBrowserContext(browser()->profile()); |
2031 download_prefs->SetDownloadPath(download_directory.path()); | 2030 download_prefs->SetDownloadPath(download_directory.path()); |
2032 | 2031 |
2033 const GURL download_page_url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath( | 2032 const GURL download_page_url(URLRequestMockHTTPJob::GetMockUrl( |
2034 FILE_PATH_LITERAL("policy/extension_install_sources_test.html")))); | 2033 "policy/extension_install_sources_test.html")); |
2035 ui_test_utils::NavigateToURL(browser(), download_page_url); | 2034 ui_test_utils::NavigateToURL(browser(), download_page_url); |
2036 | 2035 |
2037 // As long as the policy is not present, extensions are considered dangerous. | 2036 // As long as the policy is not present, extensions are considered dangerous. |
2038 content::DownloadTestObserverTerminal download_observer( | 2037 content::DownloadTestObserverTerminal download_observer( |
2039 content::BrowserContext::GetDownloadManager(browser()->profile()), 1, | 2038 content::BrowserContext::GetDownloadManager(browser()->profile()), 1, |
2040 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY); | 2039 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY); |
2041 PerformClick(0, 0); | 2040 PerformClick(0, 0); |
2042 download_observer.WaitForFinished(); | 2041 download_observer.WaitForFinished(); |
2043 | 2042 |
2044 // Install the policy and trigger another download. | 2043 // Install the policy and trigger another download. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 // set minimum version requirement is handled well. | 2209 // set minimum version requirement is handled well. |
2211 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) { | 2210 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) { |
2212 extensions::ExtensionRegistry* registry = | 2211 extensions::ExtensionRegistry* registry = |
2213 extensions::ExtensionRegistry::Get(browser()->profile()); | 2212 extensions::ExtensionRegistry::Get(browser()->profile()); |
2214 extensions::ExtensionPrefs* extension_prefs = | 2213 extensions::ExtensionPrefs* extension_prefs = |
2215 extensions::ExtensionPrefs::Get(browser()->profile()); | 2214 extensions::ExtensionPrefs::Get(browser()->profile()); |
2216 | 2215 |
2217 // Prepare the update URL for force installing. | 2216 // Prepare the update URL for force installing. |
2218 const base::FilePath path = | 2217 const base::FilePath path = |
2219 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); | 2218 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
2220 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 2219 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); |
2221 | 2220 |
2222 // Set policy to force-install the extension, it should be installed and | 2221 // Set policy to force-install the extension, it should be installed and |
2223 // enabled. | 2222 // enabled. |
2224 extensions::TestExtensionRegistryObserver install_observer( | 2223 extensions::TestExtensionRegistryObserver install_observer( |
2225 extensions::ExtensionRegistry::Get(browser()->profile())); | 2224 extensions::ExtensionRegistry::Get(browser()->profile())); |
2226 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); | 2225 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); |
2227 { | 2226 { |
2228 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); | 2227 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); |
2229 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, | 2228 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, |
2230 url.spec(), true); | 2229 url.spec(), true); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2580 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), | 2579 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), |
2581 loop.QuitClosure()); | 2580 loop.QuitClosure()); |
2582 loop.Run(); | 2581 loop.Run(); |
2583 } | 2582 } |
2584 } | 2583 } |
2585 | 2584 |
2586 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistSubresources) { | 2585 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistSubresources) { |
2587 // Checks that an image with a blacklisted URL is loaded, but an iframe with a | 2586 // Checks that an image with a blacklisted URL is loaded, but an iframe with a |
2588 // blacklisted URL is not. | 2587 // blacklisted URL is not. |
2589 | 2588 |
2590 GURL main_url = URLRequestMockHTTPJob::GetMockUrl( | 2589 GURL main_url = |
2591 base::FilePath(FILE_PATH_LITERAL("policy/blacklist-subresources.html"))); | 2590 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html"); |
2592 GURL image_url = URLRequestMockHTTPJob::GetMockUrl( | 2591 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png"); |
2593 base::FilePath(FILE_PATH_LITERAL("policy/pixel.png"))); | 2592 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html"); |
2594 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl( | |
2595 base::FilePath(FILE_PATH_LITERAL("policy/blank.html"))); | |
2596 | 2593 |
2597 // Set a blacklist containing the image and the iframe which are used by the | 2594 // Set a blacklist containing the image and the iframe which are used by the |
2598 // main document. | 2595 // main document. |
2599 base::ListValue blacklist; | 2596 base::ListValue blacklist; |
2600 blacklist.Append(new base::StringValue(image_url.spec().c_str())); | 2597 blacklist.Append(new base::StringValue(image_url.spec().c_str())); |
2601 blacklist.Append(new base::StringValue(subframe_url.spec().c_str())); | 2598 blacklist.Append(new base::StringValue(subframe_url.spec().c_str())); |
2602 PolicyMap policies; | 2599 PolicyMap policies; |
2603 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, | 2600 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, |
2604 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), | 2601 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), |
2605 nullptr); | 2602 nullptr); |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3994 POLICY_SCOPE_USER, | 3991 POLICY_SCOPE_USER, |
3995 POLICY_SOURCE_CLOUD, | 3992 POLICY_SOURCE_CLOUD, |
3996 new base::FundamentalValue(false), | 3993 new base::FundamentalValue(false), |
3997 NULL); | 3994 NULL); |
3998 UpdateProviderPolicy(policies); | 3995 UpdateProviderPolicy(policies); |
3999 EXPECT_FALSE(display_manager->unified_desktop_enabled()); | 3996 EXPECT_FALSE(display_manager->unified_desktop_enabled()); |
4000 } | 3997 } |
4001 #endif // defined(OS_CHROMEOS) | 3998 #endif // defined(OS_CHROMEOS) |
4002 | 3999 |
4003 } // namespace policy | 4000 } // namespace policy |
OLD | NEW |