Adds a test for -noserver hosted mode.

Review by: jat



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5094 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/build.xml b/user/build.xml
index 2ff72cb..9b150ed 100755
--- a/user/build.xml
+++ b/user/build.xml
@@ -13,11 +13,14 @@
 
   <fileset id="default.emma.tests" dir="${javac.junit.out}" 
        includes="**/EmmaClassLoadingTest.class" />
-  
+
   <fileset id="default.hosted.emma.tests" dir="${javac.junit.out}" 
       excludes="**/CoverageTest.class,**/CompilerSuite.class" includes="${gwt.junit.emmatestcase.includes}" />
   <!-- everything succeeds except CoverageTest.java. It fails due to a javac bug in sun/OpenJDK's Java. See the file contents for details -->
-  
+
+  <fileset id="default.noserver.tests" dir="${javac.junit.out}" includes="**/IFrameLinkerTest.class" />
+  <!-- Only IFrameLinker actually supports -noserver mode; run the other linker tests if and when they are supported -->
+
   <!--
     Default web mode test cases
   -->
@@ -49,11 +52,11 @@
 
   <!--
     Compile test code for dev/core to pick up TypeOracleTestUtils and others.
-  -->	
+  -->
   <target name="compile.dev.core.tests" description="Compiles test dependencies in dev/core">
     <gwt.ant dir="../dev/core" target="compile.tests" />
   </target>
-    
+
   <target name="compile.tests" depends="compile.dev.core.tests" description="Compiles the test code for this project">
     <mkdir dir="${javac.junit.out}" />
     <gwt.javac srcdir="test" excludes="com/google/gwt/langtest/**" destdir="${javac.junit.out}">
@@ -126,11 +129,19 @@
         <pathelement location="${gwt.build}/out/dev/core/bin-test" />
         <pathelement location="${gwt.tools.redist}/emma/emma.jar" />
       </extraclasspaths>
-    </gwt.junit> 
+    </gwt.junit>
+  </target>
+
+  <target name="test.noserver" depends="compile, compile.tests" description="Run noserver hosted-mode tests for this project.">
+    <gwt.junit test.args="${test.args}" test.out="${junit.out}/${build.host.platform}-noserver-mode" test.cases="default.noserver.tests">
+      <extraclasspaths>
+        <pathelement location="${gwt.build}/out/dev/core/bin-test" />
+      </extraclasspaths>
+    </gwt.junit>
   </target>
 
   <target name="test.web" depends="compile, compile.tests" description="Run only web-mode tests for this project.">
-    <gwt.junit test.args="${test.args} -out www -web" test.out="${junit.out}/${build.host.platform}-web-mode" test.cases="default.web.tests" >
+    <gwt.junit test.args="${test.args} -out www -web" test.out="${junit.out}/${build.host.platform}-web-mode" test.cases="default.web.tests">
       <extraclasspaths>
         <pathelement location="${gwt.build}/out/dev/core/bin-test" />
       </extraclasspaths>
@@ -167,6 +178,7 @@
       <!-- remoteweb-test is a no-op unless gwt.remote.browsers is defined -->
       <antcall target="remoteweb-test"/>
       <antcall target="test.hosted"/>
+      <antcall target="test.noserver"/>
       <antcall target="test.web"/>
       <antcall target="test.web.disableClassMetadata"/>
       <antcall target="test.web.draft"/>
@@ -179,6 +191,6 @@
     <delete file="${project.lib}" />
   </target>
   <target name="presubmit" depends="test, checkstyle" description="runs the gwt api checker, user checkstyle, and user tests">
-   <gwt.ant dir=".." target="apicheck-nobuild"/>
+    <gwt.ant dir=".." target="apicheck-nobuild"/>
   </target>
 </project>
diff --git a/user/src/com/google/gwt/junit/JUnitShell.java b/user/src/com/google/gwt/junit/JUnitShell.java
index 6563f8c..c421faa 100644
--- a/user/src/com/google/gwt/junit/JUnitShell.java
+++ b/user/src/com/google/gwt/junit/JUnitShell.java
@@ -116,6 +116,25 @@
       registerHandler(new ArgHandlerFlag() {
         @Override
         public String getPurpose() {
+          return "Causes your test to run in -noserver hosted mode (defaults to hosted mode)";
+        }
+
+        @Override
+        public String getTag() {
+          return "-noserver";
+        }
+
+        @Override
+        public boolean setFlag() {
+          runStyle = new RunStyleNoServerHosted(JUnitShell.this);
+          numClients = 1;
+          return true;
+        }
+      });
+
+      registerHandler(new ArgHandlerFlag() {
+        @Override
+        public String getPurpose() {
           return "Causes your test to run in web (compiled) mode (defaults to hosted mode)";
         }
 
@@ -590,6 +609,11 @@
   }
 
   @Override
+  protected boolean shouldAutoGenerateResources() {
+    return runStyle.shouldAutoGenerateResources();
+  }
+
+  @Override
   protected void sleep() {
     if (runStyle.isLocal()) {
       super.sleep();
diff --git a/user/src/com/google/gwt/junit/RunStyle.java b/user/src/com/google/gwt/junit/RunStyle.java
index fb20f5d..9757ad4 100644
--- a/user/src/com/google/gwt/junit/RunStyle.java
+++ b/user/src/com/google/gwt/junit/RunStyle.java
@@ -60,6 +60,15 @@
       throws UnableToCompleteException;
 
   /**
+   * Whether the embedded server should ever generate resources.  Hosted mode
+   * needs this, but not noserver hosted.  TODO(spoon) does web mode get
+   * simpler if this is turned on?
+   */
+  public boolean shouldAutoGenerateResources() {
+    return true;
+  }
+
+  /**
    * Tests whether the test was interrupted.
    * 
    * @return <code>true</code> if the test has been interrupted.
diff --git a/user/src/com/google/gwt/junit/RunStyleNoServerHosted.java b/user/src/com/google/gwt/junit/RunStyleNoServerHosted.java
new file mode 100644
index 0000000..5f54989
--- /dev/null
+++ b/user/src/com/google/gwt/junit/RunStyleNoServerHosted.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2009 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.junit;
+
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.dev.shell.BrowserWidget;
+
+/**
+ * <p>
+ * This run style simulates -noserver hosted mode. It is the same as hosted mode
+ * except for two differences:
+ * </p>
+ * 
+ * <ol>
+ * <li>The program is compiled for web mode.
+ * <li>The embedded server does not do any GWT-specific resource generation.
+ * </ol>
+ * 
+ * <p>
+ * In effect, the built-in web server gets used as a dumb web server to serve up
+ * the compiled files.
+ * </p>
+ */
+public class RunStyleNoServerHosted extends RunStyleLocalHosted {
+  RunStyleNoServerHosted(JUnitShell shell) {
+    super(shell);
+  }
+
+  @Override
+  public void maybeCompileModule(String moduleName)
+      throws UnableToCompleteException {
+    BrowserWidget browserWindow = getBrowserWindow();
+    shell.compileForWebMode(moduleName, browserWindow.getUserAgent());
+  }
+
+  @Override
+  public boolean shouldAutoGenerateResources() {
+    // pretend to be a web server that knows nothing about GWT
+    return false;
+  }
+}