michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: import android.database.Cursor; michael@0: import android.widget.ListView; michael@0: michael@0: michael@0: public class testBookmarklets extends AboutHomeTest { michael@0: public void testBookmarklets() { michael@0: final String url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL); michael@0: final String title = "alertBookmarklet"; michael@0: final String js = "javascript:alert(12 + .34)"; michael@0: boolean alerted; michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: // load a standard page so bookmarklets work michael@0: inputAndLoadUrl(url); michael@0: verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE); // Waiting for page title to ensure the page is loaded michael@0: michael@0: // verify that user-entered bookmarklets do *not* work michael@0: enterUrl(js); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.ENTER); michael@0: alerted = waitForTest(new BooleanTest() { michael@0: @Override michael@0: public boolean test() { michael@0: return mSolo.searchButton("OK", true) || mSolo.searchText("12.34", true); michael@0: } michael@0: }, 3000); michael@0: mAsserter.is(alerted, false, "Alert was not shown for user-entered bookmarklet"); michael@0: michael@0: // add the bookmarklet to the database. there's currently no way to michael@0: // add this using the UI, so we go through the content provider. michael@0: mDatabaseHelper.addOrUpdateMobileBookmark(title, js); michael@0: michael@0: // Open about:home in the Bookmarks page michael@0: openAboutHomeTab(AboutHomeTabs.BOOKMARKS); michael@0: michael@0: ListView bookmarks = findListViewWithTag("bookmarks"); michael@0: mAsserter.is(waitForNonEmptyListToLoad(bookmarks), true, "list is properly loaded"); michael@0: michael@0: int width = mDriver.getGeckoWidth(); michael@0: int height = mDriver.getGeckoHeight(); michael@0: michael@0: // Scroll down so that the bookmarks list has more items on screen. michael@0: mActions.drag(width / 2, width / 2, height - 10, height / 2); michael@0: michael@0: // Verify that bookmarklets clicked in awesomescreen work michael@0: boolean found = false; michael@0: for (int i = bookmarks.getHeaderViewsCount(); i < bookmarks.getAdapter().getCount(); i++) { michael@0: Cursor c = (Cursor)bookmarks.getItemAtPosition(i); michael@0: String aUrl = c.getString(c.getColumnIndexOrThrow("url")); michael@0: if (aUrl.equals(js)) { michael@0: found = true; michael@0: mAsserter.is(1, 1, "Found bookmarklet added to bookmarks: " + js); michael@0: mSolo.clickOnView(bookmarks.getChildAt(i)); michael@0: } michael@0: } michael@0: michael@0: if (!found) { michael@0: mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it"); michael@0: } michael@0: michael@0: alerted = waitForTest(new BooleanTest() { michael@0: @Override michael@0: public boolean test() { michael@0: return mSolo.searchButton("OK", true) && mSolo.searchText("12.34", true); michael@0: } michael@0: }, 3000); michael@0: mAsserter.is(alerted, true, "Alert was shown for clicked bookmarklet"); michael@0: michael@0: // remove the bookmarklet michael@0: mDatabaseHelper.deleteBookmark(js); michael@0: } michael@0: }