mobile/android/base/tests/testBookmarklets.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testBookmarklets.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.Actions;
     1.7 +
     1.8 +import android.database.Cursor;
     1.9 +import android.widget.ListView;
    1.10 +
    1.11 +
    1.12 +public class testBookmarklets extends AboutHomeTest {
    1.13 +    public void testBookmarklets() {
    1.14 +        final String url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    1.15 +        final String title = "alertBookmarklet";
    1.16 +        final String js = "javascript:alert(12 + .34)";
    1.17 +        boolean alerted;
    1.18 +
    1.19 +        blockForGeckoReady();
    1.20 +
    1.21 +        // load a standard page so bookmarklets work
    1.22 +        inputAndLoadUrl(url);
    1.23 +        verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE); // Waiting for page title to ensure the page is loaded
    1.24 +
    1.25 +        // verify that user-entered bookmarklets do *not* work
    1.26 +        enterUrl(js);
    1.27 +        mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
    1.28 +        alerted = waitForTest(new BooleanTest() {
    1.29 +            @Override
    1.30 +            public boolean test() {
    1.31 +                return mSolo.searchButton("OK", true) || mSolo.searchText("12.34", true);
    1.32 +            }
    1.33 +        }, 3000);
    1.34 +        mAsserter.is(alerted, false, "Alert was not shown for user-entered bookmarklet");
    1.35 +
    1.36 +        // add the bookmarklet to the database. there's currently no way to
    1.37 +        // add this using the UI, so we go through the content provider.
    1.38 +        mDatabaseHelper.addOrUpdateMobileBookmark(title, js);
    1.39 +
    1.40 +        // Open about:home in the Bookmarks page
    1.41 +        openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    1.42 +
    1.43 +        ListView bookmarks = findListViewWithTag("bookmarks");
    1.44 +        mAsserter.is(waitForNonEmptyListToLoad(bookmarks), true, "list is properly loaded");
    1.45 +
    1.46 +        int width = mDriver.getGeckoWidth();
    1.47 +        int height = mDriver.getGeckoHeight();
    1.48 +
    1.49 +        // Scroll down so that the bookmarks list has more items on screen.
    1.50 +        mActions.drag(width / 2, width / 2, height - 10, height / 2);
    1.51 +
    1.52 +        // Verify that bookmarklets clicked in awesomescreen work
    1.53 +        boolean found = false;
    1.54 +        for (int i = bookmarks.getHeaderViewsCount(); i < bookmarks.getAdapter().getCount(); i++) {
    1.55 +            Cursor c = (Cursor)bookmarks.getItemAtPosition(i);
    1.56 +            String aUrl = c.getString(c.getColumnIndexOrThrow("url"));
    1.57 +            if (aUrl.equals(js)) {
    1.58 +                found = true;
    1.59 +                mAsserter.is(1, 1, "Found bookmarklet added to bookmarks: " + js);
    1.60 +                mSolo.clickOnView(bookmarks.getChildAt(i));
    1.61 +            }
    1.62 +        }
    1.63 +
    1.64 +        if (!found) {
    1.65 +            mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it");
    1.66 +        }
    1.67 +
    1.68 +        alerted = waitForTest(new BooleanTest() {
    1.69 +            @Override
    1.70 +            public boolean test() {
    1.71 +                return mSolo.searchButton("OK", true) && mSolo.searchText("12.34", true);
    1.72 +            }
    1.73 +        }, 3000);
    1.74 +        mAsserter.is(alerted, true, "Alert was shown for clicked bookmarklet");
    1.75 +
    1.76 +        // remove the bookmarklet
    1.77 +        mDatabaseHelper.deleteBookmark(js);
    1.78 +    }
    1.79 +}

mercurial