2013-02-01 13:17:34 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { Loader } = require('sdk/test/loader');
|
|
|
|
const { browserWindows } = require('sdk/windows');
|
2013-11-27 16:43:04 -08:00
|
|
|
const { Ci } = require("chrome");
|
2013-02-01 13:17:34 -08:00
|
|
|
|
|
|
|
// TEST: browserWindows Iterator
|
2013-07-09 19:15:10 -07:00
|
|
|
exports.testBrowserWindowsIterator = function(assert) {
|
2013-02-01 13:17:34 -08:00
|
|
|
let activeWindowCount = 0;
|
|
|
|
let windows = [];
|
|
|
|
let i = 0;
|
|
|
|
for each (let window in browserWindows) {
|
|
|
|
if (window === browserWindows.activeWindow)
|
|
|
|
activeWindowCount++;
|
|
|
|
|
2013-07-09 19:15:10 -07:00
|
|
|
assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
|
|
|
|
assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
|
2013-02-01 13:17:34 -08:00
|
|
|
windows.push(window);
|
|
|
|
}
|
2013-07-09 19:15:10 -07:00
|
|
|
assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
|
2013-02-01 13:17:34 -08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (let j in browserWindows) {
|
2013-07-09 19:15:10 -07:00
|
|
|
assert.equal(j, i++, 'for (x in browserWindows) works');
|
2013-02-01 13:17:34 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-19 14:50:18 -08:00
|
|
|
|
2013-07-09 19:15:10 -07:00
|
|
|
exports.testWindowTabsObject_alt = function(assert, done) {
|
2013-02-01 13:17:34 -08:00
|
|
|
let window = browserWindows.activeWindow;
|
|
|
|
window.tabs.open({
|
2013-07-09 19:15:10 -07:00
|
|
|
url: 'data:text/html;charset=utf-8,<title>tab 2</title>',
|
2013-02-01 13:17:34 -08:00
|
|
|
inBackground: true,
|
|
|
|
onReady: function onReady(tab) {
|
2013-07-09 19:15:10 -07:00
|
|
|
assert.equal(tab.title, 'tab 2', 'Correct new tab title');
|
|
|
|
assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
|
2013-02-01 13:17:34 -08:00
|
|
|
|
|
|
|
// end test
|
2013-07-09 19:15:10 -07:00
|
|
|
tab.close(done);
|
2013-02-01 13:17:34 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// TEST: browserWindows.activeWindow
|
2013-07-09 19:15:10 -07:00
|
|
|
exports.testWindowActivateMethod_simple = function(assert) {
|
2013-02-01 13:17:34 -08:00
|
|
|
let window = browserWindows.activeWindow;
|
|
|
|
let tab = window.tabs.activeTab;
|
|
|
|
|
|
|
|
window.activate();
|
|
|
|
|
2013-07-09 19:15:10 -07:00
|
|
|
assert.equal(browserWindows.activeWindow, window,
|
|
|
|
'Active window is active after window.activate() call');
|
|
|
|
assert.equal(window.tabs.activeTab, tab,
|
|
|
|
'Active tab is active after window.activate() call');
|
2013-02-01 13:17:34 -08:00
|
|
|
};
|
2013-07-09 19:15:10 -07:00
|
|
|
|
|
|
|
require('sdk/test').run(exports);
|