Reviewers: ihab.awad, MarkM,

Description:
* StringMap.js assumed ses.es5ProblemReports existed; fixed.
* Added browser tests that initSES runs to completion even on
  (simulated) unsupported browsers.

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

Affected files:
  M     src/com/google/caja/ses/StringMap.js
  M     tests/com/google/caja/ses/SESBrowserTest.java
  M     tests/com/google/caja/ses/test-ses.html


Index: tests/com/google/caja/ses/test-ses.html
===================================================================
--- tests/com/google/caja/ses/test-ses.html     (revision 5366)
+++ tests/com/google/caja/ses/test-ses.html     (working copy)
@@ -28,6 +28,32 @@
         return decodeURIComponent((results == null) ? "" : results[1]);
       }

+      var failAtStage = JSON.parse(getUrlParam('failAtStage') || 'false');
+      switch (failAtStage) {
+ // Deliberately break SES compatibility so we can verify that initSES
+        // does not crash.
+ // Note: If another stage is added here, add it to SESBrowserTest.java
+        // too.
+        case false:
+          break;
+        case 0:
+          // repairES5 baseKludges
+          delete Object.getOwnPropertyNames;
+          break;
+        case 1:
+          // repairES5 supportedKludges
+          delete Object.freeze;
+          break;
+        case 2:
+          // Property whitelisting
+          Object.defineProperty(Object, 'testSesDummy', {
+            value: {}
+          });
+          break;
+        default:
+          throw new Error('Unrecognized failAtStage: ' + failAtStage);
+      }
+
       // Note: We are deliberately not using the ses.logger or
// ses.maxAcceptableSeverity interfaces to manage startup. This test is // intended to test that SES "just works", in the absence of supporting
@@ -48,6 +74,10 @@
       doBefore(console, 'groupCollapsed', function() { groups++; });
       doBefore(console, 'groupEnd', function() { groups--; });

+      if (!getUrlParam('load')) {
+        throw new Error('No SES file specified as ?ses=foo.js');
+      }
+
       document.write('<script type="text/javascript" src="' +
           getUrlParam('load') + '"></'+'script>');
     </script>
@@ -62,6 +92,11 @@
         success = false;
       }

+      if (failAtStage !== false && ses.ok()) {
+        console.error('test-ses: SES was supposed to fail, but did not');
+        success = false;
+      }
+
       if (!ses.ok(ses.severities.NOT_SUPPORTED)) {
         console.info('test-ses: SES not even not supported.');
         success = false;
Index: tests/com/google/caja/ses/SESBrowserTest.java
===================================================================
--- tests/com/google/caja/ses/SESBrowserTest.java       (revision 5366)
+++ tests/com/google/caja/ses/SESBrowserTest.java       (working copy)
@@ -37,4 +37,20 @@
   public final void testPlusMin() throws Exception {
     runBrowserTest("../ses/test-ses.html?load=initSESPlus-minified.js");
   }
+
+ // Testing failure cases with initSESPlus because it has more code which could
+  // cause problems.
+
+  public final void testPlusFail0() throws Exception {
+ runBrowserTest("../ses/test-ses.html?load=initSESPlus.js&failAtStage=0");
+  }
+
+  public final void testPlusFail1() throws Exception {
+ runBrowserTest("../ses/test-ses.html?load=initSESPlus.js&failAtStage=1");
+  }
+
+  public final void testPlusFail2() throws Exception {
+ runBrowserTest("../ses/test-ses.html?load=initSESPlus.js&failAtStage=2");
+  }
+
 }
Index: src/com/google/caja/ses/StringMap.js
===================================================================
--- src/com/google/caja/ses/StringMap.js        (revision 5366)
+++ src/com/google/caja/ses/StringMap.js        (working copy)
@@ -41,7 +41,8 @@
    }

    var createNull;
-   if (ses.es5ProblemReports.FREEZING_BREAKS_PROTOTYPES.beforeFailure) {
+   if (((ses.es5ProblemReports || {}).FREEZING_BREAKS_PROTOTYPES || {})
+       .beforeFailure) {
// Object.create(null) is broken; fall back to ES3-style implementation
      // (safe because we suffix keys anyway).
      createNull = function() { return {}; }


--

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