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

Unified Diff: chrome/test/functional/policy.py

Issue 8395044: Disable the Developer Tools when Javascript is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months 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/test/functional/policy.py
diff --git a/chrome/test/functional/policy.py b/chrome/test/functional/policy.py
index 2fb9cfe9fba1f7dbab6cd22bc29d1e164658c20d..6b4d76ff28c664e5ab332291305f82c56b22b975 100644
--- a/chrome/test/functional/policy.py
+++ b/chrome/test/functional/policy.py
@@ -3,8 +3,11 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import logging
+
import pyauto_functional # must come before pyauto.
import pyauto
+from pyauto_errors import JSONInterfaceError
class PolicyTest(pyauto.PyUITest):
@@ -26,11 +29,16 @@ class PolicyTest(pyauto.PyUITest):
self.assertEqual(blocked, ret)
return blocked
- def GetInnerHeight(self):
- """Returns the inner height of the content area."""
- ret = self.ExecuteJavascript(
- 'domAutomationController.send(innerHeight.toString());');
- return int(ret)
+ def IsJavascriptEnabled(self):
+ try:
+ ret = self.ExecuteJavascript('domAutomationController.send("done");')
+ return ret == 'done'
+ except JSONInterfaceError as e:
+ if 'Javascript execution was blocked' == str(e):
+ logging.debug('The previous failure was expected')
+ return False
+ else:
+ raise e
def testBlacklistPolicy(self):
"""Tests the URLBlacklist and URLWhitelist policies."""
@@ -93,6 +101,63 @@ class PolicyTest(pyauto.PyUITest):
# not even on the NTP.
self.assertFalse(self.IsBookmarkBarDetached())
+ def testJavascriptPolicies(self):
+ """Tests the Javascript policies, and their effect on other policies."""
+ # The navigation to about:blank after each policy reset is to reset the
+ # content settings state.
+ policy = {}
+ self.SetPolicies(policy)
+ self.assertTrue(self.IsJavascriptEnabled())
+ self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ policy['DeveloperToolsDisabled'] = True
+ self.SetPolicies(policy)
+ self.assertTrue(self.IsJavascriptEnabled())
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ policy['DeveloperToolsDisabled'] = False
+ self.SetPolicies(policy)
+ self.assertTrue(self.IsJavascriptEnabled())
+ self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ policy['JavascriptEnabled'] = False
+ self.SetPolicies(policy)
+ self.assertFalse(self.IsJavascriptEnabled())
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ # JavascriptEnabled = False forces DeveloperToolsDisabled to True.
+ policy['DeveloperToolsDisabled'] = False
+ self.SetPolicies(policy)
+ self.NavigateToURL('about:blank')
+ self.assertFalse(self.IsJavascriptEnabled())
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ # Javascript can also be disabled with content settings policies.
+ policy = {
+ 'DefaultJavaScriptSetting': 2,
+ }
+ self.SetPolicies(policy)
+ self.NavigateToURL('about:blank')
+ self.assertFalse(self.IsJavascriptEnabled())
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
+ # JavascriptEnabled = False also overrides the content setting.
+ policy = {
+ 'DefaultJavaScriptSetting': 1,
+ 'JavascriptEnabled': False,
+ }
+ self.SetPolicies(policy)
+ self.NavigateToURL('about:blank')
+ self.assertFalse(self.IsJavascriptEnabled())
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
+ self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
+
if __name__ == '__main__':
pyauto_functional.Main()

Powered by Google App Engine
This is Rietveld 408576698