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

Side by Side Diff: chrome/test/functional/ntp.py

Issue 5255005: Add pyauto tests for the New Tab page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 10 years 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
« no previous file with comments | « no previous file | chrome/test/functional/test_utils.py » ('j') | chrome/test/pyautolib/pyautolib.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 os 6 import os
7 7
8 import pyauto_functional # Must be imported before pyauto 8 import pyauto_functional # Must be imported before pyauto
9 import pyauto 9 import pyauto
10 import test_utils
10 11
11 12
12 class NTPTest(pyauto.PyUITest): 13 class NTPTest(pyauto.PyUITest):
13 """Test of the NTP.""" 14 """Test of the NTP."""
14 15
15 def Debug(self): 16 def Debug(self):
16 """Test method for experimentation. 17 """Test method for experimentation.
17 18
18 This method is not run automatically. 19 This method is not run automatically.
19 """ 20 """
20 while True: 21 while True:
21 raw_input('Interact with the browser and hit <enter> to dump NTP info...') 22 raw_input('Interact with the browser and hit <enter> to dump NTP info...')
22 print '*' * 20 23 print '*' * 20
23 import pprint 24 import pprint
24 pp = pprint.PrettyPrinter(indent=2) 25 pp = pprint.PrettyPrinter(indent=2)
25 pp.pprint(self._GetNTPInfo()) 26 pp.pprint(self._GetNTPInfo())
26 27
27 def __init__(self, methodName='runTest'): 28 def __init__(self, methodName='runTest'):
28 super(NTPTest, self).__init__(methodName) 29 super(NTPTest, self).__init__(methodName)
29 30
30 # Create some dummy file urls we can use in the tests. 31 # Create some dummy file urls we can use in the tests.
31 filenames = ['title1.html', 'title2.html'] 32 filenames = ['title1.html', 'title2.html']
32 titles = [u'', u'Title Of Awesomeness'] 33 titles = [u'', u'Title Of Awesomeness']
33 urls = map(lambda name: self.GetFileURLForDataPath(name), filenames) 34 urls = map(lambda name: self.GetFileURLForDataPath(name), filenames)
34 self.PAGES = map(lambda url, title: {'url': url, 'title': title}, 35 self.PAGES = map(lambda url, title: {'url': url, 'title': title},
35 urls, titles) 36 urls, titles)
36 37
38 def _NTPContainsThumbnail(self, check_thumbnail):
Nirnimesh 2010/11/24 09:58:23 docstring please
kkania 2010/11/24 17:40:35 Done.
39 for thumbnail in self.GetNTPThumbnails():
40 if check_thumbnail['url'] == thumbnail['url']:
41 return True
42 return False
43
37 def testFreshProfile(self): 44 def testFreshProfile(self):
38 """Tests that the NTP with a fresh profile is correct""" 45 """Tests that the NTP with a fresh profile is correct"""
39 thumbnails = self.GetNTPThumbnails() 46 thumbnails = self.GetNTPThumbnails()
40 default_sites = self.GetNTPDefaultSites() 47 default_sites = self.GetNTPDefaultSites()
41 self.assertEqual(len(default_sites), len(thumbnails)) 48 self.assertEqual(len(default_sites), len(thumbnails))
42 for thumbnail, default_site in zip(thumbnails, default_sites): 49 for thumbnail, default_site in zip(thumbnails, default_sites):
43 self.assertEqual(thumbnail['url'], default_site) 50 self.assertEqual(thumbnail['url'], default_site)
44 self.assertEqual(0, len(self.GetNTPRecentlyClosed())) 51 self.assertEqual(0, len(self.GetNTPRecentlyClosed()))
45 52
46 def testRemoveDefaultThumbnails(self): 53 def testRemoveDefaultThumbnails(self):
47 """Tests that the default thumbnails can be removed""" 54 """Tests that the default thumbnails can be removed"""
48 self.RemoveNTPDefaultThumbnails() 55 self.RemoveNTPDefaultThumbnails()
49 self.assertFalse(self.GetNTPThumbnails()) 56 self.assertFalse(self.GetNTPThumbnails())
50 self.RestoreAllNTPThumbnails() 57 self.RestoreAllNTPThumbnails()
51 self.assertEqual(len(self.GetNTPDefaultSites()), 58 self.assertEqual(len(self.GetNTPDefaultSites()),
52 len(self.GetNTPThumbnails())) 59 len(self.GetNTPThumbnails()))
53 self.RemoveNTPDefaultThumbnails() 60 self.RemoveNTPDefaultThumbnails()
54 self.assertFalse(self.GetNTPThumbnails()) 61 self.assertFalse(self.GetNTPThumbnails())
55 62
56 def testOneMostVisitedSite(self): 63 def testOneMostVisitedSite(self):
57 """Tests that a site is added to the most visited sites""" 64 """Tests that a site is added to the most visited sites"""
58 self.RemoveNTPDefaultThumbnails() 65 self.RemoveNTPDefaultThumbnails()
59 self.NavigateToURL(self.PAGES[1]['url']) 66 self.NavigateToURL(self.PAGES[1]['url'])
60 self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url']) 67 thumbnail = self.GetNTPThumbnails()[0]
61 self.assertEqual(self.PAGES[1]['title'], 68 self.assertEqual(self.PAGES[1]['url'], thumbnail['url'])
62 self.GetNTPThumbnails()[0]['title']) 69 self.assertEqual(self.PAGES[1]['title'], thumbnail['title'])
63 70 self.assertFalse(thumbnail['is_pinned'])
64 def testOneRecentlyClosedTab(self):
65 """Tests that closing a tab populates the recently closed tabs list"""
66 self.RemoveNTPDefaultThumbnails()
67 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
68 self.GetBrowserWindow(0).GetTab(1).Close(True)
69 self.assertEqual(self.PAGES[1]['url'],
70 self.GetNTPRecentlyClosed()[0]['url'])
71 self.assertEqual(self.PAGES[1]['title'],
72 self.GetNTPRecentlyClosed()[0]['title'])
73 71
74 def testMoveThumbnailBasic(self): 72 def testMoveThumbnailBasic(self):
75 """Tests moving a thumbnail to a different index""" 73 """Tests moving a thumbnail to a different index"""
76 self.RemoveNTPDefaultThumbnails() 74 self.RemoveNTPDefaultThumbnails()
77 self.NavigateToURL(self.PAGES[0]['url']) 75 self.NavigateToURL(self.PAGES[0]['url'])
78 self.NavigateToURL(self.PAGES[1]['url']) 76 self.NavigateToURL(self.PAGES[1]['url'])
79 thumbnails = self.GetNTPThumbnails() 77 thumbnails = self.GetNTPThumbnails()
80 self.MoveNTPThumbnail(thumbnails[0], 1) 78 self.MoveNTPThumbnail(thumbnails[0], 1)
81 self.assertTrue(self.IsNTPThumbnailPinned(thumbnails[0])) 79 self.assertTrue(self.IsNTPThumbnailPinned(thumbnails[0]))
82 self.assertFalse(self.IsNTPThumbnailPinned(thumbnails[1])) 80 self.assertFalse(self.IsNTPThumbnailPinned(thumbnails[1]))
83 self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[1]['url']) 81 self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[1]['url'])
84 self.assertEqual(1, self.GetNTPThumbnailIndex(thumbnails[0])) 82 self.assertEqual(1, self.GetNTPThumbnailIndex(thumbnails[0]))
85 83
86 def testPinningThumbnailBasic(self): 84 def testPinningThumbnailBasic(self):
87 """Tests that we can pin/unpin a thumbnail""" 85 """Tests that we can pin/unpin a thumbnail"""
88 self.RemoveNTPDefaultThumbnails() 86 self.RemoveNTPDefaultThumbnails()
89 self.NavigateToURL(self.PAGES[0]['url']) 87 self.NavigateToURL(self.PAGES[0]['url'])
90 thumbnail1 = self.GetNTPThumbnails()[0] 88 thumbnail1 = self.GetNTPThumbnails()[0]
91 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) 89 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
92 self.PinNTPThumbnail(thumbnail1) 90 self.PinNTPThumbnail(thumbnail1)
93 self.assertTrue(self.IsNTPThumbnailPinned(thumbnail1)) 91 self.assertTrue(self.IsNTPThumbnailPinned(thumbnail1))
94 self.UnpinNTPThumbnail(thumbnail1) 92 self.UnpinNTPThumbnail(thumbnail1)
95 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) 93 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
96 94
95 def testRemoveThumbnail(self):
96 """Tests removing a thumbnail works"""
97 self.RemoveNTPDefaultThumbnails()
98 for i in range(len(self.PAGES)):
Nirnimesh 2010/11/24 09:58:23 You don't really need |i| for page in self.PAGES:
kkania 2010/11/24 17:40:35 Done.
99 self.AppendTab(pyauto.GURL(self.PAGES[i]['url']))
100 self.assertTrue(self._NTPContainsThumbnail(self.PAGES[i]))
101
102 thumbnails = self.GetNTPThumbnails()
103 for i in range(len(thumbnails)):
Nirnimesh 2010/11/24 09:58:23 ditto
kkania 2010/11/24 17:40:35 Done.
104 self.assertEquals(thumbnails[i], self.GetNTPThumbnails()[0])
Nirnimesh 2010/11/24 09:58:23 this line looks like a tautology Did you mean to u
kkania 2010/11/24 17:40:35 I wanted to make sure that the thumbnails shift to
105 self.RemoveNTPThumbnail(thumbnails[i])
106 self.assertFalse(self._NTPContainsThumbnail(self.PAGES[i]))
107 self.assertFalse(self.GetNTPThumbnails())
108
109 def testIncognitoNotAppearInMostVisited(self):
110 """Tests that visiting a page in incognito mode does cause it to appear in
111 the Most Visited section"""
112 self.RemoveNTPDefaultThumbnails()
113 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
114 self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
115 self.assertEquals([], self.GetNTPThumbnails())
Nirnimesh 2010/11/24 09:58:23 assertFalse
kkania 2010/11/24 17:40:35 I was wondering about this. assertEquals([], ...)
116
117 def testRestoreOncePinnedThumbnail(self):
118 """Tests that after restoring a once pinned thumbnail, the thumbnail is
119 not pinned"""
120 self.RemoveNTPDefaultThumbnails()
121 self.NavigateToURL(self.PAGES[0]['url'])
122 thumbnail1 = self.GetNTPThumbnails()[0]
123 self.PinNTPThumbnail(thumbnail1)
124 self.RemoveNTPThumbnail(thumbnail1)
125 self.RestoreAllNTPThumbnails()
126 self.RemoveNTPDefaultThumbnails()
127 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1))
128
129 def testThumbnailPersistence(self):
130 """Tests that thumbnails persist across Chrome restarts"""
131 self.RemoveNTPDefaultThumbnails()
132 for page in self.PAGES:
133 self.AppendTab(pyauto.GURL(page['url']))
134 thumbnails = self.GetNTPThumbnails()
135 self.MoveNTPThumbnail(thumbnails[0], 1)
136 thumbnails = self.GetNTPThumbnails()
137
Nirnimesh 2010/11/24 09:58:23 please assert that |thumbnails| is not empty
kkania 2010/11/24 17:40:35 I am interested in your thoughts about this. I was
Nirnimesh 2010/11/24 20:38:11 Ok
138 self.RestartBrowser(False)
Nirnimesh 2010/11/24 09:58:23 use named arg. ie clear_profile=False
kkania 2010/11/24 17:40:35 Done.
139 self.assertEqual(thumbnails, self.GetNTPThumbnails())
140
141 def testRestoreAllRemovedThumbnails(self):
142 """Tests restoring all removed thumnails"""
Nirnimesh 2010/11/24 09:58:23 thumbnails
kkania 2010/11/24 17:40:35 Done.
143 self.RemoveNTPDefaultThumbnails()
144 for page in self.PAGES:
145 self.AppendTab(pyauto.GURL(page['url']))
146
147 thumbnails = self.GetNTPThumbnails()
148 for thumbnail in thumbnails:
149 self.RemoveNTPThumbnail(thumbnail)
150
151 self.RestoreAllNTPThumbnails()
152 self.RemoveNTPDefaultThumbnails()
Nirnimesh 2010/11/24 09:58:23 maybe this line and line 143 should be removed fro
kkania 2010/11/24 17:40:35 That's a good idea, done.
153 self.assertEquals(thumbnails, self.GetNTPThumbnails())
154
155 def testThumbnailRanking(self):
156 """Tests that the thumbnails are ordered according to visit count"""
157 self.RemoveNTPDefaultThumbnails()
158 for page in self.PAGES:
159 self.AppendTab(pyauto.GURL(page['url']))
160 thumbnails = self.GetNTPThumbnails()
161 self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[0]['url'])
162 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
163 self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url'])
164 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
165 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
166 self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[0]['url'])
167
168 def testPinnedThumbnailNeverMoves(self):
169 """Testis that once a thumnail is pinned it never moves"""
Nirnimesh 2010/11/24 09:58:23 Testis?!!
kkania 2010/11/24 17:40:35 Done.
170 self.RemoveNTPDefaultThumbnails()
171 for page in self.PAGES:
172 self.AppendTab(pyauto.GURL(page['url']))
173 self.PinNTPThumbnail(self.GetNTPThumbnails()[0])
174 thumbnails = self.GetNTPThumbnails()
175 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
176 self.assertEqual(thumbnails, self.GetNTPThumbnails())
Nirnimesh 2010/11/24 09:58:23 won't self.PAGES[1]['url']) show up in GetNTPThumb
kkania 2010/11/24 17:40:35 yes, but all the pages have already been added to
177
178 def testThumbnailTitleChangeAfterPageTitleChange(self):
179 """Tests that once a page title changes, the thumbnail title changes also"""
Nirnimesh 2010/11/24 09:58:23 s/also/too/
kkania 2010/11/24 17:40:35 Done.
180 self.RemoveNTPDefaultThumbnails()
181 self.NavigateToURL(self.PAGES[0]['url'])
182 self.assertEqual(self.PAGES[0]['title'],
183 self.GetNTPThumbnails()[0]['title'])
184 self.ExecuteJavascript('window.domAutomationController.send(' +
185 'document.title = "new title")')
186 self.assertEqual('new title', self.GetNTPThumbnails()[0]['title'])
187
188 def testCloseOneTab(self):
189 """Tests that closing a tab populates the recently closed list"""
190 self.RemoveNTPDefaultThumbnails()
191 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
192 self.GetBrowserWindow(0).GetTab(1).Close(True)
193 self.assertEqual(self.PAGES[1]['url'],
194 self.GetNTPRecentlyClosed()[0]['url'])
195 self.assertEqual(self.PAGES[1]['title'],
196 self.GetNTPRecentlyClosed()[0]['title'])
197
198 def testCloseOneWindow(self):
199 """Tests that closing a window populates the recently closed list"""
200 self.RemoveNTPDefaultThumbnails()
201 self.OpenNewBrowserWindow(True)
202 self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
203 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
204 self.CloseBrowserWindow(1)
205 expected = [{ u'type': u'window',
206 u'tabs': [
207 { u'type': u'tab',
208 u'url': self.PAGES[0]['url'],
209 u'direction': u'ltr' },
210 { u'type': u'tab',
211 u'url': self.PAGES[1]['url']}]
212 }]
213 self.assertEquals(expected, test_utils.StripUnmatchedKeys(
214 self.GetNTPRecentlyClosed(), expected))
215
216 def testCloseMultipleTabs(self):
217 """Tests closing multiple tabs"""
Nirnimesh 2010/11/24 09:58:23 Please elaborate. Should mention that it checks th
kkania 2010/11/24 17:40:35 Done.
218 self.RemoveNTPDefaultThumbnails()
219 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
220 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']))
221 self.GetBrowserWindow(0).GetTab(2).Close(True)
222 self.GetBrowserWindow(0).GetTab(1).Close(True)
223 expected = [{ u'type': u'tab',
224 u'url': self.PAGES[0]['url']
225 },
226 { u'type': u'tab',
227 u'url': self.PAGES[1]['url']
228 }]
229 self.assertEquals(expected, test_utils.StripUnmatchedKeys(
230 self.GetNTPRecentlyClosed(), expected))
231
232 def testCloseWindowWithOneTab(self):
233 """Tests that closing a window with only one tab only shows up as a tab in
234 the Recently Closed section"""
235 self.RemoveNTPDefaultThumbnails()
236 self.OpenNewBrowserWindow(True)
237 self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
238 self.CloseBrowserWindow(1)
239 expected = [{ u'type': u'tab',
240 u'url': self.PAGES[0]['url']
241 }]
242 self.assertEquals(expected, test_utils.StripUnmatchedKeys(
243 self.GetNTPRecentlyClosed(), expected))
244
245 def testCloseMultipleWindows(self):
246 """Tests closing multiple windows populates the Recently Closed list"""
247 self.RemoveNTPDefaultThumbnails()
248 self.OpenNewBrowserWindow(True)
249 self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
250 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
251 self.OpenNewBrowserWindow(True)
252 self.NavigateToURL(self.PAGES[1]['url'], 2, 0)
253 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 2)
254 self.CloseBrowserWindow(2)
255 self.CloseBrowserWindow(1)
256 expected = [{ u'type': u'window',
257 u'tabs': [
258 { u'type': u'tab',
259 u'url': self.PAGES[0]['url'],
260 u'direction': u'ltr' },
261 { u'type': u'tab',
262 u'url': self.PAGES[1]['url']}]
263 },
264 { u'type': u'window',
265 u'tabs': [
266 { u'type': u'tab',
267 u'url': self.PAGES[1]['url'],
268 u'direction': u'ltr' },
269 { u'type': u'tab',
270 u'url': self.PAGES[0]['url']}]
271 }]
272 self.assertEquals(expected, test_utils.StripUnmatchedKeys(
273 self.GetNTPRecentlyClosed(), expected))
274
275 def testRecentlyClosedShowsUniqueItems(self):
276 """Tests that the Recently Closed section does not show duplicate items"""
277 self.RemoveNTPDefaultThumbnails()
278 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
279 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']))
280 self.GetBrowserWindow(0).GetTab(1).Close(True)
281 self.GetBrowserWindow(0).GetTab(1).Close(True)
282 self.assertEquals(1, len(self.GetNTPRecentlyClosed()))
283
284 def testRecentlyClosedIncognito(self):
285 """Tests that we don't record closure of Incognito tabs or windows"""
286 self.RemoveNTPDefaultThumbnails()
287 self.RunCommand(pyauto.IDC_NEW_INCOGNITO_WINDOW)
288 self.NavigateToURL(self.PAGES[0]['url'], 1, 0)
289 self.AppendTab(pyauto.GURL(self.PAGES[0]['url']), 1)
290 self.AppendTab(pyauto.GURL(self.PAGES[1]['url']), 1)
291 self.GetBrowserWindow(1).GetTab(0).Close(True)
292 self.assertEqual([], self.GetNTPRecentlyClosed())
Nirnimesh 2010/11/24 09:58:23 assertFalse
kkania 2010/11/24 17:40:35 Done.
293 self.CloseBrowserWindow(1)
294 self.assertEqual([], self.GetNTPRecentlyClosed())
Nirnimesh 2010/11/24 09:58:23 assertFalse
kkania 2010/11/24 17:40:35 Done.
295
97 296
98 if __name__ == '__main__': 297 if __name__ == '__main__':
99 pyauto_functional.Main() 298 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « no previous file | chrome/test/functional/test_utils.py » ('j') | chrome/test/pyautolib/pyautolib.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698