Revision: 3753
Author: [email protected]
Date: Fri Sep 25 15:50:07 2009
Log: Added testcase for issue 1126: offsetParent not exposed
http://codereview.appspot.com/120049

http://code.google.com/p/google-caja/issues/detail?id=1126

offsetParent is exposed.

[email protected]

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

Modified:
 /trunk/src/com/google/caja/plugin/domita.js
 /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html

=======================================
--- /trunk/src/com/google/caja/plugin/domita.js Fri Sep 25 08:33:25 2009
+++ /trunk/src/com/google/caja/plugin/domita.js Fri Sep 25 15:50:07 2009
@@ -1083,6 +1083,14 @@

     function tameRelatedNode(node, editable, tameNodeCtor) {
       if (node === null || node === void 0) { return null; }
+      if (node === tameDocument.body___) {
+        if (tameDocument.editable___ && !editable) {
+          // FIXME: return a non-editable version of body.
+          throw new Error(NOT_EDITABLE);
+        }
+        return tameDocument.getBody();
+      }
+
       // Catch errors because node might be from a different domain.
       try {
         var docElem = node.ownerDocument.documentElement;
@@ -1511,15 +1519,8 @@
return defaultTameNode(this.node___.previousSibling, this.editable___);
     };
     TameBackedNode.prototype.getParentNode = function () {
-      var parent = this.node___.parentNode;
-      if (parent === tameDocument.body___) {
-        if (tameDocument.editable___ && !this.editable___) {
-          // FIXME: return a non-editable version of body.
-          throw new Error(NOT_EDITABLE);
-        }
-        return tameDocument.getBody();
-      }
-      return tameRelatedNode(parent, this.editable___, defaultTameNode);
+      return tameRelatedNode(
+          this.node___.parentNode, this.editable___, defaultTameNode);
     };
     TameBackedNode.prototype.getElementsByTagName = function (tagName) {
       return tameGetElementsByTagName(
=======================================
--- /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Thu Sep 24 14:16:36 2009 +++ /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Fri Sep 25 15:50:07 2009
@@ -237,6 +237,10 @@

 <p class="testcontainer" id="test-inner-HTML-style-sanitizer"></p>

+<p class="testcontainer" id="test-offset-parent" style="position:relative">
+<span id="test-offset-parent-inner">inner</span>
+</p>
+
 <div class="testcontainer" id="test-whitespace-nodes-1">
<div style="width: 150px; border: 1px solid blue; margin: 0; padding: 2px"
    id="whitespace-outer">
@@ -1781,6 +1785,19 @@
   pass('test-inner-HTML-style-sanitizer');
 });

+jsunitRegister('testOffsetParent',
+               function testOffsetParent() {
+  var outer = document.getElementById('test-offset-parent');
+  var inner = document.getElementById('test-offset-parent-inner');
+  assertEquals("wrong inner.offsetParent: " + inner.offsetParent,
+               outer, inner.offsetParent);
+  assertEquals("wrong outer.offsetParent: " + outer.offsetParent,
+               document.body, outer.offsetParent);
+  assertEquals("wront body.offsetParent: " + document.body.offsetParent,
+               undefined, document.body.offsetParent);
+  pass('test-offset-parent');
+});
+
 function assertWithin(msg, golden, actual, tolerance) {
   if (!(Math.abs(golden - actual) <= tolerance)) {
     assertEquals(msg, golden, actual);
@@ -3063,15 +3080,15 @@
     Q.when(m, f1, f2);
   } else {
     pass(prefix + '-unbundled-module-loader');
-  }
+  }
 }

-jsunitRegister('testXhrUnbundledModuleLoader',
+jsunitRegister('testXhrUnbundledModuleLoader',
                function testXhrUnbundledModuleLoader() {
   testUnbundledModuleLoader(xhrModuleLoad, "xhr");
 });

-jsunitRegister('testScriptUnbundledModuleLoader',
+jsunitRegister('testScriptUnbundledModuleLoader',
                function testScriptUnbundledModuleLoader() {
   testUnbundledModuleLoader(scriptModuleLoad, "script");
 });

Reply via email to