| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python |
| 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._GetNTPInfo()) |
| 26 |
| 27 def setUp(self): |
| 28 pyauto.PyUITest.setUp(self) |
| 29 # These tests should not have to worry about whatever defaults there are |
| 30 # in the Most Visited section. Close them. |
| 31 for thumbnail in self.GetNTPThumbnails(): |
| 32 self.RemoveNTPThumbnail(thumbnail) |
| 33 |
| 34 # Create some dummy file urls we can use in the tests. |
| 35 filenames = ['title1.html', 'title2.html'] |
| 36 titles = [u'', u'Title Of Awesomeness'] |
| 37 urls = map(lambda name: self.GetFileURLForDataPath(name), filenames) |
| 38 self.PAGES = map(lambda url, title: {'url': url, 'title': title}, |
| 39 urls, titles) |
| 40 |
| 41 def testFreshProfile(self): |
| 42 """Tests that there are no sites or closed tabs with a fresh profile""" |
| 43 # These should be zero thumbnails since we deleted them in |setUp|. |
| 44 self.assertEqual(0, len(self.GetNTPThumbnails())) |
| 45 self.assertEqual(0, len(self.GetNTPRecentlyClosed())) |
| 46 |
| 47 def testOneMostVisitedSite(self): |
| 48 """Tests that a site is added to the most visited sites""" |
| 49 self.NavigateToURL(self.PAGES[1]['url']) |
| 50 self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url']) |
| 51 self.assertEqual(self.PAGES[1]['title'], |
| 52 self.GetNTPThumbnails()[0]['title']) |
| 53 |
| 54 def testOneRecentlyClosedTab(self): |
| 55 """Tests that closing a tab populates the recently closed tabs list""" |
| 56 self.AppendTab(pyauto.GURL(self.PAGES[1]['url'])) |
| 57 self.GetBrowserWindow(0).GetTab(1).Close(True) |
| 58 self.assertEqual(self.PAGES[1]['url'], |
| 59 self.GetNTPRecentlyClosed()[0]['url']) |
| 60 self.assertEqual(self.PAGES[1]['title'], |
| 61 self.GetNTPRecentlyClosed()[0]['title']) |
| 62 |
| 63 def testMoveThumbnailBasic(self): |
| 64 """Tests moving a thumbnail to a different index""" |
| 65 self.NavigateToURL(self.PAGES[0]['url']) |
| 66 self.NavigateToURL(self.PAGES[1]['url']) |
| 67 thumbnails = self.GetNTPThumbnails() |
| 68 self.MoveNTPThumbnail(thumbnails[0], 1) |
| 69 self.assertTrue(self.IsNTPThumbnailPinned(thumbnails[0])) |
| 70 self.assertFalse(self.IsNTPThumbnailPinned(thumbnails[1])) |
| 71 self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[1]['url']) |
| 72 self.assertEqual(1, self.GetNTPThumbnailIndex(thumbnails[0])) |
| 73 |
| 74 def testPinningThumbnailBasic(self): |
| 75 """Tests that we can pin/unpin a thumbnail""" |
| 76 self.NavigateToURL(self.PAGES[0]['url']) |
| 77 thumbnail1 = self.GetNTPThumbnails()[0] |
| 78 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) |
| 79 self.PinNTPThumbnail(thumbnail1) |
| 80 self.assertTrue(self.IsNTPThumbnailPinned(thumbnail1)) |
| 81 self.UnpinNTPThumbnail(thumbnail1) |
| 82 self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) |
| 83 |
| 84 |
| 85 if __name__ == '__main__': |
| 86 pyauto_functional.Main() |
| OLD | NEW |