addon-sdk/source/test/test-windows-common.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/test/test-windows-common.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +'use strict';
     1.8 +
     1.9 +const { Loader } = require('sdk/test/loader');
    1.10 +const { browserWindows } = require('sdk/windows');
    1.11 +const { viewFor } = require('sdk/view/core');
    1.12 +const { modelFor } = require('sdk/model/core');
    1.13 +const { Ci } = require("chrome");
    1.14 +const { isBrowser, getWindowTitle } = require("sdk/window/utils");
    1.15 +
    1.16 +// TEST: browserWindows Iterator
    1.17 +exports.testBrowserWindowsIterator = function(assert) {
    1.18 +  let activeWindowCount = 0;
    1.19 +  let windows = [];
    1.20 +  let i = 0;
    1.21 +  for each (let window in browserWindows) {
    1.22 +    if (window === browserWindows.activeWindow)
    1.23 +      activeWindowCount++;
    1.24 +
    1.25 +    assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
    1.26 +    assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
    1.27 +    windows.push(window);
    1.28 +  }
    1.29 +  assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
    1.30 +
    1.31 +  i = 0;
    1.32 +  for (let j in browserWindows) {
    1.33 +    assert.equal(j, i++, 'for (x in browserWindows) works');
    1.34 +  }
    1.35 +};
    1.36 +
    1.37 +
    1.38 +exports.testWindowTabsObject_alt = function(assert, done) {
    1.39 +  let window = browserWindows.activeWindow;
    1.40 +  window.tabs.open({
    1.41 +    url: 'data:text/html;charset=utf-8,<title>tab 2</title>',
    1.42 +    inBackground: true,
    1.43 +    onReady: function onReady(tab) {
    1.44 +      assert.equal(tab.title, 'tab 2', 'Correct new tab title');
    1.45 +      assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
    1.46 +
    1.47 +      // end test
    1.48 +      tab.close(done);
    1.49 +    }
    1.50 +  });
    1.51 +};
    1.52 +
    1.53 +// TEST: browserWindows.activeWindow
    1.54 +exports.testWindowActivateMethod_simple = function(assert) {
    1.55 +  let window = browserWindows.activeWindow;
    1.56 +  let tab = window.tabs.activeTab;
    1.57 +
    1.58 +  window.activate();
    1.59 +
    1.60 +  assert.equal(browserWindows.activeWindow, window,
    1.61 +               'Active window is active after window.activate() call');
    1.62 +  assert.equal(window.tabs.activeTab, tab,
    1.63 +               'Active tab is active after window.activate() call');
    1.64 +};
    1.65 +
    1.66 +
    1.67 +exports["test getView(window)"] = function(assert, done) {
    1.68 +  browserWindows.once("open", window => {
    1.69 +    const view = viewFor(window);
    1.70 +
    1.71 +    assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
    1.72 +    assert.ok(isBrowser(view), "view is a browser window");
    1.73 +    assert.equal(getWindowTitle(view), window.title,
    1.74 +                 "window has a right title");
    1.75 +
    1.76 +    window.close(done);
    1.77 +  });
    1.78 +
    1.79 +
    1.80 +  browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
    1.81 +};
    1.82 +
    1.83 +
    1.84 +exports["test modelFor(window)"] = function(assert, done) {
    1.85 +  browserWindows.once("open", window => {
    1.86 +    const view = viewFor(window);
    1.87 +
    1.88 +    assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
    1.89 +    assert.ok(isBrowser(view), "view is a browser window");
    1.90 +    assert.ok(modelFor(view) === window, "modelFor(browserWindow) is SDK window");
    1.91 +
    1.92 +    window.close(done);
    1.93 +  });
    1.94 +
    1.95 +
    1.96 +  browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
    1.97 +};
    1.98 +
    1.99 +require('sdk/test').run(exports);

mercurial