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