Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
|
Nirnimesh
2010/11/16 22:25:05
Please add this test in PYAUTO_TESTS
kkania
2010/11/17 01:11:34
Done.
| |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import os | |
| 7 | |
| 8 import pyauto_functional # Must be imported before pyauto | |
| 9 import pyauto | |
| 10 | |
| 11 | |
| 12 class NTPTest(pyauto.PyUITest): | |
| 13 """Test of the NTP.""" | |
| 14 | |
| 15 def Debug(self): | |
| 16 """Test method for experimentation. | |
| 17 | |
| 18 This method is not run automatically. | |
| 19 """ | |
| 20 while True: | |
| 21 raw_input('Interact with the browser and hit <enter> to dump NTP info...') | |
| 22 print '*' * 20 | |
| 23 import pprint | |
| 24 pp = pprint.PrettyPrinter(indent=2) | |
| 25 pp.pprint(self.GetNTPModel()._GetInfo()) | |
| 26 | |
| 27 def setUp(self): | |
| 28 pyauto.PyUITest.setUp(self) | |
| 29 self.ntp = self.GetNTPModel() | |
| 30 # These tests should not have to worry about whatever defaults there are | |
| 31 # in the Most Visited section. Close them. | |
| 32 for thumbnail in self.ntp.GetThumbnails(): | |
| 33 self.ntp.RemoveThumbnail(thumbnail) | |
| 34 | |
| 35 # Create some dummy file urls we can use in the tests. | |
| 36 filenames = ['title1.html', 'title2.html'] | |
| 37 titles = [u'', u'Title Of Awesomeness'] | |
| 38 urls = map(lambda name: self.GetFileURLForDataPath(name), filenames) | |
| 39 self.PAGES = map(lambda url, title: {'url': url, 'title': title}, | |
| 40 urls, titles) | |
| 41 | |
| 42 def testFreshProfile(self): | |
| 43 """Tests that there are no sites or closed tabs with a fresh profile""" | |
| 44 # These should be zero thumbnails since we deleted them in |setUp|. | |
| 45 self.assertEqual(0, len(self.ntp.GetThumbnails())) | |
| 46 self.assertEqual(0, len(self.ntp.GetRecentlyClosed())) | |
| 47 | |
| 48 def testOneMostVisitedSite(self): | |
| 49 """Tests that a site is added to the most visited sites""" | |
| 50 self.NavigateToURL(self.PAGES[1]['url']) | |
| 51 self.assertEqual(self.PAGES[1]['url'], self.ntp.GetThumbnails()[0]['url']) | |
| 52 self.assertEqual(self.PAGES[1]['title'], | |
| 53 self.ntp.GetThumbnails()[0]['title']) | |
| 54 | |
| 55 def testOneRecentlyClosedTab(self): | |
| 56 """Tests that closing a tab populates the recently closed tabs list""" | |
| 57 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) | |
| 58 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
| 59 self.assertEqual(self.PAGES[1]['url'], | |
| 60 self.ntp.GetRecentlyClosed()[0]['url']) | |
| 61 self.assertEqual(self.PAGES[1]['title'], | |
| 62 self.ntp.GetRecentlyClosed()[0]['title']) | |
| 63 | |
| 64 def testMoveThumbnailBasic(self): | |
| 65 """Tests moving a thumbnail to a different index""" | |
| 66 self.NavigateToURL(self.PAGES[0]['url']) | |
| 67 self.NavigateToURL(self.PAGES[1]['url']) | |
| 68 thumbnails = self.ntp.GetThumbnails() | |
| 69 self.ntp.MoveThumbnail(thumbnails[0], 1) | |
| 70 self.assertTrue(self.ntp.IsPinned(thumbnails[0])) | |
| 71 self.assertFalse(self.ntp.IsPinned(thumbnails[1])) | |
| 72 self.assertEqual(self.PAGES[0]['url'], self.ntp.GetThumbnails()[1]['url']) | |
| 73 self.assertEqual(1, self.ntp.GetThumbnailIndex(thumbnails[0])) | |
| 74 | |
| 75 def testPinningThumbnailBasic(self): | |
| 76 """Tests that we can pin/unpin a thumbnail""" | |
| 77 self.NavigateToURL(self.PAGES[0]['url']) | |
| 78 thumbnail1 = self.ntp.GetThumbnails()[0] | |
| 79 self.assertFalse(self.ntp.IsPinned(thumbnail1)) | |
| 80 self.ntp.PinThumbnail(thumbnail1) | |
| 81 self.assertTrue(self.ntp.IsPinned(thumbnail1)) | |
| 82 self.ntp.UnpinThumbnail(thumbnail1) | |
| 83 self.assertFalse(self.ntp.IsPinned(thumbnail1)) | |
| 84 | |
| 85 | |
| 86 if __name__ == '__main__': | |
| 87 pyauto_functional.Main() | |
| OLD | NEW |