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

Side by Side 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: Fixed unit_tests, added some more tests Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import logging
7
6 import pyauto_functional # must come before pyauto. 8 import pyauto_functional # must come before pyauto.
7 import pyauto 9 import pyauto
10 from pyauto_errors import JSONInterfaceError
8 11
9 12
10 class PolicyTest(pyauto.PyUITest): 13 class PolicyTest(pyauto.PyUITest):
11 """Tests that the effects of policies are being enforced as expected.""" 14 """Tests that the effects of policies are being enforced as expected."""
12 15
13 def IsBlocked(self, url): 16 def IsBlocked(self, url):
14 """Returns true if navigating to |url| is blocked.""" 17 """Returns true if navigating to |url| is blocked."""
15 self.NavigateToURL(url) 18 self.NavigateToURL(url)
16 blocked = self.GetActiveTabTitle() == url + ' is not available' 19 blocked = self.GetActiveTabTitle() == url + ' is not available'
17 ret = self.ExecuteJavascript(""" 20 ret = self.ExecuteJavascript("""
18 var hasError = false; 21 var hasError = false;
19 var error = document.getElementById('errorDetails'); 22 var error = document.getElementById('errorDetails');
20 if (error) { 23 if (error) {
21 hasError = error.textContent.indexOf('Error 138') == 0; 24 hasError = error.textContent.indexOf('Error 138') == 0;
22 } 25 }
23 domAutomationController.send(hasError.toString()); 26 domAutomationController.send(hasError.toString());
24 """) 27 """)
25 ret = ret == 'true' 28 ret = ret == 'true'
26 self.assertEqual(blocked, ret) 29 self.assertEqual(blocked, ret)
27 return blocked 30 return blocked
28 31
29 def GetInnerHeight(self): 32 def IsJavascriptEnabled(self):
30 """Returns the inner height of the content area.""" 33 try:
31 ret = self.ExecuteJavascript( 34 ret = self.ExecuteJavascript('domAutomationController.send("done");')
32 'domAutomationController.send(innerHeight.toString());'); 35 return ret == 'done'
33 return int(ret) 36 except JSONInterfaceError as e:
37 if 'Javascript execution was blocked' == str(e):
38 logging.debug('The previous failure was expected')
39 return False
40 else:
41 raise e
34 42
35 def testBlacklistPolicy(self): 43 def testBlacklistPolicy(self):
36 """Tests the URLBlacklist and URLWhitelist policies.""" 44 """Tests the URLBlacklist and URLWhitelist policies."""
37 # This is an end to end test and not an exaustive test of the filter format. 45 # This is an end to end test and not an exaustive test of the filter format.
38 policy = { 46 policy = {
39 'URLBlacklist': [ 47 'URLBlacklist': [
40 'news.google.com', 48 'news.google.com',
41 'chromium.org', 49 'chromium.org',
42 ], 50 ],
43 'URLWhitelist': [ 51 'URLWhitelist': [
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 94
87 self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False)) 95 self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False))
88 self.assertFalse(self.GetBookmarkBarVisibility()) 96 self.assertFalse(self.GetBookmarkBarVisibility())
89 self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR) 97 self.ApplyAccelerator(pyauto.IDC_SHOW_BOOKMARK_BAR)
90 self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False)) 98 self.assertTrue(self.WaitForBookmarkBarVisibilityChange(False))
91 self.assertFalse(self.GetBookmarkBarVisibility()) 99 self.assertFalse(self.GetBookmarkBarVisibility())
92 # When disabled by policy, it should never be displayed at all, 100 # When disabled by policy, it should never be displayed at all,
93 # not even on the NTP. 101 # not even on the NTP.
94 self.assertFalse(self.IsBookmarkBarDetached()) 102 self.assertFalse(self.IsBookmarkBarDetached())
95 103
104 def testJavascriptPolicies(self):
105 """Tests the Javascript policies."""
106 # The navigation to about:blank after each policy reset is to reset the
107 # content settings state.
108 policy = {}
109 self.SetPolicies(policy)
110 self.assertTrue(self.IsJavascriptEnabled())
111 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
112 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
113
114 policy['DeveloperToolsDisabled'] = True
115 self.SetPolicies(policy)
116 self.assertTrue(self.IsJavascriptEnabled())
117 self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
118 self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
119
120 policy['DeveloperToolsDisabled'] = False
121 self.SetPolicies(policy)
122 self.assertTrue(self.IsJavascriptEnabled())
123 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
124 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
125
126 # The Developer Tools still work when javascript is disabled.
127 policy['JavascriptEnabled'] = False
128 self.SetPolicies(policy)
129 self.assertFalse(self.IsJavascriptEnabled())
130 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
131 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
132
133 # The Developer Tools can be explicitly disabled.
134 policy['DeveloperToolsDisabled'] = True
135 self.SetPolicies(policy)
136 self.NavigateToURL('about:blank')
137 self.assertFalse(self.IsJavascriptEnabled())
138 self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
139 self.assertFalse(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
140
141 # Javascript can also be disabled with content settings policies.
142 policy = {
143 'DefaultJavaScriptSetting': 2,
144 }
145 self.SetPolicies(policy)
146 self.NavigateToURL('about:blank')
147 self.assertFalse(self.IsJavascriptEnabled())
148 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS))
149 self.assertTrue(self.IsMenuCommandEnabled(pyauto.IDC_DEV_TOOLS_CONSOLE))
150
151 # JavascriptEnabled = False also overrides the content setting.
152 policy = {
153 'DefaultJavaScriptSetting': 1,
154 'JavascriptEnabled': False,
155 }
156 self.SetPolicies(policy)
157 self.NavigateToURL('about:blank')
158 self.assertFalse(self.IsJavascriptEnabled())
159
160 # Javascript is always enabled for internal Chrome pages.
161 self.NavigateToURL('chrome://settings')
162 self.assertTrue(self.IsJavascriptEnabled())
163
96 164
97 if __name__ == '__main__': 165 if __name__ == '__main__':
98 pyauto_functional.Main() 166 pyauto_functional.Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698