summaryrefslogtreecommitdiff
path: root/browser/base/content/test/browser_bug880101.js
blob: abe05b8646df5790a6bd319f774f0b8b6d6baccb (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

const URL = "about:robots";

function test() {
  let win;

  let listener = {
    onLocationChange: (webProgress, request, uri, flags) => {
      ok(webProgress.isTopLevel, "Received onLocationChange from top frame");
      is(uri.spec, URL, "Received onLocationChange for correct URL");
      finish();
    }
  };

  waitForExplicitFinish();

  // Remove the listener and window when we're done.
  registerCleanupFunction(() => {
    win.gBrowser.removeProgressListener(listener);
    win.close();
  });

  // Wait for the newly opened window.
  whenNewWindowOpened(w => win = w);

  // Open a link in a new window.
  openLinkIn(URL, "window", {});

  // On the next tick, but before the window has finished loading, access the
  // window's gBrowser property to force the tabbrowser constructor early.
  (function tryAddProgressListener() {
    executeSoon(() => {
      try {
        win.gBrowser.addProgressListener(listener);
      } catch (e) {
        // win.gBrowser wasn't ready, yet. Try again in a tick.
        tryAddProgressListener();
      }
    });
  })();
}

function whenNewWindowOpened(cb) {
  Services.obs.addObserver(function obs(win) {
    Services.obs.removeObserver(obs, "domwindowopened");
    cb(win);
  }, "domwindowopened", false);
}