Example #1
0
exports.testActiveWindow = function*(assert) {
  let windows = browserWindows;
  let window = getMostRecentWindow();

  // Raw window objects
  let rawWindow2 =  yield windowPromise(window.OpenBrowserWindow(), "load").then(focus);
  assert.pass("Window 2 was created");

  // open a tab in window 2
  yield openTab(rawWindow2, "data:text/html;charset=utf-8,<title>window 2</title>");

  assert.equal(rawWindow2.content.document.title, "window 2", "Got correct raw window 2");
  assert.equal(rawWindow2.document.title, windows[1].title, "Saw correct title on window 2");

  let rawWindow3 =  yield windowPromise(window.OpenBrowserWindow(), "load").then(focus);;
  assert.pass("Window 3 was created");

  // open a tab in window 3
  yield openTab(rawWindow3, "data:text/html;charset=utf-8,<title>window 3</title>");

  assert.equal(rawWindow3.content.document.title, "window 3", "Got correct raw window 3");
  assert.equal(rawWindow3.document.title, windows[2].title, "Saw correct title on window 3");

  assert.equal(windows.length, 3, "Correct number of browser windows");

  let count = 0;
  for (let window in windows) {
    count++;
  }
  assert.equal(count, 3, "Correct number of windows returned by iterator");
  assert.equal(windows.activeWindow.title, windows[2].title, "Correct active window title - 3");
  let window3 = windows[2];

  yield focus(rawWindow2);

  assert.equal(windows.activeWindow.title, windows[1].title, "Correct active window title - 2");
  let window2 = windows[1];

  yield new Promise(resolve => {
    onFocus(rawWindow2).then(resolve);
    window2.activate();
    assert.pass("activating window2");
  });

  assert.equal(windows.activeWindow.title, windows[1].title, "Correct active window - 2");

  yield new Promise(resolve => {
    onFocus(rawWindow3).then(resolve);
    window3.activate();
    assert.pass("activating window3");
  });

  assert.equal(windows.activeWindow.title, window3.title, "Correct active window - 3");

  yield close(rawWindow2);
  assert.equal(rawWindow2.closed, true, 'window 2 is closed');

  yield close(rawWindow3);
  assert.equal(rawWindow3.closed, true, 'window 3 is closed');
};
Example #2
0
exports.testTabsEvent_onClose = function*(assert) {
  let window = yield open().then(focus);
  let url = "data:text/html;charset=utf-8,onclose";
  let eventCount = 0;

  // add listener via property assignment
  function listener1(tab) {
    eventCount++;
  }
  tabs.on("close", listener1);

  yield new Promise(resolve => {
    // add listener via collection add
    tabs.on("close", function listener2(tab) {
      assert.equal(++eventCount, 2, "both listeners notified");
      tabs.removeListener("close", listener2);
      resolve();
    });

    tabs.on('ready', function onReady(tab) {
      tabs.removeListener('ready', onReady);
      tab.close();
    });

    tabs.open(url);
  });

  tabs.removeListener("close", listener1);
  assert.pass("done test!");

  yield close(window);
  assert.pass("window was closed!");
};
Example #3
0
 require("sdk/tabs").on("ready", function onReady(tab) {
   if (tab.url === uri) {
     require("sdk/tabs").removeListener("ready", onReady);
     assert.pass("ready event was emitted");
     close(window).then(done).then(null, assert.fail);
   }
 });
Example #4
0
 tabs.on('ready', function onReady(tab) {
   if (tab.url != url2)
     return;
   tabs.removeListener('ready', onReady);
   assert.pass("tab.load() loaded the correct url");
   close(window).then(done).then(null, assert.fail);
 });
Example #5
0
exports["test toolbar unload"] = function*(assert) {
  // We override add-on id, otherwise two instances of Toolbar host (view.js)
  // handling same updates, cause message port is bound to add-on id.
  const loader = Loader(module, null, null, {id: "toolbar-unload-addon"});
  const { Toolbar } = loader.require("sdk/ui/toolbar");

  const w1 = getMostRecentBrowserWindow();
  const w2 = open();

  yield ready(w2);

  const t1 = new Toolbar({ title: "unload" });

  yield wait(t1, "attach");

  assert.ok(isAttached(t1, w1) && isAttached(t1, w2),
            "attached to both windows");


  loader.unload();


  assert.ok(!isAttached(t1, w1) && !isAttached(t1, w2),
            "detached from both windows on unload");

  yield close(w2);
};
exports['test new top window with various URIs'] = function(assert, done) {
  let msg = 'only chrome, resource and data uris are allowed';
  assert.throws(function () {
    open('foo');
  }, msg);
  assert.throws(function () {
    open('http://foo');
  }, msg);
  assert.throws(function () {
    open('https://foo');
  }, msg); 
  assert.throws(function () {
    open('ftp://foo');
  }, msg);
  assert.throws(function () {
    open('//foo');
  }, msg);

  let chromeWindow = open('chrome://foo/content/');
  assert.ok(~windows().indexOf(chromeWindow), 'chrome URI works');
  
  let resourceWindow = open('resource://foo');
  assert.ok(~windows().indexOf(resourceWindow), 'resource URI works');

  // Wait for the window unload before ending test
  close(chromeWindow).then(close.bind(null, resourceWindow)).then(done);
};
exports['test top window creation'] = function(assert, done) {
  let window = open('data:text/html;charset=utf-8,Hello top window');
  assert.ok(~windows().indexOf(window), 'window was opened');

  // Wait for the window unload before ending test
  close(window).then(done);
};
Example #8
0
    frame.contentWindow.addEventListener('DOMContentLoaded', function ready() {
      frame.contentWindow.removeEventListener('DOMContentLoaded', ready, false);
      assert.ok(~frame.contentDocument.documentElement.innerHTML.indexOf('JS'),
                'JS was executed');

      close(window).then(done);
    }, false);
Example #9
0
    function checkEnd() {
      if (detachEventCount != 2)
        return;

      assert.pass("Got all detach events");

      close(window).then(done).then(null, assert.fail);
    }
Example #10
0
      onFocus(newWindow).then(function() {
        assert.equal(getMostRecentBrowserWindow(), newWindow, "new window is active");
        assert.equal(tab.url, url, "URL of the new tab matches");
        assert.equal(newWindow.content.location, url, "URL of new tab in new window matches");
        assert.equal(tabs.activeTab.url, url, "URL of activeTab matches");

        return close(newWindow).then(done);
      }).then(null, assert.fail);
Example #11
0
      onOpen: function(tab) {
        let count = 0;
        for (let t of tabs) count++;
        assert.equal(count, startCount + 3, "iterated tab count matches");
        assert.equal(startCount + 3, tabs.length, "iterated tab count matches length property");

        close(window).then(done).then(null, assert.fail);
      }
Example #12
0
      function() {
        assert.strictEqual(winUtils.activeBrowserWindow, browserWindow,
                          "Correct active browser window when pb mode is supported [4]");
        assert.strictEqual(winUtils.activeWindow, browserWindow,
                          "Correct active window when pb mode is supported [4]");

        close(window).then(done).then(null, assert.fail);
      }
Example #13
0
    onTrack: function(window) {
      if (window.document.documentElement.getAttribute('windowtype') === 'test:window') {
      	assert.pass('test xul window was opened');
        wt.unload();

      	close(window).then(done, assert.fail);
      }
    }
Example #14
0
  window.addEventListener("load", function onload() {
    window.addEventListener("load", onload);
    assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) !== -1,
              "window is now in windowIterator()");

    // Wait for the window unload before ending test
    close(window).then(done);
  });
Example #15
0
File: main.js Project: Croydon/jpm
    onTrack: function(window) {
      if (window.document.documentElement.getAttribute("windowtype") === "test:window") {
      	assert.pass("test xul window was opened");
        wt.unload();

      	close(window).then(done, assert.fail);
      }
    }
Example #16
0
          function whenReady(tab) {
            assert.pass("activate was called on windows focus change.");
            assert.equal(tab.url, url1, 'the activated tab url is correct');

            return close(win2).then(function() {
              assert.pass('window 2 was closed');
              return close(win1);
            }).then(done).then(null, assert.fail);
          }
Example #17
0
exports.testDestroyEdgeCaseBug = function*(assert) {
  const { Sidebar } = require('sdk/ui/sidebar');
  let testName = 'testDestroyEdgeCaseBug';
  let window = getMostRecentBrowserWindow();
  let sidebar = Sidebar({
    id: testName,
    title: testName,
    url: 'data:text/html;charset=utf-8,'+testName
  });

  // NOTE: purposely not listening to show event b/c the event happens
  //       between now and then.
  sidebar.show();

  assert.equal(isPrivate(window), false, 'the new window is not private');
  assert.equal(isSidebarShowing(window), true, 'the sidebar is showing');

  //assert.equal(isShowing(sidebar), true, 'the sidebar is showing');

  let window2 = yield open().then(focus);

  assert.equal(isPrivate(window2), false, 'the new window is not private');
  assert.equal(isSidebarShowing(window2), false, 'the sidebar is not showing');
  assert.equal(isShowing(sidebar), false, 'the sidebar is not showing');

  sidebar.destroy();
  assert.pass('destroying the sidebar');

  yield close(window2);

  let loader = Loader(module);

  assert.equal(isPrivate(window), false, 'the current window is not private');

  sidebar = loader.require('sdk/ui/sidebar').Sidebar({
    id: testName,
    title: testName,
    url:  'data:text/html;charset=utf-8,'+ testName,
    onShow: function() {
    }
  })

  assert.pass('showing the sidebar');
  yield sidebar.show();
  loader.unload();

  for (let mi of getSidebarMenuitems()) {
    let id = mi.getAttribute('id');

    if (BUILTIN_SIDEBAR_MENUITEMS.indexOf(id) < 0) {
      assert.fail('the menuitem "' + id + '" is not a built-in sidebar');
    }
    assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
  }
  assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
  assert.equal(isSidebarShowing(window), false, 'the sidebar is not showing');
}
 function onMessage2(message) {
   if (5 == message) {
     close(window).then(done);
   }
   else {
     assert.equal(message, 3, "Program gets message via onMessage2.");
     contentSymbiont.postMessage(4)
   }
 }
Example #19
0
    onTrack: function(window) {
      if (window == myWindow) {
        assert.pass("onTrack() called with our test window");

        close(myWindow).then(function() {
          wt.unload();
          done();
        }, assert.fail);
      }
    }
Example #20
0
 onReady: function(tab) {
   if (tab.url === url) {
     assert.equal(tab.contentType, "text/html");
     tab.url = urlXML;
   }
   else {
     assert.equal(tab.contentType, "text/xml");
     close(window).then(done).then(null, assert.fail);
   }
 }
Example #21
0
  open(null, { features: { private: true } }).then(function(window) {
      let ele = window.document.getElementById(makeID(testName));
      assert.ok(isPrivate(window), 'the new window is private');
      assert.ok(!!ele, 'sidebar element was added');

      sidebar.destroy();
      assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
      assert.ok(!startWindow.document.getElementById(makeID(testName)), 'sidebar id DNE');

      close(window).then(done, assert.fail);
  })
Example #22
0
  }).then(focus).then(function(window) {
    // test that there is a private window opened
    assert.equal(isPrivate(window), isWindowPBSupported, 'there is a private window open');
    assert.equal(isPrivate(winUtils.activeWindow), isWindowPBSupported);
    assert.equal(isPrivate(getMostRecentWindow()), isWindowPBSupported);
    assert.equal(isPrivate(browserWindows.activeWindow), isWindowPBSupported);

    assert.equal(browserWindows.length, 2, '2 windows open');
    assert.equal(windows(null, { includePrivate: true }).length, 2);

    return close(window);
  }).then(done).then(null, assert.fail);
exports.testBackgroundify = function(assert, done) {
  let window = open('data:text/html;charset=utf-8,backgroundy');
  assert.ok(~windows().indexOf(window),
            'window is in the list of windows');
  let backgroundy = backgroundify(window);
  assert.equal(backgroundy, window, 'backgroundify returs give window back');
  assert.ok(!~windows().indexOf(window),
            'backgroundifyied window is in the list of windows');

  // Wait for the window unload before ending test
  close(window).then(done);
};
Example #24
0
  open().then(function(window) {
      let ele = window.document.getElementById(makeID(testName));
      assert.ok(ele, 'sidebar element was added');

      // calling destroy twice should not matter
      sidebar.destroy();
      sidebar.destroy();

      assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
      assert.ok(!startWindow.document.getElementById(makeID(testName)), 'sidebar id DNE');

      close(window).then(done, assert.fail);
  })
Example #25
0
      sidebar1.once('show', function() {
        assert.pass('setting the sidebar.url causes a show event');

        assert.equal(isShowing(sidebar1), true, 'the sidebar is showing');
        assert.ok(isSidebarShowing(window), 'the new window sidebar is still showing');

        assert.ok(isChecked(document.getElementById(makeID(sidebar1.id))),
                     'the menuitem is still checked');

        sidebar1.destroy();

        close(window).then(done);
      });
Example #26
0
  open('data:text/html;charset=utf-8,Window').then(function (window) {
    let frame = create(window.document);

    assert.equal(frame.getAttribute('type'), 'content',
                 'frame type is content');
    assert.ok(frame.contentWindow, 'frame has contentWindow');
    assert.equal(frame.contentWindow.location.href, 'about:blank',
                 'by default "about:blank" is loaded');
    assert.equal(frame.docShell.allowAuth, false, 'auth disabled by default');
    assert.equal(frame.docShell.allowJavascript, false, 'js disabled by default');
    assert.equal(frame.docShell.allowPlugins, false,
                 'plugins disabled by default');
    close(window).then(done);
  });
exports['test new top window with options'] = function(assert, done) {
  let window = open('data:text/html;charset=utf-8,Hi custom top window', {
    name: 'test',
    features: { height: 100, width: 200, toolbar: true }
  });
  assert.ok(~windows().indexOf(window), 'window was opened');
  assert.equal(window.name, 'test', 'name was set');
  assert.equal(window.innerHeight, 100, 'height is set');
  assert.equal(window.innerWidth, 200, 'height is set');
  assert.equal(window.toolbar.visible, true, 'toolbar was set');

  // Wait for the window unload before ending test
  close(window).then(done);
};
Example #28
0
  window.addEventListener("load", function onload() {
    window.addEventListener("load", onload);

    assert.equal(windows().length, 2, "Two windows open");

    // Wait for the window unload before ending test
    let checked = false;

    close(window).then(function() {
      assert.ok(checked, 'the test is finished');
    }).then(done, assert.fail)

    assert.equal(windows().length, 1, "Only one window open");
    checked = true;
  });
Example #29
0
    }).then(function(window) {
      assert.ok(isPrivate(window), 'new tab is private');

      assert.equal(getTabs().length, tabCount, 'there are no new tabs found');
      getTabs().forEach(function(tab) {
        assert.equal(isPrivate(tab), false, 'all found tabs are not private');
        assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private');
        assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private');
      });

      assert.equal(browserWindows.length, windowCount, 'there are no new windows found');
      fromIterator(browserWindows).forEach(function(window) {
        assert.equal(isPrivate(window), false, 'all found windows are not private');
      });

      assert.equal(windows(null, {includePrivate: true}).length, 3, 'there are really three windows');

      close(window).then(done);
    });
Example #30
0
  }).then(focus).then(function(window) {
    // test that there is a private window opened
    assert.equal(isPrivate(window), isWindowPBSupported, 'there is a private window open');
    assert.strictEqual(window, winUtils.activeWindow);
    assert.strictEqual(window, getMostRecentWindow());

    assert.ok(!isPrivate(browserWindows.activeWindow));

    assert.equal(browserWindows.length, 1, 'only one window in browserWindows');
    assert.equal(windows().length, 1, 'only one window in windows()');

    assert.equal(windows(null, { includePrivate: true }).length, 2);

    // test that all windows in iterator are not private
    for (let window of browserWindows)
      assert.ok(!isPrivate(window), 'no window in browserWindows is private');

    close(window).then(done);
  });