OLD | NEW |
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 import time | 7 import time |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
11 | 11 |
12 | 12 |
13 class BrowsingDataTest(pyauto.PyUITest): | 13 class BrowsingDataTest(pyauto.PyUITest): |
14 """Tests that clearing browsing data works correctly.""" | 14 """Tests that clearing browsing data works correctly.""" |
15 | 15 |
| 16 def _DownloadTestFile(self, file_name): |
| 17 """Downloads the specified file from the 'downloads' directory and waits |
| 18 for downloads to complete. |
| 19 """ |
| 20 test_dir = os.path.join(self.DataDir(), 'downloads') |
| 21 file_path = os.path.join(test_dir, file_name) |
| 22 file_url = self.GetFileURLForPath(file_path) |
| 23 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), |
| 24 file_name) |
| 25 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) |
| 26 self.DownloadAndWaitForStart(file_url) |
| 27 self.WaitForAllDownloadsToComplete() |
| 28 |
| 29 def _GetURLForFile(self, file_name): |
| 30 """Returns the url for the file in the 'data' directory.""" |
| 31 return self.GetFileURLForPath(os.path.join(self.DataDir(), file_name)) |
| 32 |
16 def testClearHistory(self): | 33 def testClearHistory(self): |
17 """Verify that clearing the history works.""" | 34 """Verify that clearing the history works.""" |
18 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) | 35 self.NavigateToURL(self._GetURLForFile('title2.html')) |
19 self.NavigateToURL(url) | |
20 | |
21 history = self.GetHistoryInfo().History() | 36 history = self.GetHistoryInfo().History() |
22 self.assertEqual(1, len(history)) | 37 self.assertEqual(1, len(history)) |
23 | 38 |
24 self.ClearBrowsingData(['HISTORY'], 'EVERYTHING') | 39 self.ClearBrowsingData(['HISTORY'], 'EVERYTHING') |
25 history = self.GetHistoryInfo().History() | 40 history = self.GetHistoryInfo().History() |
26 self.assertEqual(0, len(history)) | 41 self.assertFalse(history) |
| 42 |
| 43 def testClearCookies(self): |
| 44 """Verify clearing cookies.""" |
| 45 # First build up some data with cookies. |
| 46 cookie_url = pyauto.GURL(self._GetURLForFile('title2.html')) |
| 47 cookie_val = 'foo=bar' |
| 48 self.SetCookie(cookie_url, cookie_val) |
| 49 self.assertEqual(cookie_val, self.GetCookie(cookie_url)) |
| 50 # Then clear the cookies. |
| 51 self.ClearBrowsingData(['COOKIES'], 'EVERYTHING') |
| 52 cookie_data = self.GetCookie(cookie_url) |
| 53 self.assertFalse(cookie_data) |
| 54 |
| 55 def testClearDownloads(self): |
| 56 """Verify clearing downloads.""" |
| 57 # First build up some data with downloads. |
| 58 self._DownloadTestFile('a_zip_file.zip') |
| 59 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) |
| 60 # Clear the downloads and verify they're gone. |
| 61 self.ClearBrowsingData(['DOWNLOADS'], 'EVERYTHING') |
| 62 downloads = self.GetDownloadsInfo().Downloads() |
| 63 self.assertFalse(downloads) |
27 | 64 |
28 def testClearHistoryPastHour(self): | 65 def testClearHistoryPastHour(self): |
29 """Verify that clearing the history of the past hour works and does not | 66 """Verify that clearing the history of the past hour works and does not |
30 clear history older than one hour. | 67 clear history older than one hour. |
31 """ | 68 """ |
32 title = 'Google' | 69 title = 'Google' |
33 num_secs_in_hour = 3600 | 70 num_secs_in_hour = 3600 |
34 | 71 |
35 # Forge a history item for two hours ago | 72 # Forge a history item for two hours ago |
36 now = time.time() | 73 now = time.time() |
(...skipping 11 matching lines...) Expand all Loading... |
48 self.assertEqual(2, len(history)) | 85 self.assertEqual(2, len(history)) |
49 | 86 |
50 self.ClearBrowsingData(['HISTORY'], 'LAST_HOUR') | 87 self.ClearBrowsingData(['HISTORY'], 'LAST_HOUR') |
51 history = self.GetHistoryInfo().History() | 88 history = self.GetHistoryInfo().History() |
52 self.assertEqual(1, len(history)) | 89 self.assertEqual(1, len(history)) |
53 self.assertEqual(title, history[0]['title']) | 90 self.assertEqual(title, history[0]['title']) |
54 | 91 |
55 def testClearHistoryAndDownloads(self): | 92 def testClearHistoryAndDownloads(self): |
56 """Verify that we can clear history and downloads at the same time.""" | 93 """Verify that we can clear history and downloads at the same time.""" |
57 # First build up some history and download something. | 94 # First build up some history and download something. |
58 url = self.GetFileURLForPath(os.path.join(self.DataDir(), 'title2.html')) | 95 self.NavigateToURL(self._GetURLForFile('title2.html')) |
59 self.NavigateToURL(url) | 96 self._DownloadTestFile('a_zip_file.zip') |
60 | |
61 test_dir = os.path.join(os.path.abspath(self.DataDir()), 'downloads') | |
62 file_path = os.path.join(test_dir, 'a_zip_file.zip') | |
63 file_url = self.GetFileURLForPath(file_path) | |
64 downloaded_pkg = os.path.join(self.GetDownloadDirectory().value(), | |
65 'a_zip_file.zip') | |
66 os.path.exists(downloaded_pkg) and os.remove(downloaded_pkg) | |
67 self.DownloadAndWaitForStart(file_url) | |
68 self.WaitForAllDownloadsToComplete() | |
69 | 97 |
70 # Verify that the history and download exist. | 98 # Verify that the history and download exist. |
71 self.assertEqual(1, len(self.GetHistoryInfo().History())) | 99 self.assertEqual(1, len(self.GetHistoryInfo().History())) |
72 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) | 100 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) |
73 | 101 |
74 # Clear the history and downloads and verify they're both gone. | 102 # Clear the history and downloads and verify they're both gone. |
75 self.ClearBrowsingData(['HISTORY', 'DOWNLOADS'], 'EVERYTHING') | 103 self.ClearBrowsingData(['HISTORY', 'DOWNLOADS'], 'EVERYTHING') |
76 history = self.GetHistoryInfo().History() | 104 history = self.GetHistoryInfo().History() |
77 downloads = self.GetDownloadsInfo().Downloads() | 105 downloads = self.GetDownloadsInfo().Downloads() |
78 self.assertEqual(0, len(history)) | 106 self.assertFalse(history) |
79 self.assertEqual(0, len(downloads)) | 107 self.assertFalse(downloads) |
| 108 |
| 109 def testClearingAccuracy(self): |
| 110 """Verify that clearing one thing does not clear another.""" |
| 111 # First build up some history and download something. |
| 112 self.NavigateToURL(self._GetURLForFile('title2.html')) |
| 113 self._DownloadTestFile('a_zip_file.zip') |
| 114 |
| 115 # Verify that the history and download exist. |
| 116 self.assertEqual(1, len(self.GetHistoryInfo().History())) |
| 117 self.assertEqual(1, len(self.GetDownloadsInfo().Downloads())) |
| 118 |
| 119 # Clear history and verify that downloads exist. |
| 120 self.ClearBrowsingData(['HISTORY'], 'EVERYTHING') |
| 121 history = self.GetHistoryInfo().History() |
| 122 downloads = self.GetDownloadsInfo().Downloads() |
| 123 self.assertFalse(history) |
| 124 self.assertEqual(1, len(downloads)) |
80 | 125 |
81 | 126 |
82 if __name__ == '__main__': | 127 if __name__ == '__main__': |
83 pyauto_functional.Main() | 128 pyauto_functional.Main() |
OLD | NEW |