michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0: 'use strict';
michael@0:
michael@0: const { Loader } = require('sdk/test/loader');
michael@0: const { browserWindows } = require('sdk/windows');
michael@0: const { viewFor } = require('sdk/view/core');
michael@0: const { modelFor } = require('sdk/model/core');
michael@0: const { Ci } = require("chrome");
michael@0: const { isBrowser, getWindowTitle } = require("sdk/window/utils");
michael@0:
michael@0: // TEST: browserWindows Iterator
michael@0: exports.testBrowserWindowsIterator = function(assert) {
michael@0: let activeWindowCount = 0;
michael@0: let windows = [];
michael@0: let i = 0;
michael@0: for each (let window in browserWindows) {
michael@0: if (window === browserWindows.activeWindow)
michael@0: activeWindowCount++;
michael@0:
michael@0: assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
michael@0: assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
michael@0: windows.push(window);
michael@0: }
michael@0: assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
michael@0:
michael@0: i = 0;
michael@0: for (let j in browserWindows) {
michael@0: assert.equal(j, i++, 'for (x in browserWindows) works');
michael@0: }
michael@0: };
michael@0:
michael@0:
michael@0: exports.testWindowTabsObject_alt = function(assert, done) {
michael@0: let window = browserWindows.activeWindow;
michael@0: window.tabs.open({
michael@0: url: 'data:text/html;charset=utf-8,
tab 2',
michael@0: inBackground: true,
michael@0: onReady: function onReady(tab) {
michael@0: assert.equal(tab.title, 'tab 2', 'Correct new tab title');
michael@0: assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
michael@0:
michael@0: // end test
michael@0: tab.close(done);
michael@0: }
michael@0: });
michael@0: };
michael@0:
michael@0: // TEST: browserWindows.activeWindow
michael@0: exports.testWindowActivateMethod_simple = function(assert) {
michael@0: let window = browserWindows.activeWindow;
michael@0: let tab = window.tabs.activeTab;
michael@0:
michael@0: window.activate();
michael@0:
michael@0: assert.equal(browserWindows.activeWindow, window,
michael@0: 'Active window is active after window.activate() call');
michael@0: assert.equal(window.tabs.activeTab, tab,
michael@0: 'Active tab is active after window.activate() call');
michael@0: };
michael@0:
michael@0:
michael@0: exports["test getView(window)"] = function(assert, done) {
michael@0: browserWindows.once("open", window => {
michael@0: const view = viewFor(window);
michael@0:
michael@0: assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
michael@0: assert.ok(isBrowser(view), "view is a browser window");
michael@0: assert.equal(getWindowTitle(view), window.title,
michael@0: "window has a right title");
michael@0:
michael@0: window.close(done);
michael@0: });
michael@0:
michael@0:
michael@0: browserWindows.open({ url: "data:text/html;charset=utf-8,yo" });
michael@0: };
michael@0:
michael@0:
michael@0: exports["test modelFor(window)"] = function(assert, done) {
michael@0: browserWindows.once("open", window => {
michael@0: const view = viewFor(window);
michael@0:
michael@0: assert.ok(view instanceof Ci.nsIDOMWindow, "view is a window");
michael@0: assert.ok(isBrowser(view), "view is a browser window");
michael@0: assert.ok(modelFor(view) === window, "modelFor(browserWindow) is SDK window");
michael@0:
michael@0: window.close(done);
michael@0: });
michael@0:
michael@0:
michael@0: browserWindows.open({ url: "data:text/html;charset=utf-8,yo" });
michael@0: };
michael@0:
michael@0: require('sdk/test').run(exports);