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

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

Issue 14241006: Eliminate InfoBarTabHelper. Make InfoBarService a concrete class. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 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 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 1095
1096 ServeContentTestData(); 1096 ServeContentTestData();
1097 // No plugins at startup. 1097 // No plugins at startup.
1098 EXPECT_EQ(0, CountPlugins()); 1098 EXPECT_EQ(0, CountPlugins());
1099 1099
1100 content::WebContents* contents = 1100 content::WebContents* contents =
1101 browser()->tab_strip_model()->GetActiveWebContents(); 1101 browser()->tab_strip_model()->GetActiveWebContents();
1102 ASSERT_TRUE(contents); 1102 ASSERT_TRUE(contents);
1103 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); 1103 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
1104 ASSERT_TRUE(infobar_service); 1104 ASSERT_TRUE(infobar_service);
1105 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); 1105 EXPECT_EQ(0u, infobar_service->infobar_count());
1106 1106
1107 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); 1107 base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html"));
1108 GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); 1108 GURL url(URLRequestMockHTTPJob::GetMockUrl(path));
1109 ui_test_utils::NavigateToURL(browser(), url); 1109 ui_test_utils::NavigateToURL(browser(), url);
1110 // This should have triggered the dangerous plugin infobar. 1110 // This should have triggered the dangerous plugin infobar.
1111 ASSERT_EQ(1u, infobar_service->GetInfoBarCount()); 1111 ASSERT_EQ(1u, infobar_service->infobar_count());
1112 InfoBarDelegate* infobar_delegate = 1112 InfoBarDelegate* infobar_delegate = infobar_service->infobar_at(0);
1113 infobar_service->GetInfoBarDelegateAt(0);
1114 EXPECT_TRUE(infobar_delegate->AsConfirmInfoBarDelegate()); 1113 EXPECT_TRUE(infobar_delegate->AsConfirmInfoBarDelegate());
1115 // And the plugin isn't running. 1114 // And the plugin isn't running.
1116 EXPECT_EQ(0, CountPlugins()); 1115 EXPECT_EQ(0, CountPlugins());
1117 1116
1118 // Now set a policy to always authorize this. 1117 // Now set a policy to always authorize this.
1119 PolicyMap policies; 1118 PolicyMap policies;
1120 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY, 1119 policies.Set(key::kAlwaysAuthorizePlugins, POLICY_LEVEL_MANDATORY,
1121 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); 1120 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
1122 UpdateProviderPolicy(policies); 1121 UpdateProviderPolicy(policies);
1123 // Reloading the page shouldn't trigger the infobar this time. 1122 // Reloading the page shouldn't trigger the infobar this time.
1124 ui_test_utils::NavigateToURL(browser(), url); 1123 ui_test_utils::NavigateToURL(browser(), url);
1125 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); 1124 EXPECT_EQ(0u, infobar_service->infobar_count());
1126 // And the plugin started automatically. 1125 // And the plugin started automatically.
1127 EXPECT_EQ(1, CountPlugins()); 1126 EXPECT_EQ(1, CountPlugins());
1128 } 1127 }
1129 1128
1130 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) { 1129 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) {
1131 // Verifies that access to the developer tools can be disabled. 1130 // Verifies that access to the developer tools can be disabled.
1132 1131
1133 // Open devtools. 1132 // Open devtools.
1134 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); 1133 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS));
1135 content::WebContents* contents = 1134 content::WebContents* contents =
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 #endif 1511 #endif
1513 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_TranslateEnabled) { 1512 IN_PROC_BROWSER_TEST_F(PolicyTest, MAYBE_TranslateEnabled) {
1514 // Verifies that translate can be forced enabled or disabled by policy. 1513 // Verifies that translate can be forced enabled or disabled by policy.
1515 1514
1516 // Get the InfoBarService, and verify that there are no infobars on startup. 1515 // Get the InfoBarService, and verify that there are no infobars on startup.
1517 content::WebContents* contents = 1516 content::WebContents* contents =
1518 browser()->tab_strip_model()->GetActiveWebContents(); 1517 browser()->tab_strip_model()->GetActiveWebContents();
1519 ASSERT_TRUE(contents); 1518 ASSERT_TRUE(contents);
1520 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); 1519 InfoBarService* infobar_service = InfoBarService::FromWebContents(contents);
1521 ASSERT_TRUE(infobar_service); 1520 ASSERT_TRUE(infobar_service);
1522 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); 1521 EXPECT_EQ(0u, infobar_service->infobar_count());
1523 1522
1524 // Force enable the translate feature. 1523 // Force enable the translate feature.
1525 PolicyMap policies; 1524 PolicyMap policies;
1526 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, 1525 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY,
1527 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true)); 1526 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(true));
1528 UpdateProviderPolicy(policies); 1527 UpdateProviderPolicy(policies);
1529 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test 1528 // Instead of waiting for NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, this test
1530 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the 1529 // waits for NOTIFICATION_TAB_LANGUAGE_DETERMINED because that's what the
1531 // TranslateManager observes. This allows checking that an infobar is NOT 1530 // TranslateManager observes. This allows checking that an infobar is NOT
1532 // shown below, without polling for infobars for some indeterminate amount 1531 // shown below, without polling for infobars for some indeterminate amount
1533 // of time. 1532 // of time.
1534 GURL url = ui_test_utils::GetTestUrl( 1533 GURL url = ui_test_utils::GetTestUrl(
1535 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); 1534 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
1536 content::WindowedNotificationObserver language_observer1( 1535 content::WindowedNotificationObserver language_observer1(
1537 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1536 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1538 content::NotificationService::AllSources()); 1537 content::NotificationService::AllSources());
1539 ui_test_utils::NavigateToURL(browser(), url); 1538 ui_test_utils::NavigateToURL(browser(), url);
1540 language_observer1.Wait(); 1539 language_observer1.Wait();
1541 // Verify that the translate infobar showed up. 1540 // Verify that the translate infobar showed up.
1542 ASSERT_EQ(1u, infobar_service->GetInfoBarCount()); 1541 ASSERT_EQ(1u, infobar_service->infobar_count());
1543 InfoBarDelegate* infobar_delegate = 1542 InfoBarDelegate* infobar_delegate = infobar_service->infobar_at(0);
1544 infobar_service->GetInfoBarDelegateAt(0);
1545 TranslateInfoBarDelegate* delegate = 1543 TranslateInfoBarDelegate* delegate =
1546 infobar_delegate->AsTranslateInfoBarDelegate(); 1544 infobar_delegate->AsTranslateInfoBarDelegate();
1547 ASSERT_TRUE(delegate); 1545 ASSERT_TRUE(delegate);
1548 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, 1546 EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE,
1549 delegate->infobar_type()); 1547 delegate->infobar_type());
1550 EXPECT_EQ("fr", delegate->original_language_code()); 1548 EXPECT_EQ("fr", delegate->original_language_code());
1551 1549
1552 // Now force disable translate. 1550 // Now force disable translate.
1553 infobar_service->RemoveInfoBar(infobar_delegate); 1551 infobar_service->RemoveInfoBar(infobar_delegate);
1554 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); 1552 EXPECT_EQ(0u, infobar_service->infobar_count());
1555 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, 1553 policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY,
1556 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false)); 1554 POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false));
1557 UpdateProviderPolicy(policies); 1555 UpdateProviderPolicy(policies);
1558 // Navigating to the same URL now doesn't trigger an infobar. 1556 // Navigating to the same URL now doesn't trigger an infobar.
1559 content::WindowedNotificationObserver language_observer2( 1557 content::WindowedNotificationObserver language_observer2(
1560 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, 1558 chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
1561 content::NotificationService::AllSources()); 1559 content::NotificationService::AllSources());
1562 ui_test_utils::NavigateToURL(browser(), url); 1560 ui_test_utils::NavigateToURL(browser(), url);
1563 language_observer2.Wait(); 1561 language_observer2.Wait();
1564 EXPECT_EQ(0u, infobar_service->GetInfoBarCount()); 1562 EXPECT_EQ(0u, infobar_service->infobar_count());
1565 } 1563 }
1566 1564
1567 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { 1565 IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) {
1568 // Checks that URLs can be blacklisted, and that exceptions can be made to 1566 // Checks that URLs can be blacklisted, and that exceptions can be made to
1569 // the blacklist. 1567 // the blacklist.
1570 1568
1571 // Filter |kURLS| on IO thread, so that requests to those hosts end up 1569 // Filter |kURLS| on IO thread, so that requests to those hosts end up
1572 // as URLRequestMockHTTPJobs. 1570 // as URLRequestMockHTTPJobs.
1573 const char* kURLS[] = { 1571 const char* kURLS[] = {
1574 "http://aaa.com/empty.html", 1572 "http://aaa.com/empty.html",
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
2079 GetDefaultVariationsServerURLForTesting(); 2077 GetDefaultVariationsServerURLForTesting();
2080 2078
2081 // Policy is applied and pref is already updated in local state. 2079 // Policy is applied and pref is already updated in local state.
2082 EXPECT_EQ(default_variations_url + "?restrict=restricted", 2080 EXPECT_EQ(default_variations_url + "?restrict=restricted",
2083 chrome_variations::VariationsService::GetVariationsServerURL( 2081 chrome_variations::VariationsService::GetVariationsServerURL(
2084 g_browser_process->local_state()).spec()); 2082 g_browser_process->local_state()).spec());
2085 } 2083 }
2086 #endif 2084 #endif
2087 2085
2088 } // namespace policy 2086 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_infobar_delegates.cc ('k') | chrome/browser/ssl/ssl_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698