Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/test/functional/imports.py

Issue 3140011: New PyAuto tests for importing browser data. BUG=52009 (Closed)
Patch Set: Final? Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/import/safari/mac.zip ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import glob
8 import logging
9 import optparse
10 import os
11 import shutil
12 import sys
13 import tempfile
14 import zipfile
15
16
17 import pyauto_functional # Must be imported before pyauto
18 import pyauto
19 import pyauto_utils
20
21
22 class ImportsTest(pyauto.PyUITest):
23 """Import settings from other browsers.
24
25 Import settings tables below show which items get imported on first run and
26 via preferences for different browsers and operating systems.
27
28 Bookmarks History SearchEngines Passwords Homepage
29 Firefox:
30 Win/FRUI N Y N N Y
31 Win/Prefs Y Y Y Y N
32 Mac&Lin/FRUI Y Y Y Y Y
33 Mac&Lin/Prefs Y Y Y Y N
34
35 Safari:
36 Mac/FRUI Y Y Y Y N
37 Mac/Prefs Y Y Y Y N
38 """
39 def setUp(self):
40 if pyauto.PyUITest.IsMac():
41 self._firefox_profiles_path = os.path.join(
42 os.environ['HOME'], 'Library','Application Support','Firefox')
43 self._firefox_test_profile = os.path.join(
44 pyauto.PyUITest.DataDir(), 'import', 'firefox', 'macwin.zip')
45 self._safari_profiles_path = os.path.join(
46 os.environ['HOME'], 'Library', 'Safari')
47 elif pyauto.PyUITest.IsWin():
48 self._firefox_profiles_path = os.path.join(
49 os.getenv('APPDATA'), 'Mozilla', 'Firefox')
50 self._firefox_test_profile = os.path.join(
51 pyauto.PyUITest.DataDir(), 'import', 'firefox', 'macwin.zip')
52 else:
53 self._firefox_profiles_path = os.path.join(
54 os.environ['HOME'], '.mozilla', 'firefox')
55 self._firefox_test_profile = os.path.join(
56 pyauto.PyUITest.DataDir(), 'import', 'firefox', 'linux.zip')
57
58 # Expected items for tests.
59 self._history_items = ['Google', 'Google News', u'Google \ub3c4\uc11c']
60 self._bookmark_bar_items = ['Google News']
61 self._bookmark_folder_items = ['Google', u'Google \ub3c4\uc11c']
62 self._password_items = ['etouchqa@gmail.com', 'macqa05']
63 self._home_page = 'http://news.google.com/'
64
65 self._safari_replacer = None
66 self._firefox_replacer = None
67
68 pyauto.PyUITest.setUp(self)
69
70 def tearDown(self):
71 pyauto.PyUITest.tearDown(self)
72 # Delete any replacers that were created to restore the original profiles.
Nirnimesh 2010/08/26 20:28:29 delete "that were created"
73 if self._safari_replacer:
74 del self._safari_replacer
75 if self._firefox_replacer:
76 del self._firefox_replacer
77
78 def _UnzipProfileToDir(self, profile_zip, dir):
79 """Unzip |profile_zip| into directory |dir|.
80
81 Creates |dir| if it doesn't exist.
82 """
83 zf = zipfile.ZipFile(profile_zip)
84 # Make base.
85 pushd = os.getcwd()
86 try:
87 if not os.path.isdir(dir):
88 os.mkdir(dir)
89 os.chdir(dir)
90 # Extract files.
91 for info in zf.infolist():
92 name = info.filename
93 if name.endswith('/'): # It's a directory.
94 if not os.path.isdir(name):
95 os.makedirs(name)
96 else: # It's a file.
97 dir = os.path.dirname(name)
98 if dir and not os.path.isdir(dir):
99 os.makedirs(dir)
100 out = open(name, 'wb')
101 out.write(zf.read(name))
102 out.close()
103 # Set permissions.
104 os.chmod(name, 0777)
105 finally:
106 os.chdir(pushd)
107
108 def _SwapFirefoxProfile(self):
109 """Swaps the test Firefox profile with the original one."""
110 self._firefox_replacer = pyauto_utils.ExistingPathReplacer(
111 self._firefox_profiles_path)
112 self._UnzipProfileToDir(self._firefox_test_profile,
113 self._firefox_profiles_path)
114
115 def _SwapSafariProfile(self):
116 """Swaps the test Safari profile with the original one."""
117 self._safari_replacer = pyauto_utils.ExistingPathReplacer(
118 self._safari_profiles_path)
119 self._UnzipProfileToDir(
120 os.path.join(self.DataDir(), 'import', 'safari', 'mac.zip'),
121 self._safari_profiles_path)
122
123 def _CheckForBookmarks(self, bookmark_titles, bookmark_bar):
124 """Checks that the given bookmarks exist.
125
126 Args:
127 bookmark_titles: A set of bookmark title strings.
128 bookmark_bar: True if the bookmarks are part of the bookmark bar.
129 False otherwise.
130 """
131 confirmed_titles = set()
132 bookmarks = self.GetBookmarkModel()
133 if bookmark_bar:
134 node = bookmarks.BookmarkBar()
135 else:
136 node = bookmarks.Other()
137 for title in bookmark_titles:
138 self.assertTrue([x for x in bookmark_titles \
139 if bookmarks.FindByTitle(title, [node])])
140
141 def _BookmarkDuplicatesExist(self, bookmark_titles):
142 """Returns true if any of the bookmark titles are duplicated.
143
144 Args:
145 bookmark_titles: A list of bookmark title strings.
146 """
147 bookmarks = self.GetBookmarkModel()
148 for title in bookmark_titles:
149 if len(bookmarks.FindByTitle(title)) > 1:
150 return True
151 return False
152
153 def _CheckForHistory(self, history_titles):
154 """Verifies that the given list of history items are in the history.
155
156 Args:
157 history_titles: A list of history title strings.
158 """
159 history = self.GetHistoryInfo().History()
160
161 for title in history_titles:
162 self.assertTrue([x for x in history if x['title'] == title])
163
164 def _CheckForPasswords(self, usernames):
165 """Check that password items exist for the given usernames."""
166 # Password import automation does not work on Mac. See crbug.com/52124.
167 if self.IsMac():
168 return
169 passwords = self.GetSavedPasswords()
170 for username in usernames:
171 self.assertTrue([x for x in passwords if x['username_value'] == username])
172
173 def _CheckDefaults(self, bookmarks, history, passwords, home_page,
174 search_engines):
175 """Checks the defaults for each of the possible import items.
176
177 All arguments are True if they should be checked, False otherwise."""
178 if bookmarks:
179 self._CheckForBookmarks(self._bookmark_bar_items, True)
180 self._CheckForBookmarks(self._bookmark_folder_items, False)
181 if history:
182 self._CheckForHistory(self._history_items)
183 if passwords:
184 self._CheckForPasswords(self._password_items)
185 if home_page:
186 self.assertEqual(self._home_page, self.GetPrefsInfo().Prefs()['homepage'])
187 # TODO(alyssad): Test for search engines after a hook is added.
188 # See crbug.com/52009.
189
190 # Tests.
191 def testFirefoxImportFromPrefs(self):
192 """Verify importing Firefox data through preferences."""
193 self._SwapFirefoxProfile()
194 self.ImportSettings('Mozilla Firefox', False, ['ALL'])
195 self._CheckDefaults(bookmarks=True, history=True, passwords=True,
196 home_page=False, search_engines=True)
197
198 def testFirefoxFirstRun(self):
199 """Verify importing from Firefox on the first run.
200
201 For Win, only history and homepage will only be imported.
202 Mac and Linux can import history, homepage, and bookmarks.
203 """
204 self._SwapFirefoxProfile()
205 self.ImportSettings('Mozilla Firefox', True, ['ALL'])
206 non_win = not self.IsWin()
207 self._CheckDefaults(bookmarks=non_win, history=True, passwords=True,
208 home_page=non_win, search_engines=True)
209
210 def testImportFirefoxDataTwice(self):
211 """Verify importing Firefox data twice.
212
213 Bookmarks should be duplicated, but history and passwords should not.
214 """
215 self._SwapFirefoxProfile()
216 self.ImportSettings('Mozilla Firefox', False, ['ALL'])
217 num_history_orig = len(self.GetHistoryInfo().History())
218 num_passwords_orig = len(self.GetSavedPasswords())
219
220 # Re-import and check for duplicates.
221 self.ImportSettings('Mozilla Firefox', False, ['ALL'])
222 self.assertTrue(self._BookmarkDuplicatesExist(
223 self._bookmark_bar_items + self._bookmark_folder_items))
224 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History()))
225 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords()))
226
227 def testImportFromFirefoxAndSafari(self):
228 """Verify importing from Firefox and then Safari."""
229 # This test is for Mac only.
230 if not self.IsMac():
231 return
232
233 self._SwapSafariProfile()
234 self._SwapFirefoxProfile()
235 self.ImportSettings('Mozilla Firefox', False, ['ALL'])
236 self.ImportSettings('Safari', False, ['ALL'])
237
238 self._CheckDefaults(bookmarks=True, history=True, passwords=True,
239 home_page=False, search_engines=True)
240 self.assertTrue(self._BookmarkDuplicatesExist(
241 self._bookmark_bar_items + self._bookmark_folder_items))
242
243 def testSafariImportFromPrefs(self):
244 """Verify importing Safari data through preferences."""
245 # This test is Mac only.
246 if not self.IsMac():
247 return
248 self._SwapSafariProfile()
249 self.ImportSettings('Safari', False, ['ALL'])
250 self._CheckDefaults(bookmarks=True, history=True, passwords=False,
251 home_page=False, search_engines=True)
252
253 def testSafariFirstRun(self):
254 """Verify importing Safari data on the first run."""
255 # This test is Mac only.
256 if not self.IsMac():
257 return
258 self._SwapSafariProfile()
259 self.ImportSettings('Safari', False, ['ALL'])
260 self._CheckDefaults(bookmarks=True, history=True, passwords=False,
261 home_page=False, search_engines=False)
262
263 def testImportSafariDataTwice(self):
264 """Verify importing Safari data twice.
265
266 Bookmarks should be duplicated, but history and passwords should not."""
267 # This test is Mac only.
268 if not self.IsMac():
269 return
270 self._SwapSafariProfile()
271 self.ImportSettings('Safari', False, ['ALL'])
272 num_history_orig = len(self.GetHistoryInfo().History())
273 num_passwords_orig = len(self.GetSavedPasswords())
274
275 # Re-import and check for duplicates.
276 self.ImportSettings('Safari', False, ['ALL'])
277 self.assertTrue(self._BookmarkDuplicatesExist(
278 self._bookmark_bar_items + self._bookmark_folder_items))
279 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History()))
280 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords()))
281
282
283 if __name__ == '__main__':
284 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « chrome/test/data/import/safari/mac.zip ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698