Bug 747835: Back, Forward and Reload buttons test. r=jmaher

This commit is contained in:
adrian.tamas@softvision.ro 2012-12-03 14:14:27 +02:00
parent 42e9f5bddc
commit 718c2a6f10
3 changed files with 189 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import com.jayway.android.robotium.solo.Solo;
import @ANDROID_PACKAGE_NAME@.*;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.app.Instrumentation;
import android.content.ContentValues;
import android.content.Intent;
@ -18,6 +19,8 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import android.view.View;
import android.os.Build;
import android.util.DisplayMetrics;
/**
* A convenient base class suitable for most Robocop tests.
@ -349,8 +352,30 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
public final void verifyPageTitle(String title) {
Element awesomebar = mDriver.findElement(getActivity(), "awesome_bar_title");
mAsserter.isnot(awesomebar, null, "Got the awesomebar");
assertMatches(awesomebar.getText(), title, "Page title match");
String pageTitle = null;
if (awesomebar != null) {
// Wait for the title to make sure it has been displayed in case the view
// does not update fast enough
waitForTest(new VerifyTitle(awesomebar, title), MAX_WAIT_MS);
pageTitle = awesomebar.getText();
}
mAsserter.is(pageTitle, title, "Page title is correct");
}
class VerifyTitle implements BooleanTest {
private Element mAwesomebar;
private String mTitle;
public VerifyTitle(Element awesomebar, String title) {
mAwesomebar = awesomebar;
mTitle = title;
}
public boolean test() {
String pageTitle = mAwesomebar.getText();
if (pageTitle.equals(mTitle)) {
return true;
}
return false;
}
}
public final void verifyTabCount(int expectedTabCount) {
@ -392,4 +417,112 @@ abstract class BaseTest extends ActivityInstrumentationTestCase2<Activity> {
mActions.sendKeys(url);
hitEnterAndWait();
}
class Device {
Build.VERSION mBuildVersion;
public String version; // 2.x or 3.x or 4.x
public String type; // tablet or phone
public int width;
public int height;
public Device() {
detectDevice();
}
private void detectDevice() {
// Determine device version
mBuildVersion = new Build.VERSION();
int mSDK = mBuildVersion.SDK_INT;
if (mSDK < Build.VERSION_CODES.HONEYCOMB) {
version = "2.x";
}
else {
if (mSDK > Build.VERSION_CODES.HONEYCOMB_MR2) {
version = "4.x";
}
else {
version = "3.x";
}
}
// Determine with and height
DisplayMetrics dm = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
height = dm.heightPixels;
width = dm.widthPixels;
// Determine device type
if (width > 480 && height > 480) {
type = "tablet";
}
else {
type = "phone";
}
}
public void rotate() {
if (getActivity().getRequestedOrientation () == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
mSolo.setActivityOrientation(Solo.PORTRAIT);
}
else {
mSolo.setActivityOrientation(Solo.LANDSCAPE);
}
}
}
class Navigation {
private String devType;
private String osVersion;
public Navigation(Device mDevice) {
devType = mDevice.type;
osVersion = mDevice.version;
}
public void back() {
if (devType == "tablet"){
Element backBtn = mDriver.findElement(getActivity(), "back");
backBtn.click();
}
else {
mActions.sendSpecialKey(Actions.SpecialKey.BACK);
}
}
public void forward() {
if (devType == "tablet"){
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
fwdBtn.click();
}
else {
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
mSolo.waitForText("^New Tab$");
if (osVersion != "2.x") {
Element fwdBtn = mDriver.findElement(getActivity(), "forward");
fwdBtn.click();
}
else {
mSolo.clickOnText("^Forward$");
}
}
}
public void reload() {
if (devType == "tablet"){
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
reloadBtn.click();
}
else {
mActions.sendSpecialKey(Actions.SpecialKey.MENU);
mSolo.waitForText("^New Tab$");
if (osVersion != "2.x") {
Element reloadBtn = mDriver.findElement(getActivity(), "reload");
reloadBtn.click();
}
else {
mSolo.clickOnText("^Forward$");
}
}
}
}
}

View File

@ -25,6 +25,7 @@
[testHistory]
[testVkbOverlap]
[testDoorHanger]
[testTabHistory]
# [testPermissions] # see bug 757475
# [testJarReader] # see bug 738890

View File

@ -0,0 +1,53 @@
#filter substitution
package @ANDROID_PACKAGE_NAME@.tests;
import @ANDROID_PACKAGE_NAME@.*;
import android.util.Log;
public class testTabHistory extends PixelTest {
@Override
protected int getTestType() {
return TEST_MOCHITEST;
}
/* This test will check the functionality of the Back, Forward and Reload buttons.
First it will determine the Device and the OS.
Then it will create the appropriate navigation mechanisms for back, forward and reload depending on device type and OS.
Finally it will run the tests */
public void testTabHistory() {
blockForGeckoReady();
String url = getAbsoluteUrl("/robocop/robocop_blank_01.html");
String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html");
String url3 = getAbsoluteUrl("/robocop/robocop_blank_03.html");
// Create tab history
loadAndPaint(url);
loadAndPaint(url2);
loadAndPaint(url3);
// Get the device information and create the navigation for it
Device mDevice = new Device();
Navigation nav = new Navigation(mDevice);
// Go to the 2nd page
nav.back();
mSolo.waitForText("Browser Blank Page 02");
// Go to the first page
nav.back();
mSolo.waitForText("Browser Blank Page 01");
verifyPageTitle("Browser Blank Page 01");
// Go forward to the second page
nav.forward();
mSolo.waitForText("Browser Blank Page 02");
verifyPageTitle("Browser Blank Page 02");
// Reload page
nav.reload();
verifyPageTitle("Browser Blank Page 02");
}
}