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