DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=774245
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 774245</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=774245">Mozilla Bug 774245</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">

/** Test for SpecialPowers.Components.lookupMethod in content scope. **/
SimpleTest.waitForExplicitFinish();

// We're testing things from an unprivileged perspective, so don't use
// SpecialPowers.Cu and friends, since those are SpecialPowers-wrapped versions
// that allow unprivileged tests to do privileged things.
var SC = SpecialPowers.Components;

var gLoaded = 0;
function loaded() {
  if (++gLoaded == 2)
    go();
}

var sameOriginWin;
var crossOriginWin;
function go() {
  // Grab references to the content windows.
  sameOriginWin = document.getElementById('ifr-same').contentWindow;
  crossOriginWin = document.getElementById('ifr-cross').contentWindow;

  // Test same-compartment.
  document.getElementsByTagName = function() { ok(false, "dont call me"); };
  var result = SC.lookupMethod(document, 'getElementsByTagName')('iframe');
  is(result.length, 2, "same-origin lookupMethod works");

  // Test that the method is bound.
  var gebtn = SC.lookupMethod(document, 'getElementsByTagName');
  is(Function.call.apply(gebtn, [window, 'iframe']).length, 2, "method is bound");

  // Test that lookupMethod doesn't return ChromeOnly properties when used from
  // content.
  is(SC.lookupMethod(new XMLHttpRequest(), 'getInterface'), undefined,
     "lookupMethod from content shouldn't find a ChromeOnly property");

  // Test location objects.
  var href = SC.lookupMethod(location, 'href');
  is(href(), location.href, "lookupMethod works for Location");

  // Test cross-compartment same-origin.
  sameOriginWin.setTimeout = function() { ok(false, "dont call me either"); };
  SC.lookupMethod(sameOriginWin, 'setTimeout')(continueTest, 0);
}

function continueTest() {
  // Test that cross-origin fails.
  try {
    SC.lookupMethod(crossOriginWin, 'top');
    ok(false, "Should have thrown");
  } catch (e) {
    ok(true, "Threw appropriately");
  }

  SimpleTest.finish();
}


</script>
</pre>
<iframe id="ifr-same" onload="loaded();" src="file_empty.html"></iframe>
<iframe id="ifr-cross" onload="loaded();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html"></iframe>
</body>
</html>