exports.testWindowIteratorPrivateDefault = function*(assert) { assert.equal(browserWindows.length, 1, 'only one window open'); let window = yield open('chrome://browser/content/browser.xul', { features: { private: true, chrome: true } }); yield focus(window); // test that there is a private window opened assert.equal(isPrivate(window), true, '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'); } };
exports.testShowHideSDKWindowArg = function*(assert) { const { Sidebar } = require('sdk/ui/sidebar'); let testName = 'testShowHideSDKWindowArg'; let sidebar = Sidebar({ id: testName, title: testName, url: 'data:text/html;charset=utf-8,' + testName }); let mainWindow = getMostRecentBrowserWindow(); let newWindow = yield open().then(focus); let newSDKWindow = modelFor(newWindow); yield focus(mainWindow); yield sidebar.show(newSDKWindow); assert.pass('the sidebar was shown'); assert.ok(!isSidebarShowing(mainWindow), 'sidebar is not showing in main window'); assert.ok(isSidebarShowing(newWindow), 'sidebar is showing in new window'); assert.ok(isFocused(mainWindow), 'main window is still focused'); yield sidebar.hide(newSDKWindow); assert.ok(isFocused(mainWindow), 'main window is still focused'); assert.ok(!isSidebarShowing(mainWindow), 'sidebar is not showing in main window'); assert.ok(!isSidebarShowing(newWindow), 'sidebar is not showing in new window'); sidebar.destroy(); }
let win2 = openBrowserWindow(function() { assert.pass("window 2 is open"); focus(win2).then(function() { tabs.on("activate", function onActivate(tab) { tabs.removeListener("activate", onActivate); if (tab.readyState === 'uninitialized') { tab.once('ready', whenReady); } else { whenReady(tab); } 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); } }); win1.focus(); }); }, "data:text/html;charset=utf-8,test window focus changes active tab</br><h1>Window #2");
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'); };
onOpen: function(window) { focus(viewFor(window)).then((window) => { assert.ok(isFocused(window), 'the new window is focused'); assert.ok(isFocused(browserWindows.activeWindow), 'the active window is focused'); assert.ok(!isFocused(mainWindow), 'the main window is not focused'); done(); }) }
exports.testShowHideRawWindowArg = function*(assert) { const { Sidebar } = require('sdk/ui/sidebar'); let testName = 'testShowHideRawWindowArg'; assert.pass("Creating sidebar"); let sidebar = Sidebar({ id: testName, title: testName, url: 'data:text/html;charset=utf-8,' + testName }); assert.pass("Created sidebar"); let mainWindow = getMostRecentBrowserWindow(); let newWindow = yield windowPromise(mainWindow.OpenBrowserWindow(), 'load'); assert.pass("Created the new window"); yield focus(newWindow); assert.pass("Focused the new window"); let newWindow2 = yield windowPromise(mainWindow.OpenBrowserWindow(), 'load'); assert.pass("Created the second new window"); yield focus(newWindow2); assert.pass("Focused the second new window"); yield sidebar.show(newWindow); assert.pass('the sidebar was shown'); assert.equal(isSidebarShowing(mainWindow), false, 'sidebar is not showing in main window'); assert.equal(isSidebarShowing(newWindow2), false, 'sidebar is not showing in second window'); assert.equal(isSidebarShowing(newWindow), true, 'sidebar is showing in new window'); assert.ok(isFocused(newWindow2), 'main window is still focused'); yield sidebar.hide(newWindow); assert.equal(isFocused(newWindow2), true, 'second window is still focused'); assert.equal(isSidebarShowing(mainWindow), false, 'sidebar is not showing in main window'); assert.equal(isSidebarShowing(newWindow2), false, 'sidebar is not showing in second window'); assert.equal(isSidebarShowing(newWindow), false, 'sidebar is not showing in new window'); sidebar.destroy(); }
function() { assert.strictEqual(winUtils.activeWindow, browserWindow, "Correct active window [1]"); assert.strictEqual(winUtils.activeBrowserWindow, browserWindow, "Correct active browser window [1]"); // test focus(window) focus(window).then(nextTest); },
exports.testURLSetterToSameValueReloadsSidebar = function*(assert) { const { Sidebar } = require('sdk/ui/sidebar'); let testName = 'testURLSetterToSameValueReloadsSidebar'; let window = getMostRecentBrowserWindow(); let { document } = window; let url = 'data:text/html;charset=utf-8,'+testName; let sidebar1 = Sidebar({ id: testName, title: testName, url: url }); assert.equal(sidebar1.url, url, 'url getter works'); assert.equal(isShowing(sidebar1), false, 'the sidebar is not showing'); assert.ok(!isChecked(document.getElementById(makeID(sidebar1.id))), 'the menuitem is not checked'); assert.equal(isSidebarShowing(window), false, 'the new window sidebar is not showing'); window = yield windowPromise(window.OpenBrowserWindow(), 'load'); document = window.document; assert.pass('new window was opened'); yield focus(window); assert.pass('new window was focused'); yield sidebar1.show(); assert.equal(isShowing(sidebar1), true, 'the sidebar is showing'); assert.ok(isChecked(document.getElementById(makeID(sidebar1.id))), 'the menuitem is checked'); assert.ok(isSidebarShowing(window), 'the new window sidebar is showing'); let shown = defer(); sidebar1.once('show', shown.resolve); sidebar1.url = url; assert.equal(sidebar1.url, url, 'url getter works'); assert.equal(isShowing(sidebar1), true, 'the sidebar is showing'); assert.ok(isSidebarShowing(window), 'the new window sidebar is showing'); yield shown.promise; 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(); }
selection.once("select", function() { assert.equal(browserWindows.length, 2, "there should be only two windows open."); assert.equal(getTabs().length, 2, "there should be only two tabs open: '" + getTabs().map(tab => getTabTitle(tab)).join("', '") + "'." ); // window should be focused, but force the focus anyhow.. see bug 841823 focus(window).then(function() { assert.equal(selection.text, "noodles"); closeWindow(window). then(loader.unload). then(done). then(null, assert.fail); }); });
exports['test button click'] = function*(assert) { let loader = Loader(module); let { ActionButton } = loader.require('sdk/ui'); let { browserWindows } = loader.require('sdk/windows'); let labels = []; let button = ActionButton({ id: 'my-button-8', label: 'my button', icon: './icon.png', onClick: ({label}) => labels.push(label) }); let mainWindow = browserWindows.activeWindow; let chromeWindow = getMostRecentBrowserWindow(); let window = yield openBrowserWindow().then(focus); button.state(mainWindow, { label: 'nothing' }); button.state(mainWindow.tabs.activeTab, { label: 'foo'}) button.state(browserWindows.activeWindow, { label: 'bar' }); button.click(); yield focus(chromeWindow); button.click(); assert.deepEqual(labels, ['bar', 'foo'], 'button click works'); yield close(window); loader.unload(); }