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

Unified Diff: enterprise.py

Issue 7453062: Added another class 'EnterpriseTestSetTwo'to test another set of policy values. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/chrome/test/functional/
Patch Set: '' Created 9 years, 5 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
« no previous file with comments | « no previous file | enterprise_helper_linux.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: enterprise.py
===================================================================
--- enterprise.py (revision 95020)
+++ enterprise.py (working copy)
@@ -307,6 +307,265 @@
self.assertFalse(self.GetHistoryInfo().History(),
msg='History is being saved.')
+class EnterpriseTestSetTwo(pyauto.PyUITest):
Nirnimesh 2011/08/05 19:05:23 'SetTwo' is not informative enough. In the docstr
aocampo 2011/08/05 23:04:32 Done.
+ """Test for Enterprise features.
+ Browser preferences will be managed using policies. These managed preferences
+ cannot be modified by user. This works only for Google Chrome, not Chromium.
+
+ On Linux, assume that 'suid-python' (a python binary setuid root) is
+ available on the machine under /usr/local/bin directory.
+ """
+ assert pyauto.PyUITest.IsWin() or pyauto.PyUITest.IsLinux(), \
+ 'Only runs on Win or Linux'
+
+ def Debug(self):
+ """Test method for experimentation.
+
+ This method will not run automatically.
+ """
+ import pprint
+ pp = pprint.PrettyPrinter(indent=2)
+ while True:
+ raw_input('Interact with the browser and hit <enter> to dump prefs... ')
+ pp.pprint(self.GetPrefsInfo().Prefs())
+
+ @staticmethod
+ def _Cleanup():
+ """Removes the registry key and its subkeys(if they exist).
+
+ Win: Registry Key being deleted: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google
+ Linux: Removes the chrome directory from /etc/opt
+ """
+ if pyauto.PyUITest.IsWin():
+ if subprocess.call(
+ r'reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google') == 0:
+ logging.debug(r'Removing HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google')
+ subprocess.call(r'reg delete HKLM\Software\Policies\Google /f')
+ elif pyauto.PyUITest.IsLinux():
+ sudo_cmd_file = os.path.join(os.path.dirname(__file__),
+ 'enterprise_helper_linux.py')
+ if os.path.isdir ('/etc/opt/chrome'):
+ logging.debug('Removing directory /etc/opt/chrome/')
+ subprocess.call(['suid-python', sudo_cmd_file,
+ 'remove_dir', '/etc/opt/chrome'])
+
+ @staticmethod
+ def _SetUp():
+ """Win: Add the registry keys from the .reg file.
+
+ Removes the registry key and its subkeys if they exist.
+ Adding HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google.
+
+ Linux: Copy the chrome.json file to the managed directory.
+ Remove /etc/opt/chrome directory if it exists.
+ """
+ EnterpriseTestSetTwo._Cleanup()
+ if pyauto.PyUITest.IsWin():
+ registry_location = os.path.join(EnterpriseTestSetTwo.DataDir(), 'enterprise',
Nirnimesh 2011/08/05 19:05:23 >80 chars
+ 'chrome-add-reverse.reg')
+ # Add the registry keys
+ subprocess.call('reg import %s' % registry_location)
+ elif pyauto.PyUITest.IsLinux():
+ chrome_json = os.path.join(EnterpriseTestSetTwo.DataDir(),
+ 'enterprise', 'chrome-reverse.json')
+ sudo_cmd_file = os.path.join(os.path.dirname(__file__),
+ 'enterprise_helper_linux.py')
+ policies_location = '/etc/opt/chrome/policies/managed'
+ subprocess.call(['suid-python', sudo_cmd_file,
+ 'setup_dir', policies_location])
+ # Copy chrome.json file to the managed directory
+ subprocess.call(['suid-python', sudo_cmd_file,
+ 'copy', chrome_json, policies_location])
+
+ def setUp(self):
+ # Add policies through registry or json file.
+ self._SetUp()
+ # Check if registries are created in Win.
+ if pyauto.PyUITest.IsWin():
+ registry_query_code = subprocess.call(
+ r'reg query HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google')
+ assert registry_query_code == 0, 'Could not create registries.'
+ # Check if json file is copied under correct location in Linux.
+ elif pyauto.PyUITest.IsLinux():
+ policy_file_check = os.path.isfile(
+ '/etc/opt/chrome/policies/managed/chrome-reverse.json')
Nirnimesh 2011/08/05 19:05:23 >80 chars
aocampo 2011/08/05 23:04:32 Done.
+ assert policy_file_check, 'Policy file(s) not set up.'
+ pyauto.PyUITest.setUp(self)
+
+ def tearDown(self):
+ pyauto.PyUITest.tearDown(self)
+ EnterpriseTestSetTwo._Cleanup()
+
+ def _CheckIfPrefCanBeModified(self, key, defaultval, newval):
+ """Check if the managed preferences can be modified.
+
+ Args:
+ key: The preference key that you want to modify
+ defaultval: Default value of the preference that we are trying to modify
+ newval: New value that we are trying to set
+ """
+ # Check if the default value of the preference is set as expected.
+ self.assertEqual(self.GetPrefsInfo().Prefs(key), defaultval,
+ msg='Default value of the preference is wrong.')
+ self.assertRaises(pyauto.JSONInterfaceError,
+ lambda: self.SetPrefs(key, newval))
+
+ def _GetPluginPID(self, plugin_name):
+ """Fetch the pid of the plugin process with name |plugin_name|."""
+ child_processes = self.GetBrowserInfo()['child_processes']
+ plugin_type = 'Plug-in'
+ for x in child_processes:
+ if x['type'] == plugin_type and re.search(plugin_name, x['name']):
+ return x['pid']
+ return None
+
+ # Tests for options in Basics
+ def testStartupPages(self):
+ """Verify that user cannot modify the startup page options."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ # Verify startup option
+ self.assertEquals(0, self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
+ self.assertRaises(pyauto.JSONInterfaceError,
+ lambda: self.SetPrefs(pyauto.kRestoreOnStartup, 1))
+
+ def testHomePageOptions(self):
+ """Verify that we cannot modify Homepage settings."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ # Try to configure home page URL
+ self.assertEquals('http://chromium.org',
+ self.GetPrefsInfo().Prefs('homepage'))
+ self.assertRaises(pyauto.JSONInterfaceError,
+ lambda: self.SetPrefs('homepage', 'http://www.google.com'))
+
+ # Try to reconfigure NTP as home page
+ self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kHomePageIsNewTabPage))
+ self.assertRaises(pyauto.JSONInterfaceError,
+ lambda: self.SetPrefs(pyauto.kHomePageIsNewTabPage, True))
+
+ def testShowHomeButton(self):
+ """Verify that home button option cannot be modified when it's managed."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self._CheckIfPrefCanBeModified(pyauto.kShowHomeButton, False, True)
+
+ def testInstant(self):
+ """Verify that Instant option cannot be modified."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self._CheckIfPrefCanBeModified(pyauto.kInstantEnabled, False, True)
+
+ # Tests for options in Personal Stuff
+ def testPasswordManagerEnabled(self):
+ """Verify that password manager preference cannot be modified."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self._CheckIfPrefCanBeModified(pyauto.kPasswordManagerEnabled, False, True)
+
+ # Tests for options in Under the Hood
+ def testPrivacyPrefs(self):
+ """Verify that the managed preferences cannot be modified."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ prefs_list = [
+ # (preference key, default value, new value)
+ (pyauto.kAlternateErrorPagesEnabled, False, True),
+ (pyauto.kNetworkPredictionEnabled, False, True),
+ (pyauto.kSafeBrowsingEnabled, False, True),
+ (pyauto.kSearchSuggestEnabled, False, True),
+ ]
+ # Check if the policies got applied by trying to modify
+ for key, defaultval, newval in prefs_list:
+ logging.info('Checking pref %s', key)
+ self._CheckIfPrefCanBeModified(key, defaultval, newval)
+
+ def testNotClearSiteDataOnExit(self):
+ """Verify that clear data on exit preference cannot be modified."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self._CheckIfPrefCanBeModified(pyauto.kClearSiteDataOnExit, False, True)
+
+ def testUnblockThirdPartyCookies(self):
+ """Verify that block third party cookies preference cannot be modified."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self._CheckIfPrefCanBeModified(pyauto.kBlockThirdPartyCookies, False, True)
+
+ def testEnableDevTools(self):
+ """Verify that devtools window can be launched."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ # DevTools process can be seen by PyAuto only when it's undocked.
+ self.SetPrefs(pyauto.kDevToolsOpenDocked, False)
+ self.ApplyAccelerator(pyauto.IDC_DEV_TOOLS)
+ self.assertEquals(2, len(self.GetBrowserInfo()['windows']),
+ msg='Devtools window not launched.')
+
+ def testEnableSPDY(self):
+ """Verify that SPDY is enabled."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self.NavigateToURL('chrome://net-internals/#spdy')
+ self.assertEquals(0,
+ self.FindInPage('encrypted.google.com')['match_count'])
+ self.AppendTab(pyauto.GURL('https://encrypted.google.com'))
+ self.assertEquals('Google', self.GetActiveTabTitle())
+ self.GetBrowserWindow(0).GetTab(0).Reload()
+ self.assertEquals(1,
+ self.FindInPage('encrypted.google.com', tab_index=0)['match_count'],
+ msg='SPDY is not enabled.')
+
+ def testSetDownloadDirectory(self):
+ """Verify that the downloads directory and prompt for download preferences
+ can be modified.
+ """
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ if self.IsWin():
+ download_default_dir = os.path.join(os.getenv('USERPROFILE'),'Downloads')
+ self.assertEqual(download_default_dir,
+ self.GetPrefsInfo().Prefs()['download']['default_directory'],
+ msg='Downloads directory is not set correctly.')
+ # Check for changing the download directory location
+ self.SetPrefs(pyauto.kDownloadDefaultDirectory,
+ os.getenv('USERPROFILE'))
+ elif self.IsLinux():
+ download_default_dir = os.path.join(os.getenv('HOME'), 'Downloads')
+ self.assertEqual(download_default_dir,
+ self.GetPrefsInfo().Prefs()['download']['default_directory'],
+ msg='Downloads directory is not set correctly.')
+ self.SetPrefs(pyauto.kDownloadDefaultDirectory,
+ os.getenv('HOME'))
+ # Check for changing the option 'Ask for each download'
+ self.SetPrefs(pyauto.kPromptForDownload, False)
+
+ def testIncognitoDisabled(self):
+ """Verify that incognito window can be launched."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
+ self.assertEquals(1, self.GetBrowserWindowCount())
+
+ def testEnableBrowsingHistory(self):
+ """Verify that browsing history is being saved."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'empty.html'))
+ self.NavigateToURL(url)
+ self.assertTrue(self.GetHistoryInfo().History(),
+ msg='History not is being saved.')
+
+ def testAlwaysAuthorizePluginsDisabled(self):
+ """Verify plugins are always not allowed to run when policy is set."""
+ if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
+ return
+ url = self.GetFileURLForDataPath('plugin', 'java_new.html')
+ self.NavigateToURL(url)
+ self.assertTrue(self.WaitForInfobarCount(1))
+ pid = self._GetPluginPID('Java')
+ self.assertFalse(pid, 'There is a plugin process for java')
+
Nirnimesh 2011/08/05 19:05:23 leave another blank line here
if __name__ == '__main__':
pyauto_functional.Main()
« no previous file with comments | « no previous file | enterprise_helper_linux.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698