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

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

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

Powered by Google App Engine
This is Rietveld 408576698