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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1310 UpdateProviderPolicy(policies); | 1310 UpdateProviderPolicy(policies); |
1311 // wait for devtools close | 1311 // wait for devtools close |
1312 close_observer.Wait(); | 1312 close_observer.Wait(); |
1313 // The existing devtools window should have closed. | 1313 // The existing devtools window should have closed. |
1314 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); | 1314 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
1315 // And it's not possible to open it again. | 1315 // And it's not possible to open it again. |
1316 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); | 1316 EXPECT_FALSE(chrome::ExecuteCommand(browser(), IDC_DEV_TOOLS)); |
1317 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); | 1317 EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents)); |
1318 } | 1318 } |
1319 | 1319 |
1320 namespace { | |
1321 | |
1322 // Utility for waiting until the dev-mode controls are visible/hidden | |
1323 // Uses a MutationObserver on the attributes of the DOM element. | |
1324 void WaitForExtensionsDevModeControlsVisibility( | |
1325 content::WebContents* contents, | |
1326 const char *dev_controls_accessor_js, | |
Bernhard Bauer
2016/11/29 14:14:21
Asterisk goes next to the type.
| |
1327 const char *dev_controls_visibility_check_js, | |
1328 bool expected_visible) { | |
1329 bool done = false; | |
1330 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
1331 contents, | |
1332 base::StringPrintf( | |
1333 "var screenElement = %s;" | |
1334 "function SendReplyIfAsExpected() {" | |
1335 " var is_visible = %s;" | |
1336 " if (is_visible != %s)" | |
1337 " return false;" | |
1338 " observer.disconnect();" | |
1339 " domAutomationController.send(true);" | |
1340 " return true;" | |
1341 "}" | |
1342 "var observer = new MutationObserver(SendReplyIfAsExpected);" | |
1343 "if (!SendReplyIfAsExpected()) {" | |
1344 " var options = { 'attributes': true };" | |
1345 " observer.observe(screenElement, options);" | |
1346 "}", | |
1347 dev_controls_accessor_js, | |
1348 dev_controls_visibility_check_js, | |
1349 (expected_visible ? "true" : "false")), | |
1350 &done)); | |
1351 } | |
1352 | |
1353 } // namespace | |
1354 | |
1355 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabledExtensionsDevMode) { | |
1356 // Verifies that when DeveloperToolsDisabled policy is set, the "dev mode" | |
1357 // in chrome://extensions-frame is actively turned off and the checkbox | |
1358 // is disabled. | |
1359 // Note: We don't test the indicator as it is tested in the policy pref test | |
1360 // for kDeveloperToolsDisabled. | |
1361 | |
1362 // This test currently depends on the following assumptions about the webui: | |
1363 // (1) The ID of the checkbox to toggle dev mode | |
1364 const char toggle_dev_mode_accessor_js[] = | |
1365 "document.getElementById('toggle-dev-on')"; | |
1366 // (2) The ID of the dev controls containing element | |
1367 const char dev_controls_accessor_js[] = | |
1368 "document.getElementById('dev-controls')"; | |
1369 // (3) the fact that dev-controls is displayed/hidden using its height attr | |
1370 const char dev_controls_visibility_check_js[] = | |
1371 "parseFloat(document.getElementById('dev-controls').style.height) > 0"; | |
1372 | |
1373 // Navigate to the extensions frame and enabled "Developer mode" | |
1374 ui_test_utils::NavigateToURL(browser(), | |
1375 GURL(chrome::kChromeUIExtensionsFrameURL)); | |
1376 | |
1377 content::WebContents* contents = | |
1378 browser()->tab_strip_model()->GetActiveWebContents(); | |
1379 EXPECT_TRUE(content::ExecuteScript( | |
1380 contents, base::StringPrintf("domAutomationController.send(%s.click());", | |
1381 toggle_dev_mode_accessor_js))); | |
1382 | |
1383 WaitForExtensionsDevModeControlsVisibility(contents, | |
1384 dev_controls_accessor_js, | |
1385 dev_controls_visibility_check_js, | |
1386 true); | |
1387 | |
1388 // Disable devtools via policy. | |
1389 PolicyMap policies; | |
1390 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY, | |
1391 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | |
1392 base::MakeUnique<base::FundamentalValue>(true), nullptr); | |
1393 UpdateProviderPolicy(policies); | |
1394 | |
1395 // Expect devcontrols to be hidden now... | |
1396 WaitForExtensionsDevModeControlsVisibility(contents, | |
1397 dev_controls_accessor_js, | |
1398 dev_controls_visibility_check_js, | |
1399 false); | |
1400 | |
1401 // ... and checkbox is not disabled | |
1402 bool is_toggle_dev_mode_checkbox_enabled = false; | |
1403 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
1404 contents, | |
1405 base::StringPrintf( | |
1406 "domAutomationController.send(!%s.hasAttribute('disabled'))", | |
1407 toggle_dev_mode_accessor_js), | |
1408 &is_toggle_dev_mode_checkbox_enabled)); | |
1409 EXPECT_FALSE(is_toggle_dev_mode_checkbox_enabled); | |
1410 } | |
1411 | |
1320 // TODO(samarth): remove along with rest of NTP4 code. | 1412 // TODO(samarth): remove along with rest of NTP4 code. |
1321 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { | 1413 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { |
1322 // Verifies that the web store icons can be hidden from the new tab page. | 1414 // Verifies that the web store icons can be hidden from the new tab page. |
1323 | 1415 |
1324 // Open new tab page and look for the web store icons. | 1416 // Open new tab page and look for the web store icons. |
1325 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); | 1417 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); |
1326 content::WebContents* contents = | 1418 content::WebContents* contents = |
1327 browser()->tab_strip_model()->GetActiveWebContents(); | 1419 browser()->tab_strip_model()->GetActiveWebContents(); |
1328 | 1420 |
1329 #if !defined(OS_CHROMEOS) | 1421 #if !defined(OS_CHROMEOS) |
(...skipping 2895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4225 | 4317 |
4226 SetEmptyPolicy(); | 4318 SetEmptyPolicy(); |
4227 // Policy not set. | 4319 // Policy not set. |
4228 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4320 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4229 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4321 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4230 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4322 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4231 } | 4323 } |
4232 #endif // defined(OS_CHROMEOS) | 4324 #endif // defined(OS_CHROMEOS) |
4233 | 4325 |
4234 } // namespace policy | 4326 } // namespace policy |
OLD | NEW |