test-tab-utils.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. 'use strict';
  2. const { getTabs } = require('sdk/tabs/utils');
  3. const { isGlobalPBSupported, isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
  4. const { browserWindows } = require('sdk/windows');
  5. const tabs = require('sdk/tabs');
  6. const { pb } = require('./private-browsing/helper');
  7. const { isPrivate } = require('sdk/private-browsing');
  8. const { openTab, closeTab, getTabContentWindow, getOwnerWindow } = require('sdk/tabs/utils');
  9. const { open, close } = require('sdk/window/helpers');
  10. const { windows } = require('sdk/window/utils');
  11. const { getMostRecentBrowserWindow } = require('sdk/window/utils');
  12. const { fromIterator } = require('sdk/util/array');
  13. if (isWindowPBSupported) {
  14. exports.testGetTabs = function(assert, done) {
  15. let tabCount = getTabs().length;
  16. let windowCount = browserWindows.length;
  17. open(null, {
  18. features: {
  19. private: true,
  20. toolbar: true,
  21. chrome: true
  22. }
  23. }).then(function(window) {
  24. assert.ok(isPrivate(window), 'new tab is private');
  25. assert.equal(getTabs().length, tabCount, 'there are no new tabs found');
  26. getTabs().forEach(function(tab) {
  27. assert.equal(isPrivate(tab), false, 'all found tabs are not private');
  28. assert.equal(isPrivate(getOwnerWindow(tab)), false, 'all found tabs are not private');
  29. assert.equal(isPrivate(getTabContentWindow(tab)), false, 'all found tabs are not private');
  30. });
  31. assert.equal(browserWindows.length, windowCount, 'there are no new windows found');
  32. fromIterator(browserWindows).forEach(function(window) {
  33. assert.equal(isPrivate(window), false, 'all found windows are not private');
  34. });
  35. assert.equal(windows(null, {includePrivate: true}).length, 2, 'there are really two windows');
  36. close(window).then(done);
  37. });
  38. };
  39. }
  40. else if (isTabPBSupported) {
  41. exports.testGetTabs = function(assert, done) {
  42. let startTabCount = getTabs().length;
  43. let tab = openTab(getMostRecentBrowserWindow(), 'about:blank', {
  44. isPrivate: true
  45. });
  46. assert.ok(isPrivate(getTabContentWindow(tab)), 'new tab is private');
  47. let utils_tabs = getTabs();
  48. assert.equal(utils_tabs.length, startTabCount + 1,
  49. 'there are two tabs found');
  50. assert.equal(utils_tabs[utils_tabs.length-1], tab,
  51. 'the last tab is the opened tab');
  52. assert.equal(browserWindows.length, 1, 'there is only one window');
  53. closeTab(tab);
  54. done();
  55. };
  56. }
  57. require('test').run(exports);