mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
fe44f36220
--HG-- extra : rebase_source : 376574e0c41b91c16a6be335584a4a61768bb4a9
75 lines
2.5 KiB
Java
75 lines
2.5 KiB
Java
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
import @ANDROID_PACKAGE_NAME@.*;
|
|
import android.database.Cursor;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
public class testBookmarklets extends PixelTest {
|
|
@Override
|
|
protected int getTestType() {
|
|
return TEST_MOCHITEST;
|
|
}
|
|
|
|
public void testBookmarklets() {
|
|
final String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
|
|
final String title = "alertBookmarklet";
|
|
final String js = "javascript:alert(12 + .34)";
|
|
boolean alerted;
|
|
|
|
blockForGeckoReady();
|
|
|
|
// load a standard page so bookmarklets work
|
|
loadAndPaint(url);
|
|
|
|
// verify that user-entered bookmarklets do *not* work
|
|
enterUrl(js);
|
|
mActions.sendSpecialKey(Actions.SpecialKey.ENTER);
|
|
alerted = waitForTest(new BooleanTest() {
|
|
@Override
|
|
public boolean test() {
|
|
return mSolo.searchButton("OK", true) || mSolo.searchText("12.34", true);
|
|
}
|
|
}, 3000);
|
|
mAsserter.is(alerted, false, "Alert was not shown for user-entered bookmarklet");
|
|
|
|
// add the bookmarklet to the database. there's currently no way to
|
|
// add this using the UI, so we go through the content provider.
|
|
addOrUpdateBookmark(title, js, true);
|
|
|
|
// verify that bookmarklets clicked in awesomescreen work
|
|
ListView bookmarks = getBookmarksList(title);
|
|
|
|
Boolean found = false;
|
|
if (bookmarks == null) {
|
|
mAsserter.is(true, true, "Did not find the bookmarks section in the awesomebar");
|
|
} else {
|
|
for (int i = 0; i < bookmarks.getAdapter().getCount(); i++) {
|
|
Cursor c = (Cursor)bookmarks.getItemAtPosition(i);
|
|
String turl = c.getString(c.getColumnIndexOrThrow("url"));
|
|
if (turl.equals(js)) {
|
|
found = true;
|
|
mAsserter.is(1, 1, "Found bookmarklet added to bookmarks: " + js);
|
|
mSolo.clickOnView(bookmarks.getChildAt(i));
|
|
}
|
|
}
|
|
}
|
|
if (!found) {
|
|
mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it");
|
|
}
|
|
|
|
alerted = waitForTest(new BooleanTest() {
|
|
@Override
|
|
public boolean test() {
|
|
return mSolo.searchButton("OK", true) && mSolo.searchText("12.34", true);
|
|
}
|
|
}, 3000);
|
|
mAsserter.is(alerted, true, "Alert was shown for clicked bookmarklet");
|
|
|
|
// remove the bookmarklet
|
|
deleteBookmark(js);
|
|
}
|
|
}
|