Chromium Code Reviews| 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..2a5cae6cc470cd6d5c51160eea802160f2425c60 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 = parseFloat(screenElement.style.height) > 0;" |
| + " 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);" |
| + "}", |
| + (expected_visible ? "true" : "false")), |
| + &done)); |
| +} |
| + |
| +} // namespace |
| + |
| +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.
|
| + // 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. |