| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2011 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 import time | |
| 8 | |
| 9 import pyauto_functional # Must be imported before pyauto | |
| 10 import pyauto | |
| 11 import test_utils | |
| 12 | |
| 13 | |
| 14 class BrowsingDataTest(pyauto.PyUITest): | |
| 15 """Tests that clearing browsing data works correctly.""" | |
| 16 | |
| 17 def testClearHistory(self): | |
| 18 """Verify that clearing the history works.""" | |
| 19 self.NavigateToURL(self.GetFileURLForDataPath('title2.html')) | |
| 20 history = self.GetHistoryInfo().History() | |
| 21 self.assertEqual(1, len(history)) | |
| 22 | |
| 23 self.ClearBrowsingData(['HISTORY'], 'EVERYTHING') | |
| 24 history = self.GetHistoryInfo().History() | |
| 25 self.assertFalse(history) | |
| 26 | |
| 27 def testClearCookies(self): | |
| 28 """Verify clearing cookies.""" | |
| 29 # First build up some data with cookies. | |
| 30 cookie_url = pyauto.GURL(self.GetFileURLForDataPath('title2.html')) | |
| 31 cookie_val = 'foo=bar' | |
| 32 self.SetCookie(cookie_url, cookie_val) | |
| 33 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) | |
| 34 # Then clear the cookies. | |
| 35 self.ClearBrowsingData(['COOKIES'], 'EVERYTHING') | |
| 36 cookie_data = self.GetCookie(cookie_url) | |
| 37 self.assertFalse(cookie_data) | |
| 38 | |
| 39 def testClearDownloads(self): | |
| 40 """Verify clearing downloads.""" | |
| 41 zip_file = 'a_zip_file.zip' | |
| 42 # First build up some data with downloads. | |
| 43 test_utils.DownloadFileFromDownloadsDataDir(self, zip_file) | |
| 44 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) | |
| 45 # Clear the downloads and verify they're gone. | |
| 46 self.ClearBrowsingData(['DOWNLOADS'], 'EVERYTHING') | |
| 47 downloads = self.GetDownloadsInfo().Downloads() | |
| 48 self.assertFalse(downloads) | |
| 49 | |
| 50 def testClearHistoryPastHour(self): | |
| 51 """Verify that clearing the history of the past hour works and does not | |
| 52 clear history older than one hour. | |
| 53 """ | |
| 54 title = 'Google' | |
| 55 num_secs_in_hour = 3600 | |
| 56 | |
| 57 # Forge a history item for two hours ago | |
| 58 now = time.time() | |
| 59 last_hour = now - (2 * num_secs_in_hour) | |
| 60 self.AddHistoryItem({'title': title, | |
| 61 'url': 'http://www.google.com', | |
| 62 'time': last_hour}) | |
| 63 | |
| 64 # Forge a history item for right now | |
| 65 self.AddHistoryItem({'title': 'This Will Be Cleared', | |
| 66 'url': 'http://www.dev.chromium.org', | |
| 67 'time': now}) | |
| 68 | |
| 69 history = self.GetHistoryInfo().History() | |
| 70 self.assertEqual(2, len(history)) | |
| 71 | |
| 72 self.ClearBrowsingData(['HISTORY'], 'LAST_HOUR') | |
| 73 history = self.GetHistoryInfo().History() | |
| 74 self.assertEqual(1, len(history)) | |
| 75 self.assertEqual(title, history[0]['title']) | |
| 76 | |
| 77 def testClearHistoryAndDownloads(self): | |
| 78 """Verify that we can clear history and downloads at the same time.""" | |
| 79 zip_file = 'a_zip_file.zip' | |
| 80 # First build up some history and download something. | |
| 81 self.NavigateToURL(self.GetFileURLForDataPath('title2.html')) | |
| 82 test_utils.DownloadFileFromDownloadsDataDir(self, zip_file) | |
| 83 | |
| 84 # Verify that the history and download exist. | |
| 85 self.assertEqual(1, len(self.GetHistoryInfo().History())) | |
| 86 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) | |
| 87 | |
| 88 # Clear the history and downloads and verify they're both gone. | |
| 89 self.ClearBrowsingData(['HISTORY', 'DOWNLOADS'], 'EVERYTHING') | |
| 90 history = self.GetHistoryInfo().History() | |
| 91 downloads = self.GetDownloadsInfo().Downloads() | |
| 92 self.assertFalse(history) | |
| 93 self.assertFalse(downloads) | |
| 94 | |
| 95 def testClearingAccuracy(self): | |
| 96 """Verify that clearing one thing does not clear another.""" | |
| 97 zip_file = 'a_zip_file.zip' | |
| 98 # First build up some history and download something. | |
| 99 self.NavigateToURL(self.GetFileURLForDataPath('title2.html')) | |
| 100 test_utils.DownloadFileFromDownloadsDataDir(self, zip_file) | |
| 101 # Verify that the history and download exist. | |
| 102 self.assertEqual(1, len(self.GetHistoryInfo().History())) | |
| 103 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) | |
| 104 | |
| 105 # Clear history and verify that downloads exist. | |
| 106 self.ClearBrowsingData(['HISTORY'], 'EVERYTHING') | |
| 107 history = self.GetHistoryInfo().History() | |
| 108 downloads = self.GetDownloadsInfo().Downloads() | |
| 109 self.assertFalse(history) | |
| 110 self.assertEqual(1, len(downloads)) | |
| 111 | |
| 112 def testClearAutofillData(self): | |
| 113 """Verify that clearing autofill form data works.""" | |
| 114 | |
| 115 # Add new profiles | |
| 116 profiles = [{'NAME_FIRST': ['Bill',], | |
| 117 'NAME_LAST': ['Ding',], | |
| 118 'ADDRESS_HOME_CITY': ['Mountain View',], | |
| 119 'ADDRESS_HOME_STATE': ['CA',], | |
| 120 'ADDRESS_HOME_ZIP': ['94043',],}] | |
| 121 credit_cards = [{'CREDIT_CARD_NAME': 'Bill Ding', | |
| 122 'CREDIT_CARD_NUMBER': '4111111111111111', | |
| 123 'CREDIT_CARD_EXP_MONTH': '01', | |
| 124 'CREDIT_CARD_EXP_4_DIGIT_YEAR': '2012'}] | |
| 125 | |
| 126 self.FillAutofillProfile(profiles=profiles, credit_cards=credit_cards) | |
| 127 | |
| 128 # Verify that the added profiles exist. | |
| 129 profile = self.GetAutofillProfile() | |
| 130 self.assertEqual(profiles, profile['profiles']) | |
| 131 self.assertEqual(credit_cards, profile['credit_cards']) | |
| 132 | |
| 133 # Clear the browser's autofill form data. | |
| 134 self.ClearBrowsingData(['FORM_DATA'], 'EVERYTHING') | |
| 135 | |
| 136 def _ProfileCount(type): | |
| 137 profile = self.GetAutofillProfile() | |
| 138 return len(profile[type]) | |
| 139 | |
| 140 # Verify that all profiles have been cleared. | |
| 141 self.assertTrue(self.WaitUntil(lambda: 0 == _ProfileCount('profiles'))) | |
| 142 self.assertTrue(self.WaitUntil(lambda: 0 == _ProfileCount('credit_cards'))) | |
| 143 | |
| 144 | |
| 145 if __name__ == '__main__': | |
| 146 pyauto_functional.Main() | |
| OLD | NEW |