Bug 808608 - Fix test_bug802557. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 21 Nov 2012 13:20:05 -0800
changeset 113932 81bea5f51d637fc52ddaa279b36c4f6bafcf3df9
parent 113931 783573d542dfe17473170e0981faf7c021bf222e
child 113933 030c89e22e3ec525338a3afdbd0f119195779fa3
push id18459
push userbobbyholley@gmail.com
push dateWed, 21 Nov 2012 21:21:06 +0000
treeherdermozilla-inbound@030c89e22e3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs808608, 802557
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 808608 - Fix test_bug802557. r=bz There are a number of fixes to this important tests, so this warrants a separate patch. First of all, the boundTo machinery goes away, because we no longer have same- compartment Xrays giving us the weird bound methods. Furthermore, now that the sensitive methods are just regular old methods off the prototype. They'll fail correctly when used on a same-scope object, but not for cross-scope XOWs they'll just fail in the GetWrappedNativeOfJSObject rat's nest (when they can't unwrap the security wrapper), so we'll just get a generic XPConnect error instead of a security exception. I want to fix this soon, so I changed the skipMessageCheck stuff to use todo_is. However, _that_ caused an UNEXPECTED-PASS for the DefaultValue test (which was the only one of the array of tests that was throwing a security exception in step 2). So I added an annotation for that in item[2].
js/xpconnect/tests/mochitest/file_bug802557.html
js/xpconnect/tests/mochitest/test_bug802557.html
--- a/js/xpconnect/tests/mochitest/file_bug802557.html
+++ b/js/xpconnect/tests/mochitest/file_bug802557.html
@@ -29,16 +29,20 @@ var gTests = {
   getHrefViaApply: function() {
     return Function.call.apply(gGHR, [window.location]);
   },
   getHrefViaPrototype: function() {
     return Object.getOwnPropertyDescriptor(Location.prototype, 'href').get.call(window.location);
   }
 };
 
+gTests.getLocationApply1.skipMessageCheck = true;
+gTests.getLocationApply2.skipMessageCheck = true;
+gTests.getLocationApply3.skipMessageCheck = true;
 gTests.getLocationViaPrototype.skipMessageCheck = true;
+gTests.getHrefViaApply.skipMessageCheck = true;
 gTests.getHrefViaPrototype.skipMessageCheck = true;
 
 </script>
 </head>
 <body>
 </body>
 </html>
--- a/js/xpconnect/tests/mochitest/test_bug802557.html
+++ b/js/xpconnect/tests/mochitest/test_bug802557.html
@@ -27,58 +27,54 @@ SimpleTest.waitForExplicitFinish();
 // to check the message to make sure we're throwing a security exception and not
 // something else.
 function checkThrows(fun, desc, skipMessageCheck) {
   try {
     fun();
     ok(false, "Didn't throw when " + desc);
   } catch(e) {
     ok(true, "Threw when " + desc + " " + e);
-    if (!skipMessageCheck)
-      ok(/denied|insecure/.exec(e), "Should be security exception");
+    (skipMessageCheck ? todo : ok)(/denied|insecure/.exec(e), "Should be security exception");
   }
 }
 
 var loadCount = 0;
 var ifr = document.getElementById('ifr');
 var iWin = ifr.contentWindow;
-function boundTo(item, l) { return item[3] && item[2] === l; };
 function go() {
   ++loadCount;
 
   if (loadCount == 1) {
     gLoc = iWin.location;
     // Note that accessors pulled off Xrays are currently bound. This is bug 658909.
     // [getter, description, locationObj, bound]
-    gGetters = [[ location.toString, 'toString from LW', location, true ],
-                [ gLoc.toString, 'toString from XLW', gLoc, true ],
-                [ Location.prototype.toString, 'toString from Location.prototype', location, false ],
-                [ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype', gLoc, false ],
-                [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW', location, true ],
-                [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW', gLoc, true ],
-                [ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype', location, false ],
-                [ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype', gLoc, false ],
-                [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', location, false]];
+    gGetters = [[ location.toString, 'toString from LW' ],
+                [ gLoc.toString, 'toString from XLW' ],
+                [ Location.prototype.toString, 'toString from Location.prototype' ],
+                [ iWin.Location.prototype.toString, 'toString from iWin.Location.prototype' ],
+                [ Object.__lookupGetter__.call(location, 'href'), 'href getter from LW' ],
+                [ Object.__lookupGetter__.call(gLoc, 'href'), 'href getter from XLW' ],
+                [ Object.getOwnPropertyDescriptor(Location.prototype, 'href').get, 'href getter from Location.prototype' ],
+                [ Object.getOwnPropertyDescriptor(iWin.Location.prototype, 'href').get, 'href getter from iWin.Location.prototype' ],
+                [ function() { return this + ''; }, 'implicit conversion via [[DefaultValue]]', /* doMessageCheck = */ true ]];
     gGetters.forEach(function(item) {
       try {
-        (boundTo(item, gLoc) ? todo_is : is)(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
-        (boundTo(item, location) ? todo_is : is)(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
+        is(item[0].call(location), location.toString(), 'Same-origin LW: ' + item[1]);
+        is(item[0].call(gLoc), gLoc.toString(), 'Same-origin XLW: ' + item[1]);
       } catch (e) {
         ok(false, "Threw while applying " + item[1] + " to same-origin location object: " + e);
       }
     });
     ifr.src = "http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html";
   }
   else if (loadCount == 2) {
     gGetters.forEach(function(item) {
-      // If the getter is bound to our local window.location, it's not going to throw
-      if (!boundTo(item, window.location))
-        checkThrows(function() { item[0].call(gLoc); },
-                    'call()ing ' + item[1] + ' after navigation cross-origin',
-                    /* skipMessageCheck = */ true);
+      checkThrows(function() { item[0].call(gLoc); },
+                  'call()ing ' + item[1] + ' after navigation cross-origin',
+                  /* skipMessageCheck = */ false);
     });
     ifr.src = 'http://mochi.test:8888/tests/js/xpconnect/tests/mochitest/file_bug802557.html';
   }
   else if (loadCount == 3) {
     gTestFunctions = ifr.contentWindow.gTests;
     var win = ifr.contentWindow;
     for (fun in gTestFunctions)
        is(gTestFunctions[fun](), win.location.toString(), "allowed via " + fun);