mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-18 06:45:33 +00:00
Bug 1126048 - Add test to ensure state is correct when switching to loading pages. r=mcomella
This commit is contained in:
parent
88eddc548c
commit
1db7dacec6
@ -115,6 +115,7 @@ public class StringHelper {
|
||||
public static final String ROBOCOP_ADOBE_FLASH_URL = "/robocop/robocop_adobe_flash.html";
|
||||
public static final String ROBOCOP_INPUT_URL = "/robocop/robocop_input.html";
|
||||
public static final String ROBOCOP_READER_MODE_BASIC_ARTICLE = "/robocop/reader_mode_pages/basic_article.html";
|
||||
public static final String ROBOCOP_LINK_TO_SLOW_LOADING = "/robocop/robocop_link_to_slow_loading.html";
|
||||
|
||||
private static final String ROBOCOP_JS_HARNESS_URL = "/robocop/robocop_javascript.html";
|
||||
|
||||
|
@ -14,6 +14,7 @@ import org.mozilla.gecko.tests.components.AboutHomeComponent;
|
||||
import org.mozilla.gecko.tests.components.AppMenuComponent;
|
||||
import org.mozilla.gecko.tests.components.BaseComponent;
|
||||
import org.mozilla.gecko.tests.components.GeckoViewComponent;
|
||||
import org.mozilla.gecko.tests.components.TabStripComponent;
|
||||
import org.mozilla.gecko.tests.components.ToolbarComponent;
|
||||
import org.mozilla.gecko.tests.helpers.HelperInitializer;
|
||||
|
||||
@ -40,6 +41,7 @@ abstract class UITest extends BaseRobocopTest
|
||||
protected AboutHomeComponent mAboutHome;
|
||||
protected AppMenuComponent mAppMenu;
|
||||
protected GeckoViewComponent mGeckoView;
|
||||
protected TabStripComponent mTabStrip;
|
||||
protected ToolbarComponent mToolbar;
|
||||
|
||||
@Override
|
||||
@ -92,6 +94,7 @@ abstract class UITest extends BaseRobocopTest
|
||||
mAboutHome = new AboutHomeComponent(this);
|
||||
mAppMenu = new AppMenuComponent(this);
|
||||
mGeckoView = new GeckoViewComponent(this);
|
||||
mTabStrip = new TabStripComponent(this);
|
||||
mToolbar = new ToolbarComponent(this);
|
||||
}
|
||||
|
||||
|
49
mobile/android/base/tests/components/TabStripComponent.java
Normal file
49
mobile/android/base/tests/components/TabStripComponent.java
Normal file
@ -0,0 +1,49 @@
|
||||
package org.mozilla.gecko.tests.components;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import org.mozilla.gecko.tests.UITestContext;
|
||||
import org.mozilla.gecko.tests.helpers.DeviceHelper;
|
||||
import org.mozilla.gecko.widget.TwoWayView;
|
||||
|
||||
import static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
|
||||
|
||||
/**
|
||||
* A class representing any interactions that take place on the tablet tab strip.
|
||||
*/
|
||||
public class TabStripComponent extends BaseComponent {
|
||||
// Using a text id because the layout and therefore the id might be stripped from the (non-tablet) build
|
||||
private static final String TAB_STRIP_ID = "tab_strip";
|
||||
|
||||
public TabStripComponent(final UITestContext testContext) {
|
||||
super(testContext);
|
||||
}
|
||||
|
||||
public void switchToTab(int index) {
|
||||
// The tab strip is only available on tablets
|
||||
DeviceHelper.assertIsTablet();
|
||||
|
||||
View tabView = getTabView(index);
|
||||
|
||||
mSolo.clickOnView(tabView);
|
||||
}
|
||||
|
||||
private View getTabView(int index) {
|
||||
TwoWayView tabStrip = getTabStripView();
|
||||
|
||||
fAssertTrue(String.format("Tab strip contains at least %d tabs", index + 1), tabStrip.getChildCount() > index);
|
||||
|
||||
View tabView = tabStrip.getChildAt(index);
|
||||
fAssertNotNull(String.format("Tab at index %d is not null", index), tabView);
|
||||
|
||||
return tabView;
|
||||
}
|
||||
|
||||
private TwoWayView getTabStripView() {
|
||||
TwoWayView tabStrip = (TwoWayView) mSolo.getView("tab_strip");
|
||||
|
||||
fAssertNotNull("Tab strip is not null", tabStrip);
|
||||
|
||||
return tabStrip;
|
||||
}
|
||||
}
|
@ -84,6 +84,11 @@ public class ToolbarComponent extends BaseComponent {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ToolbarComponent assertBackButtonIsNotEnabled() {
|
||||
fAssertFalse("The back button is not enabled", isBackButtonEnabled());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root View for the browser toolbar.
|
||||
*/
|
||||
@ -306,4 +311,8 @@ public class ToolbarComponent extends BaseComponent {
|
||||
private boolean isUrlEditTextSelected() {
|
||||
return getUrlEditText().isSelected();
|
||||
}
|
||||
|
||||
private boolean isBackButtonEnabled() {
|
||||
return getBackButton().isEnabled();
|
||||
}
|
||||
}
|
||||
|
50
mobile/android/base/tests/helpers/GeckoClickHelper.java
Normal file
50
mobile/android/base/tests/helpers/GeckoClickHelper.java
Normal file
@ -0,0 +1,50 @@
|
||||
package org.mozilla.gecko.tests.helpers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.jayway.android.robotium.solo.Solo;
|
||||
|
||||
import org.mozilla.gecko.Driver;
|
||||
import org.mozilla.gecko.tests.StringHelper;
|
||||
import org.mozilla.gecko.tests.UITestContext;
|
||||
|
||||
/**
|
||||
* Provides helper functions for clicking elements rendered by the Gecko engine.
|
||||
*/
|
||||
public class GeckoClickHelper {
|
||||
private static Solo sSolo;
|
||||
private static Activity sActivity;
|
||||
private static Driver sDriver;
|
||||
|
||||
protected static void init(final UITestContext context) {
|
||||
sSolo = context.getSolo();
|
||||
sActivity = context.getActivity();
|
||||
sDriver = context.getDriver();
|
||||
}
|
||||
|
||||
private GeckoClickHelper() { /* To disallow instantiation. */ }
|
||||
|
||||
/**
|
||||
* Long press the link and select "Open Link in New Tab" from the context menu.
|
||||
*
|
||||
* The link should be positioned at the top of the page, at least 60px high and
|
||||
* aligned to the middle.
|
||||
*/
|
||||
public static void openCentralizedLinkInNewTab() {
|
||||
openLinkContextMenu();
|
||||
|
||||
// Click on "Open Link in New Tab"
|
||||
sSolo.clickOnText(StringHelper.CONTEXT_MENU_ITEMS_IN_NORMAL_TAB[0]);
|
||||
}
|
||||
|
||||
private static void openLinkContextMenu() {
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
sActivity.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||
|
||||
sSolo.clickLongOnScreen(
|
||||
sDriver.getGeckoLeft() + sDriver.getGeckoWidth() / 2,
|
||||
sDriver.getGeckoTop() + 30 * dm.density
|
||||
);
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ public final class HelperInitializer {
|
||||
AssertionHelper.init(context);
|
||||
|
||||
DeviceHelper.init(context);
|
||||
GeckoClickHelper.init(context);
|
||||
GeckoHelper.init(context);
|
||||
JavascriptBridge.init(context);
|
||||
NavigationHelper.init(context);
|
||||
|
@ -157,6 +157,7 @@ skip-if = android_version == "10"
|
||||
[testSessionHistory]
|
||||
# disabled on Android 4.3, bug 1144879
|
||||
skip-if = android_version == "18"
|
||||
[testStateWhileLoading]
|
||||
|
||||
# testSelectionHandler disabled on Android 2.3 by trailing skip-if, due to bug 980074
|
||||
# also disabled on Android 4.3, bug 1144882
|
||||
|
12
mobile/android/base/tests/robocop_link_to_slow_loading.html
Normal file
12
mobile/android/base/tests/robocop_link_to_slow_loading.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Link</title>
|
||||
<meta name="viewport" content="initial-scale=1.0"/>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
<div style="text-align: center; margin: 0; padding: 0">
|
||||
<a style="font-size: 60px" href="robocop_slow_loading.html">Slow Loading Page</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
22
mobile/android/base/tests/robocop_slow_loading.html
Normal file
22
mobile/android/base/tests/robocop_slow_loading.html
Normal file
@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Slow Loading</title>
|
||||
<meta name="viewport" content="initial-scale=1.0"/>
|
||||
<meta charset="utf-8">
|
||||
<script type="text/javascript">
|
||||
|
||||
// Busy wait for 10 seconds (There's no sleep function in JavaScript)
|
||||
var start = new Date();
|
||||
var now = null;
|
||||
do {
|
||||
now = new Date();
|
||||
} while (now - start < 10000);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
<div style="text-align: center; margin: 0; padding: 0">
|
||||
<h1>This page is loading very slow.</h1>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
40
mobile/android/base/tests/testStateWhileLoading.java
Normal file
40
mobile/android/base/tests/testStateWhileLoading.java
Normal file
@ -0,0 +1,40 @@
|
||||
package org.mozilla.gecko.tests;
|
||||
|
||||
import org.mozilla.gecko.tests.helpers.DeviceHelper;
|
||||
import org.mozilla.gecko.tests.helpers.GeckoClickHelper;
|
||||
import org.mozilla.gecko.tests.helpers.GeckoHelper;
|
||||
import org.mozilla.gecko.tests.helpers.NavigationHelper;
|
||||
import org.mozilla.gecko.tests.helpers.WaitHelper;
|
||||
|
||||
/**
|
||||
* This test ensures the back/forward state is correct when switching to loading pages
|
||||
* to prevent regressions like Bug 1124190.
|
||||
*/
|
||||
public class testStateWhileLoading extends UITest {
|
||||
public void testStateWhileLoading() {
|
||||
if (!DeviceHelper.isTablet()) {
|
||||
// This test case only covers tablets currently.
|
||||
return;
|
||||
}
|
||||
|
||||
GeckoHelper.blockForReady();
|
||||
|
||||
NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_LINK_TO_SLOW_LOADING);
|
||||
|
||||
GeckoClickHelper.openCentralizedLinkInNewTab();
|
||||
|
||||
WaitHelper.waitForPageLoad(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTabStrip.switchToTab(1);
|
||||
|
||||
// Assert that the state of the back button is correct
|
||||
// after switching to the new (still loading) tab.
|
||||
mToolbar.assertBackButtonIsNotEnabled();
|
||||
}
|
||||
});
|
||||
|
||||
// Assert that the state of the back button is still correct after the page has loaded.
|
||||
mToolbar.assertBackButtonIsNotEnabled();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user