test-window-tabs.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. const tabs = require('sdk/tabs');
  3. const { isPrivate } = require('sdk/private-browsing');
  4. const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
  5. const { promise: windowPromise, close, focus } = require('sdk/window/helpers');
  6. const { getMostRecentBrowserWindow } = require('sdk/window/utils');
  7. exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
  8. let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
  9. windowPromise(window, 'load').then(focus).then(function (window) {
  10. assert.ok(isPrivate(window), 'new window is private');
  11. tabs.open({
  12. url: 'about:blank',
  13. onOpen: function(tab) {
  14. assert.ok(isPrivate(tab), 'new tab is private');
  15. assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
  16. assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
  17. close(window).then(done, assert.fail);
  18. }
  19. })
  20. }, assert.fail).then(null, assert.fail);
  21. }
  22. exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
  23. let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
  24. windowPromise(window, 'load').then(focus).then(function (window) {
  25. assert.equal(isPrivate(window), false, 'new window is not private');
  26. tabs.open({
  27. url: 'about:blank',
  28. onOpen: function(tab) {
  29. assert.equal(isPrivate(tab), false, 'new tab is not private');
  30. assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
  31. assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
  32. close(window).then(done, assert.fail);
  33. }
  34. })
  35. }, assert.fail).then(null, assert.fail);
  36. }
  37. exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(assert, done) {
  38. let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
  39. windowPromise(window, 'load').then(focus).then(function (window) {
  40. assert.ok(isPrivate(window), 'new window is private');
  41. tabs.open({
  42. url: 'about:blank',
  43. isPrivate: true,
  44. onOpen: function(tab) {
  45. assert.ok(isPrivate(tab), 'new tab is private');
  46. assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
  47. assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
  48. close(window).then(done, assert.fail);
  49. }
  50. })
  51. }, assert.fail).then(null, assert.fail);
  52. }
  53. exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function(assert, done) {
  54. let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
  55. windowPromise(window, 'load').then(focus).then(function (window) {
  56. assert.equal(isPrivate(window), false, 'new window is not private');
  57. tabs.open({
  58. url: 'about:blank',
  59. isPrivate: false,
  60. onOpen: function(tab) {
  61. assert.equal(isPrivate(tab), false, 'new tab is not private');
  62. assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
  63. assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
  64. close(window).then(done, assert.fail);
  65. }
  66. })
  67. }, assert.fail).then(null, assert.fail);
  68. }