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

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 2529083002: Make extensions developer mode adhere to policy (Closed)
Patch Set: Get rid of busy loop in test Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index ff9bdf7ccc147d8c4b9e143bb20ab930a92fe5b5..8e6ab55c640280babbbf82d5270894c10a487092 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -1317,6 +1317,86 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) {
EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents));
}
+namespace {
+
+void WaitForExtensionsDevModeControlsVisibility(content::WebContents* contents,
+ bool expected_visible) {
+ // Visibility of dev-controls is controlled through its height - wait for that
+ bool done = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "var screenElement = document.getElementById('dev-controls');"
+ "function SendReplyIfAsExpected() {"
+ " var is_visible = screenElement.offsetHeight > 0;"
+ " if (is_visible != %s)"
+ " return false;"
+ " domAutomationController.send(true);"
+ " observer.disconnect();"
+ " return true;"
+ "}"
+ "var observer = new MutationObserver(SendReplyIfAsExpected);"
+ "if (!SendReplyIfAsExpected()) {"
+ " var options = { 'attributes': true };"
+ " observer.observe(screenElement, options);"
+ "}",
+ (expected_visible ? "true" : "false")),
+ &done));
+}
+
+} // namespace
+
+IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabledExtensionsDevMode) {
+ // Verifies that when DeveloperToolsDisabled policy is set, the "dev mode"
+ // in chrome://extensions-frame is also not accessible.
+ // Also verifies that the developer mode related buttons are actively hidden
+ // when the policy comes in.
+ // Note: We don't test the indicator as it is tested in the policy pref test
+ // for kDeveloperToolsDisabled.
+
+ const char js_toggle_dev_mode_checkbox[] =
+ "document.getElementById('toggle-dev-on')";
+
+ // Navigate to the extensions frame and enabled "Developer mode"
+ ui_test_utils::NavigateToURL(browser(),
+ GURL(chrome::kChromeUIExtensionsFrameURL));
+
+ content::WebContents* contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(content::ExecuteScript(
+ contents, base::StringPrintf("domAutomationController.send(%s.click());",
+ js_toggle_dev_mode_checkbox)));
+
+ WaitForExtensionsDevModeControlsVisibility(contents, true);
+
+ // Disable devtools via policy.
+ PolicyMap policies;
+ policies.Set(key::kDeveloperToolsDisabled, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::FundamentalValue>(true), nullptr);
+ UpdateProviderPolicy(policies);
+
+ // Expect devcontrols to be hidden now...
+ WaitForExtensionsDevModeControlsVisibility(contents, false);
+
+ // ... and checkbox state
+ bool is_toggle_dev_mode_checkbox_checked = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents, base::StringPrintf("domAutomationController.send(%s.checked);",
+ js_toggle_dev_mode_checkbox),
+ &is_toggle_dev_mode_checkbox_checked));
+ EXPECT_FALSE(is_toggle_dev_mode_checkbox_checked);
+
+ bool is_toggle_dev_mode_checkbox_enabled = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "domAutomationController.send(!%s.hasAttribute('disabled'))",
+ js_toggle_dev_mode_checkbox),
+ &is_toggle_dev_mode_checkbox_enabled));
+ EXPECT_FALSE(is_toggle_dev_mode_checkbox_enabled);
+}
+
// TODO(samarth): remove along with rest of NTP4 code.
IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_WebStoreIconHidden) {
// Verifies that the web store icons can be hidden from the new tab page.

Powered by Google App Engine
This is Rietveld 408576698