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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 'use strict';
     6 const { Loader } = require('sdk/test/loader');
     7 const { browserWindows } = require('sdk/windows');
     8 const { viewFor } = require('sdk/view/core');
     9 const { modelFor } = require('sdk/model/core');
    10 const { Ci } = require("chrome");
    11 const { isBrowser, getWindowTitle } = require("sdk/window/utils");
    13 // TEST: browserWindows Iterator
    14 exports.testBrowserWindowsIterator = function(assert) {
    15   let activeWindowCount = 0;
    16   let windows = [];
    17   let i = 0;
    18   for each (let window in browserWindows) {
    19     if (window === browserWindows.activeWindow)
    20       activeWindowCount++;
    22     assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
    23     assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
    24     windows.push(window);
    25   }
    26   assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
    28   i = 0;
    29   for (let j in browserWindows) {
    30     assert.equal(j, i++, 'for (x in browserWindows) works');
    31   }
    32 };
    35 exports.testWindowTabsObject_alt = function(assert, done) {
    36   let window = browserWindows.activeWindow;
    37   window.tabs.open({
    38     url: 'data:text/html;charset=utf-8,<title>tab 2</title>',
    39     inBackground: true,
    40     onReady: function onReady(tab) {
    41       assert.equal(tab.title, 'tab 2', 'Correct new tab title');
    42       assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
    44       // end test
    45       tab.close(done);
    46     }
    47   });
    48 };
    50 // TEST: browserWindows.activeWindow
    51 exports.testWindowActivateMethod_simple = function(assert) {
    52   let window = browserWindows.activeWindow;
    53   let tab = window.tabs.activeTab;
    55   window.activate();
    57   assert.equal(browserWindows.activeWindow, window,
    58                'Active window is active after window.activate() call');
    59   assert.equal(window.tabs.activeTab, tab,
    60                'Active tab is active after window.activate() call');
    61 };
    64 exports["test getView(window)"] = function(assert, done) {
    65   browserWindows.once("open", window => {
    66     const view = viewFor(window);
    68     assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
    69     assert.ok(isBrowser(view), "view is a browser window");
    70     assert.equal(getWindowTitle(view), window.title,
    71                  "window has a right title");
    73     window.close(done);
    74   });
    77   browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
    78 };
    81 exports["test modelFor(window)"] = function(assert, done) {
    82   browserWindows.once("open", window => {
    83     const view = viewFor(window);
    85     assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
    86     assert.ok(isBrowser(view), "view is a browser window");
    87     assert.ok(modelFor(view) === window, "modelFor(browserWindow) is SDK window");
    89     window.close(done);
    90   });
    93   browserWindows.open({ url: "data:text/html;charset=utf-8,<title>yo</title>" });
    94 };
    96 require('sdk/test').run(exports);

mercurial