| 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 __init__(self, methodName='runTest'): | 
 |  28     super(NTPTest, self).__init__(methodName) | 
 |  29  | 
 |  30     # Create some dummy file urls we can use in the tests. | 
 |  31     filenames = ['title1.html', 'title2.html'] | 
 |  32     titles = [u'', u'Title Of Awesomeness'] | 
 |  33     urls = map(lambda name: self.GetFileURLForDataPath(name), filenames) | 
 |  34     self.PAGES = map(lambda url, title: {'url': url, 'title': title}, | 
 |  35                      urls, titles) | 
 |  36  | 
 |  37   def testFreshProfile(self): | 
 |  38     """Tests that the NTP with a fresh profile is correct""" | 
 |  39     thumbnails = self.GetNTPThumbnails() | 
 |  40     default_sites = self.GetNTPDefaultSites() | 
 |  41     self.assertEqual(len(default_sites), len(thumbnails)) | 
 |  42     for thumbnail, default_site in zip(thumbnails, default_sites): | 
 |  43       self.assertEqual(thumbnail['url'], default_site) | 
 |  44     self.assertEqual(0, len(self.GetNTPRecentlyClosed())) | 
 |  45  | 
 |  46   def testRemoveDefaultThumbnails(self): | 
 |  47     """Tests that the default thumbnails can be removed""" | 
 |  48     self.RemoveNTPDefaultThumbnails() | 
 |  49     self.assertFalse(self.GetNTPThumbnails()) | 
 |  50     self.RestoreAllNTPThumbnails() | 
 |  51     self.assertEqual(len(self.GetNTPDefaultSites()), | 
 |  52                      len(self.GetNTPThumbnails())) | 
 |  53     self.RemoveNTPDefaultThumbnails() | 
 |  54     self.assertFalse(self.GetNTPThumbnails()) | 
 |  55  | 
 |  56   def testOneMostVisitedSite(self): | 
 |  57     """Tests that a site is added to the most visited sites""" | 
 |  58     self.RemoveNTPDefaultThumbnails() | 
 |  59     self.NavigateToURL(self.PAGES[1]['url']) | 
 |  60     self.assertEqual(self.PAGES[1]['url'], self.GetNTPThumbnails()[0]['url']) | 
 |  61     self.assertEqual(self.PAGES[1]['title'], | 
 |  62                      self.GetNTPThumbnails()[0]['title']) | 
 |  63  | 
 |  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  | 
 |  74   def testMoveThumbnailBasic(self): | 
 |  75     """Tests moving a thumbnail to a different index""" | 
 |  76     self.RemoveNTPDefaultThumbnails() | 
 |  77     self.NavigateToURL(self.PAGES[0]['url']) | 
 |  78     self.NavigateToURL(self.PAGES[1]['url']) | 
 |  79     thumbnails = self.GetNTPThumbnails() | 
 |  80     self.MoveNTPThumbnail(thumbnails[0], 1) | 
 |  81     self.assertTrue(self.IsNTPThumbnailPinned(thumbnails[0])) | 
 |  82     self.assertFalse(self.IsNTPThumbnailPinned(thumbnails[1])) | 
 |  83     self.assertEqual(self.PAGES[0]['url'], self.GetNTPThumbnails()[1]['url']) | 
 |  84     self.assertEqual(1, self.GetNTPThumbnailIndex(thumbnails[0])) | 
 |  85  | 
 |  86   def testPinningThumbnailBasic(self): | 
 |  87     """Tests that we can pin/unpin a thumbnail""" | 
 |  88     self.RemoveNTPDefaultThumbnails() | 
 |  89     self.NavigateToURL(self.PAGES[0]['url']) | 
 |  90     thumbnail1 = self.GetNTPThumbnails()[0] | 
 |  91     self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) | 
 |  92     self.PinNTPThumbnail(thumbnail1) | 
 |  93     self.assertTrue(self.IsNTPThumbnailPinned(thumbnail1)) | 
 |  94     self.UnpinNTPThumbnail(thumbnail1) | 
 |  95     self.assertFalse(self.IsNTPThumbnailPinned(thumbnail1)) | 
 |  96  | 
 |  97  | 
 |  98 if __name__ == '__main__': | 
 |  99   pyauto_functional.Main() | 
| OLD | NEW |