Revision: 5563
Author:   [email protected]
Date:     Mon Aug 19 22:19:02 2013 UTC
Log:      Fix repairES5 tests crashing with no <body>.
https://codereview.appspot.com/13109044

Fixes <https://code.google.com/p/google-caja/issues/detail?id=1830>.

Also fix ses-tests.json labels to be hyphen-separated symbols.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=5563

Added:
 /trunk/tests/com/google/caja/ses/test-ses-early.html
Modified:
 /trunk/src/com/google/caja/ses/repairES5.js
 /trunk/tests/com/google/caja/ses/ses-tests.json

=======================================
--- /dev/null
+++ /trunk/tests/com/google/caja/ses/test-ses-early.html Mon Aug 19 22:19:02 2013 UTC
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+  <head>
+    <title>SES in &lt;head&gt; test</title>
+    <script src="initSES-minified.js"></script>
+  </head>
+  <body class="readytotest">
+    <script type="text/javascript">
+      'use strict';
+      if (ses.ok(ses.severities.NEW_SYMPTOM)) {
+        document.title = 'all tests passed - ' + document.title;
+      } else {
+        document.title = 'failed - ' + document.title;
+        console.error('test-ses: assertions failed');
+      }
+    </script>
+</html>
=======================================
--- /trunk/src/com/google/caja/ses/repairES5.js Fri Aug 16 17:13:31 2013 UTC
+++ /trunk/src/com/google/caja/ses/repairES5.js Mon Aug 19 22:19:02 2013 UTC
@@ -871,11 +871,13 @@
   function inTestFrame(callback) {
     if (!document || !document.createElement) { return undefined; }
     var iframe = document.createElement('iframe');
-    document.body.appendChild(iframe);
+ var container = document.body || document.getElementsByTagName('head')[0] ||
+        document.documentElement || document;
+    container.appendChild(iframe);
     try {
       return callback(iframe.contentWindow);
     } finally {
-      iframe.parentNode.removeChild(iframe);
+      container.removeChild(iframe);
     }
   }

=======================================
--- /trunk/tests/com/google/caja/ses/ses-tests.json Wed Jul 31 16:40:58 2013 UTC +++ /trunk/tests/com/google/caja/ses/ses-tests.json Mon Aug 19 22:19:02 2013 UTC
@@ -1,6 +1,6 @@
 [
   {
-    "label": "ses loading tests",
+    "label": "ses-loading",
     "bare": "../ses/test-ses-loading.html",
     "mode": "none",
     "tests": [
@@ -31,11 +31,16 @@
       {
         "label": "fail-2",
         "params": { "load": "initSES.js", "failAtStage": "2" }
+      },
+      {
+        "label": "early",
+        "comment": "Ensure loading in <head> works.",
+        "bare": "../ses/test-ses-early.html"
       }
     ]
   },
   {
-    "label": "ses mitigation tests",
+    "label": "ses-mitigation",
     "bare": "../ses/test-ses-mitigation.html",
     "mode": "none",
     "tests": [

--

--- 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