From c6d6e1b035594e3fe9a6a2a0f212e42362b480f9 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Tue, 3 Sep 2013 21:19:26 -0700 Subject: [PATCH] Bug 908344 - Test for bookmark keyword. r=wesj --- .../android/base/tests/AboutHomeTest.java.in | 36 +++++++++++++++++++ mobile/android/base/tests/robocop.ini | 1 + .../base/tests/testBookmarkKeyword.java.in | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 mobile/android/base/tests/testBookmarkKeyword.java.in diff --git a/mobile/android/base/tests/AboutHomeTest.java.in b/mobile/android/base/tests/AboutHomeTest.java.in index 2f069dcbb48b..f860d4fc100d 100644 --- a/mobile/android/base/tests/AboutHomeTest.java.in +++ b/mobile/android/base/tests/AboutHomeTest.java.in @@ -141,6 +141,42 @@ abstract class AboutHomeTest extends BaseTest { } } + /** + * Updates the title and keyword of a bookmark with the given URL. + * + * Warning: This method assumes that there's only one bookmark with the given URL. + */ + protected void updateBookmark(String url, String title, String keyword) { + try { + ContentResolver resolver = getActivity().getContentResolver(); + ClassLoader classLoader = getActivity().getClassLoader(); + Class browserDB = classLoader.loadClass("org.mozilla.gecko.db.BrowserDB"); + Method getBookmarkForUrl = browserDB.getMethod("getBookmarkForUrl", ContentResolver.class, String.class); + + // Get the id for the bookmark with the given URL. + Cursor c = null; + try { + c = (Cursor) getBookmarkForUrl.invoke(null, resolver, url); + if (!c.moveToFirst()) { + mAsserter.ok(false, "Getting bookmark with url", "Couldn't find bookmark with url = " + url); + return; + } + + int id = c.getInt(c.getColumnIndexOrThrow("_id")); + Method updateBookmark = browserDB.getMethod("updateBookmark", ContentResolver.class, int.class, String.class, String.class, String.class); + updateBookmark.invoke(null, resolver, id, url, title, keyword); + + mAsserter.ok(true, "Updating bookmark", "Updating bookmark with url = " + url); + } finally { + if (c != null) { + c.close(); + } + } + } catch (Exception e) { + mAsserter.ok(false, "Exception updating bookmark: ", e.toString()); + } + } + protected void deleteBookmark(String url) { try { ContentResolver resolver = getActivity().getContentResolver(); diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index b57d455b0e4d..eba2ff8fe2f2 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -2,6 +2,7 @@ # [testAwesomebarSwipes] # disabled on fig - bug 880060 # [testBookmark] # disabled on fig - bug 880060 # [testBookmarklets] # disabled on fig - bug 880060 +[testBookmarkKeyword] [testBrowserSearchVisibility] [testJNI] # [testLoad] # see bug 851861 diff --git a/mobile/android/base/tests/testBookmarkKeyword.java.in b/mobile/android/base/tests/testBookmarkKeyword.java.in new file mode 100644 index 000000000000..374083fb390b --- /dev/null +++ b/mobile/android/base/tests/testBookmarkKeyword.java.in @@ -0,0 +1,36 @@ +#filter substitution +package @ANDROID_PACKAGE_NAME@.tests; + +import @ANDROID_PACKAGE_NAME@.*; + +public class testBookmarkKeyword extends AboutHomeTest { + + @Override + protected int getTestType() { + return TEST_MOCHITEST; + } + + public void testBookmarkKeyword() { + blockForGeckoReady(); + + final String url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); + final String title = "Browser Blank Page 01"; + final String keyword = "testkeyword"; + + // Add a bookmark, and update it to have a keyword. + addOrUpdateMobileBookmark(title, url); + updateBookmark(url, title, keyword); + + // Enter the keyword in the urlbar. + inputAndLoadUrl(keyword); + + // Wait for the page to load. + waitForText(title); + + // Make sure the title of the page appeared. + verifyPageTitle(title); + + // Delete the bookmark to clean up. + deleteBookmark(url); + } +}