test-panel.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict';
  2. const { open, focus, close } = require('sdk/window/helpers');
  3. const { isPrivate } = require('sdk/private-browsing');
  4. const { defer } = require('sdk/core/promise');
  5. const { browserWindows: windows } = require('sdk/windows');
  6. const BROWSER = 'chrome://browser/content/browser.xul';
  7. exports.testRequirePanel = function(assert) {
  8. require('sdk/panel');
  9. assert.ok('the panel module should not throw an error');
  10. };
  11. exports.testShowPanelInPrivateWindow = function(assert, done) {
  12. let panel = require('sdk/panel').Panel({
  13. contentURL: "data:text/html;charset=utf-8,"
  14. });
  15. assert.ok(windows.length > 0, 'there is at least one open window');
  16. for (let window of windows) {
  17. assert.equal(isPrivate(window), false, 'open window is private');
  18. }
  19. testShowPanel(assert, panel).
  20. then(makeEmptyPrivateBrowserWindow).
  21. then(focus).
  22. then(function(window) {
  23. assert.equal(isPrivate(window), true, 'opened window is private');
  24. assert.pass('private window was focused');
  25. return window;
  26. }).
  27. then(function(window) {
  28. let { promise, resolve } = defer();
  29. assert.ok(!panel.isShowing, 'the panel is not showing [1]');
  30. panel.once('show', function() {
  31. assert.ok(panel.isShowing, 'the panel is showing');
  32. panel.once('hide', function() {
  33. assert.ok(!panel.isShowing, 'the panel is not showing [2]');
  34. resolve(window);
  35. });
  36. panel.hide();
  37. });
  38. panel.show();
  39. return promise;
  40. }).
  41. then(close).
  42. then(done, assert.fail.bind(assert));
  43. };
  44. function makeEmptyPrivateBrowserWindow(options) {
  45. options = options || {};
  46. return open(BROWSER, {
  47. features: {
  48. chrome: true,
  49. toolbar: true,
  50. private: true
  51. }
  52. });
  53. }
  54. function testShowPanel(assert, panel) {
  55. let { promise, resolve } = defer();
  56. let shown = false;
  57. assert.ok(!panel.isShowing, 'the panel is not showing [1]');
  58. panel.once('hide', function() {
  59. assert.ok(!panel.isShowing, 'the panel is not showing [2]');
  60. assert.ok(shown, 'the panel was shown')
  61. resolve(null);
  62. });
  63. panel.once('show', function() {
  64. shown = true;
  65. assert.ok(panel.isShowing, 'the panel is showing');
  66. panel.hide();
  67. });
  68. panel.show();
  69. return promise;
  70. }
  71. //Test disabled because of bug 911071
  72. module.exports = {}