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 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 33 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
34 #include "chrome/browser/devtools/devtools_window.h" | 34 #include "chrome/browser/devtools/devtools_window.h" |
35 #include "chrome/browser/download/download_prefs.h" | 35 #include "chrome/browser/download/download_prefs.h" |
36 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | 36 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" |
37 #include "chrome/browser/extensions/crx_installer.h" | 37 #include "chrome/browser/extensions/crx_installer.h" |
38 #include "chrome/browser/extensions/extension_service.h" | 38 #include "chrome/browser/extensions/extension_service.h" |
39 #include "chrome/browser/extensions/unpacked_installer.h" | 39 #include "chrome/browser/extensions/unpacked_installer.h" |
40 #include "chrome/browser/extensions/updater/extension_cache_fake.h" | 40 #include "chrome/browser/extensions/updater/extension_cache_fake.h" |
41 #include "chrome/browser/extensions/updater/extension_updater.h" | 41 #include "chrome/browser/extensions/updater/extension_updater.h" |
42 #include "chrome/browser/infobars/infobar.h" | 42 #include "chrome/browser/infobars/infobar.h" |
| 43 #include "chrome/browser/infobars/infobar_manager.h" |
43 #include "chrome/browser/infobars/infobar_service.h" | 44 #include "chrome/browser/infobars/infobar_service.h" |
44 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 45 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
45 #include "chrome/browser/media/media_stream_devices_controller.h" | 46 #include "chrome/browser/media/media_stream_devices_controller.h" |
46 #include "chrome/browser/metrics/variations/variations_service.h" | 47 #include "chrome/browser/metrics/variations/variations_service.h" |
47 #include "chrome/browser/net/url_request_mock_util.h" | 48 #include "chrome/browser/net/url_request_mock_util.h" |
48 #include "chrome/browser/plugins/plugin_prefs.h" | 49 #include "chrome/browser/plugins/plugin_prefs.h" |
49 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | 50 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
50 #include "chrome/browser/policy/profile_policy_connector.h" | 51 #include "chrome/browser/policy/profile_policy_connector.h" |
51 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 52 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
52 #include "chrome/browser/prefs/session_startup_pref.h" | 53 #include "chrome/browser/prefs/session_startup_pref.h" |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 | 1331 |
1331 ServeContentTestData(); | 1332 ServeContentTestData(); |
1332 // No plugins at startup. | 1333 // No plugins at startup. |
1333 EXPECT_EQ(0, CountPlugins()); | 1334 EXPECT_EQ(0, CountPlugins()); |
1334 | 1335 |
1335 content::WebContents* contents = | 1336 content::WebContents* contents = |
1336 browser()->tab_strip_model()->GetActiveWebContents(); | 1337 browser()->tab_strip_model()->GetActiveWebContents(); |
1337 ASSERT_TRUE(contents); | 1338 ASSERT_TRUE(contents); |
1338 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | 1339 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
1339 ASSERT_TRUE(infobar_service); | 1340 ASSERT_TRUE(infobar_service); |
1340 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1341 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); |
| 1342 EXPECT_EQ(0u, infobar_manager->infobar_count()); |
1341 | 1343 |
1342 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); | 1344 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); |
1343 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); | 1345 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); |
1344 ui_test_utils::NavigateToURL(browser(), url); | 1346 ui_test_utils::NavigateToURL(browser(), url); |
1345 // This should have triggered the dangerous plugin infobar. | 1347 // This should have triggered the dangerous plugin infobar. |
1346 ASSERT_EQ(1u, infobar_service->infobar_count()); | 1348 ASSERT_EQ(1u, infobar_manager->infobar_count()); |
1347 EXPECT_TRUE( | 1349 EXPECT_TRUE( |
1348 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); | 1350 infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); |
1349 // And the plugin isn't running. | 1351 // And the plugin isn't running. |
1350 EXPECT_EQ(0, CountPlugins()); | 1352 EXPECT_EQ(0, CountPlugins()); |
1351 | 1353 |
1352 // Now set a policy to always authorize this. | 1354 // Now set a policy to always authorize this. |
1353 PolicyMap policies; | 1355 PolicyMap policies; |
1354 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY, | 1356 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY, |
1355 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); | 1357 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); |
1356 UpdateProviderPolicy(policies); | 1358 UpdateProviderPolicy(policies); |
1357 // Reloading the page shouldn't trigger the infobar this time. | 1359 // Reloading the page shouldn't trigger the infobar this time. |
1358 ui_test_utils::NavigateToURL(browser(), url); | 1360 ui_test_utils::NavigateToURL(browser(), url); |
1359 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1361 EXPECT_EQ(0u, infobar_manager->infobar_count()); |
1360 // And the plugin started automatically. | 1362 // And the plugin started automatically. |
1361 EXPECT_EQ(1, CountPlugins()); | 1363 EXPECT_EQ(1, CountPlugins()); |
1362 } | 1364 } |
1363 | 1365 |
1364 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { | 1366 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { |
1365 // Verifies that access to the developer tools can be disabled. | 1367 // Verifies that access to the developer tools can be disabled. |
1366 | 1368 |
1367 // Open devtools. | 1369 // Open devtools. |
1368 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1370 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
1369 content::WebContents* contents = | 1371 content::WebContents* contents = |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 TranslateService::SetUseInfobar(true); | 1871 TranslateService::SetUseInfobar(true); |
1870 | 1872 |
1871 // Verifies that translate can be forced enabled or disabled by policy. | 1873 // Verifies that translate can be forced enabled or disabled by policy. |
1872 | 1874 |
1873 // Get the InfoBarService, and verify that there are no infobars on startup. | 1875 // Get the InfoBarService, and verify that there are no infobars on startup. |
1874 content::WebContents* contents = | 1876 content::WebContents* contents = |
1875 browser()->tab_strip_model()->GetActiveWebContents(); | 1877 browser()->tab_strip_model()->GetActiveWebContents(); |
1876 ASSERT_TRUE(contents); | 1878 ASSERT_TRUE(contents); |
1877 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); | 1879 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); |
1878 ASSERT_TRUE(infobar_service); | 1880 ASSERT_TRUE(infobar_service); |
1879 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1881 InfoBarManager* infobar_manager = infobar_service->infobar_manager(); |
| 1882 EXPECT_EQ(0u, infobar_manager->infobar_count()); |
1880 | 1883 |
1881 // Force enable the translate feature. | 1884 // Force enable the translate feature. |
1882 PolicyMap policies; | 1885 PolicyMap policies; |
1883 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, | 1886 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
1884 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); | 1887 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true), NULL); |
1885 UpdateProviderPolicy(policies); | 1888 UpdateProviderPolicy(policies); |
1886 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test | 1889 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test |
1887 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the | 1890 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the |
1888 // TranslateManager observes. This allows checking that an infobar is NOT | 1891 // TranslateManager observes. This allows checking that an infobar is NOT |
1889 // shown below, without polling for infobars for some indeterminate amount | 1892 // shown below, without polling for infobars for some indeterminate amount |
(...skipping 12 matching lines...) Expand all Loading... |
1902 TranslateTabHelper::FromWebContents(contents); | 1905 TranslateTabHelper::FromWebContents(contents); |
1903 ASSERT_TRUE(translate_tab_helper); | 1906 ASSERT_TRUE(translate_tab_helper); |
1904 LanguageState& language_state = translate_tab_helper->GetLanguageState(); | 1907 LanguageState& language_state = translate_tab_helper->GetLanguageState(); |
1905 EXPECT_EQ("fr", language_state.original_language()); | 1908 EXPECT_EQ("fr", language_state.original_language()); |
1906 EXPECT_TRUE(language_state.page_needs_translation()); | 1909 EXPECT_TRUE(language_state.page_needs_translation()); |
1907 EXPECT_FALSE(language_state.translation_pending()); | 1910 EXPECT_FALSE(language_state.translation_pending()); |
1908 EXPECT_FALSE(language_state.translation_declined()); | 1911 EXPECT_FALSE(language_state.translation_declined()); |
1909 EXPECT_FALSE(language_state.IsPageTranslated()); | 1912 EXPECT_FALSE(language_state.IsPageTranslated()); |
1910 | 1913 |
1911 // Verify that the translate infobar showed up. | 1914 // Verify that the translate infobar showed up. |
1912 ASSERT_EQ(1u, infobar_service->infobar_count()); | 1915 ASSERT_EQ(1u, infobar_manager->infobar_count()); |
1913 InfoBar* infobar = infobar_service->infobar_at(0); | 1916 InfoBar* infobar = infobar_manager->infobar_at(0); |
1914 TranslateInfoBarDelegate* translate_infobar_delegate = | 1917 TranslateInfoBarDelegate* translate_infobar_delegate = |
1915 infobar->delegate()->AsTranslateInfoBarDelegate(); | 1918 infobar->delegate()->AsTranslateInfoBarDelegate(); |
1916 ASSERT_TRUE(translate_infobar_delegate); | 1919 ASSERT_TRUE(translate_infobar_delegate); |
1917 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, | 1920 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, |
1918 translate_infobar_delegate->translate_step()); | 1921 translate_infobar_delegate->translate_step()); |
1919 EXPECT_EQ("fr", translate_infobar_delegate->original_language_code()); | 1922 EXPECT_EQ("fr", translate_infobar_delegate->original_language_code()); |
1920 | 1923 |
1921 // Now force disable translate. | 1924 // Now force disable translate. |
1922 infobar_service->RemoveInfoBar(infobar); | 1925 infobar_manager->RemoveInfoBar(infobar); |
1923 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1926 EXPECT_EQ(0u, infobar_manager->infobar_count()); |
1924 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, | 1927 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, |
1925 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false), NULL); | 1928 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false), NULL); |
1926 UpdateProviderPolicy(policies); | 1929 UpdateProviderPolicy(policies); |
1927 // Navigating to the same URL now doesn't trigger an infobar. | 1930 // Navigating to the same URL now doesn't trigger an infobar. |
1928 content::WindowedNotificationObserver language_observer2( | 1931 content::WindowedNotificationObserver language_observer2( |
1929 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1932 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1930 content::NotificationService::AllSources()); | 1933 content::NotificationService::AllSources()); |
1931 ui_test_utils::NavigateToURL(browser(), url); | 1934 ui_test_utils::NavigateToURL(browser(), url); |
1932 language_observer2.Wait(); | 1935 language_observer2.Wait(); |
1933 EXPECT_EQ(0u, infobar_service->infobar_count()); | 1936 EXPECT_EQ(0u, infobar_manager->infobar_count()); |
1934 } | 1937 } |
1935 | 1938 |
1936 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { | 1939 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { |
1937 // Checks that URLs can be blacklisted, and that exceptions can be made to | 1940 // Checks that URLs can be blacklisted, and that exceptions can be made to |
1938 // the blacklist. | 1941 // the blacklist. |
1939 | 1942 |
1940 // Filter |kURLS| on IO thread, so that requests to those hosts end up | 1943 // Filter |kURLS| on IO thread, so that requests to those hosts end up |
1941 // as URLRequestMockHTTPJobs. | 1944 // as URLRequestMockHTTPJobs. |
1942 const char* kURLS[] = { | 1945 const char* kURLS[] = { |
1943 "http://aaa.com/empty.html", | 1946 "http://aaa.com/empty.html", |
(...skipping 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2971 PrefService* prefs = browser()->profile()->GetPrefs(); | 2974 PrefService* prefs = browser()->profile()->GetPrefs(); |
2972 EXPECT_TRUE(extensions::NativeMessageProcessHost::IsHostAllowed( | 2975 EXPECT_TRUE(extensions::NativeMessageProcessHost::IsHostAllowed( |
2973 prefs, "host.name")); | 2976 prefs, "host.name")); |
2974 EXPECT_FALSE(extensions::NativeMessageProcessHost::IsHostAllowed( | 2977 EXPECT_FALSE(extensions::NativeMessageProcessHost::IsHostAllowed( |
2975 prefs, "other.host.name")); | 2978 prefs, "other.host.name")); |
2976 } | 2979 } |
2977 | 2980 |
2978 #endif // !defined(CHROME_OS) | 2981 #endif // !defined(CHROME_OS) |
2979 | 2982 |
2980 } // namespace policy | 2983 } // namespace policy |
OLD | NEW |