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
|
#!/usr/bin/env python
# Copyright (c) 2012 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 cgi
import os
import pyauto_functional # Must be imported before pyauto
import pyauto
class InstantSettingsTest(pyauto.PyUITest):
"""Test Chrome Instant settings."""
def testEnableDisableInstant(self):
"""Test to verify default Chrome Instant setting.
Check if the setting can be enabled and disabled."""
self.assertFalse(self.GetPrefsInfo().Prefs(pyauto.kInstantEnabled),
msg='Instant is enabled by default.')
# Enable Instant.
self.SetPrefs(pyauto.kInstantEnabled, True)
self.assertTrue(self.GetPrefsInfo().Prefs(pyauto.kInstantEnabled),
msg='Instant is not enabled.')
# Make sure Instant works.
self.SetOmniboxText('google')
self.assertTrue(self.WaitUntil(
lambda: self.GetInstantInfo().get('current') and not
self.GetInstantInfo().get('loading')))
title = self.GetInstantInfo()['title']
self.assertEqual('Google', title, msg='Instant did not load.')
# Disable Instant.
self.SetPrefs(pyauto.kInstantEnabled, False)
self.assertFalse(self.GetInstantInfo()['enabled'],
msg='Instant is not disabled.')
class InstantTest(pyauto.PyUITest):
"""TestCase for Omnibox Instant feature."""
def setUp(self):
pyauto.PyUITest.setUp(self)
self.SetPrefs(pyauto.kInstantEnabled, True)
def _DoneLoading(self):
info = self.GetInstantInfo()
return info.get('current') and not info.get('loading')
def _DoneLoadingGoogleQuery(self, query):
"""Wait for Omnibox Instant to load Google search result
and verify location URL contains the specifed query.
Args:
query: Value of query parameter.
E.g., http://www.google.com?q=hi so query is 'hi'.
"""
self.assertTrue(self.WaitUntil(self._DoneLoading))
location = self.GetInstantInfo().get('location')
if location is not None:
q = cgi.parse_qs(location).get('q')
if q is not None and query in q:
return True
return False
def testInstantLoadsSearchResults(self):
"""Test that Instant loads search results based on omnibox input."""
# Initiate Instant search (at default google.com).
self.SetOmniboxText('chrome instant')
self.assertTrue(self.WaitUntil(self._DoneLoading))
location = self.GetInstantInfo()['location']
self.assertTrue('google.com' in location,
msg='No google.com in %s' % location)
def testInstantCaseSensitivity(self):
"""Verify that Chrome Instant results are case insensitive."""
# Text in lowercase letters.
self.SetOmniboxText('google')
self.assertTrue(self.WaitUntil(self._DoneLoading))
lowercase_instant_info = self.GetInstantInfo()
# Text in uppercase letters.
self.SetOmniboxText('GOOGLE')
self.assertTrue(self.WaitUntil(self._DoneLoading))
uppercase_instant_info = self.GetInstantInfo()
# Check lowercase and uppercase text results are same.
self.assertEquals(lowercase_instant_info, uppercase_instant_info,
msg='Lowercase and uppercase Instant info do not match.')
# Text in mixed case letters.
self.SetOmniboxText('GooGle')
self.assertTrue(self.WaitUntil(self._DoneLoading))
mixedcase_instant_info = self.GetInstantInfo()
# Check mixedcase and uppercase text results are same.
self.assertEquals(mixedcase_instant_info, uppercase_instant_info,
msg='Mixedcase and uppercase Instant info do not match.')
def testInstantWithNonInstantSearchEngine(self):
"""Verify that Instant is inactive for non-Instant search engines."""
# Check with Yahoo!, which doesn't support Instant yet.
self.MakeSearchEngineDefault('yahoo.com')
self.assertFalse(self.GetInstantInfo()['active'],
msg='Instant is active for Yahoo!')
# Check with Bing, which doesn't support Instant yet.
self.MakeSearchEngineDefault('bing.com')
self.assertFalse(self.GetInstantInfo()['active'],
msg='Instant is active for Bing.')
def testInstantDisabledInIncognito(self):
"""Test that Instant is disabled in incognito mode."""
self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
self.SetOmniboxText('google', windex=1)
self.assertFalse(self.GetInstantInfo()['active'],
'Instant enabled in incognito mode.')
def testInstantDisabledForURLs(self):
"""Test that Instant is disabled for non-search URLs."""
self.SetOmniboxText('http://www.google.com/')
self.WaitUntilOmniboxQueryDone()
self.assertFalse(self.GetInstantInfo()['current'],
'Instant enabled for non-search URLs.')
self.SetOmniboxText('google.es')
self.WaitUntilOmniboxQueryDone()
self.assertFalse(self.GetInstantInfo()['current'],
'Instant enabled for non-search URLs.')
self.SetOmniboxText(self.GetFileURLForDataPath('title2.html'))
self.WaitUntilOmniboxQueryDone()
self.assertFalse(self.GetInstantInfo()['current'],
'Instant enabled for non-search URLs.')
def testInstantDisabledForJavaScript(self):
"""Test that Instant is disabled for JavaScript URLs."""
self.SetOmniboxText('javascript:')
self.assertFalse(self.GetInstantInfo()['current'],
'Instant enabled for JavaScript URL.')
def testInstantLoadsFor100CharsLongQuery(self):
"""Test that Instant loads for search query of 100 characters."""
query = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz' \
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv'
self.assertEqual(100, len(query))
self.SetOmniboxText(query)
self.assertTrue(self.WaitUntil(self._DoneLoadingGoogleQuery, args=[query]))
def _BringUpInstant(self):
"""Helper function to bring up Instant."""
self.SetOmniboxText('google')
self.assertTrue(self.WaitUntil(self._DoneLoading))
self.assertTrue('www.google.com' in self.GetInstantInfo()['location'],
msg='No www.google.com in %s' %
self.GetInstantInfo()['location'])
def testInstantOverlayNotStoredInHistory(self):
"""Test that Instant overlay page is not stored in history."""
self._BringUpInstant()
history = self.GetHistoryInfo().History()
self.assertEqual(0, len(history), msg='Instant URL stored in history.')
def testFindInCanDismissInstant(self):
"""Test that Instant preview is dismissed by find-in-page."""
self._BringUpInstant()
self.OpenFindInPage()
self.assertFalse(self.GetInstantInfo()['current'],
'Find-in-page does not dismiss Instant.')
def testNTPCanDismissInstant(self):
"""Test that Instant preview is dismissed by adding new tab page."""
self.NavigateToURL('about:blank');
self._BringUpInstant()
self.AppendTab(pyauto.GURL('chrome://newtab'))
self.assertFalse(self.GetInstantInfo()['current'],
'NTP does not dismiss Instant.')
def testExtnPageCanDismissInstant(self):
"""Test that Instant preview is dismissed by extension page."""
self._BringUpInstant()
self.AppendTab(pyauto.GURL('chrome://extensions'))
self.assertFalse(self.GetInstantInfo()['current'],
'Extension page does not dismiss Instant.')
def _AssertInstantDoesNotDownloadFile(self, path):
"""Asserts Instant does not download the specified file.
Args:
path: Path to file.
"""
self.NavigateToURL('chrome://downloads')
filepath = self.GetFileURLForDataPath(path)
self.SetOmniboxText(filepath)
self.WaitUntilOmniboxQueryDone()
self.WaitForAllDownloadsToComplete()
self.assertFalse(self.GetDownloadsInfo().Downloads(),
msg='Should not download: %s' % filepath)
def testInstantDoesNotDownloadZipFile(self):
"""Test that Instant does not download zip file."""
self._AssertInstantDoesNotDownloadFile(os.path.join('zip', 'test.zip'))
def testInstantDoesNotDownloadPDFFile(self):
"""Test that Instant does not download PDF file."""
self._AssertInstantDoesNotDownloadFile(os.path.join('printing',
'cloud_print_unittest.pdf'))
if __name__ == '__main__':
pyauto_functional.Main()
|