mobile/android/base/tests/testBookmarklets.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:b070c704accb
1 package org.mozilla.gecko.tests;
2
3 import org.mozilla.gecko.Actions;
4
5 import android.database.Cursor;
6 import android.widget.ListView;
7
8
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;
15
16 blockForGeckoReady();
17
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
21
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");
32
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);
36
37 // Open about:home in the Bookmarks page
38 openAboutHomeTab(AboutHomeTabs.BOOKMARKS);
39
40 ListView bookmarks = findListViewWithTag("bookmarks");
41 mAsserter.is(waitForNonEmptyListToLoad(bookmarks), true, "list is properly loaded");
42
43 int width = mDriver.getGeckoWidth();
44 int height = mDriver.getGeckoHeight();
45
46 // Scroll down so that the bookmarks list has more items on screen.
47 mActions.drag(width / 2, width / 2, height - 10, height / 2);
48
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 }
60
61 if (!found) {
62 mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it");
63 }
64
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");
72
73 // remove the bookmarklet
74 mDatabaseHelper.deleteBookmark(js);
75 }
76 }

mercurial