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

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

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

Powered by Google App Engine
This is Rietveld 408576698