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

Unified 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 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 a284e2ed2a39f02e410e86e6b2be98992a305c85..15248b58cde52a8288a67c0ca2e0f6b13550023a 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -1318,6 +1318,98 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DeveloperToolsDisabled) {
EXPECT_FALSE(DevToolsWindow::GetInstanceForInspectedWebContents(contents));
}
+namespace {
+
+// Utility for waiting until the dev-mode controls are visible/hidden
+// Uses a MutationObserver on the attributes of the DOM element.
+void WaitForExtensionsDevModeControlsVisibility(
+ content::WebContents* contents,
+ const char* dev_controls_accessor_js,
+ const char* dev_controls_visibility_check_js,
+ bool expected_visible) {
+ bool done = false;
+ ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "var screenElement = %s;"
+ "function SendReplyIfAsExpected() {"
+ " var is_visible = %s;"
+ " if (is_visible != %s)"
+ " return false;"
+ " observer.disconnect();"
+ " domAutomationController.send(true);"
+ " return true;"
+ "}"
+ "var observer = new MutationObserver(SendReplyIfAsExpected);"
+ "if (!SendReplyIfAsExpected()) {"
+ " var options = { 'attributes': true };"
+ " observer.observe(screenElement, options);"
+ "}",
+ dev_controls_accessor_js,
+ dev_controls_visibility_check_js,
+ (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 actively turned off and the checkbox
+ // is disabled.
+ // Note: We don't test the indicator as it is tested in the policy pref test
+ // for kDeveloperToolsDisabled.
+
+ // This test currently depends on the following assumptions about the webui:
+ // (1) The ID of the checkbox to toggle dev mode
+ const char toggle_dev_mode_accessor_js[] =
+ "document.getElementById('toggle-dev-on')";
+ // (2) The ID of the dev controls containing element
+ const char dev_controls_accessor_js[] =
+ "document.getElementById('dev-controls')";
+ // (3) the fact that dev-controls is displayed/hidden using its height attr
+ const char dev_controls_visibility_check_js[] =
+ "parseFloat(document.getElementById('dev-controls').style.height) > 0";
+
+ // 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());",
+ toggle_dev_mode_accessor_js)));
+
+ WaitForExtensionsDevModeControlsVisibility(contents,
+ dev_controls_accessor_js,
+ dev_controls_visibility_check_js,
+ 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,
+ dev_controls_accessor_js,
+ dev_controls_visibility_check_js,
+ false);
+
+ // ... and checkbox is not disabled
+ bool is_toggle_dev_mode_checkbox_enabled = false;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ contents,
+ base::StringPrintf(
+ "domAutomationController.send(!%s.hasAttribute('disabled'))",
+ toggle_dev_mode_accessor_js),
+ &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.
« 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