John Stalcup has uploaded a new change for review.
https://gwt-review.googlesource.com/3590
Change subject: adds regression testing against future changes that might
accidentally push all fragment code into the leftover fragment
......................................................................
adds regression testing against future changes that might accidentally push
all fragment code into the leftover fragment
Change-Id: I34d21081ea4e90b95f5b2d77a7a647e388e25335
---
M user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
M user/src/com/google/gwt/core/client/impl/XhrLoadingStrategy.java
M user/test/com/google/gwt/dev/jjs/RunAsyncFailure.gwt.xml
A user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
M user/test/com/google/gwt/dev/jjs/test/RunAsyncFailureTest.java
5 files changed, 104 insertions(+), 26 deletions(-)
diff --git
a/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
b/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
index 130200c..8bca11b 100644
--- a/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
+++ b/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
@@ -174,9 +174,11 @@
return __gwtStartLoadingFragment(fragment, $entry(loadFailed));
}-*/;
- private DownloadStrategy downloadStrategy;
+ protected DownloadStrategy downloadStrategy;
private final FragmentReloadTracker manualRetryNumbers =
FragmentReloadTracker.create();
+ public LoadingStrategyBase() {}
+
/**
* Subclasses should create a DownloadStrategy and pass it into this
constructor.
*/
diff --git
a/user/src/com/google/gwt/core/client/impl/XhrLoadingStrategy.java
b/user/src/com/google/gwt/core/client/impl/XhrLoadingStrategy.java
index 1ced92f..1a0ddaf 100644
--- a/user/src/com/google/gwt/core/client/impl/XhrLoadingStrategy.java
+++ b/user/src/com/google/gwt/core/client/impl/XhrLoadingStrategy.java
@@ -29,7 +29,7 @@
/**
* Uses XHR's to download the code.
*/
- protected static class XhrDownloadStrategy implements DownloadStrategy {
+ protected class XhrDownloadStrategy implements DownloadStrategy {
@Override
public void tryDownload(final RequestData request) {
final XMLHttpRequest xhr = XMLHttpRequest.create();
@@ -37,13 +37,14 @@
xhr.open(HTTP_GET, request.getUrl());
xhr.setOnReadyStateChange(new ReadyStateChangeHandler() {
+ @Override
public void onReadyStateChange(XMLHttpRequest ignored) {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
xhr.clearOnReadyStateChange();
if ((xhr.getStatus() == HTTP_STATUS_OK || xhr.getStatus() ==
HTTP_STATUS_NON_HTTP)
&& xhr.getResponseText() != null
&& xhr.getResponseText().length() != 0) {
- request.tryInstall(xhr.getResponseText());
+ tryInstall(request, xhr.getResponseText());
} else {
// If the download fails
request.onLoadError(
@@ -70,7 +71,10 @@
static final int HTTP_STATUS_OK = 200;
public XhrLoadingStrategy() {
- super(new XhrDownloadStrategy());
+ downloadStrategy = new XhrDownloadStrategy();
}
+ protected void tryInstall(RequestData request, String responseText) {
+ request.tryInstall(responseText);
+ }
}
\ No newline at end of file
diff --git a/user/test/com/google/gwt/dev/jjs/RunAsyncFailure.gwt.xml
b/user/test/com/google/gwt/dev/jjs/RunAsyncFailure.gwt.xml
index 0fa0e34..e14cd9d 100644
--- a/user/test/com/google/gwt/dev/jjs/RunAsyncFailure.gwt.xml
+++ b/user/test/com/google/gwt/dev/jjs/RunAsyncFailure.gwt.xml
@@ -15,8 +15,9 @@
<module>
<inherits name="com.google.gwt.core.Core" />
<source path="test" />
- <servlet path="/runAsyncFailure/*"
- class="com.google.gwt.user.server.runasync.RunAsyncFailureServlet" />
- <set-configuration-property name="iframe.linker.deferredjs.subdir"
- value="runAsyncFailure/deferredjs" />
+ <servlet path="/runAsyncFailure/*"
class="com.google.gwt.user.server.runasync.RunAsyncFailureServlet" />
+ <set-configuration-property name="iframe.linker.deferredjs.subdir"
value="runAsyncFailure/deferredjs" />
+ <replace-with
class="com.google.gwt.dev.jjs.test.LoggingXhrLoadingStrategy">
+ <when-type-is
class="com.google.gwt.core.client.impl.AsyncFragmentLoader.LoadingStrategy"/>
+ </replace-with>
</module>
diff --git
a/user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
b/user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
new file mode 100644
index 0000000..816c286
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package com.google.gwt.dev.jjs.test;
+
+import com.google.gwt.core.client.impl.XhrLoadingStrategy;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An Xhr based fragment loading strategy that logs fragment index +
fragment text pairs for later
+ * introspection.
+ */
+public class LoggingXhrLoadingStrategy extends XhrLoadingStrategy {
+ public static Map<Integer, String> sourceByFragmentIndex = new
HashMap<Integer, String>();
+
+ @Override
+ protected void tryInstall(RequestData request, String responseText) {
+ sourceByFragmentIndex.put(request.getFragment(), responseText);
+ super.tryInstall(request, responseText);
+ }
+}
\ No newline at end of file
diff --git a/user/test/com/google/gwt/dev/jjs/test/RunAsyncFailureTest.java
b/user/test/com/google/gwt/dev/jjs/test/RunAsyncFailureTest.java
index 8b771cf..959745b 100644
--- a/user/test/com/google/gwt/dev/jjs/test/RunAsyncFailureTest.java
+++ b/user/test/com/google/gwt/dev/jjs/test/RunAsyncFailureTest.java
@@ -25,6 +25,8 @@
import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.Timer;
+import java.util.Map.Entry;
+
/**
* Tests runAsync server/network failure handling.
*
@@ -44,22 +46,23 @@
this.expectedSuccessfulAttempt = expectedSuccessfulAttempt;
token = sToken++;
}
-
+
public int getToken() {
return token;
}
-
- public boolean onSuccessHelper(String test) {
+
+ public boolean onSuccessHelper(String testMessage) {
int token = getToken();
log("onSuccess: attempt = " + attempt + ", token = " + token);
+ assertNotInLeftOverFragment(testMessage);
if (attempt == expectedSuccessfulAttempt) {
return true;
} else {
// We don't really care about the test string, but we need to use
it
// somewhere so it doesn't get dead stripped out. Each test passes
// in a unique string so it ends up in it's fragment.
- fail(test + " - Succeeded on attempt: " + attempt +
- " but should have succeeded on attempt: " +
expectedSuccessfulAttempt);
+ fail(testMessage + " - Succeeded on attempt: " + attempt
+ + " but should have succeeded on attempt: " +
expectedSuccessfulAttempt);
}
return false;
}
@@ -90,7 +93,24 @@
public String getModuleName() {
return "com.google.gwt.dev.jjs.RunAsyncFailure";
}
-
+
+ private static void assertNotInLeftOverFragment(String text) {
+ assertFalse(getLeftOverFragmentText().contains(text));
+ }
+
+ protected static String getLeftOverFragmentText() {
+ String leftOverFragmentText = "";
+ int highestFragmentIndex = -1;
+ for (Entry<Integer, String> entry :
+ LoggingXhrLoadingStrategy.sourceByFragmentIndex.entrySet()) {
+ if (entry.getKey() > highestFragmentIndex) {
+ highestFragmentIndex = entry.getKey();
+ leftOverFragmentText = entry.getValue();
+ }
+ }
+ return leftOverFragmentText;
+ }
+
/**
* Some subclasses of this test use linkers that do not support retries,
in
* which case the expected number of manual retries before success will
always
@@ -105,24 +125,29 @@
// always succeed on the first try.
private void runAsync1(final int attempt, final int
expectedSuccessfulAttempt) {
- GWT.runAsync(new MyRunAsyncCallback(attempt,
expectedSuccessfulAttempt) {
- public void onFailure(Throwable caught) {
- onFailureHelper(caught, new Timer() {
+ // Uses the alternative form of GWT.runAsync to broaden test coverage.
+ GWT.runAsync(
+ RunAsyncFailureTest.class, new MyRunAsyncCallback(attempt,
expectedSuccessfulAttempt) {
@Override
- public void run() {
- runAsync1(attempt + 1, expectedSuccessfulAttempt);
+ public void onFailure(Throwable caught) {
+ onFailureHelper(caught, new Timer() {
+ @Override
+ public void run() {
+ runAsync1(attempt + 1, expectedSuccessfulAttempt);
+ }
+ });
+ }
+
+ @Override
+ public void onSuccess() {
+ if (onSuccessHelper("DOWNLOAD_FAILURE_TEST_1")) {
finishTest(); }
}
});
- }
-
- public void onSuccess() {
- if (onSuccessHelper("DOWNLOAD_FAILURE_TEST_1")) { finishTest(); }
- }
- });
}
private void runAsync2(final int attempt, final int
expectedSuccessfulAttempt) {
GWT.runAsync(new MyRunAsyncCallback(attempt,
expectedSuccessfulAttempt) {
+ @Override
public void onFailure(Throwable caught) {
onFailureHelper(caught, new Timer() {
@Override
@@ -132,6 +157,7 @@
});
}
+ @Override
public void onSuccess() {
if (onSuccessHelper("DOWNLOAD_FAILURE_TEST_2")) { finishTest(); }
}
@@ -140,6 +166,7 @@
private void runAsync3(final int attempt, final int
expectedSuccessfulAttempt) {
GWT.runAsync(new MyRunAsyncCallback(attempt,
expectedSuccessfulAttempt) {
+ @Override
public void onFailure(Throwable caught) {
onFailureHelper(caught, new Timer() {
@Override
@@ -149,6 +176,7 @@
});
}
+ @Override
public void onSuccess() {
if (onSuccessHelper("DOWNLOAD_FAILURE_TEST_3")) { finishTest(); }
}
@@ -157,11 +185,15 @@
private void runAsync4() {
GWT.runAsync(new RunAsyncCallback() {
+ @Override
public void onFailure(Throwable caught) {
// This call should fail since no retries are done if the code
downloads
// successfully, but fails to install.
+ assertNotInLeftOverFragment("INSTALL_FAILURE_TEST");
finishTest();
}
+
+ @Override
public void onSuccess() {
// Use the string "INSTALL_FAILURE_TEST" so we can identify this
// fragment on the server. In the fail message is good enough.
@@ -172,9 +204,13 @@
private void runAsync5() {
GWT.runAsync(new RunAsyncCallback() {
+ @Override
public void onFailure(Throwable caught) {
+ assertNotInLeftOverFragment("INSTALL_FAILURE_TEST_2");
staticWrittenByAsync++;
}
+
+ @Override
public void onSuccess() {
// Use the string "INSTALL_FAILURE_TEST" so we can identify this
// fragment on the server. In the fail message is good enough.
@@ -182,7 +218,7 @@
}
});
}
-
+
/**
* Test the basic functionality of retrying runAsync until is succeeds.
* A Timer is used to avoid nesting GWT.runAsync calls.
--
To view, visit https://gwt-review.googlesource.com/3590
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I34d21081ea4e90b95f5b2d77a7a647e388e25335
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: John Stalcup <[email protected]>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.