Bug 908344 - Test for bookmark keyword. r=wesj
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Tue, 03 Sep 2013 21:19:26 -0700
changeset 158305 021cf0a2602aef810c9f4706576615f2a81d3a12
parent 158304 7d8523c3dc5740aa4e5119089e750d8eff41bfae
child 158306 c50dc9643c47a69a05d044ce500c28c70d70ed00
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs908344
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 908344 - Test for bookmark keyword. r=wesj
mobile/android/base/tests/AboutHomeTest.java.in
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testBookmarkKeyword.java.in
--- a/mobile/android/base/tests/AboutHomeTest.java.in
+++ b/mobile/android/base/tests/AboutHomeTest.java.in
@@ -136,16 +136,52 @@ abstract class AboutHomeTest extends Bas
             Method addBookmark = browserDB.getMethod("addBookmark", ContentResolver.class, String.class, String.class);
             addBookmark.invoke(null, resolver, title, url);
             mAsserter.ok(true, "Inserting/updating a new bookmark", "Inserting/updating the bookmark with the title = " + title + " and the url = " + url);
         } catch (Exception e) {
             mAsserter.ok(false, "Exception adding bookmark: ", e.toString());
         }
     }
 
+    /**
+     * 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();
             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) {
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -1,12 +1,13 @@
 [testAwesomebar]
 # [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
 [testNewTab]
 [testOrderedBroadcast]
 [testPrefsObserver]
 # [testPanCorrectness] # see bug 851861
 # [test_bug720538] # disabled on fig - bug 897072
new file mode 100644
--- /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);
+    }
+}