Reviewers: ihab.awad,

Description:
* jQuery UI tabs expects that <a href="#foo">.href ===
  window.location + '#foo', so implement that.
* Fix toString overrides in Domado not working in ES5/3 mode with the +
  operator.

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

Affected files:
  M     src/com/google/caja/plugin/domado.js
  M     tests/com/google/caja/plugin/test-domado-dom-guest.html
  M     tests/com/google/caja/plugin/test-domado-global-location.js
  M     tests/com/google/caja/plugin/third-party-tests.json


Index: tests/com/google/caja/plugin/test-domado-global-location.js
===================================================================
--- tests/com/google/caja/plugin/test-domado-global-location.js (revision 5561) +++ tests/com/google/caja/plugin/test-domado-global-location.js (working copy)
@@ -51,6 +51,8 @@
         window.location.search);
   }

+ assertEquals('implicit toString', window.location.href, '' + window.location);
+
   // document.location is an identical property to window.location
   assertTrue('document.location', window.location === document.location);
 }
Index: tests/com/google/caja/plugin/third-party-tests.json
===================================================================
--- tests/com/google/caja/plugin/third-party-tests.json (revision 5561)
+++ tests/com/google/caja/plugin/third-party-tests.json (working copy)
@@ -124,7 +124,7 @@
       },
       {
         "guest": "css",
-        "expected-pass": { "firefox": 239, "chrome": 241 },
+        "expected-pass": { "firefox": 237, "chrome": 241 },
         "comment": [
           "Current failure categories:",
             "Not yet examined."
@@ -222,7 +222,7 @@
       },
       {
         "guest": "dialog",
-        "expected-pass": { "firefox": 294, "chrome": 306 },
+        "expected-pass": { "firefox": 291, "chrome": 306 },
         "comment": [
           "Current failure categories:",
             "What may be event simulation failures",
@@ -271,7 +271,7 @@
       },
       {
         "guest": "tabs",
-        "expected-pass": { "firefox": 487, "chrome": 519 },
+        "expected-pass": { "firefox": 547, "chrome": 594 },
         "comment": [
           "Current modifications made to test suite:",
"Work around lost-signal problems due to lack of event simulation",
Index: tests/com/google/caja/plugin/test-domado-dom-guest.html
===================================================================
--- tests/com/google/caja/plugin/test-domado-dom-guest.html     (revision 5561)
+++ tests/com/google/caja/plugin/test-domado-dom-guest.html     (working copy)
@@ -3254,28 +3254,30 @@
 </script>

 <div class="testcontainer" id="testHash">
-  <a id='test-hash' href="#foo">test a.hash</a>
+  <a id='test-hash' href="#foo">test a.hash and hash in a.href</a>
 </div>
 <script type="text/javascript">
   jsunitRegister('testHash', function testHash() {
     var a = document.getElementById('test-hash');
+
     assertEquals('#foo', a.hash);
     // a.href is an absolute url; a.getAttribute('href') is just the hash
     assertEquals('#foo', a.getAttribute('href'));
-    // TODO(felix8a): maybe this should succeed?
-    //assertEquals('#foo', a.href.substr(-4));
+    assertEquals(window.location + '#foo', a.href);
+
     a.hash = '#bar';
     assertEquals('#bar', a.hash);
     // setting a.hash forces a.getAttribute('href') to be a resolved url
-    // TODO(felix8a): maybe this should succeed?
-    //assertEquals('#bar', a.href.substr(-4));
-    pass('testHash');
+    assertEquals(window.location + '#bar', a.getAttribute('href'));
+    assertEquals(window.location + '#bar', a.href);
+
+    pass();
   });
 </script>

 <div class="testcontainer" id="testBaseURI"></div>
 <script type="text/javascript">
-  jsunitRegister('testBaseURI', function testHash() {
+  jsunitRegister('testBaseURI', function testBaseURI() {
     // http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-baseURI
     var loc = window.location;
     assertEquals(
Index: src/com/google/caja/plugin/domado.js
===================================================================
--- src/com/google/caja/plugin/domado.js        (revision 5561)
+++ src/com/google/caja/plugin/domado.js        (working copy)
@@ -323,8 +323,15 @@
    * Alias for a common pattern: non-enumerable toString method.
    */
   function setToString(obj, fn) {
-    Object.defineProperty(obj, 'toString',
-        allowNonWritableOverride(obj, 'toString', {value: fn}));
+    // ES5/3's virtualization of toString does not work properly w/
+    // defineProperty
+ if ('USELESS' in cajaVM) { // TODO(kpreid): Better condition/kill this code + // Under ES5/3, this will have the overridable semantics we wanted anyway
+      obj.toString = fn;
+    } else {
+      Object.defineProperty(obj, 'toString',
+          allowNonWritableOverride(obj, 'toString', {value: fn}));
+    }
   }

   /**
@@ -1825,6 +1832,8 @@
var window = bridalMaker.getWindow(outerContainerNode, makeDOMAccessible);
       window = makeDOMAccessible(window);

+      makeDOMAccessible(document.location);
+
// Note that feralPseudoWindow may be an Element or a Window depending.
       var feralPseudoDocument, feralPseudoWindow;
       if (outerContainerNode.nodeType === 9) { // Document node
@@ -2197,7 +2206,19 @@
             if (realValue && '#' === realValue.charAt(0)) {
               return unsuffix(realValue, idSuffix, realValue);
             } else {
-              return realValue;
+              // convert "http://hostpage#fragment-suffix"; into
+              // "http://guestpage#fragment";
+              var parsed = URI.parse(realValue);
+              var frag = parsed.getRawFragment();
+              parsed.setRawFragment('');
+              var fragless = parsed.toString();
+              // compare against document's base URL
+              // .baseURI not available on IE
+ if (fragless === (document.baseURI || document.location.href)) {
+                fragless = domicile.pseudoLocation.href;
+              }
+              return fragless +
+ (frag === null ? '' : '#' + unsuffix(frag, idSuffix, frag));
             }
           case html4.atype.URI_FRAGMENT:
             if (realValue && '#' === realValue.charAt(0)) {
@@ -2777,6 +2798,25 @@
       // configuration.
       var NP_writePolicyOnly = PT.filter(false, identity, true, identity);

+      function NP_UriValuedProperty(schemaEl, schemaAttr) {
+        return Props.markPropMaker(function(env) {
+          var prop = env.prop;
+          return {
+            // this is not just an attribute wrapper because the .href is
+            // expected to be absolute even if the attribute is not.
+            // But we can still use the same virt logic.
+            get: env.amplifying(function(privates) {
+              return virtualizeAttributeValue(
+                  html4.atype.URI, privates.feral[prop]);
+            }),
+            set: env.amplifying(function(privates, value) {
+              privates.feral.href = rewriteAttribute(
+                  schemaEl, schemaAttr, html4.atype.URI, value);
+            })
+          };
+        });
+      }
+
       var nodeClassNoImplWarnings = {};
       var elementTamerCache = {};
       function makeTameNodeByType(node) {
@@ -4607,8 +4647,7 @@
             false,
             // TODO(felix8a): add suffix if href is self
             identity),
-          // TODO(felix8a): fragment rewriting?
-          href: NP_writePolicyOnly
+          href: NP_UriValuedProperty('a', 'href')
         }; }
       });



--

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