gecko-dev/mobile/android/base/tests/testImportFromAndroid.java
Brian Nicholson 4a207df851 Bug 905703 - Remove preprocessing from robocop harness and tests. r=nalexander
--HG--
rename : build/mobile/robocop/Actions.java.in => build/mobile/robocop/Actions.java
rename : build/mobile/robocop/Assert.java.in => build/mobile/robocop/Assert.java
rename : build/mobile/robocop/Driver.java.in => build/mobile/robocop/Driver.java
rename : build/mobile/robocop/Element.java.in => build/mobile/robocop/Element.java
rename : build/mobile/robocop/FennecInstrumentationTestRunner.java.in => build/mobile/robocop/FennecInstrumentationTestRunner.java
rename : build/mobile/robocop/FennecMochitestAssert.java.in => build/mobile/robocop/FennecMochitestAssert.java
rename : build/mobile/robocop/FennecNativeActions.java.in => build/mobile/robocop/FennecNativeActions.java
rename : build/mobile/robocop/FennecNativeDriver.java.in => build/mobile/robocop/FennecNativeDriver.java
rename : build/mobile/robocop/FennecNativeElement.java.in => build/mobile/robocop/FennecNativeElement.java
rename : build/mobile/robocop/FennecTalosAssert.java.in => build/mobile/robocop/FennecTalosAssert.java
rename : build/mobile/robocop/PaintedSurface.java.in => build/mobile/robocop/PaintedSurface.java
rename : build/mobile/robocop/RoboCopException.java.in => build/mobile/robocop/RoboCopException.java
rename : build/mobile/robocop/RobocopUtils.java.in => build/mobile/robocop/RobocopUtils.java
rename : mobile/android/base/tests/AboutHomeTest.java.in => mobile/android/base/tests/AboutHomeTest.java
rename : mobile/android/base/tests/BaseTest.java.in => mobile/android/base/tests/BaseTest.java
rename : mobile/android/base/tests/ContentContextMenuTest.java.in => mobile/android/base/tests/ContentContextMenuTest.java
rename : mobile/android/base/tests/ContentProviderTest.java.in => mobile/android/base/tests/ContentProviderTest.java
rename : mobile/android/base/tests/DatabaseHelper.java.in => mobile/android/base/tests/DatabaseHelper.java
rename : mobile/android/base/tests/JavascriptTest.java.in => mobile/android/base/tests/JavascriptTest.java
rename : mobile/android/base/tests/MotionEventHelper.java.in => mobile/android/base/tests/MotionEventHelper.java
rename : mobile/android/base/tests/MotionEventReplayer.java.in => mobile/android/base/tests/MotionEventReplayer.java
rename : mobile/android/base/tests/PixelTest.java.in => mobile/android/base/tests/PixelTest.java
rename : mobile/android/base/tests/StringHelper.java.in => mobile/android/base/tests/StringHelper.java
rename : mobile/android/base/tests/testAboutPage.java.in => mobile/android/base/tests/testAboutPage.java
rename : mobile/android/base/tests/testAddSearchEngine.java.in => mobile/android/base/tests/testAddSearchEngine.java
rename : mobile/android/base/tests/testAddonManager.java.in => mobile/android/base/tests/testAddonManager.java
rename : mobile/android/base/tests/testAwesomebar.java.in => mobile/android/base/tests/testAwesomebar.java
rename : mobile/android/base/tests/testAwesomebarSwipes.java.in => mobile/android/base/tests/testAwesomebarSwipes.java
rename : mobile/android/base/tests/testAxisLocking.java.in => mobile/android/base/tests/testAxisLocking.java
rename : mobile/android/base/tests/testBookmark.java.in => mobile/android/base/tests/testBookmark.java
rename : mobile/android/base/tests/testBookmarkFolders.java.in => mobile/android/base/tests/testBookmarkFolders.java
rename : mobile/android/base/tests/testBookmarkKeyword.java.in => mobile/android/base/tests/testBookmarkKeyword.java
rename : mobile/android/base/tests/testBookmarklets.java.in => mobile/android/base/tests/testBookmarklets.java
rename : mobile/android/base/tests/testBookmarksPage.java.in => mobile/android/base/tests/testBookmarksPage.java
rename : mobile/android/base/tests/testBrowserProvider.java.in => mobile/android/base/tests/testBrowserProvider.java
rename : mobile/android/base/tests/testBrowserProviderPerf.java.in => mobile/android/base/tests/testBrowserProviderPerf.java
rename : mobile/android/base/tests/testBrowserSearchVisibility.java.in => mobile/android/base/tests/testBrowserSearchVisibility.java
rename : mobile/android/base/tests/testCheck.java.in => mobile/android/base/tests/testCheck.java
rename : mobile/android/base/tests/testCheck2.java.in => mobile/android/base/tests/testCheck2.java
rename : mobile/android/base/tests/testClearPrivateData.java.in => mobile/android/base/tests/testClearPrivateData.java
rename : mobile/android/base/tests/testDeviceSearchEngine.java.in => mobile/android/base/tests/testDeviceSearchEngine.java
rename : mobile/android/base/tests/testDistribution.java.in => mobile/android/base/tests/testDistribution.java
rename : mobile/android/base/tests/testDoorHanger.java.in => mobile/android/base/tests/testDoorHanger.java
rename : mobile/android/base/tests/testFindInPage.java.in => mobile/android/base/tests/testFindInPage.java
rename : mobile/android/base/tests/testFlingCorrectness.java.in => mobile/android/base/tests/testFlingCorrectness.java
rename : mobile/android/base/tests/testFormHistory.java.in => mobile/android/base/tests/testFormHistory.java
rename : mobile/android/base/tests/testGetUserMedia.java.in => mobile/android/base/tests/testGetUserMedia.java
rename : mobile/android/base/tests/testHistory.java.in => mobile/android/base/tests/testHistory.java
rename : mobile/android/base/tests/testHomeBanner.java.in => mobile/android/base/tests/testHomeBanner.java
rename : mobile/android/base/tests/testImportFromAndroid.java.in => mobile/android/base/tests/testImportFromAndroid.java
rename : mobile/android/base/tests/testInputUrlBar.java.in => mobile/android/base/tests/testInputUrlBar.java
rename : mobile/android/base/tests/testJNI.java.in => mobile/android/base/tests/testJNI.java
rename : mobile/android/base/tests/testJarReader.java.in => mobile/android/base/tests/testJarReader.java
rename : mobile/android/base/tests/testLinkContextMenu.java.in => mobile/android/base/tests/testLinkContextMenu.java
rename : mobile/android/base/tests/testLoad.java.in => mobile/android/base/tests/testLoad.java
rename : mobile/android/base/tests/testMailToContextMenu.java.in => mobile/android/base/tests/testMailToContextMenu.java
rename : mobile/android/base/tests/testMasterPassword.java.in => mobile/android/base/tests/testMasterPassword.java
rename : mobile/android/base/tests/testNewTab.java.in => mobile/android/base/tests/testNewTab.java
rename : mobile/android/base/tests/testOrderedBroadcast.java.in => mobile/android/base/tests/testOrderedBroadcast.java
rename : mobile/android/base/tests/testOverscroll.java.in => mobile/android/base/tests/testOverscroll.java
rename : mobile/android/base/tests/testPan.java.in => mobile/android/base/tests/testPan.java
rename : mobile/android/base/tests/testPanCorrectness.java.in => mobile/android/base/tests/testPanCorrectness.java
rename : mobile/android/base/tests/testPasswordEncrypt.java.in => mobile/android/base/tests/testPasswordEncrypt.java
rename : mobile/android/base/tests/testPasswordProvider.java.in => mobile/android/base/tests/testPasswordProvider.java
rename : mobile/android/base/tests/testPermissions.java.in => mobile/android/base/tests/testPermissions.java
rename : mobile/android/base/tests/testPictureLinkContextMenu.java.in => mobile/android/base/tests/testPictureLinkContextMenu.java
rename : mobile/android/base/tests/testPrefsObserver.java.in => mobile/android/base/tests/testPrefsObserver.java
rename : mobile/android/base/tests/testPrivateBrowsing.java.in => mobile/android/base/tests/testPrivateBrowsing.java
rename : mobile/android/base/tests/testPromptGridInput.java.in => mobile/android/base/tests/testPromptGridInput.java
rename : mobile/android/base/tests/testReaderMode.java.in => mobile/android/base/tests/testReaderMode.java
rename : mobile/android/base/tests/testSearchSuggestions.java.in => mobile/android/base/tests/testSearchSuggestions.java
rename : mobile/android/base/tests/testSettingsMenuItems.java.in => mobile/android/base/tests/testSettingsMenuItems.java
rename : mobile/android/base/tests/testShareLink.java.in => mobile/android/base/tests/testShareLink.java
rename : mobile/android/base/tests/testSharedPreferences.java.in => mobile/android/base/tests/testSharedPreferences.java
rename : mobile/android/base/tests/testSystemPages.java.in => mobile/android/base/tests/testSystemPages.java
rename : mobile/android/base/tests/testTabHistory.java.in => mobile/android/base/tests/testTabHistory.java
rename : mobile/android/base/tests/testThumbnails.java.in => mobile/android/base/tests/testThumbnails.java
rename : mobile/android/base/tests/testVkbOverlap.java.in => mobile/android/base/tests/testVkbOverlap.java
rename : mobile/android/base/tests/test_bug720538.java.in => mobile/android/base/tests/test_bug720538.java
extra : rebase_source : c8d715aa110b07c6010054a674879e143a5f04e7
extra : amend_source : fb5714b78e055e336b5e0c6a0da8eb8c931ff09e
extra : histedit_source : ec57d8ba94000092438a2ba0bf4fb66091e98513%2C114ade72bb9b72b96557da74f1179734fa347e5c
2013-11-07 11:18:51 -05:00

211 lines
9.1 KiB
Java

package org.mozilla.gecko.tests;
import org.mozilla.gecko.*;
import android.app.Activity;
import android.provider.Browser;
import android.content.ContentValues;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import java.util.ArrayList;
import java.util.Arrays;
/**
* This test covers the Import from Android feature
* The test will save the existing bookmarks and history then will do an Import
* After the import it will check that the bookmarks and history items from Android are imported
* Then it will test that the old data from Firefox is not lost
* At the end will test that a second import will not duplicate information
*/
public class testImportFromAndroid extends AboutHomeTest {
private static final int MAX_WAIT_TIMEOUT = 15000;
ArrayList<String> androidData = new ArrayList<String>();
ArrayList<String> firefoxHistory = new ArrayList<String>();
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testImportFromAndroid() {
ArrayList<String> firefoxBookmarks = new ArrayList<String>();
ArrayList<String> oldFirefoxHistory = new ArrayList<String>();
ArrayList<String> oldFirefoxBookmarks = new ArrayList<String>();
blockForGeckoReady();
// Get the Android history
androidData = getAndroidUrls("history");
// Add some overlapping data from the Android Stock Browser to Firefox before import
addData();
// Get the initial bookmarks and history
oldFirefoxBookmarks = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.BOOKMARKS);
oldFirefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY);
// Import the bookmarks and history
importDataFromAndroid();
// Get the Android history and the Firefox bookmarks and history lists
firefoxHistory = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY);
firefoxBookmarks = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.BOOKMARKS);
/**
* Add a delay to make sure the imported items are added to the array lists
* if there are a lot of history items in the Android Browser database
*/
boolean success = waitForTest(new BooleanTest() {
@Override
public boolean test() {
if (androidData.size() <= firefoxHistory.size()) {
return true;
} else {
return false;
}
}
}, MAX_WAIT_MS);
/**
* Verify the history and bookmarks are imported
* Android history also contains the android bookmarks so we don't need to get them separately here
*/
for (String url:androidData) {
mAsserter.ok(firefoxHistory.contains(url)||firefoxBookmarks.contains(url), "Checking if Android" + (firefoxBookmarks.contains(url) ? " Bookmark" : " History item") + " is present", url + " was imported");
}
// Verify the original Firefox Bookmarks are not deleted
for (String url:oldFirefoxBookmarks) {
mAsserter.ok(firefoxBookmarks.contains(url), "Checking if original Firefox Bookmark is present", " Firefox Bookmark " + url + " was not removed");
}
// Verify the original Firefox History is not deleted
for (String url:oldFirefoxHistory) {
mAsserter.ok(firefoxHistory.contains(url), "Checking original Firefox History item is present", " Firefox History item " + url + " was not removed");
}
// Import data again and make sure bookmarks are not duplicated
importDataFromAndroid();
// Verify bookmarks are not duplicated
ArrayList<String> verifiedBookmarks = new ArrayList<String>();
firefoxBookmarks = mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.BOOKMARKS);
for (String url:firefoxBookmarks) {
if (verifiedBookmarks.contains(url)) {
mAsserter.ok(false, "Bookmark " + url + " should not be duplicated", "Bookmark is duplicated");
} else {
verifiedBookmarks.add(url);
mAsserter.ok(true, "Bookmark " + url + " was not duplicated", "Bookmark is unique");
}
}
// Verify history count is not increased after the second import
mAsserter.ok(firefoxHistory.size() == mDatabaseHelper.getBrowserDBUrls(DatabaseHelper.BrowserDataType.HISTORY).size(), "The number of history entries was not increased", "None of the items were duplicated");
}
private void addData() {
ArrayList<String> androidBookmarks = getAndroidUrls("bookmarks");
// Add a few Bookmarks from Android to Firefox Mobile
for (String url:androidBookmarks) {
// Add every 3rd bookmark to Firefox Mobile
if ((androidBookmarks.indexOf(url) % 3) == 0) {
mDatabaseHelper.addOrUpdateMobileBookmark("Bookmark Number" + String.valueOf(androidBookmarks.indexOf(url)), url);
}
}
// Add a few history items in Firefox Mobile
ContentResolver resolver = getActivity().getContentResolver();
Uri uri = Uri.parse("content://" + TestConstants.ANDROID_PACKAGE_NAME + ".db.browser/history");
uri = uri.buildUpon().appendQueryParameter("profile", "default")
.appendQueryParameter("sync", "true").build();
for (String url:androidData) {
// Add every 3rd website from Android History to Firefox Mobile
if ((androidData.indexOf(url) % 3) == 0) {
ContentValues values = new ContentValues();
values.put("title", "Page" + url);
values.put("url", url);
values.put("date", System.currentTimeMillis());
values.put("visits", androidData.indexOf(url));
resolver.insert(uri, values);
}
}
}
private void importDataFromAndroid() {
waitForText("Enter Search or Address");
selectSettingsItem(StringHelper.CUSTOMIZE_SECTION_LABEL, StringHelper.IMPORT_FROM_ANDROID_LABEL);
// Wait for the Import form Android pop-up to be opened. It has the same title as the option so waiting for the "Cancel" button
waitForText("Cancel");
mSolo.clickOnButton("Import");
// Wait until the import pop-up is dismissed. This depending on the number of items in the android history can take up to a few seconds
boolean importComplete = waitForTest(new BooleanTest() {
public boolean test() {
return !mSolo.searchText("Please wait...");
}
}, MAX_WAIT_TIMEOUT);
mAsserter.ok(importComplete, "Waiting for import to finish and the pop-up to be dismissed", "Import was completed and the pop-up was dismissed");
// Import has finished. Waiting to get back to the Settings Menu and looking for the Import&Export subsection
if ("phone".equals(mDevice.type)) {
// Phones don't have headers like tablets, so we need to pop up one more level.
waitForText(StringHelper.IMPORT_FROM_ANDROID_LABEL);
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
}
waitForText("Privacy"); // Settings is a header for the settings menu page. Waiting for Privacy ensures we are back in the top Settings view
mActions.sendSpecialKey(Actions.SpecialKey.BACK); // Exit Settings
// Make sure the settings menu has been closed.
mAsserter.ok(mSolo.waitForText("Enter Search or Address"), "Waiting for search bar", "Search bar found");
}
public ArrayList<String> getAndroidUrls(String data) {
// Return bookmarks or history depending on what the user asks for
ArrayList<String> urls = new ArrayList<String>();
ContentResolver resolver = getActivity().getContentResolver();
Browser mBrowser = new Browser();
Cursor cursor = null;
try {
if (data.equals("history")) {
cursor = mBrowser.getAllVisitedUrls(resolver);
} else if (data.equals("bookmarks")) {
cursor = mBrowser.getAllBookmarks(resolver);
}
if (cursor != null) {
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++ ) {
urls.add(cursor.getString(cursor.getColumnIndex("url")));
if(!cursor.isLast()) {
cursor.moveToNext();
}
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return urls;
}
public void deleteImportedData() {
// Bookmarks
ArrayList<String> androidBookmarks = getAndroidUrls("bookmarks");
for (String url:androidBookmarks) {
mDatabaseHelper.deleteBookmark(url);
}
// History
for (String url:androidData) {
mDatabaseHelper.deleteHistoryItem(url);
}
}
public void tearDown() throws Exception {
deleteImportedData();
super.tearDown();
}
}