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

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

Issue 2529083002: Make extensions developer mode adhere to policy (Closed)
Patch Set: Guard against Preference not being found 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 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void WaitForExtensionsDevModeControlsVisibility(content::WebContents* contents,
1323 bool expected_visible) {
1324 // Visibility of dev-controls is controlled through its height - wait for that
1325 bool done = false;
1326 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
1327 contents,
1328 base::StringPrintf(
1329 "var screenElement = document.getElementById('dev-controls');"
1330 "function SendReplyIfAsExpected() {"
1331 " var is_visible = parseFloat(screenElement.style.height) > 0;"
1332 " if (is_visible != %s)"
1333 " return false;"
1334 " observer.disconnect();"
1335 " domAutomationController.send(true);"
1336 " return true;"
1337 "}"
1338 "var observer = new MutationObserver(SendReplyIfAsExpected);"
1339 "if (!SendReplyIfAsExpected()) {"
1340 " var options = { 'attributes': true };"
1341 " observer.observe(screenElement, options);"
1342 "}",
1343 (expected_visible ? "true" : "false")),
1344 &done));
1345 }
1346
1347 } // namespace
1348
1349 IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabledExtensionsDevMode) {
Devlin 2016/11/28 17:34:01 This is a pretty fragile browser test for a number
pmarko 2016/11/29 12:40:22 unittest: good idea, I'll check if I can add one.
Devlin 2016/11/30 19:19:50 Ah, okay, that makes more sense. If this is delib
pmarko 2016/12/02 00:20:07 Acknowledged.
1350 // Verifies that when DeveloperToolsDisabled policy is set, the "dev mode"
1351 // in chrome://extensions-frame is also not accessible.
1352 // Also verifies that the developer mode related buttons are actively hidden
1353 // when the policy comes in.
1354 // Note: We don't test the indicator as it is tested in the policy pref test
1355 // for kDeveloperToolsDisabled.
1356
1357 const char js_toggle_dev_mode_checkbox[] =
1358 "document.getElementById('toggle-dev-on')";
1359
1360 // Navigate to the extensions frame and enabled "Developer mode"
1361 ui_test_utils::NavigateToURL(browser(),
1362 GURL(chrome::kChromeUIExtensionsFrameURL));
1363
1364 content::WebContents* contents =
1365 browser()->tab_strip_model()->GetActiveWebContents();
1366 EXPECT_TRUE(content::ExecuteScript(
1367 contents, base::StringPrintf("domAutomationController.send(%s.click());",
1368 js_toggle_dev_mode_checkbox)));
1369
1370 WaitForExtensionsDevModeControlsVisibility(contents, true);
1371
1372 // Disable devtools via policy.
1373 PolicyMap policies;
1374 policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY,
1375 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
1376 base::MakeUnique<base::FundamentalValue>(true), nullptr);
1377 UpdateProviderPolicy(policies);
1378
1379 // Expect devcontrols to be hidden now...
1380 WaitForExtensionsDevModeControlsVisibility(contents, false);
1381
1382 // ... and checkbox state
1383 bool is_toggle_dev_mode_checkbox_checked = false;
1384 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1385 contents, base::StringPrintf("domAutomationController.send(%s.checked);",
1386 js_toggle_dev_mode_checkbox),
1387 &is_toggle_dev_mode_checkbox_checked));
1388 EXPECT_FALSE(is_toggle_dev_mode_checkbox_checked);
1389
1390 bool is_toggle_dev_mode_checkbox_enabled = false;
1391 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
1392 contents,
1393 base::StringPrintf(
1394 "domAutomationController.send(!%s.hasAttribute('disabled'))",
1395 js_toggle_dev_mode_checkbox),
1396 &is_toggle_dev_mode_checkbox_enabled));
1397 EXPECT_FALSE(is_toggle_dev_mode_checkbox_enabled);
1398 }
1399
1320 // TODO(samarth): remove along with rest of NTP4 code. 1400 // TODO(samarth): remove along with rest of NTP4 code.
1321 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) { 1401 IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) {
1322 // Verifies that the web store icons can be hidden from the new tab page. 1402 // Verifies that the web store icons can be hidden from the new tab page.
1323 1403
1324 // Open new tab page and look for the web store icons. 1404 // Open new tab page and look for the web store icons.
1325 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL)); 1405 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
1326 content::WebContents* contents = 1406 content::WebContents* contents =
1327 browser()->tab_strip_model()->GetActiveWebContents(); 1407 browser()->tab_strip_model()->GetActiveWebContents();
1328 1408
1329 #if !defined(OS_CHROMEOS) 1409 #if !defined(OS_CHROMEOS)
(...skipping 2895 matching lines...) Expand 10 before | Expand all | Expand 10 after
4225 4305
4226 SetEmptyPolicy(); 4306 SetEmptyPolicy();
4227 // Policy not set. 4307 // Policy not set.
4228 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4308 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4229 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4309 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4230 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4310 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4231 } 4311 }
4232 #endif // defined(OS_CHROMEOS) 4312 #endif // defined(OS_CHROMEOS)
4233 4313
4234 } // namespace policy 4314 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698