gecko-dev/mobile/android/base/tests/testBookmarklets.java.in

78 lines
2.7 KiB
Java

#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.database.Cursor;
import android.view.View;
import android.widget.ListView;
import java.util.ArrayList;
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() {
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();
Boolean found = false;
if (bookmarks == null) {
mAsserter.is(true, true, "Did not find the bookmarks section in the awesomebar");
} else if (mSolo.waitForText(title)) {
for (int i = 0; i < bookmarks.getChildCount(); 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));
}
}
} else {
mAsserter.is(true, true, "Did not find the title '" + title + "' of the bookmark in the list");
}
if (!found) {
mAsserter.is(found, true, "Found the bookmark: " + js + " and clicked on it");
}
alerted = waitForTest(new BooleanTest() {
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);
}
}