mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 901432 - Clean-up BaseTest and add a new subclass AboutHomeTest (r=gbrown)
This commit is contained in:
parent
e8d623a781
commit
0b29fa787b
321
mobile/android/base/tests/AboutHomeTest.java.in
Normal file
321
mobile/android/base/tests/AboutHomeTest.java.in
Normal file
@ -0,0 +1,321 @@
|
||||
#filter substitution
|
||||
package @ANDROID_PACKAGE_NAME@.tests;
|
||||
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class is an extension of BaseTest that helps with interaction with about:home
|
||||
* This class contains methods that access the different tabs from about:home, methods that get information like history and bookmarks from the database, edit and remove bookmarks and history items
|
||||
* The purpose of this class is to collect all the logically connected methods that deal with about:home
|
||||
* To use any of these methods in your test make sure it extends AboutHomeTest instead of BaseTest
|
||||
*/
|
||||
abstract class AboutHomeTest extends BaseTest {
|
||||
protected enum BrowserDataType {BOOKMARKS, HISTORY};
|
||||
protected enum AboutHomeTabs {MOST_VISITED, MOST_RECENT, TABS_FROM_LAST_TIME, BOOKMARKS, READING_LIST};
|
||||
protected ArrayList<String> aboutHomeTabs = new ArrayList<String>() {{
|
||||
add("HISTORY");
|
||||
add("BOOKMARKS");
|
||||
add("READING_LIST");
|
||||
}};
|
||||
|
||||
// Labels for the about:home tabs
|
||||
protected static final String HISTORY_LABEL = "HISTORY";
|
||||
protected static final String BOOKMARKS_LABEL = "BOOKMARKS";
|
||||
protected static final String READING_LIST_LABEL = "READING LIST";
|
||||
protected static final String MOST_RECENT_LABEL = "Most recent";
|
||||
protected static final String TABS_FROM_LAST_TIME_LABEL = "Open all tabs from last time";
|
||||
|
||||
/**
|
||||
* This method can be used to check if an URL is present in the bookmarks database
|
||||
*/
|
||||
protected boolean isBookmark(String url) {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method isBookmarked = browserDB.getMethod("isBookmark", ContentResolver.class, String.class);
|
||||
return (Boolean)isBookmarked.invoke(null, resolver, url);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception while checking if url is bookmarked: ", e.toString()); // Fail before returning
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: Write new versions of these methods and update their consumers to use the new about:home pages.
|
||||
*/
|
||||
protected ListView getHistoryList(String waitText, int expectedChildCount) {
|
||||
return null;
|
||||
}
|
||||
protected ListView getHistoryList(String waitText) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Uri buildUri(BrowserDataType dataType) {
|
||||
Uri uri = null;
|
||||
if (dataType == BrowserDataType.BOOKMARKS || dataType == BrowserDataType.HISTORY) {
|
||||
uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/" + dataType.toString().toLowerCase());
|
||||
} else {
|
||||
mAsserter.ok(false, "The wrong data type has been provided = " + dataType.toString(), "Please provide a BrowserDataType value");
|
||||
}
|
||||
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
||||
.appendQueryParameter("sync", "true").build();
|
||||
return uri;
|
||||
}
|
||||
|
||||
protected void addOrUpdateMobileBookmark(String title, String url) {
|
||||
if (isBookmark(url)) {
|
||||
updateBookmark(title, url, null);
|
||||
} else {
|
||||
addMobileBookmark(title, url);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addMobileBookmark(String title, String url) {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method addBookmark = browserDB.getMethod("addBookmark", ContentResolver.class, String.class, String.class);
|
||||
addBookmark.invoke(null, resolver, title, url);
|
||||
mAsserter.ok(true, "Inserting a new bookmark", "Inserter the bookmark with the title = " + title + " and the url = " + url);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception adding bookmark: ", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateBookmark(String title, String url, String keyword) {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method updateBookmark = browserDB.getMethod("updateBookmark", ContentResolver.class, String.class, String.class);
|
||||
updateBookmark.invoke(null, resolver, title, url, keyword);
|
||||
mAsserter.ok(true, "Updating existing bookmark", "Setting the values to title = " + title + ", url = " + url + " and keyword = " + keyword);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception updating bookmark: ", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteBookmark(String url) {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method removeBookmark = browserDB.getMethod("removeBookmarksWithURL", ContentResolver.class, String.class);
|
||||
removeBookmark.invoke(null, resolver, url);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception deleting bookmark: ", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected void deleteHistoryItem(String url) {
|
||||
try {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method removeHistory = browserDB.getMethod("removeHistoryEntry", ContentResolver.class, String.class);
|
||||
removeHistory.invoke(null, resolver, url);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception deleting history item: ", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
protected Long getFolderId(String guid) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
Long folderId = Long.valueOf(-1);
|
||||
Uri bookmarksUri = buildUri(BrowserDataType.BOOKMARKS);
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = resolver.query(bookmarksUri,
|
||||
new String[] { "_id" },
|
||||
"guid = ?",
|
||||
new String[] { guid },
|
||||
null);
|
||||
if (c.moveToFirst()) {
|
||||
folderId = c.getLong(c.getColumnIndexOrThrow("_id"));
|
||||
}
|
||||
if (folderId == -1) {
|
||||
mAsserter.ok(false, "Making sure that we got the correct folder", "We didn't get the correct folder id");
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
return folderId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param a BrowserDataType value - either HISTORY or BOOKMARKS
|
||||
* @return an ArrayList of the urls in the Firefox for Android Bookmarks or History databases
|
||||
*/
|
||||
protected ArrayList<String> getBrowserDBUrls(BrowserDataType dataType) {
|
||||
ArrayList<String> browserData = new ArrayList<String>();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
ClassLoader classLoader = getActivity().getClassLoader();
|
||||
Cursor cursor = null;
|
||||
Uri uri = buildUri(dataType);
|
||||
if (dataType == BrowserDataType.HISTORY) {
|
||||
try {
|
||||
Class browserDBClass = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method getAllVisitedHistory = browserDBClass.getMethod("getAllVisitedHistory", ContentResolver.class);
|
||||
cursor = (Cursor)getAllVisitedHistory.invoke(null, resolver);
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception while getting history", e.toString());
|
||||
}
|
||||
} else if (dataType == BrowserDataType.BOOKMARKS) {
|
||||
try {
|
||||
Class browserDBClass = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB");
|
||||
Method getBookmarks = browserDBClass.getMethod("getBookmarksInFolder", ContentResolver.class, Long.TYPE);
|
||||
cursor = (Cursor)getBookmarks.invoke(null, resolver, getFolderId("mobile"));
|
||||
} catch (Exception e) {
|
||||
mAsserter.ok(false, "Exception while getting bookmarks", e.toString());
|
||||
}
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
for (int i = 0; i < cursor.getCount(); i++ ) {
|
||||
// The url field may be null for folders in the structure of the Bookmarks table for Firefox so we should eliminate those
|
||||
if (cursor.getString(cursor.getColumnIndex("url")) != null) {
|
||||
browserData.add(cursor.getString(cursor.getColumnIndex("url")));
|
||||
}
|
||||
if(!cursor.isLast()) {
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mAsserter.ok(false, "We could not retrieve any data from the database", "The cursor was null");
|
||||
}
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
return browserData;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME: rewrite this to work with fig when rewriting the testBookmarksTab test
|
||||
* This method will edit the bookmark with index = bookmarkIndex from the list of bookmarks
|
||||
* For the field index:
|
||||
* fieldIndex = 1 - the Bookmark name
|
||||
* fieldIndex = 2 - the Bookmark url
|
||||
* fieldIndex = 3 - the Bookmark keyword
|
||||
*/
|
||||
protected void editBookmark(int bookmarkIndex, int fieldIndex, String addedText, ListView list) {
|
||||
|
||||
// Open the Edit Bookmark context menu
|
||||
View child;
|
||||
mSolo.clickOnText("Bookmarks");
|
||||
child = list.getChildAt(bookmarkIndex);
|
||||
mAsserter.ok(child != null, "edit item can be retrieved", child != null ? child.toString() : "null!");
|
||||
waitForText("Switch to tab");
|
||||
mSolo.clickLongOnView(child);
|
||||
waitForText("Share");
|
||||
mSolo.clickOnText("Edit");
|
||||
waitForText("Edit Bookmark");
|
||||
|
||||
// Clear the Field
|
||||
mSolo.clearEditText(fieldIndex);
|
||||
|
||||
// Enter the new text
|
||||
mSolo.clickOnEditText(fieldIndex);
|
||||
mActions.sendKeys(addedText);
|
||||
mSolo.clickOnText("OK");
|
||||
waitForText("Bookmark updated");
|
||||
}
|
||||
|
||||
// FIXME: rewrite this to work with fig when rewriting the testBookmarksTab test
|
||||
protected boolean checkBookmarkEdit(int bookmarkIndex, String addedText, ListView list) {
|
||||
// Open the Edit Bookmark context menu
|
||||
View child;
|
||||
mSolo.clickOnText("Bookmarks");
|
||||
child = list.getChildAt(bookmarkIndex);
|
||||
mAsserter.ok(child != null, "check item can be retrieved", child != null ? child.toString() : "null!");
|
||||
waitForText("Switch to tab");
|
||||
mSolo.clickLongOnView(child);
|
||||
waitForText("Share");
|
||||
mSolo.clickOnText("Edit");
|
||||
waitForText("Edit Bookmark");
|
||||
|
||||
// Check if the new text was added
|
||||
if (mSolo.searchText(addedText)) {
|
||||
clickOnButton("Cancel");
|
||||
waitForText("about:home");
|
||||
return true;
|
||||
} else {
|
||||
clickOnButton("Cancel");
|
||||
waitForText("about:home");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method can be used to open the different tabs of about:home
|
||||
* @param AboutHomeTabs enum item {MOST_VISITED, MOST_RECENT, TABS_FROM_LAST_TIME, BOOKMARKS, READING_LIST}
|
||||
*/
|
||||
protected void openAboutHomeTab(AboutHomeTabs tab) {
|
||||
int halfWidth = mDriver.getGeckoWidth() / 2;
|
||||
int halfHeight = mDriver.getGeckoHeight() / 2;
|
||||
focusUrlBar();
|
||||
ViewPager pager = (ViewPager)mSolo.getView(ViewPager.class, 0);
|
||||
switch (tab) {
|
||||
case BOOKMARKS : {
|
||||
mSolo.clickOnText(BOOKMARKS_LABEL);
|
||||
waitForEnabledText(BOOKMARKS_LABEL);
|
||||
mAsserter.is(pager.getCurrentItem(), aboutHomeTabs.indexOf(tab.toString()), "Bookmarks page is selected");
|
||||
break;
|
||||
}
|
||||
case MOST_RECENT: {
|
||||
mSolo.clickOnText(BOOKMARKS_LABEL);
|
||||
waitForEnabledText(BOOKMARKS_LABEL);
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
waitForEnabledText(HISTORY_LABEL);
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mAsserter.is(pager.getCurrentItem(), aboutHomeTabs.indexOf(HISTORY_LABEL), "The history tab is selected");
|
||||
mSolo.clickOnView(tabwidget.getChildAt(1));
|
||||
mAsserter.ok(waitForText(MOST_RECENT_LABEL), "Checking that we are in the most recent tab of about:home", "We are in the most recent tab");
|
||||
break;
|
||||
}
|
||||
case READING_LIST: {
|
||||
mSolo.clickOnText(BOOKMARKS_LABEL);
|
||||
waitForEnabledText(BOOKMARKS_LABEL);
|
||||
mActions.drag(halfWidth, 0, halfHeight, halfHeight);
|
||||
waitForEnabledText(READING_LIST_LABEL);
|
||||
mAsserter.is(pager.getCurrentItem(), aboutHomeTabs.indexOf(tab.toString()), "Reading List is selected");
|
||||
break;
|
||||
}
|
||||
case MOST_VISITED: {
|
||||
mSolo.clickOnText(BOOKMARKS_LABEL);
|
||||
waitForEnabledText(BOOKMARKS_LABEL);
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
waitForEnabledText(HISTORY_LABEL);
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mAsserter.is(pager.getCurrentItem(), aboutHomeTabs.indexOf(HISTORY_LABEL), "The history tab is selected");
|
||||
mSolo.clickOnView(tabwidget.getChildAt(0));
|
||||
break;
|
||||
}
|
||||
case TABS_FROM_LAST_TIME: {
|
||||
mSolo.clickOnText(BOOKMARKS_LABEL);
|
||||
waitForEnabledText(BOOKMARKS_LABEL);
|
||||
mActions.drag(0, halfWidth, halfHeight, halfHeight);
|
||||
waitForEnabledText(HISTORY_LABEL);
|
||||
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
|
||||
mAsserter.is(pager.getCurrentItem(), aboutHomeTabs.indexOf(HISTORY_LABEL), "The history tab is selected");
|
||||
mSolo.clickOnView(tabwidget.getChildAt(2));
|
||||
mAsserter.ok(waitForText(TABS_FROM_LAST_TIME_LABEL), "Checking that we are in the Tabs from last time tab of about:home", "We are in the Tabs from last time tab");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -65,6 +65,10 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
protected static final String URL_EDIT_TEXT_ID = "url_edit_text";
|
||||
protected static final String URL_BAR_TITLE_ID = "url_bar_title";
|
||||
|
||||
// Settings menu paths
|
||||
protected static final String PRIVACY_LABEL = "Privacy";
|
||||
protected static final String CLEAR_PRIVATE_DATA_LABEL = "Clear private data";
|
||||
|
||||
private static Class<Activity> mLauncherActivityClass;
|
||||
private Activity mActivity;
|
||||
protected Solo mSolo;
|
||||
@ -195,7 +199,12 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
@Override
|
||||
public boolean test() {
|
||||
EditText urlEditText = mSolo.getEditText(0);
|
||||
return urlEditText.hasFocus();
|
||||
if (urlEditText.isInputMethodTarget()) {
|
||||
return true;
|
||||
} else {
|
||||
mSolo.clickOnEditText(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}, MAX_WAIT_ENABLED_TEXT_MS);
|
||||
|
||||
@ -525,72 +534,6 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
|
||||
}
|
||||
|
||||
protected boolean isBookmark(String[] bookmarks, String aValue) {
|
||||
for (int i = 0; i < bookmarks.length; i++) {
|
||||
if (bookmarks[i].equals(aValue))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public long addOrUpdateBookmark(String title, String url, boolean bookmarklet) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
Uri bookmarksUri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
|
||||
bookmarksUri = bookmarksUri.buildUpon().appendQueryParameter("profile", "default").build();
|
||||
long folderId = -1;
|
||||
Cursor c = null;
|
||||
// NOTE: this is hardcoded to toolbar/mobile and triggered from bookmarklet because the existing
|
||||
// testcases were written this way
|
||||
String location = "toolbar";
|
||||
if (bookmarklet) {
|
||||
location = "mobile";
|
||||
}
|
||||
try {
|
||||
c = resolver.query(bookmarksUri,
|
||||
new String[] { "_id" },
|
||||
"guid = ?",
|
||||
new String[] { location },
|
||||
null);
|
||||
if (c.moveToFirst()) {
|
||||
folderId = c.getLong(c.getColumnIndexOrThrow("_id"));
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
ContentValues values = new ContentValues();
|
||||
values.put("title", title);
|
||||
values.put("url", url);
|
||||
values.put("parent", folderId);
|
||||
long now = System.currentTimeMillis();
|
||||
values.put("modified", now);
|
||||
if (!bookmarklet) {
|
||||
values.put("type", 1);
|
||||
values.put("guid", url);
|
||||
values.put("position", 10);
|
||||
values.put("created", now);
|
||||
}
|
||||
int updated = resolver.update(bookmarksUri,
|
||||
values,
|
||||
"url = ?",
|
||||
new String[] { url });
|
||||
if (updated == 0) {
|
||||
Uri uri = resolver.insert(bookmarksUri, values);
|
||||
mAsserter.ok(true, "Inserted at: ", uri.toString());
|
||||
return ContentUris.parseId(uri);
|
||||
}
|
||||
return ContentUris.parseId(bookmarksUri);
|
||||
}
|
||||
|
||||
public void deleteBookmark(String title) {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
|
||||
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
||||
.appendQueryParameter("sync", "true").build();
|
||||
resolver.delete(uri, "title = ?", new String[] { title });
|
||||
}
|
||||
|
||||
public void addTab(String url) {
|
||||
Element tabs = null;
|
||||
Element addTab = null;
|
||||
@ -655,59 +598,12 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will edit the bookmark with index = bookmarkIndex from the list of bookmarks
|
||||
* For the field index:
|
||||
* fieldIndex = 1 - the Bookmark name
|
||||
* fieldIndex = 2 - the Bookmark url
|
||||
* fieldIndex = 3 - the Bookmark keyword
|
||||
*/
|
||||
public void editBookmark(int bookmarkIndex, int fieldIndex, String addedText, ListView list) {
|
||||
|
||||
// Open the Edit Bookmark context menu
|
||||
View child;
|
||||
mSolo.clickOnText("Bookmarks");
|
||||
child = list.getChildAt(bookmarkIndex);
|
||||
mAsserter.ok(child != null, "edit item can be retrieved", child != null ? child.toString() : "null!");
|
||||
waitForText("Switch to tab");
|
||||
mSolo.clickLongOnView(child);
|
||||
waitForText("Share");
|
||||
mSolo.clickOnText("Edit");
|
||||
waitForText("Edit Bookmark");
|
||||
|
||||
// Clear the Field
|
||||
mSolo.clearEditText(fieldIndex);
|
||||
|
||||
// Enter the new text
|
||||
mSolo.clickOnEditText(fieldIndex);
|
||||
mActions.sendKeys(addedText);
|
||||
mSolo.clickOnText("OK");
|
||||
waitForText("Bookmark updated");
|
||||
}
|
||||
|
||||
public boolean checkBookmarkEdit(int bookmarkIndex, String addedText, ListView list) {
|
||||
Device mDevice = new Device();
|
||||
// Open the Edit Bookmark context menu
|
||||
View child;
|
||||
mSolo.clickOnText("Bookmarks");
|
||||
child = list.getChildAt(bookmarkIndex);
|
||||
mAsserter.ok(child != null, "check item can be retrieved", child != null ? child.toString() : "null!");
|
||||
waitForText("Switch to tab");
|
||||
mSolo.clickLongOnView(child);
|
||||
waitForText("Share");
|
||||
mSolo.clickOnText("Edit");
|
||||
waitForText("Edit Bookmark");
|
||||
|
||||
// Check if the new text was added
|
||||
if (mSolo.searchText(addedText)) {
|
||||
clickOnButton("Cancel");
|
||||
waitForText("about:home");
|
||||
return true;
|
||||
} else {
|
||||
clickOnButton("Cancel");
|
||||
waitForText("about:home");
|
||||
return false;
|
||||
}
|
||||
public void clearPrivateData() {
|
||||
selectSettingsItem(PRIVACY_LABEL, CLEAR_PRIVATE_DATA_LABEL);
|
||||
Actions.EventExpecter clearData = mActions.expectGeckoEvent("Sanitize:Finished");
|
||||
mSolo.clickOnText("Clear data");
|
||||
clearData.blockForEvent();
|
||||
clearData.unregisterListener();
|
||||
}
|
||||
|
||||
class Device {
|
||||
|
@ -7,7 +7,7 @@ import android.database.Cursor;
|
||||
import android.widget.ListView;
|
||||
|
||||
|
||||
public class testBookmarklets extends PixelTest {
|
||||
public class testBookmarklets extends AboutHomeTest {
|
||||
@Override
|
||||
protected int getTestType() {
|
||||
return TEST_MOCHITEST;
|
||||
@ -22,7 +22,7 @@ public class testBookmarklets extends PixelTest {
|
||||
blockForGeckoReady();
|
||||
|
||||
// load a standard page so bookmarklets work
|
||||
loadAndPaint(url);
|
||||
loadUrl(url);
|
||||
|
||||
// verify that user-entered bookmarklets do *not* work
|
||||
enterUrl(js);
|
||||
@ -37,7 +37,7 @@ public class testBookmarklets extends PixelTest {
|
||||
|
||||
// add the bookmarklet to the database. there's currently no way to
|
||||
// add this using the UI, so we go through the content provider.
|
||||
addOrUpdateBookmark(title, js, true);
|
||||
addOrUpdateMobileBookmark(title, js);
|
||||
|
||||
// verify that bookmarklets clicked in awesomescreen work
|
||||
/* Removed by Bug 896576 - [fig] Remove [getBookmarksList] from BaseTest
|
||||
|
@ -4,7 +4,7 @@ package @ANDROID_PACKAGE_NAME@.tests;
|
||||
import @ANDROID_PACKAGE_NAME@.*;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class testClearPrivateData extends PixelTest {
|
||||
public class testClearPrivateData extends AboutHomeTest {
|
||||
|
||||
@Override
|
||||
protected int getTestType() {
|
||||
@ -19,7 +19,7 @@ public class testClearPrivateData extends PixelTest {
|
||||
private void clearHistory() {
|
||||
// Loading a page so we are sure that there is at least one history entry
|
||||
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
|
||||
loadAndPaint(url);
|
||||
loadUrl(url);
|
||||
|
||||
/* Removed by Bug 896576 - [fig] Remove [getHistoryList] from BaseTest
|
||||
// Checking that the history list is not empty
|
||||
|
@ -8,7 +8,7 @@ import java.util.ArrayList;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public class testHistory extends PixelTest {
|
||||
public class testHistory extends AboutHomeTest {
|
||||
private View mFirstChild;
|
||||
|
||||
@Override
|
||||
@ -23,11 +23,11 @@ public class testHistory extends PixelTest {
|
||||
String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html");
|
||||
String url3 = getAbsoluteUrl("/robocop/robocop_blank_03.html");
|
||||
|
||||
loadAndPaint(url);
|
||||
loadUrl(url);
|
||||
verifyPageTitle("Browser Blank Page 01");
|
||||
loadAndPaint(url2);
|
||||
loadUrl(url2);
|
||||
verifyPageTitle("Browser Blank Page 02");
|
||||
loadAndPaint(url3);
|
||||
loadUrl(url3);
|
||||
verifyPageTitle("Browser Blank Page 03");
|
||||
|
||||
/* Removed by Bug 896576 - [fig] Remove [getHistoryList] from BaseTest
|
||||
|
@ -19,7 +19,7 @@ import java.util.Arrays;
|
||||
* At the end will test that a second import will not duplicate information
|
||||
*/
|
||||
|
||||
public class testImportFromAndroid extends PixelTest {
|
||||
public class testImportFromAndroid extends AboutHomeTest {
|
||||
ArrayList<String> androidData = new ArrayList<String>();
|
||||
ArrayList<String> firefoxHistory = new ArrayList<String>();
|
||||
|
||||
@ -41,15 +41,15 @@ public class testImportFromAndroid extends PixelTest {
|
||||
addData();
|
||||
|
||||
// Get the initial bookmarks and history
|
||||
oldFirefoxBookmarks = getFirefoxData("bookmarks");
|
||||
oldFirefoxHistory = getFirefoxData("history");
|
||||
oldFirefoxBookmarks = getBrowserDBUrls(BrowserDataType.BOOKMARKS);
|
||||
oldFirefoxHistory = getBrowserDBUrls(BrowserDataType.HISTORY);
|
||||
|
||||
// Import the bookmarks and history
|
||||
importDataFromAndroid();
|
||||
|
||||
// Get the Android history and the Firefox bookmarks and history lists
|
||||
firefoxHistory = getFirefoxData("history");
|
||||
firefoxBookmarks = getFirefoxData("bookmarks");
|
||||
firefoxHistory = getBrowserDBUrls(BrowserDataType.HISTORY);
|
||||
firefoxBookmarks = getBrowserDBUrls(BrowserDataType.BOOKMARKS);
|
||||
|
||||
/**
|
||||
* Add a delay to make sure the imported items are added to the array lists
|
||||
@ -89,7 +89,7 @@ public class testImportFromAndroid extends PixelTest {
|
||||
|
||||
// Verify bookmarks are not duplicated
|
||||
ArrayList<String> verifiedBookmarks = new ArrayList<String>();
|
||||
firefoxBookmarks = getFirefoxData("bookmarks");
|
||||
firefoxBookmarks = getBrowserDBUrls(BrowserDataType.BOOKMARKS);
|
||||
for (String url:firefoxBookmarks) {
|
||||
if (verifiedBookmarks.contains(url)) {
|
||||
mAsserter.ok(false, "Bookmark " + url + " should not be duplicated", "Bookmark is duplicated");
|
||||
@ -100,7 +100,7 @@ public class testImportFromAndroid extends PixelTest {
|
||||
}
|
||||
|
||||
// Verify history count is not increased after the second import
|
||||
mAsserter.ok(firefoxHistory.size() == getFirefoxData("history").size(), "The number of history entries was not increased", "None of the items were duplicated");
|
||||
mAsserter.ok(firefoxHistory.size() == getBrowserDBUrls(BrowserDataType.HISTORY).size(), "The number of history entries was not increased", "None of the items were duplicated");
|
||||
}
|
||||
|
||||
private void addData() {
|
||||
@ -110,7 +110,7 @@ public class testImportFromAndroid extends PixelTest {
|
||||
for (String url:androidBookmarks) {
|
||||
// Add every 3rd bookmark to Firefox Mobile
|
||||
if ((androidBookmarks.indexOf(url) % 3) == 0) {
|
||||
addOrUpdateBookmark("Bookmar Number" + String.valueOf(androidBookmarks.indexOf(url)), url, true);
|
||||
addOrUpdateMobileBookmark("Bookmar Number" + String.valueOf(androidBookmarks.indexOf(url)), url);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,54 +184,15 @@ public class testImportFromAndroid extends PixelTest {
|
||||
return urls;
|
||||
}
|
||||
|
||||
public ArrayList<String> getFirefoxData(String data) {
|
||||
ArrayList<String> firefoxData = new ArrayList<String>();
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
Cursor cursor = null;
|
||||
Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/" + data);
|
||||
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
||||
.appendQueryParameter("sync", "true").build();
|
||||
try {
|
||||
cursor = resolver.query(uri, null, null, null, null);
|
||||
if (cursor != null) {
|
||||
cursor.moveToFirst();
|
||||
for (int i = 0; i < cursor.getCount(); i++ ) {
|
||||
/**
|
||||
* The url field may be null for folders in the structure of the Bookmarks table for Firefox
|
||||
* so we should eliminate thouse
|
||||
*/
|
||||
if (cursor.getString(cursor.getColumnIndex("url")) != null) {
|
||||
firefoxData.add(cursor.getString(cursor.getColumnIndex("url")));
|
||||
}
|
||||
if(!cursor.isLast()) {
|
||||
cursor.moveToNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return firefoxData;
|
||||
}
|
||||
|
||||
public void deleteImportedData() {
|
||||
ContentResolver resolver = getActivity().getContentResolver();
|
||||
// Bookmarks
|
||||
Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/bookmarks");
|
||||
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
||||
.appendQueryParameter("sync", "true").build();
|
||||
ArrayList<String> androidBookmarks = getAndroidUrls("bookmarks");
|
||||
for (String url:androidBookmarks) {
|
||||
resolver.delete(uri, "url = ?", new String[] { url });
|
||||
deleteBookmark(url);
|
||||
}
|
||||
// History
|
||||
uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/history");
|
||||
uri = uri.buildUpon().appendQueryParameter("profile", "default")
|
||||
.appendQueryParameter("sync", "true").build();
|
||||
for (String url:androidData) {
|
||||
resolver.delete(uri, "url = ?", new String[] { url });
|
||||
deleteHistoryItem(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user