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

165 lines
6.3 KiB
Java

#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import android.view.View;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.TabWidget;
import android.text.TextUtils;
import android.content.ContentResolver;
import android.net.Uri;
import java.util.Arrays;
import java.util.ArrayList;
import @ANDROID_PACKAGE_NAME@.*;
/* Tests opening the all pages tab, that items look correct, clicking on an item
and long tapping on an item
*/
public class testAllPagesTab extends BaseTest {
private static final String ABOUT_HOME_URL = "about:home";
private static ListView listview = null;
private String[] mBookmarks = new String[] {
"Firefox: About your browser",
"Firefox Start",
"Firefox: Support",
"Firefox: Customize with add-ons"
};
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
public void testAllPagesTab() {
blockForGeckoReady();
// load one page so there is something in our history
String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
loadUrl(url);
testList(url);
testClick("about:firefox");
testContextMenu(url);
}
private void testList(String url) {
final ListView list = getAllPagesList(mBookmarks[0], 5);
// some basic checks for the tab strip
TabWidget tabwidget = (TabWidget)mSolo.getView(TabWidget.class, 0);
mAsserter.is(tabwidget.getTabCount(), 3, "Three tabs shown");
mAsserter.is(tabwidget.isStripEnabled(), false, "Strip is hidden");
// check that the right tab is selected
TabHost host = (TabHost)mSolo.getView(TabHost.class, 0);
// This test fails, only when we're running tests
// mAsserter.is(host.getCurrentTab(), 0, "All pages tab is selected in tab strip");
mAsserter.isnot(list, null, "checking that all pages list exists and has 5 children (the default bookmarks)");
final int count = list.getAdapter().getCount();
String loadUrl = "";
for (int i = count - 1; i >= 0; i--) {
View child = list.getChildAt(i);
if (child == null) {
// this may simply indicate that the item is not visible
Object item = list.getAdapter().getItem(i);
mAsserter.ok(item != null, "adapter item is set", item != null ? item.toString() : "null!");
continue;
}
ArrayList<View> views = mSolo.getViews(child);
ArrayList<ImageView> imageViews = new ArrayList<ImageView>();
int expectedImages = 1;
for (int j = 0; j < views.size(); j++) {
View v = views.get(j);
if (v instanceof TextView) {
TextView t = (TextView)v;
String string = t.getText().toString();
mAsserter.ok(!TextUtils.isEmpty(string), "TextView is filled in", string);
if (i == 1 || string.startsWith("http")) {
loadUrl = string;
}
if (isBookmark(mBookmarks, string)) {
expectedImages = 2;
}
} else if (v instanceof ImageView) {
imageViews.add((ImageView)v);
}
}
int visible = 0;
for (int j = 0; j < imageViews.size(); j++) {
ImageView img = imageViews.get(j);
visible += (img.getVisibility() == View.VISIBLE) ? 1 : 0;
}
mAsserter.is(visible, expectedImages, "Correct number of ImageViews visible");
}
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
}
private void testContextMenu(String url) {
ListView list = getAllPagesList(mBookmarks[0], 5);
View child = list.getChildAt(0);
mAsserter.ok(child != null, "first list item can be retrieved", child != null ? child.toString() : "null!");
mSolo.clickLongOnView(child);
// TODO: Test clicking these does the right thing
mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has Open in New Tab option", "Open in New Tab");
mAsserter.ok(mSolo.waitForText("Share"), "Context menu has Share option", "Share");
mAsserter.ok(mSolo.searchText("Remove", true), "Context menu has Remove option", "Remove");
mAsserter.ok(mSolo.searchText("Add to Home Screen", true), "Context menu has Add to Home Screen option", "Add to Home Screen");
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
}
private void testClick(String url) {
ListView list = getAllPagesList(mBookmarks[0], 5);
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
// Avoid clicking the first item. Its the first item because its in an open tab, and will just switch to it
View child = list.getChildAt(1);
mAsserter.ok(child != null, "first list item can be retrieved", child != null ? child.toString() : "null!");
// dump text for this child, to be sure of which list item is clicked
ArrayList<View> views = mSolo.getViews(child);
for (int j = 0; j < views.size(); j++) {
View v = views.get(j);
if (v instanceof TextView) {
TextView t = (TextView)v;
String string = t.getText().toString();
mAsserter.dumpLog("first list item has text: " + string);
}
}
mSolo.clickOnView(child);
contentEventExpecter.blockForEvent();
contentEventExpecter.unregisterListener();
mSolo.sleep(500);
verifyUrl(url);
}
@Override
public void tearDown() throws Exception {
ContentResolver resolver = getActivity().getContentResolver();
Uri uri = Uri.parse("content://@ANDROID_PACKAGE_NAME@.db.browser/history");
uri = uri.buildUpon().appendQueryParameter("profile", "default")
.appendQueryParameter("sync", "true").build();
resolver.delete(uri, "url = ?", new String[] {
"http://mochi.test:8888/tests/robocop/robocop_big_link.html"
});
super.tearDown();
}
}