summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralyssad@google.com <alyssad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 00:41:23 +0000
committeralyssad@google.com <alyssad@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 00:41:23 +0000
commit39a46ad4bf69fd1b6fadb19fe61d4a5e6d5a100f (patch)
tree2b02610eea6e3b45dd1ee5f5581559f1efba0474
parente8554cb59d7d0613a4fe442089893bd69e60bdd0 (diff)
downloadchromium_src-39a46ad4bf69fd1b6fadb19fe61d4a5e6d5a100f.zip
chromium_src-39a46ad4bf69fd1b6fadb19fe61d4a5e6d5a100f.tar.gz
chromium_src-39a46ad4bf69fd1b6fadb19fe61d4a5e6d5a100f.tar.bz2
New PyAuto tests for importing browser data. BUG=52009
Tests for importing browser data from Firefox, Safari, and IE. Review URL: http://codereview.chromium.org/3140011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57619 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/test/data/import/README22
-rw-r--r--chrome/test/data/import/firefox/linux.zipbin0 -> 12814630 bytes
-rw-r--r--chrome/test/data/import/firefox/macwin.zipbin0 -> 3843778 bytes
-rw-r--r--chrome/test/data/import/safari/mac.zipbin0 -> 45105 bytes
-rw-r--r--chrome/test/functional/imports.py284
5 files changed, 306 insertions, 0 deletions
diff --git a/chrome/test/data/import/README b/chrome/test/data/import/README
new file mode 100644
index 0000000..9c568c2
--- /dev/null
+++ b/chrome/test/data/import/README
@@ -0,0 +1,22 @@
+Profiles for import settings go in this folder. They are used by the tests
+in chrome/test/functional/imports.py.
+
+For each profile, the following items are included:
+History:
+http://www.google.com
+http://news.google.com
+http://books.google.com/bkshp?hl=ko&tab=wp
+
+Bookmarks:
+http://news.google.com (bookmark bar)
+http://www.google.com
+http://books.google.com/bkshp?hl=ko&tab=wp
+
+Passwords:
+For Facebook, the password for the test account etouchqa@gmail.com is saved.
+For Google, the password for the test account macqa05 is saved.
+
+Home Page:
+http://news.google.com
+
+TODO(alyssad): In the future, add search engines.
diff --git a/chrome/test/data/import/firefox/linux.zip b/chrome/test/data/import/firefox/linux.zip
new file mode 100644
index 0000000..e4cf00c
--- /dev/null
+++ b/chrome/test/data/import/firefox/linux.zip
Binary files differ
diff --git a/chrome/test/data/import/firefox/macwin.zip b/chrome/test/data/import/firefox/macwin.zip
new file mode 100644
index 0000000..41d6823
--- /dev/null
+++ b/chrome/test/data/import/firefox/macwin.zip
Binary files differ
diff --git a/chrome/test/data/import/safari/mac.zip b/chrome/test/data/import/safari/mac.zip
new file mode 100644
index 0000000..5211d01
--- /dev/null
+++ b/chrome/test/data/import/safari/mac.zip
Binary files differ
diff --git a/chrome/test/functional/imports.py b/chrome/test/functional/imports.py
new file mode 100644
index 0000000..6d530e9
--- /dev/null
+++ b/chrome/test/functional/imports.py
@@ -0,0 +1,284 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import glob
+import logging
+import optparse
+import os
+import shutil
+import sys
+import tempfile
+import zipfile
+
+
+import pyauto_functional # Must be imported before pyauto
+import pyauto
+import pyauto_utils
+
+
+class ImportsTest(pyauto.PyUITest):
+ """Import settings from other browsers.
+
+ Import settings tables below show which items get imported on first run and
+ via preferences for different browsers and operating systems.
+
+ Bookmarks History SearchEngines Passwords Homepage
+ Firefox:
+ Win/FRUI N Y N N Y
+ Win/Prefs Y Y Y Y N
+ Mac&Lin/FRUI Y Y Y Y Y
+ Mac&Lin/Prefs Y Y Y Y N
+
+ Safari:
+ Mac/FRUI Y Y Y Y N
+ Mac/Prefs Y Y Y Y N
+ """
+ def setUp(self):
+ if pyauto.PyUITest.IsMac():
+ self._firefox_profiles_path = os.path.join(
+ os.environ['HOME'], 'Library','Application Support','Firefox')
+ self._firefox_test_profile = os.path.join(
+ pyauto.PyUITest.DataDir(), 'import', 'firefox', 'macwin.zip')
+ self._safari_profiles_path = os.path.join(
+ os.environ['HOME'], 'Library', 'Safari')
+ elif pyauto.PyUITest.IsWin():
+ self._firefox_profiles_path = os.path.join(
+ os.getenv('APPDATA'), 'Mozilla', 'Firefox')
+ self._firefox_test_profile = os.path.join(
+ pyauto.PyUITest.DataDir(), 'import', 'firefox', 'macwin.zip')
+ else:
+ self._firefox_profiles_path = os.path.join(
+ os.environ['HOME'], '.mozilla', 'firefox')
+ self._firefox_test_profile = os.path.join(
+ pyauto.PyUITest.DataDir(), 'import', 'firefox', 'linux.zip')
+
+ # Expected items for tests.
+ self._history_items = ['Google', 'Google News', u'Google \ub3c4\uc11c']
+ self._bookmark_bar_items = ['Google News']
+ self._bookmark_folder_items = ['Google', u'Google \ub3c4\uc11c']
+ self._password_items = ['etouchqa@gmail.com', 'macqa05']
+ self._home_page = 'http://news.google.com/'
+
+ self._safari_replacer = None
+ self._firefox_replacer = None
+
+ pyauto.PyUITest.setUp(self)
+
+ def tearDown(self):
+ pyauto.PyUITest.tearDown(self)
+ # Delete any replacers to restore the original profiles.
+ if self._safari_replacer:
+ del self._safari_replacer
+ if self._firefox_replacer:
+ del self._firefox_replacer
+
+ def _UnzipProfileToDir(self, profile_zip, dir):
+ """Unzip |profile_zip| into directory |dir|.
+
+ Creates |dir| if it doesn't exist.
+ """
+ zf = zipfile.ZipFile(profile_zip)
+ # Make base.
+ pushd = os.getcwd()
+ try:
+ if not os.path.isdir(dir):
+ os.mkdir(dir)
+ os.chdir(dir)
+ # Extract files.
+ for info in zf.infolist():
+ name = info.filename
+ if name.endswith('/'): # It's a directory.
+ if not os.path.isdir(name):
+ os.makedirs(name)
+ else: # It's a file.
+ dir = os.path.dirname(name)
+ if dir and not os.path.isdir(dir):
+ os.makedirs(dir)
+ out = open(name, 'wb')
+ out.write(zf.read(name))
+ out.close()
+ # Set permissions.
+ os.chmod(name, 0777)
+ finally:
+ os.chdir(pushd)
+
+ def _SwapFirefoxProfile(self):
+ """Swaps the test Firefox profile with the original one."""
+ self._firefox_replacer = pyauto_utils.ExistingPathReplacer(
+ self._firefox_profiles_path)
+ self._UnzipProfileToDir(self._firefox_test_profile,
+ self._firefox_profiles_path)
+
+ def _SwapSafariProfile(self):
+ """Swaps the test Safari profile with the original one."""
+ self._safari_replacer = pyauto_utils.ExistingPathReplacer(
+ self._safari_profiles_path)
+ self._UnzipProfileToDir(
+ os.path.join(self.DataDir(), 'import', 'safari', 'mac.zip'),
+ self._safari_profiles_path)
+
+ def _CheckForBookmarks(self, bookmark_titles, bookmark_bar):
+ """Checks that the given bookmarks exist.
+
+ Args:
+ bookmark_titles: A set of bookmark title strings.
+ bookmark_bar: True if the bookmarks are part of the bookmark bar.
+ False otherwise.
+ """
+ confirmed_titles = set()
+ bookmarks = self.GetBookmarkModel()
+ if bookmark_bar:
+ node = bookmarks.BookmarkBar()
+ else:
+ node = bookmarks.Other()
+ for title in bookmark_titles:
+ self.assertTrue([x for x in bookmark_titles \
+ if bookmarks.FindByTitle(title, [node])])
+
+ def _BookmarkDuplicatesExist(self, bookmark_titles):
+ """Returns true if any of the bookmark titles are duplicated.
+
+ Args:
+ bookmark_titles: A list of bookmark title strings.
+ """
+ bookmarks = self.GetBookmarkModel()
+ for title in bookmark_titles:
+ if len(bookmarks.FindByTitle(title)) > 1:
+ return True
+ return False
+
+ def _CheckForHistory(self, history_titles):
+ """Verifies that the given list of history items are in the history.
+
+ Args:
+ history_titles: A list of history title strings.
+ """
+ history = self.GetHistoryInfo().History()
+
+ for title in history_titles:
+ self.assertTrue([x for x in history if x['title'] == title])
+
+ def _CheckForPasswords(self, usernames):
+ """Check that password items exist for the given usernames."""
+ # Password import automation does not work on Mac. See crbug.com/52124.
+ if self.IsMac():
+ return
+ passwords = self.GetSavedPasswords()
+ for username in usernames:
+ self.assertTrue([x for x in passwords if x['username_value'] == username])
+
+ def _CheckDefaults(self, bookmarks, history, passwords, home_page,
+ search_engines):
+ """Checks the defaults for each of the possible import items.
+
+ All arguments are True if they should be checked, False otherwise."""
+ if bookmarks:
+ self._CheckForBookmarks(self._bookmark_bar_items, True)
+ self._CheckForBookmarks(self._bookmark_folder_items, False)
+ if history:
+ self._CheckForHistory(self._history_items)
+ if passwords:
+ self._CheckForPasswords(self._password_items)
+ if home_page:
+ self.assertEqual(self._home_page, self.GetPrefsInfo().Prefs()['homepage'])
+ # TODO(alyssad): Test for search engines after a hook is added.
+ # See crbug.com/52009.
+
+ # Tests.
+ def testFirefoxImportFromPrefs(self):
+ """Verify importing Firefox data through preferences."""
+ self._SwapFirefoxProfile()
+ self.ImportSettings('Mozilla Firefox', False, ['ALL'])
+ self._CheckDefaults(bookmarks=True, history=True, passwords=True,
+ home_page=False, search_engines=True)
+
+ def testFirefoxFirstRun(self):
+ """Verify importing from Firefox on the first run.
+
+ For Win, only history and homepage will only be imported.
+ Mac and Linux can import history, homepage, and bookmarks.
+ """
+ self._SwapFirefoxProfile()
+ self.ImportSettings('Mozilla Firefox', True, ['ALL'])
+ non_win = not self.IsWin()
+ self._CheckDefaults(bookmarks=non_win, history=True, passwords=True,
+ home_page=non_win, search_engines=True)
+
+ def testImportFirefoxDataTwice(self):
+ """Verify importing Firefox data twice.
+
+ Bookmarks should be duplicated, but history and passwords should not.
+ """
+ self._SwapFirefoxProfile()
+ self.ImportSettings('Mozilla Firefox', False, ['ALL'])
+ num_history_orig = len(self.GetHistoryInfo().History())
+ num_passwords_orig = len(self.GetSavedPasswords())
+
+ # Re-import and check for duplicates.
+ self.ImportSettings('Mozilla Firefox', False, ['ALL'])
+ self.assertTrue(self._BookmarkDuplicatesExist(
+ self._bookmark_bar_items + self._bookmark_folder_items))
+ self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History()))
+ self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords()))
+
+ def testImportFromFirefoxAndSafari(self):
+ """Verify importing from Firefox and then Safari."""
+ # This test is for Mac only.
+ if not self.IsMac():
+ return
+
+ self._SwapSafariProfile()
+ self._SwapFirefoxProfile()
+ self.ImportSettings('Mozilla Firefox', False, ['ALL'])
+ self.ImportSettings('Safari', False, ['ALL'])
+
+ self._CheckDefaults(bookmarks=True, history=True, passwords=True,
+ home_page=False, search_engines=True)
+ self.assertTrue(self._BookmarkDuplicatesExist(
+ self._bookmark_bar_items + self._bookmark_folder_items))
+
+ def testSafariImportFromPrefs(self):
+ """Verify importing Safari data through preferences."""
+ # This test is Mac only.
+ if not self.IsMac():
+ return
+ self._SwapSafariProfile()
+ self.ImportSettings('Safari', False, ['ALL'])
+ self._CheckDefaults(bookmarks=True, history=True, passwords=False,
+ home_page=False, search_engines=True)
+
+ def testSafariFirstRun(self):
+ """Verify importing Safari data on the first run."""
+ # This test is Mac only.
+ if not self.IsMac():
+ return
+ self._SwapSafariProfile()
+ self.ImportSettings('Safari', False, ['ALL'])
+ self._CheckDefaults(bookmarks=True, history=True, passwords=False,
+ home_page=False, search_engines=False)
+
+ def testImportSafariDataTwice(self):
+ """Verify importing Safari data twice.
+
+ Bookmarks should be duplicated, but history and passwords should not."""
+ # This test is Mac only.
+ if not self.IsMac():
+ return
+ self._SwapSafariProfile()
+ self.ImportSettings('Safari', False, ['ALL'])
+ num_history_orig = len(self.GetHistoryInfo().History())
+ num_passwords_orig = len(self.GetSavedPasswords())
+
+ # Re-import and check for duplicates.
+ self.ImportSettings('Safari', False, ['ALL'])
+ self.assertTrue(self._BookmarkDuplicatesExist(
+ self._bookmark_bar_items + self._bookmark_folder_items))
+ self.assertEqual(num_history_orig, len(self.GetHistoryInfo().History()))
+ self.assertEqual(num_passwords_orig, len(self.GetSavedPasswords()))
+
+
+if __name__ == '__main__':
+ pyauto_functional.Main()