");
    document.documentElement.appendChild(gFrame);
  },
  function testInheritFromCurrent_system(cb) {
    loadListener(gFrame, function () {
      is(window.inheritedSystem, undefined, "load in type=content iframe shouldn't inherit system principal from current document");
      cb();
    }, true);
    gFrame.setAttribute("src", "data:text/html,");
  },
  function testInheritFromCreated(cb) {
    // Open a new chrome window with a type="content" iframe, so that it has no
    // same-type parent.
    // Load a javascript: URI in it to ensure that GetInheritedPrincipal will
    // force creation of a content viewer.
    let xulWinURL = 'data:application/vnd.mozilla.xul+xml,' +
                    '';
    let newWin = window.openDialog(xulWinURL, "chrome_window", "chrome");
    loadListener(newWin, function () {
      let frame = newWin.document.createElement("iframe");
      frame.setAttribute("type", "content");
      frame.setAttribute("src", "javascript:'1';");
      loadListener(frame, function () {
        is(frame.contentWindow.document.body.textContent, "1", "content viewer was created");
        SimpleTest.executeSoon(function () {
          newWin.close();
          cb();
        })
      });
      newWin.document.documentElement.appendChild(frame);
    });
  }
];

addLoadEvent(function onLoad() {
  ok(Components.stack, "this test must be run with the system principal");
  SimpleTest.executeSoon(nextTest);
});

function loadListener(target, func) {
  target.addEventListener("load", function lis() {
    target.removeEventListener("load", lis, true);
    func();
  }, true);
}

function nextTest() {
  if (tests.length) {
    let test = tests.shift();
    SimpleTest.executeSoon(function () {
      info("running " + test.name);
      test(nextTest);
    });
  } else
    SimpleTest.executeSoon(SimpleTest.finish);
}

]]>