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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 PluginPrefs* plugin_prefs = | 1365 PluginPrefs* plugin_prefs = |
1366 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1366 PluginPrefs::GetForProfile(browser()->profile()).get(); |
1367 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1367 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1368 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1368 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
1369 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1369 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1370 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 1370 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
1371 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1371 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1372 | 1372 |
1373 // Now disable it with a policy. | 1373 // Now disable it with a policy. |
1374 base::ListValue disabled_plugins; | 1374 base::ListValue disabled_plugins; |
1375 disabled_plugins.Append(new base::StringValue("*Flash*")); | 1375 disabled_plugins.AppendString("*Flash*"); |
1376 PolicyMap policies; | 1376 PolicyMap policies; |
1377 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 1377 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
1378 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr); | 1378 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr); |
1379 UpdateProviderPolicy(policies); | 1379 UpdateProviderPolicy(policies); |
1380 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1380 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1381 // The user shouldn't be able to enable it. | 1381 // The user shouldn't be able to enable it. |
1382 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); | 1382 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); |
1383 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1383 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1384 } | 1384 } |
1385 | 1385 |
1386 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { | 1386 IN_PROC_BROWSER_TEST_F(PolicyTest, DisabledPluginsExceptions) { |
1387 // Verifies that plugins with an exception in the blacklist can be enabled. | 1387 // Verifies that plugins with an exception in the blacklist can be enabled. |
1388 | 1388 |
1389 // Verify that the Flash plugin exists and that it can be enabled and disabled | 1389 // Verify that the Flash plugin exists and that it can be enabled and disabled |
1390 // by the user. | 1390 // by the user. |
1391 std::vector<content::WebPluginInfo> plugins; | 1391 std::vector<content::WebPluginInfo> plugins; |
1392 GetPluginList(&plugins); | 1392 GetPluginList(&plugins); |
1393 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1393 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); |
1394 if (!flash) | 1394 if (!flash) |
1395 return; | 1395 return; |
1396 PluginPrefs* plugin_prefs = | 1396 PluginPrefs* plugin_prefs = |
1397 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1397 PluginPrefs::GetForProfile(browser()->profile()).get(); |
1398 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1398 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1399 | 1399 |
1400 // Disable all plugins. | 1400 // Disable all plugins. |
1401 base::ListValue disabled_plugins; | 1401 base::ListValue disabled_plugins; |
1402 disabled_plugins.Append(new base::StringValue("*")); | 1402 disabled_plugins.AppendString("*"); |
1403 PolicyMap policies; | 1403 PolicyMap policies; |
1404 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 1404 policies.Set(key::kDisabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
1405 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr); | 1405 POLICY_SOURCE_CLOUD, disabled_plugins.CreateDeepCopy(), nullptr); |
1406 UpdateProviderPolicy(policies); | 1406 UpdateProviderPolicy(policies); |
1407 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1407 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1408 // The user shouldn't be able to enable it. | 1408 // The user shouldn't be able to enable it. |
1409 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); | 1409 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, true)); |
1410 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1410 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1411 | 1411 |
1412 // Now open an exception for flash. | 1412 // Now open an exception for flash. |
1413 base::ListValue disabled_plugins_exceptions; | 1413 base::ListValue disabled_plugins_exceptions; |
1414 disabled_plugins_exceptions.Append(new base::StringValue("*Flash*")); | 1414 disabled_plugins_exceptions.AppendString("*Flash*"); |
1415 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY, | 1415 policies.Set(key::kDisabledPluginsExceptions, POLICY_LEVEL_MANDATORY, |
1416 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1416 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1417 disabled_plugins_exceptions.CreateDeepCopy(), nullptr); | 1417 disabled_plugins_exceptions.CreateDeepCopy(), nullptr); |
1418 UpdateProviderPolicy(policies); | 1418 UpdateProviderPolicy(policies); |
1419 // It should revert to the user's preference automatically. | 1419 // It should revert to the user's preference automatically. |
1420 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1420 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1421 // And the user should be able to disable and enable again. | 1421 // And the user should be able to disable and enable again. |
1422 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1422 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
1423 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1423 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1424 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); | 1424 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, true)); |
1425 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1425 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1426 } | 1426 } |
1427 | 1427 |
1428 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { | 1428 IN_PROC_BROWSER_TEST_F(PolicyTest, EnabledPlugins) { |
1429 // Verifies that a plugin can be force-installed with a policy. | 1429 // Verifies that a plugin can be force-installed with a policy. |
1430 std::vector<content::WebPluginInfo> plugins; | 1430 std::vector<content::WebPluginInfo> plugins; |
1431 GetPluginList(&plugins); | 1431 GetPluginList(&plugins); |
1432 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); | 1432 const content::WebPluginInfo* flash = GetFlashPlugin(plugins); |
1433 if (!flash) | 1433 if (!flash) |
1434 return; | 1434 return; |
1435 PluginPrefs* plugin_prefs = | 1435 PluginPrefs* plugin_prefs = |
1436 PluginPrefs::GetForProfile(browser()->profile()).get(); | 1436 PluginPrefs::GetForProfile(browser()->profile()).get(); |
1437 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1437 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1438 | 1438 |
1439 // The user disables it and then a policy forces it to be enabled. | 1439 // The user disables it and then a policy forces it to be enabled. |
1440 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); | 1440 EXPECT_TRUE(SetPluginEnabled(plugin_prefs, flash, false)); |
1441 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); | 1441 EXPECT_FALSE(plugin_prefs->IsPluginEnabled(*flash)); |
1442 base::ListValue plugin_list; | 1442 base::ListValue plugin_list; |
1443 plugin_list.Append(new base::StringValue(content::kFlashPluginName)); | 1443 plugin_list.AppendString(content::kFlashPluginName); |
1444 PolicyMap policies; | 1444 PolicyMap policies; |
1445 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 1445 policies.Set(key::kEnabledPlugins, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
1446 POLICY_SOURCE_CLOUD, plugin_list.CreateDeepCopy(), nullptr); | 1446 POLICY_SOURCE_CLOUD, plugin_list.CreateDeepCopy(), nullptr); |
1447 UpdateProviderPolicy(policies); | 1447 UpdateProviderPolicy(policies); |
1448 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1448 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1449 // The user can't disable it anymore. | 1449 // The user can't disable it anymore. |
1450 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false)); | 1450 EXPECT_FALSE(SetPluginEnabled(plugin_prefs, flash, false)); |
1451 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); | 1451 EXPECT_TRUE(plugin_prefs->IsPluginEnabled(*flash)); |
1452 | 1452 |
1453 // When a plugin is both enabled and disabled, the whitelist takes precedence. | 1453 // When a plugin is both enabled and disabled, the whitelist takes precedence. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 // Verify that the first download location wasn't affected. | 1598 // Verify that the first download location wasn't affected. |
1599 EXPECT_FALSE(base::PathExists(initial_dir.path().Append(file))); | 1599 EXPECT_FALSE(base::PathExists(initial_dir.path().Append(file))); |
1600 } | 1600 } |
1601 | 1601 |
1602 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSelective) { | 1602 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallBlacklistSelective) { |
1603 // Verifies that blacklisted extensions can't be installed. | 1603 // Verifies that blacklisted extensions can't be installed. |
1604 ExtensionService* service = extension_service(); | 1604 ExtensionService* service = extension_service(); |
1605 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1605 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1606 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1606 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1607 base::ListValue blacklist; | 1607 base::ListValue blacklist; |
1608 blacklist.Append(new base::StringValue(kGoodCrxId)); | 1608 blacklist.AppendString(kGoodCrxId); |
1609 PolicyMap policies; | 1609 PolicyMap policies; |
1610 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1610 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1611 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1611 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1612 blacklist.CreateDeepCopy(), nullptr); | 1612 blacklist.CreateDeepCopy(), nullptr); |
1613 UpdateProviderPolicy(policies); | 1613 UpdateProviderPolicy(policies); |
1614 | 1614 |
1615 // "good.crx" is blacklisted. | 1615 // "good.crx" is blacklisted. |
1616 EXPECT_FALSE(InstallExtension(kGoodCrxName)); | 1616 EXPECT_FALSE(InstallExtension(kGoodCrxName)); |
1617 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1617 EXPECT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1618 | 1618 |
(...skipping 11 matching lines...) Expand all Loading... |
1630 #else | 1630 #else |
1631 #define MAYBE_ExtensionInstallBlacklistWildcard ExtensionInstallBlacklistWildcar
d | 1631 #define MAYBE_ExtensionInstallBlacklistWildcard ExtensionInstallBlacklistWildcar
d |
1632 #endif | 1632 #endif |
1633 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallBlacklistWildcard) { | 1633 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_ExtensionInstallBlacklistWildcard) { |
1634 // Verify that a wildcard blacklist takes effect. | 1634 // Verify that a wildcard blacklist takes effect. |
1635 EXPECT_TRUE(InstallExtension(kAdBlockCrxName)); | 1635 EXPECT_TRUE(InstallExtension(kAdBlockCrxName)); |
1636 ExtensionService* service = extension_service(); | 1636 ExtensionService* service = extension_service(); |
1637 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1637 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1638 ASSERT_TRUE(service->GetExtensionById(kAdBlockCrxId, true)); | 1638 ASSERT_TRUE(service->GetExtensionById(kAdBlockCrxId, true)); |
1639 base::ListValue blacklist; | 1639 base::ListValue blacklist; |
1640 blacklist.Append(new base::StringValue("*")); | 1640 blacklist.AppendString("*"); |
1641 PolicyMap policies; | 1641 PolicyMap policies; |
1642 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1642 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1643 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1643 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1644 blacklist.CreateDeepCopy(), nullptr); | 1644 blacklist.CreateDeepCopy(), nullptr); |
1645 UpdateProviderPolicy(policies); | 1645 UpdateProviderPolicy(policies); |
1646 | 1646 |
1647 // AdBlock was automatically removed. | 1647 // AdBlock was automatically removed. |
1648 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1648 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1649 | 1649 |
1650 // And can't be installed again, nor can good.crx. | 1650 // And can't be installed again, nor can good.crx. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 ASSERT_EQ(1u, imports.size()); | 1728 ASSERT_EQ(1u, imports.size()); |
1729 EXPECT_EQ(kSharedModuleId, imports[0].extension_id); | 1729 EXPECT_EQ(kSharedModuleId, imports[0].extension_id); |
1730 } | 1730 } |
1731 | 1731 |
1732 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallWhitelist) { | 1732 IN_PROC_BROWSER_TEST_F(PolicyTest, ExtensionInstallWhitelist) { |
1733 // Verifies that the whitelist can open exceptions to the blacklist. | 1733 // Verifies that the whitelist can open exceptions to the blacklist. |
1734 ExtensionService* service = extension_service(); | 1734 ExtensionService* service = extension_service(); |
1735 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); | 1735 ASSERT_FALSE(service->GetExtensionById(kGoodCrxId, true)); |
1736 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); | 1736 ASSERT_FALSE(service->GetExtensionById(kAdBlockCrxId, true)); |
1737 base::ListValue blacklist; | 1737 base::ListValue blacklist; |
1738 blacklist.Append(new base::StringValue("*")); | 1738 blacklist.AppendString("*"); |
1739 base::ListValue whitelist; | 1739 base::ListValue whitelist; |
1740 whitelist.Append(new base::StringValue(kGoodCrxId)); | 1740 whitelist.AppendString(kGoodCrxId); |
1741 PolicyMap policies; | 1741 PolicyMap policies; |
1742 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, | 1742 policies.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, |
1743 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1743 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1744 blacklist.CreateDeepCopy(), nullptr); | 1744 blacklist.CreateDeepCopy(), nullptr); |
1745 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, | 1745 policies.Set(key::kExtensionInstallWhitelist, POLICY_LEVEL_MANDATORY, |
1746 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1746 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1747 whitelist.CreateDeepCopy(), nullptr); | 1747 whitelist.CreateDeepCopy(), nullptr); |
1748 UpdateProviderPolicy(policies); | 1748 UpdateProviderPolicy(policies); |
1749 // "adblock.crx" is blacklisted. | 1749 // "adblock.crx" is blacklisted. |
1750 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); | 1750 EXPECT_FALSE(InstallExtension(kAdBlockCrxName)); |
(...skipping 15 matching lines...) Expand all Loading... |
1766 | 1766 |
1767 // Extensions that are force-installed come from an update URL, which defaults | 1767 // Extensions that are force-installed come from an update URL, which defaults |
1768 // to the webstore. Use a mock URL for this test with an update manifest | 1768 // to the webstore. Use a mock URL for this test with an update manifest |
1769 // that includes "good_v1.crx". | 1769 // that includes "good_v1.crx". |
1770 base::FilePath path = | 1770 base::FilePath path = |
1771 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); | 1771 base::FilePath(kTestExtensionsDir).Append(kGoodV1CrxManifestName); |
1772 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); | 1772 GURL url(URLRequestMockHTTPJob::GetMockUrl(path.MaybeAsASCII())); |
1773 | 1773 |
1774 // Setting the forcelist extension should install "good_v1.crx". | 1774 // Setting the forcelist extension should install "good_v1.crx". |
1775 base::ListValue forcelist; | 1775 base::ListValue forcelist; |
1776 forcelist.Append(new base::StringValue( | 1776 forcelist.AppendString( |
1777 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str()))); | 1777 base::StringPrintf("%s;%s", kGoodCrxId, url.spec().c_str())); |
1778 PolicyMap policies; | 1778 PolicyMap policies; |
1779 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, | 1779 policies.Set(key::kExtensionInstallForcelist, POLICY_LEVEL_MANDATORY, |
1780 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 1780 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
1781 forcelist.CreateDeepCopy(), nullptr); | 1781 forcelist.CreateDeepCopy(), nullptr); |
1782 extensions::TestExtensionRegistryObserver observer( | 1782 extensions::TestExtensionRegistryObserver observer( |
1783 extensions::ExtensionRegistry::Get(browser()->profile())); | 1783 extensions::ExtensionRegistry::Get(browser()->profile())); |
1784 UpdateProviderPolicy(policies); | 1784 UpdateProviderPolicy(policies); |
1785 observer.WaitForExtensionWillBeInstalled(); | 1785 observer.WaitForExtensionWillBeInstalled(); |
1786 // Note: Cannot check that the notification details match the expected | 1786 // Note: Cannot check that the notification details match the expected |
1787 // exception, since the details object has already been freed prior to | 1787 // exception, since the details object has already been freed prior to |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 base::Bind(RedirectHostsToTestData, kURLS, arraysize(kURLS)), | 2436 base::Bind(RedirectHostsToTestData, kURLS, arraysize(kURLS)), |
2437 loop.QuitClosure()); | 2437 loop.QuitClosure()); |
2438 loop.Run(); | 2438 loop.Run(); |
2439 } | 2439 } |
2440 | 2440 |
2441 // Verify that "bbb.com" opens before applying the blacklist. | 2441 // Verify that "bbb.com" opens before applying the blacklist. |
2442 CheckCanOpenURL(browser(), kURLS[1]); | 2442 CheckCanOpenURL(browser(), kURLS[1]); |
2443 | 2443 |
2444 // Set a blacklist. | 2444 // Set a blacklist. |
2445 base::ListValue blacklist; | 2445 base::ListValue blacklist; |
2446 blacklist.Append(new base::StringValue("bbb.com")); | 2446 blacklist.AppendString("bbb.com"); |
2447 PolicyMap policies; | 2447 PolicyMap policies; |
2448 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2448 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2449 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); | 2449 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
2450 UpdateProviderPolicy(policies); | 2450 UpdateProviderPolicy(policies); |
2451 FlushBlacklistPolicy(); | 2451 FlushBlacklistPolicy(); |
2452 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. | 2452 // All bbb.com URLs are blocked, and "aaa.com" is still unblocked. |
2453 CheckCanOpenURL(browser(), kURLS[0]); | 2453 CheckCanOpenURL(browser(), kURLS[0]); |
2454 for (size_t i = 1; i < arraysize(kURLS); ++i) | 2454 for (size_t i = 1; i < arraysize(kURLS); ++i) |
2455 CheckURLIsBlocked(browser(), kURLS[i]); | 2455 CheckURLIsBlocked(browser(), kURLS[i]); |
2456 | 2456 |
2457 // Whitelist some sites of bbb.com. | 2457 // Whitelist some sites of bbb.com. |
2458 base::ListValue whitelist; | 2458 base::ListValue whitelist; |
2459 whitelist.Append(new base::StringValue("sub.bbb.com")); | 2459 whitelist.AppendString("sub.bbb.com"); |
2460 whitelist.Append(new base::StringValue("bbb.com/policy")); | 2460 whitelist.AppendString("bbb.com/policy"); |
2461 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2461 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2462 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); | 2462 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
2463 UpdateProviderPolicy(policies); | 2463 UpdateProviderPolicy(policies); |
2464 FlushBlacklistPolicy(); | 2464 FlushBlacklistPolicy(); |
2465 CheckURLIsBlocked(browser(), kURLS[1]); | 2465 CheckURLIsBlocked(browser(), kURLS[1]); |
2466 CheckCanOpenURL(browser(), kURLS[2]); | 2466 CheckCanOpenURL(browser(), kURLS[2]); |
2467 CheckCanOpenURL(browser(), kURLS[3]); | 2467 CheckCanOpenURL(browser(), kURLS[3]); |
2468 CheckCanOpenURL(browser(), kURLS[4]); | 2468 CheckCanOpenURL(browser(), kURLS[4]); |
2469 | 2469 |
2470 { | 2470 { |
(...skipping 11 matching lines...) Expand all Loading... |
2482 // blacklisted URL is not. | 2482 // blacklisted URL is not. |
2483 | 2483 |
2484 GURL main_url = | 2484 GURL main_url = |
2485 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html"); | 2485 URLRequestMockHTTPJob::GetMockUrl("policy/blacklist-subresources.html"); |
2486 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png"); | 2486 GURL image_url = URLRequestMockHTTPJob::GetMockUrl("policy/pixel.png"); |
2487 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html"); | 2487 GURL subframe_url = URLRequestMockHTTPJob::GetMockUrl("policy/blank.html"); |
2488 | 2488 |
2489 // Set a blacklist containing the image and the iframe which are used by the | 2489 // Set a blacklist containing the image and the iframe which are used by the |
2490 // main document. | 2490 // main document. |
2491 base::ListValue blacklist; | 2491 base::ListValue blacklist; |
2492 blacklist.Append(new base::StringValue(image_url.spec().c_str())); | 2492 blacklist.AppendString(image_url.spec().c_str()); |
2493 blacklist.Append(new base::StringValue(subframe_url.spec().c_str())); | 2493 blacklist.AppendString(subframe_url.spec().c_str()); |
2494 PolicyMap policies; | 2494 PolicyMap policies; |
2495 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2495 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2496 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); | 2496 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
2497 UpdateProviderPolicy(policies); | 2497 UpdateProviderPolicy(policies); |
2498 FlushBlacklistPolicy(); | 2498 FlushBlacklistPolicy(); |
2499 | 2499 |
2500 std::string blacklisted_image_load_result; | 2500 std::string blacklisted_image_load_result; |
2501 ui_test_utils::NavigateToURL(browser(), main_url); | 2501 ui_test_utils::NavigateToURL(browser(), main_url); |
2502 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 2502 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
2503 browser()->tab_strip_model()->GetActiveWebContents(), | 2503 browser()->tab_strip_model()->GetActiveWebContents(), |
(...skipping 25 matching lines...) Expand all Loading... |
2529 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; | 2529 const std::string base_path = "file://" + test_path.AsUTF8Unsafe() +"/"; |
2530 const std::string folder_path = base_path + "apptest/"; | 2530 const std::string folder_path = base_path + "apptest/"; |
2531 const std::string file_path1 = base_path + "title1.html"; | 2531 const std::string file_path1 = base_path + "title1.html"; |
2532 const std::string file_path2 = folder_path + "basic.html"; | 2532 const std::string file_path2 = folder_path + "basic.html"; |
2533 | 2533 |
2534 CheckCanOpenURL(browser(), file_path1.c_str()); | 2534 CheckCanOpenURL(browser(), file_path1.c_str()); |
2535 CheckCanOpenURL(browser(), file_path2.c_str()); | 2535 CheckCanOpenURL(browser(), file_path2.c_str()); |
2536 | 2536 |
2537 // Set a blacklist for all the files. | 2537 // Set a blacklist for all the files. |
2538 base::ListValue blacklist; | 2538 base::ListValue blacklist; |
2539 blacklist.Append(new base::StringValue("file://*")); | 2539 blacklist.AppendString("file://*"); |
2540 PolicyMap policies; | 2540 PolicyMap policies; |
2541 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2541 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2542 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); | 2542 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
2543 UpdateProviderPolicy(policies); | 2543 UpdateProviderPolicy(policies); |
2544 FlushBlacklistPolicy(); | 2544 FlushBlacklistPolicy(); |
2545 | 2545 |
2546 CheckURLIsBlocked(browser(), file_path1.c_str()); | 2546 CheckURLIsBlocked(browser(), file_path1.c_str()); |
2547 CheckURLIsBlocked(browser(), file_path2.c_str()); | 2547 CheckURLIsBlocked(browser(), file_path2.c_str()); |
2548 | 2548 |
2549 // Replace the URLblacklist with disabling the file scheme. | 2549 // Replace the URLblacklist with disabling the file scheme. |
2550 blacklist.Remove(base::StringValue("file://*"), NULL); | 2550 blacklist.Remove(base::StringValue("file://*"), NULL); |
2551 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2551 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2552 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); | 2552 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
2553 UpdateProviderPolicy(policies); | 2553 UpdateProviderPolicy(policies); |
2554 FlushBlacklistPolicy(); | 2554 FlushBlacklistPolicy(); |
2555 | 2555 |
2556 PrefService* prefs = browser()->profile()->GetPrefs(); | 2556 PrefService* prefs = browser()->profile()->GetPrefs(); |
2557 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); | 2557 const base::ListValue* list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
2558 EXPECT_EQ(list_url->Find(base::StringValue("file://*")), | 2558 EXPECT_EQ(list_url->Find(base::StringValue("file://*")), |
2559 list_url->end()); | 2559 list_url->end()); |
2560 | 2560 |
2561 base::ListValue disabledscheme; | 2561 base::ListValue disabledscheme; |
2562 disabledscheme.Append(new base::StringValue("file")); | 2562 disabledscheme.AppendString("file"); |
2563 policies.Set(key::kDisabledSchemes, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2563 policies.Set(key::kDisabledSchemes, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2564 POLICY_SOURCE_CLOUD, disabledscheme.CreateDeepCopy(), nullptr); | 2564 POLICY_SOURCE_CLOUD, disabledscheme.CreateDeepCopy(), nullptr); |
2565 UpdateProviderPolicy(policies); | 2565 UpdateProviderPolicy(policies); |
2566 FlushBlacklistPolicy(); | 2566 FlushBlacklistPolicy(); |
2567 | 2567 |
2568 list_url = prefs->GetList(policy_prefs::kUrlBlacklist); | 2568 list_url = prefs->GetList(policy_prefs::kUrlBlacklist); |
2569 EXPECT_NE(list_url->Find(base::StringValue("file://*")), | 2569 EXPECT_NE(list_url->Find(base::StringValue("file://*")), |
2570 list_url->end()); | 2570 list_url->end()); |
2571 | 2571 |
2572 // Whitelist one folder and blacklist an another just inside. | 2572 // Whitelist one folder and blacklist an another just inside. |
2573 base::ListValue whitelist; | 2573 base::ListValue whitelist; |
2574 whitelist.Append(new base::StringValue(base_path)); | 2574 whitelist.AppendString(base_path); |
2575 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2575 policies.Set(key::kURLWhitelist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2576 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); | 2576 POLICY_SOURCE_CLOUD, whitelist.CreateDeepCopy(), nullptr); |
2577 blacklist.Append(new base::StringValue(folder_path)); | 2577 blacklist.AppendString(folder_path); |
2578 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 2578 policies.Set(key::kURLBlacklist, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
2579 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); | 2579 POLICY_SOURCE_CLOUD, blacklist.CreateDeepCopy(), nullptr); |
2580 UpdateProviderPolicy(policies); | 2580 UpdateProviderPolicy(policies); |
2581 FlushBlacklistPolicy(); | 2581 FlushBlacklistPolicy(); |
2582 | 2582 |
2583 CheckCanOpenURL(browser(), file_path1.c_str()); | 2583 CheckCanOpenURL(browser(), file_path1.c_str()); |
2584 CheckURLIsBlocked(browser(), file_path2.c_str()); | 2584 CheckURLIsBlocked(browser(), file_path2.c_str()); |
2585 } | 2585 } |
2586 | 2586 |
2587 namespace { | 2587 namespace { |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3101 BrowserThread::IO, | 3101 BrowserThread::IO, |
3102 FROM_HERE, | 3102 FROM_HERE, |
3103 base::Bind( | 3103 base::Bind( |
3104 RedirectHostsToTestData, kRestoredURLs, arraysize(kRestoredURLs))); | 3104 RedirectHostsToTestData, kRestoredURLs, arraysize(kRestoredURLs))); |
3105 } | 3105 } |
3106 | 3106 |
3107 void ListOfURLs() { | 3107 void ListOfURLs() { |
3108 // Verifies that policy can set the startup pages to a list of URLs. | 3108 // Verifies that policy can set the startup pages to a list of URLs. |
3109 base::ListValue urls; | 3109 base::ListValue urls; |
3110 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i) { | 3110 for (size_t i = 0; i < arraysize(kRestoredURLs); ++i) { |
3111 urls.Append(new base::StringValue(kRestoredURLs[i])); | 3111 urls.AppendString(kRestoredURLs[i]); |
3112 expected_urls_.push_back(GURL(kRestoredURLs[i])); | 3112 expected_urls_.push_back(GURL(kRestoredURLs[i])); |
3113 } | 3113 } |
3114 PolicyMap policies; | 3114 PolicyMap policies; |
3115 policies.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, | 3115 policies.Set(key::kRestoreOnStartup, POLICY_LEVEL_MANDATORY, |
3116 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3116 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
3117 base::WrapUnique(new base::FundamentalValue( | 3117 base::WrapUnique(new base::FundamentalValue( |
3118 SessionStartupPref::kPrefValueURLs)), | 3118 SessionStartupPref::kPrefValueURLs)), |
3119 nullptr); | 3119 nullptr); |
3120 policies.Set(key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY, | 3120 policies.Set(key::kRestoreOnStartupURLs, POLICY_LEVEL_MANDATORY, |
3121 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, urls.CreateDeepCopy(), | 3121 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, urls.CreateDeepCopy(), |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3705 g_browser_process->local_state(), std::string()); | 3705 g_browser_process->local_state(), std::string()); |
3706 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, | 3706 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url, |
3707 base::CompareCase::SENSITIVE)); | 3707 base::CompareCase::SENSITIVE)); |
3708 std::string value; | 3708 std::string value; |
3709 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 3709 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
3710 EXPECT_EQ("restricted", value); | 3710 EXPECT_EQ("restricted", value); |
3711 } | 3711 } |
3712 | 3712 |
3713 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistSelective) { | 3713 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistSelective) { |
3714 base::ListValue blacklist; | 3714 base::ListValue blacklist; |
3715 blacklist.Append(new base::StringValue("host.name")); | 3715 blacklist.AppendString("host.name"); |
3716 PolicyMap policies; | 3716 PolicyMap policies; |
3717 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, | 3717 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
3718 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3718 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
3719 blacklist.CreateDeepCopy(), nullptr); | 3719 blacklist.CreateDeepCopy(), nullptr); |
3720 UpdateProviderPolicy(policies); | 3720 UpdateProviderPolicy(policies); |
3721 | 3721 |
3722 PrefService* prefs = browser()->profile()->GetPrefs(); | 3722 PrefService* prefs = browser()->profile()->GetPrefs(); |
3723 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( | 3723 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( |
3724 prefs, "host.name")); | 3724 prefs, "host.name")); |
3725 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed( | 3725 EXPECT_TRUE(extensions::MessageService::IsNativeMessagingHostAllowed( |
3726 prefs, "other.host.name")); | 3726 prefs, "other.host.name")); |
3727 } | 3727 } |
3728 | 3728 |
3729 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistWildcard) { | 3729 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingBlacklistWildcard) { |
3730 base::ListValue blacklist; | 3730 base::ListValue blacklist; |
3731 blacklist.Append(new base::StringValue("*")); | 3731 blacklist.AppendString("*"); |
3732 PolicyMap policies; | 3732 PolicyMap policies; |
3733 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, | 3733 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
3734 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3734 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
3735 blacklist.CreateDeepCopy(), nullptr); | 3735 blacklist.CreateDeepCopy(), nullptr); |
3736 UpdateProviderPolicy(policies); | 3736 UpdateProviderPolicy(policies); |
3737 | 3737 |
3738 PrefService* prefs = browser()->profile()->GetPrefs(); | 3738 PrefService* prefs = browser()->profile()->GetPrefs(); |
3739 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( | 3739 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( |
3740 prefs, "host.name")); | 3740 prefs, "host.name")); |
3741 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( | 3741 EXPECT_FALSE(extensions::MessageService::IsNativeMessagingHostAllowed( |
3742 prefs, "other.host.name")); | 3742 prefs, "other.host.name")); |
3743 } | 3743 } |
3744 | 3744 |
3745 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingWhitelist) { | 3745 IN_PROC_BROWSER_TEST_F(PolicyTest, NativeMessagingWhitelist) { |
3746 base::ListValue blacklist; | 3746 base::ListValue blacklist; |
3747 blacklist.Append(new base::StringValue("*")); | 3747 blacklist.AppendString("*"); |
3748 base::ListValue whitelist; | 3748 base::ListValue whitelist; |
3749 whitelist.Append(new base::StringValue("host.name")); | 3749 whitelist.AppendString("host.name"); |
3750 PolicyMap policies; | 3750 PolicyMap policies; |
3751 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, | 3751 policies.Set(key::kNativeMessagingBlacklist, POLICY_LEVEL_MANDATORY, |
3752 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3752 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
3753 blacklist.CreateDeepCopy(), nullptr); | 3753 blacklist.CreateDeepCopy(), nullptr); |
3754 policies.Set(key::kNativeMessagingWhitelist, POLICY_LEVEL_MANDATORY, | 3754 policies.Set(key::kNativeMessagingWhitelist, POLICY_LEVEL_MANDATORY, |
3755 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3755 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
3756 whitelist.CreateDeepCopy(), nullptr); | 3756 whitelist.CreateDeepCopy(), nullptr); |
3757 UpdateProviderPolicy(policies); | 3757 UpdateProviderPolicy(policies); |
3758 | 3758 |
3759 PrefService* prefs = browser()->profile()->GetPrefs(); | 3759 PrefService* prefs = browser()->profile()->GetPrefs(); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4033 | 4033 |
4034 SetEmptyPolicy(); | 4034 SetEmptyPolicy(); |
4035 // Policy not set. | 4035 // Policy not set. |
4036 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4036 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4037 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4037 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4038 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4038 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4039 } | 4039 } |
4040 #endif // defined(OS_CHROMEOS) | 4040 #endif // defined(OS_CHROMEOS) |
4041 | 4041 |
4042 } // namespace policy | 4042 } // namespace policy |
OLD | NEW |