mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
152 lines
5.3 KiB
Java
152 lines
5.3 KiB
Java
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@.tests;
|
|
|
|
import android.app.Activity;
|
|
import android.view.View;
|
|
import android.widget.ListView;
|
|
import android.widget.ExpandableListView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TabHost;
|
|
import android.widget.TextView;
|
|
import android.widget.ImageView;
|
|
import android.text.TextUtils;
|
|
|
|
import android.content.ContentValues;
|
|
import android.content.ContentResolver;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.ArrayList;
|
|
import java.io.File;
|
|
|
|
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 String[] bookmarks = new String[] {
|
|
"about:firefox",
|
|
"about:home",
|
|
"http://support.mozilla.org/en-US/mobile",
|
|
"https://addons.mozilla.org/en-US/android/"
|
|
};
|
|
|
|
@Override
|
|
protected int getTestType() {
|
|
return TEST_MOCHITEST;
|
|
}
|
|
|
|
public void testAllPagesTab() {
|
|
mActions.expectGeckoEvent("Gecko:Ready").blockForEvent();
|
|
|
|
// load one page so there is something in our history
|
|
String url = getAbsoluteUrl("/robocop/robocop_big_link.html");
|
|
loadUrl(url);
|
|
|
|
testList(url);
|
|
testClick(url);
|
|
testContextMenu(url);
|
|
}
|
|
|
|
private void testList(String url) {
|
|
ListView list = getAllPagesList(url);
|
|
mSolo.waitForText(url);
|
|
|
|
mAsserter.ok(list != null, "checking that all pages list exists", list.toString());
|
|
|
|
mAsserter.is(list.getChildCount(), 5, "all pages list has 5 children (the default bookmarks)");
|
|
|
|
final int count = list.getChildCount();
|
|
String loadUrl = "";
|
|
for (int i = count - 1; i >= 0; i--) {
|
|
View child = list.getChildAt(i);
|
|
|
|
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;
|
|
}
|
|
|
|
int index = Arrays.binarySearch(bookmarks, string);
|
|
if (index > -1) {
|
|
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(url);
|
|
mSolo.waitForText(url);
|
|
|
|
View child = list.getChildAt(0);
|
|
mSolo.clickLongOnView(child);
|
|
|
|
// TODO: Test clicking these does the right thing
|
|
mAsserter.ok(mSolo.waitForText("Open in New Tab"), "Context menu has New Tab option", "Open in New Tab");
|
|
mAsserter.ok(mSolo.searchText("Share", true), "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(url);
|
|
mSolo.waitForText(url);
|
|
|
|
Actions.EventExpecter contentEventExpecter = mActions.expectGeckoEvent("DOMContentLoaded");
|
|
View child = list.getChildAt(0);
|
|
mSolo.clickOnView(child);
|
|
contentEventExpecter.blockForEvent();
|
|
verifyUrl(url);
|
|
}
|
|
|
|
private ListView getAllPagesList(String url) {
|
|
Activity awesomeBarActivity = clickOnAwesomeBar();
|
|
mSolo.waitForText(url);
|
|
|
|
TabHost tabHost = (TabHost)mSolo.getView(TabHost.class, 0);
|
|
int listId = mDriver.findElement(getActivity(), "awesomebar_list").getId();
|
|
return (ListView)tabHost.getCurrentView().findViewById(listId);
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|