summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/unit/head.js
blob: be3d74401a1acb8ee0af6ab501ace1013f416abb (plain)
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
"use strict";

// Wraps the given object in an XPConnect wrapper and, if an interface
// is passed, queries the result to that interface.
function xpcWrap(obj, iface) {
  let ifacePointer = Cc[
    "@mozilla.org/supports-interface-pointer;1"
  ].createInstance(Ci.nsISupportsInterfacePointer);

  ifacePointer.data = obj;
  if (iface) {
    return ifacePointer.data.QueryInterface(iface);
  }
  return ifacePointer.data;
}

function createContentWindow(uri) {
  const principal = Services.scriptSecurityManager
    .createContentPrincipalFromOrigin(uri);
  const webnav = Services.appShell.createWindowlessBrowser(false);
  const docShell = webnav.docShell;
  docShell.createAboutBlankDocumentViewer(principal, principal);
  return webnav.document.defaultView;
}

function createChromeWindow() {
  const principal = Services.scriptSecurityManager.getSystemPrincipal();
  const webnav = Services.appShell.createWindowlessBrowser(true);
  const docShell = webnav.docShell;
  docShell.createAboutBlankDocumentViewer(principal, principal);
  return webnav.document.defaultView;
}