From 718c2a6f10253a62c7a4a6dc68e0ba4b9bfef4d1 Mon Sep 17 00:00:00 2001 From: "adrian.tamas@softvision.ro" Date: Mon, 3 Dec 2012 14:14:27 +0200 Subject: [PATCH] Bug 747835: Back, Forward and Reload buttons test. r=jmaher --- mobile/android/base/tests/BaseTest.java.in | 137 +++++++++++++++++- mobile/android/base/tests/robocop.ini | 1 + .../android/base/tests/testTabHistory.java.in | 53 +++++++ 3 files changed, 189 insertions(+), 2 deletions(-) create mode 100755 mobile/android/base/tests/testTabHistory.java.in diff --git a/mobile/android/base/tests/BaseTest.java.in b/mobile/android/base/tests/BaseTest.java.in index 832b76e712e..6911ed29eb8 100755 --- a/mobile/android/base/tests/BaseTest.java.in +++ b/mobile/android/base/tests/BaseTest.java.in @@ -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 { 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 { 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$"); + } + } + } + } } diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index 73d1f4ce04f..a8df1d7801e 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -25,6 +25,7 @@ [testHistory] [testVkbOverlap] [testDoorHanger] +[testTabHistory] # [testPermissions] # see bug 757475 # [testJarReader] # see bug 738890 diff --git a/mobile/android/base/tests/testTabHistory.java.in b/mobile/android/base/tests/testTabHistory.java.in new file mode 100755 index 00000000000..748c3b7306e --- /dev/null +++ b/mobile/android/base/tests/testTabHistory.java.in @@ -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"); + } +}