Bug 908344 - Test for bookmark keyword. r=wesj

This commit is contained in:
Margaret Leibovic 2013-09-03 21:19:26 -07:00
parent dfa23284a3
commit c6d6e1b035
3 changed files with 73 additions and 0 deletions

View File

@ -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();

View File

@ -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

View File

@ -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);
}
}