Reviewers: kpreid2, MarkM,

Description:
This adds ses/explicit.html to the list of tests run,
so we can gather a record of how browsers behave.

This also modifies browser capture (in a dumb/easy way)
so that some test runs will always be captured
whether they pass or fail.

Please review this at https://codereview.appspot.com/13171045/

Affected files:
  M     src/com/google/caja/ses/explicit.html
  M     tests/com/google/caja/plugin/BrowserTestCase.java
  M     tests/com/google/caja/plugin/WebDriverHandle.java
  M     tests/com/google/caja/plugin/browser-tests.json


Index: src/com/google/caja/ses/explicit.html
===================================================================
--- src/com/google/caja/ses/explicit.html       (revision 5573)
+++ src/com/google/caja/ses/explicit.html       (working copy)
@@ -36,6 +36,9 @@
 <div id="scriptTest">scriptTest...</div>
 <div id="amdLoaderTest">AMD loader test...</div>

+<!-- for communication with automated test driver -->
+<div id="testSignals" class="testcontainer"></div>
+
 <script src="useHTMLLogger.js"></script>
 <script>
   function gebi(id) {
@@ -67,8 +70,20 @@

 <script>
   var amdLoaderTest = gebi('amdLoaderTest');
-  function appendText(node, text) {
+  var testSignals = gebi('testSignals');
+  testSignals.className += ' readytotest';
+  var expected = 4;
+  var passes = 0;
+  function done() {
     "use strict";
+    if (passes === expected) {
+      document.title += ' - all tests passed';
+    }
+    testSignals.className += ' done';
+  }
+  function appendResult(node, text) {
+    "use strict";
+    if (/^succeeded/.test(text)) { passes += 1; }
     node.appendChild(document.createTextNode(text));
   }
   (function() {
@@ -77,10 +92,11 @@
     var moduleTest = gebi('moduleTest');
     var scriptTest = gebi('scriptTest');
     if (!ses.ok()) {
-      appendText(exprTest, 'cancelled');
-      appendText(moduleTest, 'cancelled');
-      appendText(scriptTest, 'cancelled');
-      appendText(amdLoaderTest, 'cancelled');
+      appendResult(exprTest, 'cancelled');
+      appendResult(moduleTest, 'cancelled');
+      appendResult(scriptTest, 'cancelled');
+      appendResult(amdLoaderTest, 'cancelled');
+      done();
       return;
     }

@@ -92,7 +108,7 @@

var output = cajaVM.eval('3+4') * cajaVM.compileExpr('window')(imports);
     var text1 = output === 42 ? 'succeeded' : 'failed: ' + output;
-    appendText(exprTest, text1);
+    appendResult(exprTest, text1);

     // Test ability to bootstrap support for a limited form of
     // CommonJS modules.
@@ -119,7 +135,7 @@
       "returned": 77
     }, void 0, ' ');
     var text2 = did === should ? 'succeeded' : 'failed: ' + did;
-    appendText(moduleTest, text2);
+    appendResult(moduleTest, text2);

     // Tests the ability to do inter-module linkage as scripts
     // traditionally did, by modification of (virtual) shared
@@ -128,7 +144,7 @@
     cajaVM.compileModule('this.x = 88;')(imports);
     var text3 = cajaVM.compileExpr('x')(imports) === 88 ?
       'succeeded' : 'failed';
-    appendText(scriptTest, text3);
+    appendResult(scriptTest, text3);

   })();
 </script>
@@ -210,9 +226,11 @@
     Q(amdTestP).then(function(amdTest) {
       var amdTestStatus = amdTest === 'this is a test' ?
         'succeeded' : 'failed, unexpected: ' + amdTest;
-      appendText(amdLoaderTest, amdTestStatus);
+      appendResult(amdLoaderTest, amdTestStatus);
+      done();
     }, function(reason) {
-      appendText(amdLoaderTest, 'failed: ' + reason);
+      appendResult(amdLoaderTest, 'failed: ' + reason);
+      done();
     }).end();
   })();
 </script>
Index: tests/com/google/caja/plugin/BrowserTestCase.java
===================================================================
--- tests/com/google/caja/plugin/BrowserTestCase.java   (revision 5573)
+++ tests/com/google/caja/plugin/BrowserTestCase.java   (working copy)
@@ -152,7 +152,7 @@
         result = driveBrowser(driver);
         passed = true;
       } finally {
-        wdh.captureResults(label, passed);
+        captureResults(label, passed);
         wdh.end(passed || isKnownFailure);
       }
     } catch (Exception e) {
@@ -163,6 +163,23 @@
     return result;
   }

+  private void captureResults(String label, boolean passed) {
+    if (alwaysCapture(label)) {
+      wdh.captureResults("keep." + label);
+    } else if (!passed) {
+      wdh.captureResults("fail." + label);
+    } else if (TestFlag.CAPTURE_PASSES.truthy()) {
+      wdh.captureResults("pass." + label);
+    }
+  }
+
+  protected boolean alwaysCapture(String label) {
+    // TODO(felix8a): maybe this should be a flag in browser-tests.json
+    return (
+        label.startsWith("guest-scan-") ||
+        label.equals("ses-explicit"));
+  }
+
   protected static String escapeUri(String s) {
     StringBuilder sb = new StringBuilder();
     Escaping.escapeUri(s, sb);
Index: tests/com/google/caja/plugin/WebDriverHandle.java
===================================================================
--- tests/com/google/caja/plugin/WebDriverHandle.java   (revision 5573)
+++ tests/com/google/caja/plugin/WebDriverHandle.java   (working copy)
@@ -199,16 +199,13 @@
     }
   }

-  public void captureResults(String name, boolean passed) {
+  public void captureResults(String name) {
     if (driver == null) { return; }

-    if (passed && !TestFlag.CAPTURE_PASSES.truthy()) { return; }
-
     String dir = TestFlag.CAPTURE_TO.getString("");
     if ("".equals(dir)) { return; }

     if (!dir.endsWith("/")) { dir = dir + "/"; }
-    dir += passed ? "pass/" : "fail/";
     mkdirs(dir);

     // Try to capture the final html
Index: tests/com/google/caja/plugin/browser-tests.json
===================================================================
--- tests/com/google/caja/plugin/browser-tests.json     (revision 5573)
+++ tests/com/google/caja/plugin/browser-tests.json     (working copy)
@@ -10,6 +10,14 @@
     },
     { "driver": "meta-test.js" }
   ]},
+  {
+    "label": "ses-explicit",
+    "bare": "../../../../../src/com/google/caja/ses/explicit.html",
+    "mode": "none",
+    "comment": [
+      "Detailed SES initialization report"
+    ]
+  },
   { "label": "cajajs", "tests": [
     {
       "driver": "test-cajajs-invocation.js",


--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" 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.

Reply via email to