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

Side by Side Diff: chrome/browser/errorpage_browsertest.cc

Issue 977323003: Disable easter egg on enterprised enrolled devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove debug, fix indentation in JS Created 5 years, 9 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "net/test/url_request/url_request_mock_http_job.h" 46 #include "net/test/url_request/url_request_mock_http_job.h"
47 #include "net/url_request/url_request_context.h" 47 #include "net/url_request/url_request_context.h"
48 #include "net/url_request/url_request_context_getter.h" 48 #include "net/url_request/url_request_context_getter.h"
49 #include "net/url_request/url_request_filter.h" 49 #include "net/url_request/url_request_filter.h"
50 #include "net/url_request/url_request_interceptor.h" 50 #include "net/url_request/url_request_interceptor.h"
51 #include "net/url_request/url_request_job.h" 51 #include "net/url_request/url_request_job.h"
52 #include "net/url_request/url_request_test_job.h" 52 #include "net/url_request/url_request_test_job.h"
53 #include "net/url_request/url_request_test_util.h" 53 #include "net/url_request/url_request_test_util.h"
54 #include "ui/base/l10n/l10n_util.h" 54 #include "ui/base/l10n/l10n_util.h"
55 55
56 #if defined(OS_CHROMEOS)
57 #include "chrome/browser/browser_process.h"
58 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
59 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
60 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h"
61 #include "chrome/grit/generated_resources.h"
62 #include "components/policy/core/common/mock_configuration_policy_provider.h"
63 #include "components/policy/core/common/policy_types.h"
64 #include "content/public/test/browser_test_utils.h"
65 #include "ui/base/l10n/l10n_util.h"
66 #endif
67
56 using content::BrowserThread; 68 using content::BrowserThread;
57 using content::NavigationController; 69 using content::NavigationController;
58 using net::URLRequestFailedJob; 70 using net::URLRequestFailedJob;
59 using net::URLRequestTestJob; 71 using net::URLRequestTestJob;
60 72
61 namespace { 73 namespace {
62 74
63 // Returns true if |text| is displayed on the page |browser| is currently 75 // Returns true if |text| is displayed on the page |browser| is currently
64 // displaying. Uses "innerText", so will miss hidden text, and whitespace 76 // displaying. Uses "innerText", so will miss hidden text, and whitespace
65 // space handling may be weird. 77 // space handling may be weird.
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 BrowsingDataRemover* remover = 877 BrowsingDataRemover* remover =
866 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 878 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
867 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 879 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
868 BrowsingDataHelper::UNPROTECTED_WEB); 880 BrowsingDataHelper::UNPROTECTED_WEB);
869 ui_test_utils::NavigateToURL(browser(), test_url); 881 ui_test_utils::NavigateToURL(browser(), test_url);
870 EXPECT_TRUE(ProbeStaleCopyValue(false)); 882 EXPECT_TRUE(ProbeStaleCopyValue(false));
871 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 883 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel()));
872 EXPECT_EQ(0, link_doctor_interceptor()->num_requests()); 884 EXPECT_EQ(0, link_doctor_interceptor()->num_requests());
873 } 885 }
874 886
887 // Check that the easter egg is present and initialised and is not disabled.
888 IN_PROC_BROWSER_TEST_F(ErrorPageTest, CheckEasterEggIsNotDisabled) {
889 ui_test_utils::NavigateToURL(browser(),
890 URLRequestFailedJob::GetMockHttpUrl(net::ERR_INTERNET_DISCONNECTED));
891
892 content::WebContents* web_contents =
893 browser()->tab_strip_model()->GetActiveWebContents();
894
895 // Check for no disabled message container.
896 std::string command = base::StringPrintf(
897 "var hasDisableContainer = document.querySelectorAll('.snackbar').length;"
898 "domAutomationController.send(hasDisableContainer);");
899 int result;
900 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
901 web_contents, command, &result));
902 EXPECT_EQ(0, result);
903
904 // Presence of the canvas container.
905 command = base::StringPrintf(
906 "var runnerCanvas = document.querySelectorAll('.runner-canvas').length;"
907 "domAutomationController.send(runnerCanvas);");
908 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
909 web_contents, command, &result));
910 EXPECT_EQ(1, result);
911 }
912
875 class ErrorPageAutoReloadTest : public InProcessBrowserTest { 913 class ErrorPageAutoReloadTest : public InProcessBrowserTest {
876 public: 914 public:
877 void SetUpCommandLine(base::CommandLine* command_line) override { 915 void SetUpCommandLine(base::CommandLine* command_line) override {
878 command_line->AppendSwitch(switches::kEnableOfflineAutoReload); 916 command_line->AppendSwitch(switches::kEnableOfflineAutoReload);
879 } 917 }
880 918
881 void InstallInterceptor(const GURL& url, int requests_to_fail) { 919 void InstallInterceptor(const GURL& url, int requests_to_fail) {
882 interceptor_ = new FailFirstNRequestsInterceptor(requests_to_fail); 920 interceptor_ = new FailFirstNRequestsInterceptor(requests_to_fail);
883 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_); 921 scoped_ptr<net::URLRequestInterceptor> owned_interceptor(interceptor_);
884 922
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 BrowsingDataRemover* remover = 1101 BrowsingDataRemover* remover =
1064 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile()); 1102 BrowsingDataRemover::CreateForUnboundedRange(browser()->profile());
1065 remover->Remove(BrowsingDataRemover::REMOVE_CACHE, 1103 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1066 BrowsingDataHelper::UNPROTECTED_WEB); 1104 BrowsingDataHelper::UNPROTECTED_WEB);
1067 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 1105 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
1068 browser(), test_url, 2); 1106 browser(), test_url, 2);
1069 EXPECT_TRUE(ProbeStaleCopyValue(false)); 1107 EXPECT_TRUE(ProbeStaleCopyValue(false));
1070 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel())); 1108 EXPECT_FALSE(IsDisplayingText(browser(), GetLoadStaleButtonLabel()));
1071 } 1109 }
1072 1110
1111 #if defined(OS_CHROMEOS)
1112 class ErrorPageOfflineTest : public ErrorPageTest {
1113 protected:
1114 // Mock policy provider for both user and device policies.
1115 policy::MockConfigurationPolicyProvider policy_provider_;
1116
1117 void SetUpInProcessBrowserTestFixture() override {
1118 // Set up fake install attributes.
1119 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes(
1120 new policy::StubEnterpriseInstallAttributes());
1121 attributes->SetDomain("example.com");
1122 attributes->SetRegistrationUser("user@example.com");
1123 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(
1124 attributes.release());
1125
1126 // Sets up a mock policy provider for user and device policies.
1127 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_))
1128 .WillRepeatedly(testing::Return(true));
1129 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
1130 &policy_provider_);
1131
1132 ErrorPageTest::SetUpInProcessBrowserTestFixture();
1133 }
1134 };
1135
1136 IN_PROC_BROWSER_TEST_F(ErrorPageOfflineTest, CheckEasterEggIsDisabled) {
1137 // Check for enterprise enrollment.
1138 policy::BrowserPolicyConnectorChromeOS* connector =
1139 g_browser_process->platform_part()->browser_policy_connector_chromeos();
1140 EXPECT_TRUE(connector->IsEnterpriseManaged());
1141
1142 ui_test_utils::NavigateToURL(browser(),
1143 URLRequestFailedJob::GetMockHttpUrl(net::ERR_INTERNET_DISCONNECTED));
1144
1145 content::WebContents* web_contents =
1146 browser()->tab_strip_model()->GetActiveWebContents();
1147
1148 std::string command = base::StringPrintf(
1149 "var hasText = document.querySelector('.snackbar').innerText;"
1150 "domAutomationController.send(hasText);");
1151 std::string result = "";
1152 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
1153 web_contents, command, &result));
1154
1155 std::string disabled_text =
1156 l10n_util::GetStringUTF8(IDS_ERRORPAGE_FUN_DISABLED);
1157 EXPECT_EQ(disabled_text, result);
1158 }
1159 #endif
1160
1073 // A test fixture that simulates failing requests for an IDN domain name. 1161 // A test fixture that simulates failing requests for an IDN domain name.
1074 class ErrorPageForIDNTest : public InProcessBrowserTest { 1162 class ErrorPageForIDNTest : public InProcessBrowserTest {
1075 public: 1163 public:
1076 // Target hostname in different forms. 1164 // Target hostname in different forms.
1077 static const char kHostname[]; 1165 static const char kHostname[];
1078 static const char kHostnameJSUnicode[]; 1166 static const char kHostnameJSUnicode[];
1079 1167
1080 // InProcessBrowserTest: 1168 // InProcessBrowserTest:
1081 void SetUpOnMainThread() override { 1169 void SetUpOnMainThread() override {
1082 // Clear AcceptLanguages to force punycode decoding. 1170 // Clear AcceptLanguages to force punycode decoding.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 ui_test_utils::NavigateToURL( 1205 ui_test_utils::NavigateToURL(
1118 browser(), 1206 browser(),
1119 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT, 1207 URLRequestFailedJob::GetMockHttpUrlForHostname(net::ERR_UNSAFE_PORT,
1120 kHostname)); 1208 kHostname));
1121 1209
1122 ToggleHelpBox(browser()); 1210 ToggleHelpBox(browser());
1123 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode)); 1211 EXPECT_TRUE(IsDisplayingText(browser(), kHostnameJSUnicode));
1124 } 1212 }
1125 1213
1126 } // namespace 1214 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698