1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
|
#!/usr/bin/python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import subprocess
import re
import pyauto_functional # must be imported before pyauto
import pyauto
class EnterpriseTest(pyauto.PyUITest):
"""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.
"""
while True:
raw_input('Interact with the browser and hit <enter> to dump prefs... ')
self.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.
"""
EnterpriseTest._Cleanup()
if pyauto.PyUITest.IsWin():
registry_location = os.path.join(EnterpriseTest.DataDir(), 'enterprise',
'chrome-add.reg')
# Add the registry keys
subprocess.call('reg import %s' % registry_location)
elif pyauto.PyUITest.IsLinux():
chrome_json = os.path.join(EnterpriseTest.DataDir(),
'enterprise', 'chrome.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.json')
assert policy_file_check, 'Policy file(s) not set up.'
pyauto.PyUITest.setUp(self)
def tearDown(self):
pyauto.PyUITest.tearDown(self)
EnterpriseTest._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(4, self.GetPrefsInfo().Prefs(pyauto.kRestoreOnStartup))
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kRestoreOnStartup, 1))
# Verify URLs to open on startup
self.assertEquals(['http://chromium.org'],
self.GetPrefsInfo().Prefs(pyauto.kURLsToRestoreOnStartup))
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kURLsToRestoreOnStartup,
['http://www.google.com']))
def testHomePageOptions(self):
"""Verify that we cannot modify Homepage URL."""
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 remove NTP as home page
self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kHomePageIsNewTabPage))
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kHomePageIsNewTabPage, False))
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, True, False)
def testInstant(self):
"""Verify that Instant option cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kInstantEnabled, True, False)
# Tests for options in Personal Stuff
def testPasswordManager(self):
"""Verify that password manager preference cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kPasswordManagerEnabled, True, False)
def testPasswordManagerNotAllowShowPasswords(self):
"""Verify that password manager preference not to show passwords
cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kPasswordManagerAllowShowPasswords,
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, True, False),
(pyauto.kAutofillEnabled, False, True),
(pyauto.kNetworkPredictionEnabled, True, False),
(pyauto.kSafeBrowsingEnabled, True, False),
(pyauto.kSearchSuggestEnabled, True, False),
]
# 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 testClearSiteDataOnExit(self):
"""Verify that clear data on exit preference cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kClearSiteDataOnExit, True, False)
def testBlockThirdPartyCookies(self):
"""Verify that clear data on exit preference cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kBlockThirdPartyCookies, True, False)
# Tests for general options
def testApplicationLocale(self):
"""Verify that Chrome can be launched only in a specific locale."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
if self.IsWin():
self.assertTrue(re.search('hi',
self.GetPrefsInfo().Prefs()['intl']['accept_languages']),
msg='Chrome locale is not Hindi.')
# TODO(sunandt): Try changing the application locale to another language.
elif self.IsLinux():
logging.info("Locale policy not supported in Linux")
pass
def testDisableDevTools(self):
"""Verify that devtools window cannot 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(1, len(self.GetBrowserInfo()['windows']),
msg='Devtools window launched.')
def testDisableSPDY(self):
"""Verify that SPDY is disabled."""
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(0,
self.FindInPage('encrypted.google.com', tab_index=0)['match_count'],
msg='SPDY is not disabled.')
def testDisabledPlugins(self):
"""Verify that disabled plugins cannot be enabled."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
for plugin in self.GetPluginsInfo().Plugins():
if re.search('Flash', plugin['name']):
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.EnablePlugin(plugin['path']))
return
def testDisabledPluginsException(self):
"""Verify that plugins given exceptions can be managed by users.
Chrome PDF Viewer is disabled using DisabledPlugins policy.
User can still toggle the plugin setting when an exception is given for a
plugin. So we are trying to enable Chrome PDF Viewer.
"""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
for plugin in self.GetPluginsInfo().Plugins():
if re.search('Chrome PDF Viewer', plugin['name']):
self.EnablePlugin(plugin['path'])
return
def testSetDownloadDirectory(self):
"""Verify that the downloads directory and prompt for download preferences
cannot be modified.
"""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self.assertEqual('Downloads',
self.GetPrefsInfo().Prefs()['download']['default_directory'],
msg='Downloads directory is not set correctly.')
if self.IsWin():
# Check for changing the download directory location
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kDownloadDefaultDirectory,
os.getenv('USERPROFILE')))
elif self.IsLinux():
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kDownloadDefaultDirectory,
os.getenv('HOME')))
# Check for changing the option 'Ask for each download'
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kPromptForDownload, True))
def testEnabledPlugins(self):
"""Verify that enabled plugins cannot be disabled."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
for plugin in self.GetPluginsInfo().Plugins():
if re.search('Java', plugin['name']):
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.DisablePlugin(plugin['path']))
return
logging.debug('Java is not present.')
def testIncognitoEnabled(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(2, self.GetBrowserWindowCount())
def testDisableBrowsingHistory(self):
"""Verify that browsing history is not being saved."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'empty.html'))
self.NavigateToURL(url)
self.assertFalse(self.GetHistoryInfo().History(),
msg='History is being saved.')
def testAlwaysAuthorizePlugins(self):
"""Verify plugins are always 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.assertFalse(self.WaitForInfobarCount(1))
pid = self._GetPluginPID('Java')
self.assertTrue(pid, 'No plugin process for java')
def testDisablePopups(self):
"""Verify popups are not allowed if policy disables popups."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
url = self.GetFileURLForDataPath('popup_blocker', 'popup-window-open.html')
self.NavigateToURL(url)
self.assertEqual(1, len(self.GetBlockedPopupsInfo()),
msg='Popup not blocked')
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kManagedDefaultPopupsSetting, 1))
def testTranslateEnabled(self):
"""Verify that translate happens if policy enables it."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kEnableTranslate))
url = self.GetFileURLForDataPath('translate', 'es', 'google.html')
self.NavigateToURL(url)
self.assertTrue(self.WaitForInfobarCount(1))
translate_info = self.GetTranslateInfo()
self.assertEqual('es', translate_info['original_language'])
self.assertFalse(translate_info['page_translated'])
self.assertTrue(translate_info['can_translate_page'])
self.assertTrue('translate_bar' in translate_info)
self._CheckIfPrefCanBeModified(pyauto.kEnableTranslate, True, False)
def testEditBookmarksEnabled(self):
"""Verify that bookmarks can be edited if policy sets it."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kEditBookmarksEnabled, True, False)
def testDefaultSearchProviderEnabled(self):
"""Verify a default search is performed when the user types text in the
omnibox that is not a URL
"""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kDefaultSearchProviderEnabled, True,
False)
intranet_engine = [x for x in self.GetSearchEngineInfo()
if x['keyword'] == 'mis']
self.assertTrue(intranet_engine)
self.assertTrue(intranet_engine[0]['is_default'])
self.SetOmniboxText('google chrome')
self.WaitUntilOmniboxQueryDone()
self.OmniboxAcceptInput()
self.assertTrue(re.search('search.my.company',
self.GetActiveTabURL().spec()))
class EnterpriseTestReverse(pyauto.PyUITest):
"""Test for the Enterprise features that uses the opposite values of the
policies used by above test class 'EnterpriseTest'.
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.
"""
while True:
raw_input('Interact with the browser and hit <enter> to dump prefs... ')
self.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.
"""
EnterpriseTestReverse._Cleanup()
if pyauto.PyUITest.IsWin():
registry_location = os.path.join(EnterpriseTestReverse.DataDir(),
'enterprise', 'chrome-add-reverse.reg')
# Add the registry keys
subprocess.call('reg import %s' % registry_location)
elif pyauto.PyUITest.IsLinux():
chrome_json = os.path.join(EnterpriseTestReverse.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')
assert policy_file_check, 'Policy file(s) not set up.'
pyauto.PyUITest.setUp(self)
def tearDown(self):
pyauto.PyUITest.tearDown(self)
EnterpriseTestReverse._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)
def testPasswordManagerAllowShowPasswords(self):
"""Verify that password manager preference to show passwords
cannot be modified."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kPasswordManagerAllowShowPasswords,
True, False)
# 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 = self.GetDownloadDirectory().value()
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')
def testEnablePopups(self):
"""Verify popups are allowed if policy enables popups."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
url = self.GetFileURLForDataPath('popup_blocker', 'popup-window-open.html')
self.NavigateToURL(url)
self.assertEqual(2, self.GetBrowserWindowCount(),
msg='Popup could not be launched');
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.SetPrefs(pyauto.kManagedDefaultPopupsSetting, 2))
def testTranslateDisabled(self):
"""Verify that translate does not happen if policy disables it."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kEnableTranslate))
url = self.GetFileURLForDataPath('translate', 'es', 'google.html')
self.NavigateToURL(url)
self.assertFalse(self.WaitForInfobarCount(1))
self._CheckIfPrefCanBeModified(pyauto.kEnableTranslate, False, True)
def testEditBookmarksDisabled(self):
"""Verify that bookmarks cannot be edited if policy sets it."""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kEditBookmarksEnabled, False, True)
def testDefaultSearchProviderDisabled(self):
"""Verify that inputting text in omnibox does not trigger search when
default search provider is disabled.
"""
if self.GetBrowserInfo()['properties']['branding'] != 'Google Chrome':
return
self._CheckIfPrefCanBeModified(pyauto.kDefaultSearchProviderEnabled, False,
True)
self.SetOmniboxText('deli')
self.WaitUntilOmniboxQueryDone()
self.assertRaises(pyauto.JSONInterfaceError,
lambda: self.OmniboxAcceptInput())
if __name__ == '__main__':
pyauto_functional.Main()
|