Bug 1253381 - Move existing JavascriptBridge tests to JavascriptBridgeTest. r=sebastian draft
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 03 Mar 2016 13:34:39 -0800
changeset 336603 7edde4fa1fbb6a73e4e6eac358593b731afbc167
parent 336602 66f0881e7b7b94f719a8337112711fffadf894bb
child 336660 5a6aaa4f4d2ef770d091db4f88958f5339777bfc
push id12141
push usermichael.l.comella@gmail.com
push dateThu, 03 Mar 2016 21:39:01 +0000
reviewerssebastian
bugs1253381
milestone47.0a1
Bug 1253381 - Move existing JavascriptBridge tests to JavascriptBridgeTest. r=sebastian MozReview-Commit-ID: 7UQfbpzpGAg
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testEventDispatcher.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoRequest.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testJavascriptBridge.java
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testEventDispatcher.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testEventDispatcher.java
@@ -1,18 +1,16 @@
 /* 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 static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
 
-import org.mozilla.gecko.tests.helpers.*;
-
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.NativeEventListener;
 import org.mozilla.gecko.util.NativeJSObject;
 import org.mozilla.gecko.util.ThreadUtils;
 
@@ -21,43 +19,41 @@ import android.os.Bundle;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
 /**
  * Tests the proper operation of EventDispatcher,
  * including associated NativeJSObject objects.
  */
-public class testEventDispatcher extends UITest
+public class testEventDispatcher extends JavascriptBridgeTest
         implements BundleEventListener, GeckoEventListener, NativeEventListener {
 
     private static final String TEST_JS = "testEventDispatcher.js";
     private static final String GECKO_EVENT = "Robocop:TestGeckoEvent";
     private static final String GECKO_RESPONSE_EVENT = "Robocop:TestGeckoResponse";
     private static final String NATIVE_EVENT = "Robocop:TestNativeEvent";
     private static final String NATIVE_RESPONSE_EVENT = "Robocop:TestNativeResponse";
     private static final String NATIVE_EXCEPTION_EVENT = "Robocop:TestNativeException";
     private static final String UI_EVENT = "Robocop:TestUIEvent";
     private static final String UI_RESPONSE_EVENT = "Robocop:TestUIResponse";
     private static final String BACKGROUND_EVENT = "Robocop:TestBackgroundEvent";
     private static final String BACKGROUND_RESPONSE_EVENT = "Robocop:TestBackgrondResponse";
 
     private static final long WAIT_FOR_BUNDLE_EVENT_TIMEOUT_MILLIS = 20000; // 20 seconds
 
-    private JavascriptBridge js;
     private NativeJSObject savedMessage;
 
     private boolean handledGeckoEvent;
     private boolean handledNativeEvent;
     private boolean handledAsyncEvent;
 
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        js = new JavascriptBridge(this);
 
         EventDispatcher.getInstance().registerGeckoThreadListener(
                 (GeckoEventListener) this, GECKO_EVENT, GECKO_RESPONSE_EVENT);
         EventDispatcher.getInstance().registerGeckoThreadListener(
                 (NativeEventListener) this,
                 NATIVE_EVENT, NATIVE_RESPONSE_EVENT, NATIVE_EXCEPTION_EVENT);
         EventDispatcher.getInstance().registerUiThreadListener(
                 this, UI_EVENT, UI_RESPONSE_EVENT);
@@ -72,17 +68,16 @@ public class testEventDispatcher extends
         EventDispatcher.getInstance().unregisterGeckoThreadListener(
                 (NativeEventListener) this,
                 NATIVE_EVENT, NATIVE_RESPONSE_EVENT, NATIVE_EXCEPTION_EVENT);
         EventDispatcher.getInstance().unregisterUiThreadListener(
                 this, UI_EVENT, UI_RESPONSE_EVENT);
         EventDispatcher.getInstance().unregisterBackgroundThreadListener(
                 this, BACKGROUND_EVENT, BACKGROUND_RESPONSE_EVENT);
 
-        js.disconnect();
         super.tearDown();
     }
 
     private synchronized void waitForAsyncEvent() {
         final long startTime = System.nanoTime();
         while (!handledAsyncEvent) {
             if (System.nanoTime() - startTime
                     >= WAIT_FOR_BUNDLE_EVENT_TIMEOUT_MILLIS * 1e6 /* ns per ms */) {
@@ -98,18 +93,17 @@ public class testEventDispatcher extends
     }
 
     private synchronized void notifyAsyncEvent() {
         handledAsyncEvent = true;
         notifyAll();
     }
 
     public void testEventDispatcher() {
-        GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(mStringHelper.getHarnessUrlForJavascript(TEST_JS));
+        blockForReadyAndLoadJS(TEST_JS);
 
         js.syncCall("send_test_message", GECKO_EVENT);
         fAssertTrue("Should have handled Gecko event synchronously", handledGeckoEvent);
 
         js.syncCall("send_message_for_response", GECKO_RESPONSE_EVENT, "success");
         js.syncCall("send_message_for_response", GECKO_RESPONSE_EVENT, "error");
 
         js.syncCall("send_test_message", NATIVE_EVENT);
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoRequest.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoRequest.java
@@ -5,49 +5,31 @@
 package org.mozilla.gecko.tests;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import com.jayway.android.robotium.solo.Condition;
 
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.tests.helpers.AssertionHelper;
-import org.mozilla.gecko.tests.helpers.GeckoHelper;
-import org.mozilla.gecko.tests.helpers.JavascriptBridge;
-import org.mozilla.gecko.tests.helpers.NavigationHelper;
 import org.mozilla.gecko.tests.helpers.WaitHelper;
 import org.mozilla.gecko.util.GeckoRequest;
 import org.mozilla.gecko.util.NativeJSObject;
 
 /**
  * Tests sending and receiving Gecko requests using the GeckoRequest API.
  */
-public class testGeckoRequest extends UITest {
+public class testGeckoRequest extends JavascriptBridgeTest {
     private static final String TEST_JS = "testGeckoRequest.js";
     private static final String REQUEST_EVENT = "Robocop:GeckoRequest";
     private static final String REQUEST_EXCEPTION_EVENT = "Robocop:GeckoRequestException";
     private static final int MAX_WAIT_MS = 5000;
 
-    private JavascriptBridge js;
-
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        js = new JavascriptBridge(this);
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        js.disconnect();
-        super.tearDown();
-    }
-
     public void testGeckoRequest() {
-        GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(mStringHelper.getHarnessUrlForJavascript(TEST_JS));
+        blockForReadyAndLoadJS(TEST_JS);
 
         // Register a listener for this request.
         js.syncCall("add_request_listener", REQUEST_EVENT);
 
         // Make sure we receive the expected response.
         checkFooRequest();
 
         // Try registering a second listener for this request, which should fail.
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testInputConnection.java
@@ -10,46 +10,31 @@ import static org.mozilla.gecko.tests.he
 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertText;
 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelection;
 import static org.mozilla.gecko.tests.helpers.TextInputHelper.assertTextAndSelectionAt;
 import static org.mozilla.gecko.tests.helpers.TextInputHelper.getText;
 import static org.mozilla.gecko.tests.helpers.WaitHelper.waitFor;
 
 import org.mozilla.gecko.tests.components.GeckoViewComponent.InputConnectionTest;
 import org.mozilla.gecko.tests.helpers.GeckoHelper;
-import org.mozilla.gecko.tests.helpers.JavascriptBridge;
 import org.mozilla.gecko.tests.helpers.NavigationHelper;
 
 import com.jayway.android.robotium.solo.Condition;
 
 import android.view.KeyEvent;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputConnection;
 
 /**
  * Tests the proper operation of GeckoInputConnection
  */
-public class testInputConnection extends UITest {
+public class testInputConnection extends JavascriptBridgeTest {
 
     private static final String INITIAL_TEXT = "foo";
 
-    private JavascriptBridge js;
-
-    @Override // UITest
-    public void setUp() throws Exception {
-        super.setUp();
-        js = new JavascriptBridge(this);
-    }
-
-    @Override // UITest
-    public void tearDown() throws Exception {
-        js.disconnect();
-        super.tearDown();
-    }
-
     public void testInputConnection() throws InterruptedException {
         GeckoHelper.blockForReady();
 
         final String url = mStringHelper.ROBOCOP_INPUT_URL;
         NavigationHelper.enterAndLoadUrl(url);
         mToolbar.assertTitle(url);
 
         // First run tests inside the normal input field.
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testJavascriptBridge.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testJavascriptBridge.java
@@ -1,47 +1,31 @@
 /* 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 static org.mozilla.gecko.tests.helpers.AssertionHelper.*;
 
-import org.mozilla.gecko.tests.helpers.*;
-
 import org.json.JSONException;
 import org.json.JSONObject;
 
 /**
  * Tests the proper operation of JavascriptBridge and JavaBridge,
  * which are used by tests for communication between Java and JS.
  */
-public class testJavascriptBridge extends UITest {
+public class testJavascriptBridge extends JavascriptBridgeTest {
 
     private static final String TEST_JS = "testJavascriptBridge.js";
 
-    private JavascriptBridge js;
     private boolean syncCallReceived;
 
-    @Override
-    public void setUp() throws Exception {
-        super.setUp();
-        js = new JavascriptBridge(this);
-    }
-
-    @Override
-    public void tearDown() throws Exception {
-        js.disconnect();
-        super.tearDown();
-    }
-
     public void testJavascriptBridge() {
-        GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(mStringHelper.getHarnessUrlForJavascript(TEST_JS));
+        blockForReadyAndLoadJS(TEST_JS);
         js.syncCall("check_js_int_arg", 1);
     }
 
     public void checkJavaIntArg(final int int2) {
         // Async call from JS
         fAssertEquals("Integer argument matches", 2, int2);
         js.syncCall("check_js_double_arg", 3.0D);
     }