mobile/android/base/tests/testBookmarklets.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 package org.mozilla.gecko.tests;
     3 import org.mozilla.gecko.Actions;
     5 import android.database.Cursor;
     6 import android.widget.ListView;
     9 public class testBookmarklets extends AboutHomeTest {
    10     public void testBookmarklets() {
    11         final String url = getAbsoluteUrl(StringHelper.ROBOCOP_BLANK_PAGE_01_URL);
    12         final String title = "alertBookmarklet";
    13         final String js = "javascript:alert(12 + .34)";
    14         boolean alerted;
    16         blockForGeckoReady();
    18         // load a standard page so bookmarklets work
    19         inputAndLoadUrl(url);
    20         verifyPageTitle(StringHelper.ROBOCOP_BLANK_PAGE_01_TITLE); // Waiting for page title to ensure the page is loaded
    22         // verify that user-entered bookmarklets do *not* work
    23         enterUrl(js);
    24         mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
    25         alerted = waitForTest(new BooleanTest() {
    26             @Override
    27             public boolean test() {
    28                 return mSolo.searchButton("OK", true) || mSolo.searchText("12.34", true);
    29             }
    30         }, 3000);
    31         mAsserter.is(alerted, false, "Alert was not shown for user-entered bookmarklet");
    33         // add the bookmarklet to the database. there's currently no way to
    34         // add this using the UI, so we go through the content provider.
    35         mDatabaseHelper.addOrUpdateMobileBookmark(title, js);
    37         // Open about:home in the Bookmarks page
    38         openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
    40         ListView bookmarks = findListViewWithTag("bookmarks");
    41         mAsserter.is(waitForNonEmptyListToLoad(bookmarks), true, "list is properly loaded");
    43         int width = mDriver.getGeckoWidth();
    44         int height = mDriver.getGeckoHeight();
    46         // Scroll down so that the bookmarks list has more items on screen.
    47         mActions.drag(width / 2, width / 2, height - 10, height / 2);
    49         // Verify that bookmarklets clicked in awesomescreen work
    50         boolean found = false;
    51         for (int i = bookmarks.getHeaderViewsCount(); i < bookmarks.getAdapter().getCount(); i++) {
    52             Cursor c = (Cursor)bookmarks.getItemAtPosition(i);
    53             String aUrl = c.getString(c.getColumnIndexOrThrow("url"));
    54             if (aUrl.equals(js)) {
    55                 found = true;
    56                 mAsserter.is(1, 1, "Found bookmarklet added to bookmarks: " + js);
    57                 mSolo.clickOnView(bookmarks.getChildAt(i));
    58             }
    59         }
    61         if (!found) {
    62             mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it");
    63         }
    65         alerted = waitForTest(new BooleanTest() {
    66             @Override
    67             public boolean test() {
    68                 return mSolo.searchButton("OK", true) && mSolo.searchText("12.34", true);
    69             }
    70         }, 3000);
    71         mAsserter.is(alerted, true, "Alert was shown for clicked bookmarklet");
    73         // remove the bookmarklet
    74         mDatabaseHelper.deleteBookmark(js);
    75     }
    76 }

mercurial