Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/browser/policy/policy_browsertest.cc

Issue 1391423002: net: Remove FilePath version of URLRequestMockHTTPJob::GetMockUrl(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix download_browsertest.cc typos Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 // Downloads a file named |file| and expects it to be saved to |dir|, which 371 // Downloads a file named |file| and expects it to be saved to |dir|, which
372 // must be empty. 372 // must be empty.
373 void DownloadAndVerifyFile( 373 void DownloadAndVerifyFile(
374 Browser* browser, const base::FilePath& dir, const base::FilePath& file) { 374 Browser* browser, const base::FilePath& dir, const base::FilePath& file) {
375 content::DownloadManager* download_manager = 375 content::DownloadManager* download_manager =
376 content::BrowserContext::GetDownloadManager(browser->profile()); 376 content::BrowserContext::GetDownloadManager(browser->profile());
377 content::DownloadTestObserverTerminal observer( 377 content::DownloadTestObserverTerminal observer(
378 download_manager, 1, 378 download_manager, 1,
379 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 379 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
380 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 380 GURL url(URLRequestMockHTTPJob::GetMockUrl(file.MaybeAsASCII()));
381 base::FilePath downloaded = dir.Append(file); 381 base::FilePath downloaded = dir.Append(file);
382 EXPECT_FALSE(base::PathExists(downloaded)); 382 EXPECT_FALSE(base::PathExists(downloaded));
383 ui_test_utils::NavigateToURL(browser, url); 383 ui_test_utils::NavigateToURL(browser, url);
384 observer.WaitForFinished(); 384 observer.WaitForFinished();
385 EXPECT_EQ( 385 EXPECT_EQ(
386 1u, observer.NumDownloadsSeenInState(content::DownloadItem::COMPLETE)); 386 1u, observer.NumDownloadsSeenInState(content::DownloadItem::COMPLETE));
387 EXPECT_TRUE(base::PathExists(downloaded)); 387 EXPECT_TRUE(base::PathExists(downloaded));
388 base::FileEnumerator enumerator(dir, false, base::FileEnumerator::FILES); 388 base::FileEnumerator enumerator(dir, false, base::FileEnumerator::FILES);
389 EXPECT_EQ(file, enumerator.Next().BaseName()); 389 EXPECT_EQ(file, enumerator.Next().BaseName());
390 EXPECT_EQ(base::FilePath(), enumerator.Next()); 390 EXPECT_EQ(base::FilePath(), enumerator.Next());
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 content::WindowedNotificationObserver observer( 1842 content::WindowedNotificationObserver observer(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 } 1936 }
1937 1937
1938 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) { 1938 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionRecommendedInstallationMode) {
1939 // Verifies that extensions that are recommended-installed by policies are 1939 // Verifies that extensions that are recommended-installed by policies are
1940 // installed, can be disabled but not uninstalled. 1940 // installed, can be disabled but not uninstalled.
1941 ExtensionService* service = extension_service(); 1941 ExtensionService* service = extension_service();
1942 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); 1942 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true));
1943 1943
1944 base::FilePath path = 1944 base::FilePath path =
1945 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); 1945 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
1946 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); 1946 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII()));
1947 1947
1948 // Setting the forcelist extension should install "good_v1.crx". 1948 // Setting the forcelist extension should install "good_v1.crx".
1949 base::DictionaryValue dict_value; 1949 base::DictionaryValue dict_value;
1950 dict_value.SetString(std::string(kGoodCrxId) + "." + 1950 dict_value.SetString(std::string(kGoodCrxId) + "." +
1951 extensions::schema_constants::kInstallationMode, 1951 extensions::schema_constants::kInstallationMode,
1952 extensions::schema_constants::kNormalInstalled); 1952 extensions::schema_constants::kNormalInstalled);
1953 dict_value.SetString( 1953 dict_value.SetString(
1954 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl, 1954 std::string(kGoodCrxId) + "." + extensions::schema_constants::kUpdateUrl,
1955 url.spec()); 1955 url.spec());
1956 PolicyMap policies; 1956 PolicyMap policies;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 // Flaky on windows; http://crbug.com/295729 . 2015 // Flaky on windows; http://crbug.com/295729 .
2016 #if defined(OS_WIN) 2016 #if defined(OS_WIN)
2017 #define MAYBE_ExtensionInstallSources DISABLED_ExtensionInstallSources 2017 #define MAYBE_ExtensionInstallSources DISABLED_ExtensionInstallSources
2018 #else 2018 #else
2019 #define MAYBE_ExtensionInstallSources ExtensionInstallSources 2019 #define MAYBE_ExtensionInstallSources ExtensionInstallSources
2020 #endif 2020 #endif
2021 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) { 2021 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallSources) {
2022 extensions::ScopedTestDialogAutoConfirm auto_confirm( 2022 extensions::ScopedTestDialogAutoConfirm auto_confirm(
2023 extensions::ScopedTestDialogAutoConfirm::ACCEPT); 2023 extensions::ScopedTestDialogAutoConfirm::ACCEPT);
2024 2024
2025 const GURL install_source_url(URLRequestMockHTTPJob::GetMockUrl( 2025 const GURL install_source_url(
2026 base::FilePath(FILE_PATH_LITERAL("extensions/*")))); 2026 URLRequestMockHTTPJob::GetMockUrl("extensions/*"));
2027 const GURL referrer_url(URLRequestMockHTTPJob::GetMockUrl( 2027 const GURL referrer_url(URLRequestMockHTTPJob::GetMockUrl("policy/*"));
2028 base::FilePath(FILE_PATH_LITERAL("policy/*"))));
2029 2028
2030 base::ScopedTempDir download_directory; 2029 base::ScopedTempDir download_directory;
2031 ASSERT_TRUE(download_directory.CreateUniqueTempDir()); 2030 ASSERT_TRUE(download_directory.CreateUniqueTempDir());
2032 DownloadPrefs* download_prefs = 2031 DownloadPrefs* download_prefs =
2033 DownloadPrefs::FromBrowserContext(browser()->profile()); 2032 DownloadPrefs::FromBrowserContext(browser()->profile());
2034 download_prefs->SetDownloadPath(download_directory.path()); 2033 download_prefs->SetDownloadPath(download_directory.path());
2035 2034
2036 const GURL download_page_url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath( 2035 const GURL download_page_url(URLRequestMockHTTPJob::GetMockUrl(
2037 FILE_PATH_LITERAL("policy/extension_install_sources_test.html")))); 2036 "policy/extension_install_sources_test.html"));
2038 ui_test_utils::NavigateToURL(browser(), download_page_url); 2037 ui_test_utils::NavigateToURL(browser(), download_page_url);
2039 2038
2040 // As long as the policy is not present, extensions are considered dangerous. 2039 // As long as the policy is not present, extensions are considered dangerous.
2041 content::DownloadTestObserverTerminal download_observer( 2040 content::DownloadTestObserverTerminal download_observer(
2042 content::BrowserContext::GetDownloadManager(browser()->profile()), 1, 2041 content::BrowserContext::GetDownloadManager(browser()->profile()), 1,
2043 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY); 2042 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY);
2044 PerformClick(0, 0); 2043 PerformClick(0, 0);
2045 download_observer.WaitForFinished(); 2044 download_observer.WaitForFinished();
2046 2045
2047 // Install the policy and trigger another download. 2046 // Install the policy and trigger another download.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2216 // set minimum version requirement is handled well. 2215 // set minimum version requirement is handled well.
2217 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) { 2216 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionMinimumVersionForceInstalled) {
2218 extensions::ExtensionRegistry* registry = 2217 extensions::ExtensionRegistry* registry =
2219 extensions::ExtensionRegistry::Get(browser()->profile()); 2218 extensions::ExtensionRegistry::Get(browser()->profile());
2220 extensions::ExtensionPrefs* extension_prefs = 2219 extensions::ExtensionPrefs* extension_prefs =
2221 extensions::ExtensionPrefs::Get(browser()->profile()); 2220 extensions::ExtensionPrefs::Get(browser()->profile());
2222 2221
2223 // Prepare the update URL for force installing. 2222 // Prepare the update URL for force installing.
2224 const base::FilePath path = 2223 const base::FilePath path =
2225 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); 2224 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName);
2226 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); 2225 const GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII()));
2227 2226
2228 // Set policy to force-install the extension, it should be installed and 2227 // Set policy to force-install the extension, it should be installed and
2229 // enabled. 2228 // enabled.
2230 content::WindowedNotificationObserver install_observer( 2229 content::WindowedNotificationObserver install_observer(
2231 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, 2230 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2232 content::NotificationService::AllSources()); 2231 content::NotificationService::AllSources());
2233 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId)); 2232 EXPECT_FALSE(registry->enabled_extensions().Contains(kGoodCrxId));
2234 { 2233 {
2235 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_); 2234 extensions::ExtensionManagementPolicyUpdater management_policy(&provider_);
2236 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId, 2235 management_policy.SetIndividualExtensionAutoInstalled(kGoodCrxId,
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)), 2586 base::Bind(UndoRedirectHostsToTestData, kURLS, arraysize(kURLS)),
2588 loop.QuitClosure()); 2587 loop.QuitClosure());
2589 loop.Run(); 2588 loop.Run();
2590 } 2589 }
2591 } 2590 }
2592 2591
2593 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistSubresources) { 2592 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklistSubresources) {
2594 // Checks that an image with a blacklisted URL is loaded, but an iframe with a 2593 // Checks that an image with a blacklisted URL is loaded, but an iframe with a
2595 // blacklisted URL is not. 2594 // blacklisted URL is not.
2596 2595
2597 GURL main_url = URLRequestMockHTTPJob::GetMockUrl( 2596 GURL main_url =
2598 base::FilePath(FILE_PATH_LITERAL("policy/blacklist-subresources.html"))); 2597 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html");
2599 GURL image_url = URLRequestMockHTTPJob::GetMockUrl( 2598 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png");
2600 base::FilePath(FILE_PATH_LITERAL("policy/pixel.png"))); 2599 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html");
2601 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl(
2602 base::FilePath(FILE_PATH_LITERAL("policy/blank.html")));
2603 2600
2604 // Set a blacklist containing the image and the iframe which are used by the 2601 // Set a blacklist containing the image and the iframe which are used by the
2605 // main document. 2602 // main document.
2606 base::ListValue blacklist; 2603 base::ListValue blacklist;
2607 blacklist.Append(new base::StringValue(image_url.spec().c_str())); 2604 blacklist.Append(new base::StringValue(image_url.spec().c_str()));
2608 blacklist.Append(new base::StringValue(subframe_url.spec().c_str())); 2605 blacklist.Append(new base::StringValue(subframe_url.spec().c_str()));
2609 PolicyMap policies; 2606 PolicyMap policies;
2610 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, 2607 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY,
2611 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(), 2608 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, blacklist.DeepCopy(),
2612 nullptr); 2609 nullptr);
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after
4001 POLICY_SCOPE_USER, 3998 POLICY_SCOPE_USER,
4002 POLICY_SOURCE_CLOUD, 3999 POLICY_SOURCE_CLOUD,
4003 new base::FundamentalValue(false), 4000 new base::FundamentalValue(false),
4004 NULL); 4001 NULL);
4005 UpdateProviderPolicy(policies); 4002 UpdateProviderPolicy(policies);
4006 EXPECT_FALSE(display_manager->unified_desktop_enabled()); 4003 EXPECT_FALSE(display_manager->unified_desktop_enabled());
4007 } 4004 }
4008 #endif // defined(OS_CHROMEOS) 4005 #endif // defined(OS_CHROMEOS)
4009 4006
4010 } // namespace policy 4007 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698