John Stalcup has submitted this change and it was merged.
Change subject: Adds a regression test for fragment splitting
......................................................................
Adds a regression test for fragment splitting
Test to verifies that future changes don't accidentally
push *all* code into the leftover fragment.
Change-Id: I34d21081ea4e90b95f5b2d77a7a647e388e25335
Review-Link: https://gwt-review.googlesource.com/#/c/3590/
---
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/CompilerSuite.java
A user/test/com/google/gwt/dev/jjs/RunAsyncContent.gwt.xml
A user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
A user/test/com/google/gwt/dev/jjs/test/RunAsyncContentTest.java
6 files changed, 200 insertions(+), 3 deletions(-)
Approvals:
Matthew Dempsky: Looks good to me, but someone else must approve
Leeroy Jenkins: Verified
Goktug Gokdogan: Looks good to me, approved
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..5c0d38b 100644
--- a/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
+++ b/user/src/com/google/gwt/core/client/impl/LoadingStrategyBase.java
@@ -57,7 +57,7 @@
* RequestData's tryInstall() function, and if it fails, it should call
it's
* RequestData's onLoadError() function.
*/
- interface DownloadStrategy {
+ protected interface DownloadStrategy {
void tryDownload(final RequestData request);
}
@@ -110,8 +110,12 @@
this.downloadStrategy = downloadStrategy;
}
+ public LoadTerminatedHandler getErrorHandler() { return errorHandler; }
+
public int getFragment() { return fragment; }
+ public int getRetryCount() { return retryCount; }
+
public String getUrl() { return url; }
public void onLoadError(Throwable e, boolean mayRetry) {
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..e6054ff 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 {
+ public static class XhrDownloadStrategy implements DownloadStrategy {
@Override
public void tryDownload(final RequestData request) {
final XMLHttpRequest xhr = XMLHttpRequest.create();
diff --git a/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
b/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
index 1e35dd0..47e4018 100644
--- a/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
+++ b/user/test/com/google/gwt/dev/jjs/CompilerSuite.java
@@ -22,8 +22,8 @@
import com.google.gwt.dev.jjs.test.BlankInterfaceTest;
import com.google.gwt.dev.jjs.test.ClassCastTest;
import com.google.gwt.dev.jjs.test.ClassObjectTest;
-import com.google.gwt.dev.jjs.test.CompilerTest;
import com.google.gwt.dev.jjs.test.CompilerMiscRegressionTest;
+import com.google.gwt.dev.jjs.test.CompilerTest;
import com.google.gwt.dev.jjs.test.CoverageTest;
import com.google.gwt.dev.jjs.test.EnhancedForLoopTest;
import com.google.gwt.dev.jjs.test.EnumsTest;
@@ -47,6 +47,7 @@
import com.google.gwt.dev.jjs.test.MiscellaneousTest;
import com.google.gwt.dev.jjs.test.NativeLongTest;
import com.google.gwt.dev.jjs.test.ObjectIdentityTest;
+import com.google.gwt.dev.jjs.test.RunAsyncContentTest;
import com.google.gwt.dev.jjs.test.RunAsyncFailureTest;
import com.google.gwt.dev.jjs.test.RunAsyncMetricsIntegrationTest;
import com.google.gwt.dev.jjs.test.RunAsyncTest;
@@ -97,6 +98,7 @@
suite.addTestSuite(MiscellaneousTest.class);
suite.addTestSuite(NativeLongTest.class);
suite.addTestSuite(ObjectIdentityTest.class);
+ suite.addTestSuite(RunAsyncContentTest.class);
suite.addTestSuite(RunAsyncFailureTest.class);
suite.addTestSuite(RunAsyncMetricsIntegrationTest.class);
suite.addTestSuite(RunAsyncTest.class);
diff --git a/user/test/com/google/gwt/dev/jjs/RunAsyncContent.gwt.xml
b/user/test/com/google/gwt/dev/jjs/RunAsyncContent.gwt.xml
new file mode 100644
index 0000000..a123392
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/RunAsyncContent.gwt.xml
@@ -0,0 +1,21 @@
+<!--
-->
+<!-- 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 -->
+<!-- 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. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<module>
+ <inherits name="com.google.gwt.core.Core" />
+ <source path="test" />
+ <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..7d237bd
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/test/LoggingXhrLoadingStrategy.java
@@ -0,0 +1,62 @@
+/*
+ * 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.LoadingStrategyBase;
+import
com.google.gwt.core.client.impl.XhrLoadingStrategy.XhrDownloadStrategy;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+/**
+ * An Xhr based fragment loading strategy that logs fragment index +
fragment text pairs for later
+ * introspection.
+ */
+public class LoggingXhrLoadingStrategy extends LoadingStrategyBase {
+ private static Map<Integer, String> sourceByFragmentIndex = new
HashMap<Integer, String>();
+
+ 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;
+ }
+
+ public LoggingXhrLoadingStrategy() {
+ super(new XhrDownloadStrategy() {
+ @Override
+ public void tryDownload(final RequestData request) {
+ super.tryDownload(new RequestData(
+ request.getUrl(), request.getErrorHandler(),
request.getFragment(), this,
+ request.getRetryCount()) {
+
+ @Override
+ public void tryInstall(String code) {
+ super.tryInstall(code);
+ sourceByFragmentIndex.put(request.getFragment(), code);
+ }
+ });
+ }
+ });
+ }
+}
\ No newline at end of file
diff --git a/user/test/com/google/gwt/dev/jjs/test/RunAsyncContentTest.java
b/user/test/com/google/gwt/dev/jjs/test/RunAsyncContentTest.java
new file mode 100644
index 0000000..fb5dee3
--- /dev/null
+++ b/user/test/com/google/gwt/dev/jjs/test/RunAsyncContentTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.GWT;
+import com.google.gwt.core.client.RunAsyncCallback;
+import com.google.gwt.junit.DoNotRunWith;
+import com.google.gwt.junit.Platform;
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests that content unique to the execution of a particular fragment is
not physically included in
+ * the shared leftOver fragment. Also tests that shared content does
physically exist in the shared
+ * leftOver fragment.
+ *
+ * Skipped in dev mode because of its different runAsync loading strategy.
+ */
+@DoNotRunWith(Platform.Devel)
+public class RunAsyncContentTest extends GWTTestCase {
+
+ private static final int RUNASYNC_TIMEOUT = 30000;
+
+ @Override
+ public String getModuleName() {
+ // References the .gwt.xml file that sets up deferred binding for
LoggingXhrLoadingStrategy.
+ return "com.google.gwt.dev.jjs.RunAsyncContent";
+ }
+
+ public void testSharedContent() {
+ delayTestFinish(RUNASYNC_TIMEOUT);
+
+ GWT.runAsync(new RunAsyncCallback() {
+ @Override
+ public void onFailure(Throwable caught) {
+ reportUncaughtException(caught);
+ }
+
+ @Override
+ public void onSuccess() {
+ String sharedContent = "Same String in multiple fragments.";
+
assertTrue(LoggingXhrLoadingStrategy.getLeftOverFragmentText().contains(sharedContent));
+ // Doesn't matter which one finishes first since that is not taken
into account in code
+ // splitting logic.
+ finishTest();
+ }
+ });
+ GWT.runAsync(new RunAsyncCallback() {
+ @Override
+ public void onFailure(Throwable caught) {
+ reportUncaughtException(caught);
+ }
+
+ @Override
+ public void onSuccess() {
+ String sharedContent = "Same String in multiple fragments.";
+
assertTrue(LoggingXhrLoadingStrategy.getLeftOverFragmentText().contains(sharedContent));
+ // Doesn't matter which one finishes first since that is not taken
into account in code
+ // splitting logic.
+ finishTest();
+ }
+ });
+ }
+
+ public void testUniqueContent() {
+ delayTestFinish(RUNASYNC_TIMEOUT);
+ GWT.runAsync(new RunAsyncCallback() {
+ @Override
+ public void onFailure(Throwable caught) {
+ reportUncaughtException(caught);
+ }
+
+ @Override
+ public void onSuccess() {
+ String uniqueContent = "Fragment From Regular RunAsync";
+
assertFalse(LoggingXhrLoadingStrategy.getLeftOverFragmentText().contains(uniqueContent));
+ finishTest();
+ }
+ });
+ }
+
+ public void testUniqueContentWithClassLiteral() {
+ delayTestFinish(RUNASYNC_TIMEOUT);
+ GWT.runAsync(RunAsyncContentTest.class, new RunAsyncCallback() {
+ @Override
+ public void onFailure(Throwable caught) {
+ reportUncaughtException(caught);
+ }
+
+ @Override
+ public void onSuccess() {
+ String uniqueContent = "Fragment From RunAsync With Class Literal";
+
assertFalse(LoggingXhrLoadingStrategy.getLeftOverFragmentText().contains(uniqueContent));
+ finishTest();
+ }
+ });
+ }
+}
--
To view, visit https://gwt-review.googlesource.com/3590
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I34d21081ea4e90b95f5b2d77a7a647e388e25335
Gerrit-PatchSet: 6
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: John Stalcup <[email protected]>
Gerrit-Reviewer: Goktug Gokdogan <[email protected]>
Gerrit-Reviewer: John Stalcup <[email protected]>
Gerrit-Reviewer: Leeroy Jenkins <[email protected]>
Gerrit-Reviewer: Matthew Dempsky <[email protected]>
Gerrit-Reviewer: Roberto Lublinerman <[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.