Bug 1253381 - Add JavascriptBridgeTest. r=sebastian
MozReview-Commit-ID: HVBXqDmFVc0
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/JavascriptBridgeTest.java
@@ -0,0 +1,47 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.tests;
+
+import org.mozilla.gecko.tests.helpers.GeckoHelper;
+import org.mozilla.gecko.tests.helpers.JavascriptBridge;
+import org.mozilla.gecko.tests.helpers.NavigationHelper;
+
+/**
+ * Extended to write tests using JavascriptBridge, which allows Java and JS to communicate back-and-forth.
+ * If you don't need back-and-forth communication, consider {@link JavascriptTest}.
+ *
+ * To write a test:
+ * * Extend this class
+ * * Add your javascript file to the base robocop directory (see where `testJavascriptBridge.js` is located)
+ * * In the main test method, call {@link #blockForReadyAndLoadJS(String)} with your javascript file name
+ * (don't include the path) or if you're loading a non-harness url, be sure to call {@link GeckoHelper#blockForReady()}
+ * * You can access js calls via the {@link #js} field
+ * - Read {@link JavascriptBridge} javadoc for more information about using the API.
+ */
+public class JavascriptBridgeTest extends UITest {
+
+ // A protected field for easy access by sub-classes and a private field so
+ // we can close the JS bridge if the sub-classes re-assign the protected field.
+ // Not very Java-like but simpler than a method.
+ private JavascriptBridge _js;
+ protected JavascriptBridge js;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ _js = new JavascriptBridge(this);
+ js = _js;
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ _js.disconnect();
+ super.tearDown();
+ }
+
+ protected void blockForReadyAndLoadJS(final String jsFilename) {
+ NavigationHelper.enterAndLoadUrl(mStringHelper.getHarnessUrlForJavascript(jsFilename));
+ }
+}