OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 glob | 6 import glob |
7 import logging | 7 import logging |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import shutil | 10 import shutil |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 # TODO(nirnimesh): Anything else to be done on other platforms? | 194 # TODO(nirnimesh): Anything else to be done on other platforms? |
195 return True | 195 return True |
196 | 196 |
197 def _ImportFromFirefox(self, bookmarks, history, passwords, home_page, | 197 def _ImportFromFirefox(self, bookmarks, history, passwords, home_page, |
198 search_engines, window_index=0): | 198 search_engines, window_index=0): |
199 """Verify importing individual Firefox data through preferences""" | 199 """Verify importing individual Firefox data through preferences""" |
200 if not self._CanRunFirefoxTests(): | 200 if not self._CanRunFirefoxTests(): |
201 logging.warn('Not running firefox import tests.') | 201 logging.warn('Not running firefox import tests.') |
202 return | 202 return |
203 self._SwapFirefoxProfile() | 203 self._SwapFirefoxProfile() |
204 self.ImportSettings('Mozilla Firefox', False, self._to_import, window_index) | 204 self.ImportSettings('Mozilla Firefox', self._to_import, window_index) |
205 self._CheckDefaults(bookmarks, history, passwords, home_page, | 205 self._CheckDefaults(bookmarks, history, passwords, home_page, |
206 search_engines, window_index) | 206 search_engines, window_index) |
207 | 207 |
208 def _GetProfilePath(self): | 208 def _GetProfilePath(self): |
209 """Get profile paths when multiprofile windows are open. | 209 """Get profile paths when multiprofile windows are open. |
210 | 210 |
211 Returns: | 211 Returns: |
212 profile: Path for multiprofiles. | 212 profile: Path for multiprofiles. |
213 """ | 213 """ |
214 profiles_list = self.GetMultiProfileInfo()['profiles'] | 214 profiles_list = self.GetMultiProfileInfo()['profiles'] |
215 profile1_path = profile2_path = default_path = None | 215 profile1_path = profile2_path = default_path = None |
216 for profile in profiles_list: | 216 for profile in profiles_list: |
217 if profile['path'].find('Profile 1') != -1: | 217 if profile['path'].find('Profile 1') != -1: |
218 profile1_path = profile['path'] | 218 profile1_path = profile['path'] |
219 elif profile['path'].find('Profile 2') != -1: | 219 elif profile['path'].find('Profile 2') != -1: |
220 profile2_path = profile['path'] | 220 profile2_path = profile['path'] |
221 elif profile['path'].find('Default') != -1: | 221 elif profile['path'].find('Default') != -1: |
222 default_path = profile['path'] | 222 default_path = profile['path'] |
223 return default_path, profile1_path, profile2_path | 223 return default_path, profile1_path, profile2_path |
224 | 224 |
225 # Tests. | 225 # Tests. |
226 def testFirefoxImportFromPrefs(self): | 226 def testFirefoxImportFromPrefs(self): |
227 """Verify importing Firefox data through preferences.""" | 227 """Verify importing Firefox data through preferences.""" |
228 if not self._CanRunFirefoxTests(): | 228 if not self._CanRunFirefoxTests(): |
229 logging.warn('Not running firefox import tests.') | 229 logging.warn('Not running firefox import tests.') |
230 return | 230 return |
231 if self.IsWinVista(): # Broken on vista. crbug.com/89768 | 231 if self.IsWinVista(): # Broken on vista. crbug.com/89768 |
232 return | 232 return |
233 self._SwapFirefoxProfile() | 233 self._SwapFirefoxProfile() |
234 self.ImportSettings('Mozilla Firefox', False, self._to_import) | 234 self.ImportSettings('Mozilla Firefox', self._to_import) |
235 self._CheckDefaults(bookmarks=True, history=True, passwords=True, | 235 self._CheckDefaults(bookmarks=True, history=True, passwords=True, |
236 home_page=False, search_engines=True) | 236 home_page=False, search_engines=True) |
237 | 237 |
238 def testFirefoxFirstRun(self): | |
239 """Verify importing from Firefox on the first run. | |
240 | |
241 For Win, only history and homepage will only be imported. | |
242 Mac and Linux can import history, homepage, and bookmarks. | |
243 """ | |
244 if not self._CanRunFirefoxTests(): | |
245 logging.warn('Not running firefox import tests.') | |
246 return | |
247 self._SwapFirefoxProfile() | |
248 self.ImportSettings('Mozilla Firefox', True, self._to_import) | |
249 non_win = not self.IsWin() | |
250 self._CheckDefaults(bookmarks=non_win, history=True, passwords=True, | |
251 home_page=non_win, search_engines=True) | |
252 | |
253 def testImportFirefoxDataTwice(self): | 238 def testImportFirefoxDataTwice(self): |
254 """Verify importing Firefox data twice. | 239 """Verify importing Firefox data twice. |
255 | 240 |
256 Bookmarks should be duplicated, but history and passwords should not. | 241 Bookmarks should be duplicated, but history and passwords should not. |
257 """ | 242 """ |
258 if not self._CanRunFirefoxTests(): | 243 if not self._CanRunFirefoxTests(): |
259 logging.warn('Not running firefox import tests.') | 244 logging.warn('Not running firefox import tests.') |
260 return | 245 return |
261 if self.IsWinVista(): # Broken on vista. crbug.com/89768 | 246 if self.IsWinVista(): # Broken on vista. crbug.com/89768 |
262 return | 247 return |
263 self._SwapFirefoxProfile() | 248 self._SwapFirefoxProfile() |
264 self.ImportSettings('Mozilla Firefox', False, self._to_import) | 249 self.ImportSettings('Mozilla Firefox', self._to_import) |
265 num_history_orig = len(self.GetHistoryInfo().History()) | 250 num_history_orig = len(self.GetHistoryInfo().History()) |
266 num_passwords_orig = len(self.GetSavedPasswords()) | 251 num_passwords_orig = len(self.GetSavedPasswords()) |
267 | 252 |
268 # Re-import and check for duplicates. | 253 # Re-import and check for duplicates. |
269 self.ImportSettings('Mozilla Firefox', False, self._to_import) | 254 self.ImportSettings('Mozilla Firefox', self._to_import) |
270 self.assertTrue(self._BookmarkDuplicatesExist( | 255 self.assertTrue(self._BookmarkDuplicatesExist( |
271 self._bookmark_bar_items + self._bookmark_folder_items)) | 256 self._bookmark_bar_items + self._bookmark_folder_items)) |
272 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History())) | 257 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History())) |
273 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords())) | 258 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords())) |
274 | 259 |
275 def testImportFirefoxBookmarksFromPrefs(self): | 260 def testImportFirefoxBookmarksFromPrefs(self): |
276 """Verify importing Firefox bookmarks through preferences.""" | 261 """Verify importing Firefox bookmarks through preferences.""" |
277 self._ImportFromFirefox(bookmarks=True, history=False, passwords=False, | 262 self._ImportFromFirefox(bookmarks=True, history=False, passwords=False, |
278 home_page=False, search_engines=False) | 263 home_page=False, search_engines=False) |
279 | 264 |
(...skipping 15 matching lines...) Expand all Loading... |
295 home_page=False, search_engines=True) | 280 home_page=False, search_engines=True) |
296 | 281 |
297 def testImportFromFirefoxAndSafari(self): | 282 def testImportFromFirefoxAndSafari(self): |
298 """Verify importing from Firefox and then Safari.""" | 283 """Verify importing from Firefox and then Safari.""" |
299 # This test is for Mac only. | 284 # This test is for Mac only. |
300 if not self.IsMac(): | 285 if not self.IsMac(): |
301 return | 286 return |
302 | 287 |
303 self._SwapSafariProfile() | 288 self._SwapSafariProfile() |
304 self._SwapFirefoxProfile() | 289 self._SwapFirefoxProfile() |
305 self.ImportSettings('Mozilla Firefox', False, self._to_import) | 290 self.ImportSettings('Mozilla Firefox', self._to_import) |
306 self.ImportSettings('Safari', False, self._to_import) | 291 self.ImportSettings('Safari', self._to_import) |
307 | 292 |
308 self._CheckDefaults(bookmarks=True, history=True, passwords=True, | 293 self._CheckDefaults(bookmarks=True, history=True, passwords=True, |
309 home_page=False, search_engines=True) | 294 home_page=False, search_engines=True) |
310 self.assertTrue(self._BookmarkDuplicatesExist( | 295 self.assertTrue(self._BookmarkDuplicatesExist( |
311 self._bookmark_bar_items + self._bookmark_folder_items)) | 296 self._bookmark_bar_items + self._bookmark_folder_items)) |
312 | 297 |
313 def testSafariImportFromPrefs(self): | 298 def testSafariImportFromPrefs(self): |
314 """Verify importing Safari data through preferences.""" | 299 """Verify importing Safari data through preferences.""" |
315 # This test is Mac only. | 300 # This test is Mac only. |
316 if not self.IsMac(): | 301 if not self.IsMac(): |
317 return | 302 return |
318 self._SwapSafariProfile() | 303 self._SwapSafariProfile() |
319 self.ImportSettings('Safari', False, self._to_import) | 304 self.ImportSettings('Safari', self._to_import) |
320 self._CheckDefaults(bookmarks=True, history=True, passwords=False, | 305 self._CheckDefaults(bookmarks=True, history=True, passwords=False, |
321 home_page=False, search_engines=True) | 306 home_page=False, search_engines=True) |
322 | 307 |
323 def testSafariFirstRun(self): | |
324 """Verify importing Safari data on the first run.""" | |
325 # This test is Mac only. | |
326 if not self.IsMac(): | |
327 return | |
328 self._SwapSafariProfile() | |
329 self.ImportSettings('Safari', False, self._to_import) | |
330 self._CheckDefaults(bookmarks=True, history=True, passwords=False, | |
331 home_page=False, search_engines=False) | |
332 | |
333 def testImportSafariDataTwice(self): | 308 def testImportSafariDataTwice(self): |
334 """Verify importing Safari data twice. | 309 """Verify importing Safari data twice. |
335 | 310 |
336 Bookmarks should be duplicated, but history and passwords should not.""" | 311 Bookmarks should be duplicated, but history and passwords should not.""" |
337 # This test is Mac only. | 312 # This test is Mac only. |
338 if not self.IsMac(): | 313 if not self.IsMac(): |
339 return | 314 return |
340 self._SwapSafariProfile() | 315 self._SwapSafariProfile() |
341 self.ImportSettings('Safari', False, self._to_import) | 316 self.ImportSettings('Safari', self._to_import) |
342 num_history_orig = len(self.GetHistoryInfo().History()) | 317 num_history_orig = len(self.GetHistoryInfo().History()) |
343 num_passwords_orig = len(self.GetSavedPasswords()) | 318 num_passwords_orig = len(self.GetSavedPasswords()) |
344 | 319 |
345 # Re-import and check for duplicates. | 320 # Re-import and check for duplicates. |
346 self.ImportSettings('Safari', False, self._to_import) | 321 self.ImportSettings('Safari', self._to_import) |
347 self.assertTrue(self._BookmarkDuplicatesExist( | 322 self.assertTrue(self._BookmarkDuplicatesExist( |
348 self._bookmark_bar_items + self._bookmark_folder_items)) | 323 self._bookmark_bar_items + self._bookmark_folder_items)) |
349 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History())) | 324 self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History())) |
350 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords())) | 325 self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords())) |
351 | 326 |
352 def testFireFoxImportBookmarksMultiProfile(self): | 327 def testFireFoxImportBookmarksMultiProfile(self): |
353 """Verify importing Firefox bookmarks through preferences. | 328 """Verify importing Firefox bookmarks through preferences. |
354 | 329 |
355 Bookmarks are imported from Firefox through the preferences for multiple | 330 Bookmarks are imported from Firefox through the preferences for multiple |
356 profiles.""" | 331 profiles.""" |
(...skipping 19 matching lines...) Expand all Loading... |
376 bookmarks = self.GetBookmarkModel(1) | 351 bookmarks = self.GetBookmarkModel(1) |
377 node = bookmarks.FindByTitle('GoogleNews') | 352 node = bookmarks.FindByTitle('GoogleNews') |
378 self.assertEqual(0, len(node)) | 353 self.assertEqual(0, len(node)) |
379 # Assert if 'BING' is present. | 354 # Assert if 'BING' is present. |
380 node = bookmarks.FindByTitle('BING') | 355 node = bookmarks.FindByTitle('BING') |
381 self.assertEqual(1, len(node)) | 356 self.assertEqual(1, len(node)) |
382 | 357 |
383 | 358 |
384 if __name__ == '__main__': | 359 if __name__ == '__main__': |
385 pyauto_functional.Main() | 360 pyauto_functional.Main() |
OLD | NEW |