Bug 1068336 - Part 1: Add a slug to avoid caching robocop_testharness.js. r=mcomella
authorNick Alexander <nalexander@mozilla.com>
Fri, 19 Sep 2014 11:17:53 -0700
changeset 206255 2192dc45e484b1ba551396a640393d66506b1cfa
parent 206254 92d6f9e6cbc397bc5130b094a89605d0a5584866
child 206256 d75c3d4ba074a041465f4af34cf13d499e0d0c99
push id27519
push userkwierso@gmail.com
push dateFri, 19 Sep 2014 23:56:39 +0000
treeherdermozilla-central@a85324dfc960 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1068336
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1068336 - Part 1: Add a slug to avoid caching robocop_testharness.js. r=mcomella
mobile/android/base/tests/JavascriptTest.java
mobile/android/base/tests/StringHelper.java
mobile/android/base/tests/testEventDispatcher.java
mobile/android/base/tests/testGeckoRequest.java
mobile/android/base/tests/testJavascriptBridge.java
--- a/mobile/android/base/tests/JavascriptTest.java
+++ b/mobile/android/base/tests/JavascriptTest.java
@@ -1,20 +1,16 @@
 package org.mozilla.gecko.tests;
 
+import org.json.JSONObject;
+import org.mozilla.gecko.Actions;
 import org.mozilla.gecko.tests.helpers.JavascriptBridge;
 import org.mozilla.gecko.tests.helpers.JavascriptMessageParser;
 
 import android.util.Log;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.json.JSONObject;
-import org.mozilla.gecko.Actions;
-import org.mozilla.gecko.Assert;
 
 public class JavascriptTest extends BaseTest {
     private static final String LOGTAG = "JavascriptTest";
     private static final String EVENT_TYPE = JavascriptBridge.EVENT_TYPE;
 
     private final String javascriptUrl;
 
     public JavascriptTest(String javascriptUrl) {
@@ -27,18 +23,17 @@ public class JavascriptTest extends Base
 
         // We want to be waiting for Robocop messages before the page is loaded
         // because the test harness runs each test in the suite (and possibly
         // completes testing) before the page load event is fired.
         final Actions.EventExpecter expecter =
             mActions.expectGeckoEvent(EVENT_TYPE);
         mAsserter.dumpLog("Registered listener for " + EVENT_TYPE);
 
-        final String url = getAbsoluteUrl(StringHelper.ROBOCOP_JS_HARNESS_URL +
-                                          "?path=" + javascriptUrl);
+        final String url = getAbsoluteUrl(StringHelper.getHarnessUrlForJavascript(javascriptUrl));
         mAsserter.dumpLog("Loading JavaScript test from " + url);
         loadUrl(url);
 
         final JavascriptMessageParser testMessageParser =
                 new JavascriptMessageParser(mAsserter, false);
         try {
             while (!testMessageParser.isTestFinished()) {
                 if (Log.isLoggable(LOGTAG, Log.VERBOSE)) {
--- a/mobile/android/base/tests/StringHelper.java
+++ b/mobile/android/base/tests/StringHelper.java
@@ -99,17 +99,35 @@ public class StringHelper {
     public static final String ROBOCOP_GEOLOCATION_URL = "/robocop/robocop_geolocation.html";
     public static final String ROBOCOP_LOGIN_URL = "/robocop/robocop_login.html";
     public static final String ROBOCOP_OFFLINE_STORAGE_URL = "/robocop/robocop_offline_storage.html";
     public static final String ROBOCOP_PICTURE_LINK_URL = "/robocop/robocop_picture_link.html";
     public static final String ROBOCOP_SEARCH_URL = "/robocop/robocop_search.html";
     public static final String ROBOCOP_TEXT_PAGE_URL = "/robocop/robocop_text_page.html";
     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_JS_HARNESS_URL = "/robocop/robocop_javascript.html";
+
+    private static final String ROBOCOP_JS_HARNESS_URL = "/robocop/robocop_javascript.html";
+
+    /**
+     * Build a URL for loading a Javascript file in the Robocop Javascript
+     * harness.
+     * <p>
+     * We append a random slug to avoid caching: see
+     * <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache">https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache</a>.
+     *
+     * @param javascriptUrl to load.
+     * @return URL with harness wrapper.
+     */
+    public static String getHarnessUrlForJavascript(String javascriptUrl) {
+        // We include a slug to make sure we never cache the harness.
+        return ROBOCOP_JS_HARNESS_URL +
+                "?slug=" + System.currentTimeMillis() +
+                "&path=" + javascriptUrl;
+    }
 
     // Robocop page titles
     public static final String ROBOCOP_BIG_LINK_TITLE = "Big Link";
     public static final String ROBOCOP_BIG_MAILTO_TITLE = "Big Mailto";
     public static final String ROBOCOP_BLANK_PAGE_01_TITLE = "Browser Blank Page 01";
     public static final String ROBOCOP_BLANK_PAGE_02_TITLE = "Browser Blank Page 02";
     public static final String ROBOCOP_BLANK_PAGE_03_TITLE = "Browser Blank Page 03";
     public static final String ROBOCOP_BLANK_PAGE_04_TITLE = "Browser Blank Page 04";
--- a/mobile/android/base/tests/testEventDispatcher.java
+++ b/mobile/android/base/tests/testEventDispatcher.java
@@ -54,18 +54,17 @@ public class testEventDispatcher extends
                 NATIVE_EVENT, NATIVE_RESPONSE_EVENT, NATIVE_EXCEPTION_EVENT);
 
         js.disconnect();
         super.tearDown();
     }
 
     public void testEventDispatcher() {
         GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_JS_HARNESS_URL +
-                                         "?path=" + TEST_JS);
+        NavigationHelper.enterAndLoadUrl(StringHelper.getHarnessUrlForJavascript(TEST_JS));
 
         js.syncCall("send_test_message", GECKO_EVENT);
         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);
         js.syncCall("send_message_for_response", NATIVE_RESPONSE_EVENT, "success");
         js.syncCall("send_message_for_response", NATIVE_RESPONSE_EVENT, "error");
         js.syncCall("send_test_message", NATIVE_EXCEPTION_EVENT);
--- a/mobile/android/base/tests/testGeckoRequest.java
+++ b/mobile/android/base/tests/testGeckoRequest.java
@@ -33,17 +33,17 @@ public class testGeckoRequest extends UI
     @Override
     public void tearDown() throws Exception {
         js.disconnect();
         super.tearDown();
     }
 
     public void testGeckoRequest() {
         GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_JS_HARNESS_URL + "?path=" + TEST_JS);
+        NavigationHelper.enterAndLoadUrl(StringHelper.getHarnessUrlForJavascript(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/base/tests/testJavascriptBridge.java
+++ b/mobile/android/base/tests/testJavascriptBridge.java
@@ -27,18 +27,17 @@ public class testJavascriptBridge extend
     @Override
     public void tearDown() throws Exception {
         js.disconnect();
         super.tearDown();
     }
 
     public void testJavascriptBridge() {
         GeckoHelper.blockForReady();
-        NavigationHelper.enterAndLoadUrl(StringHelper.ROBOCOP_JS_HARNESS_URL +
-                                         "?path=" + TEST_JS);
+        NavigationHelper.enterAndLoadUrl(StringHelper.getHarnessUrlForJavascript(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);
     }