summaryrefslogtreecommitdiffstats
path: root/dom/base/test/browser_messagemanager_targetframeloader.js
blob: 62c8482addd218db8485a981044563b6d826a652 (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
33
34
35
36
function frameScript() {
  sendSyncMessage("Test:Message");
  sendAsyncMessage("Test:Message");
  sendAsyncMessage("Test:Done");
}

function test() {
  waitForExplicitFinish();

  var newTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
  gBrowser.selectedTab = newTab;

  let browser = newTab.linkedBrowser;
  let frameLoader = browser.frameLoader;
  ok(frameLoader !== null, "frameLoader looks okay");

  browser.messageManager.loadFrameScript(
    "data:,(" + frameScript.toString() + ")()",
    false
  );

  browser.messageManager.addMessageListener("Test:Message", msg => {
    ok(msg.target === browser, "<browser> is correct");
    ok(msg.targetFrameLoader === frameLoader, "frameLoader is correct");
    ok(
      browser.frameLoader === msg.targetFrameLoader,
      "browser frameloader is correct"
    );
  });

  browser.messageManager.addMessageListener("Test:Done", () => {
    info("Finished");
    gBrowser.removeCurrentTab();
    finish();
  });
}