michael@0: 'use strict'; michael@0: michael@0: const { open, focus, close } = require('sdk/window/helpers'); michael@0: const { isPrivate } = require('sdk/private-browsing'); michael@0: const { defer } = require('sdk/core/promise'); michael@0: const { browserWindows: windows } = require('sdk/windows'); michael@0: michael@0: const BROWSER = 'chrome://browser/content/browser.xul'; michael@0: michael@0: exports.testRequirePanel = function(assert) { michael@0: require('sdk/panel'); michael@0: assert.ok('the panel module should not throw an error'); michael@0: }; michael@0: michael@0: exports.testShowPanelInPrivateWindow = function(assert, done) { michael@0: let panel = require('sdk/panel').Panel({ michael@0: contentURL: "data:text/html;charset=utf-8," michael@0: }); michael@0: michael@0: assert.ok(windows.length > 0, 'there is at least one open window'); michael@0: for (let window of windows) { michael@0: assert.equal(isPrivate(window), false, 'open window is private'); michael@0: } michael@0: michael@0: testShowPanel(assert, panel). michael@0: then(makeEmptyPrivateBrowserWindow). michael@0: then(focus). michael@0: then(function(window) { michael@0: assert.equal(isPrivate(window), true, 'opened window is private'); michael@0: assert.pass('private window was focused'); michael@0: return window; michael@0: }). michael@0: then(function(window) { michael@0: let { promise, resolve } = defer(); michael@0: michael@0: assert.ok(!panel.isShowing, 'the panel is not showing [1]'); michael@0: michael@0: panel.once('show', function() { michael@0: assert.ok(panel.isShowing, 'the panel is showing'); michael@0: michael@0: panel.once('hide', function() { michael@0: assert.ok(!panel.isShowing, 'the panel is not showing [2]'); michael@0: michael@0: resolve(window); michael@0: }); michael@0: michael@0: panel.hide(); michael@0: }); michael@0: michael@0: panel.show(); michael@0: michael@0: return promise; michael@0: }). michael@0: then(close). michael@0: then(done). michael@0: then(null, assert.fail); michael@0: }; michael@0: michael@0: michael@0: function makeEmptyPrivateBrowserWindow(options) { michael@0: options = options || {}; michael@0: return open(BROWSER, { michael@0: features: { michael@0: chrome: true, michael@0: toolbar: true, michael@0: private: true michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function testShowPanel(assert, panel) { michael@0: let { promise, resolve } = defer(); michael@0: let shown = false; michael@0: michael@0: assert.ok(!panel.isShowing, 'the panel is not showing [1]'); michael@0: michael@0: panel.once('hide', function() { michael@0: assert.ok(!panel.isShowing, 'the panel is not showing [2]'); michael@0: assert.ok(shown, 'the panel was shown') michael@0: michael@0: resolve(null); michael@0: }); michael@0: michael@0: panel.once('show', function() { michael@0: shown = true; michael@0: michael@0: assert.ok(panel.isShowing, 'the panel is showing'); michael@0: michael@0: panel.hide(); michael@0: }); michael@0: michael@0: panel.show(); michael@0: michael@0: return promise; michael@0: } michael@0: michael@0: //Test disabled because of bug 911071 michael@0: module.exports = {}