Reviewers: MarkM,

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

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

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

Affected files:
  src/com/google/caja/ses/repairES5.js
  tests/com/google/caja/ses/ses-tests.json
  tests/com/google/caja/ses/test-ses-early.html


Index: tests/com/google/caja/ses/ses-tests.json
===================================================================
--- tests/com/google/caja/ses/ses-tests.json    (revision 5562)
+++ tests/com/google/caja/ses/ses-tests.json    (working copy)
@@ -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": [
Index: tests/com/google/caja/ses/test-ses-early.html
===================================================================
--- tests/com/google/caja/ses/test-ses-early.html       (revision 0)
+++ tests/com/google/caja/ses/test-ses-early.html       (revision 0)
@@ -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>
Index: src/com/google/caja/ses/repairES5.js
===================================================================
--- src/com/google/caja/ses/repairES5.js        (revision 5562)
+++ src/com/google/caja/ses/repairES5.js        (working copy)
@@ -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);
     }
   }



--

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