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

77 lines
2.6 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 AboutHomeTest {
@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
loadUrl(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.
addOrUpdateMobileBookmark(title, js);
// verify that bookmarklets clicked in awesomescreen work
/* Removed by Bug 896576 - [fig] Remove [getBookmarksList] from BaseTest
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);
}
}