test-windows-common.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. 'use strict';
  5. const { Loader } = require('sdk/test/loader');
  6. const { browserWindows } = require('sdk/windows');
  7. const { Ci } = require("chrome");
  8. // TEST: browserWindows Iterator
  9. exports.testBrowserWindowsIterator = function(assert) {
  10. let activeWindowCount = 0;
  11. let windows = [];
  12. let i = 0;
  13. for each (let window in browserWindows) {
  14. if (window === browserWindows.activeWindow)
  15. activeWindowCount++;
  16. assert.equal(windows.indexOf(window), -1, 'window not already in iterator');
  17. assert.equal(browserWindows[i++], window, 'browserWindows[x] works');
  18. windows.push(window);
  19. }
  20. assert.equal(activeWindowCount, 1, 'activeWindow was found in the iterator');
  21. i = 0;
  22. for (let j in browserWindows) {
  23. assert.equal(j, i++, 'for (x in browserWindows) works');
  24. }
  25. };
  26. exports.testWindowTabsObject_alt = function(assert, done) {
  27. let window = browserWindows.activeWindow;
  28. window.tabs.open({
  29. url: 'data:text/html;charset=utf-8,<title>tab 2</title>',
  30. inBackground: true,
  31. onReady: function onReady(tab) {
  32. assert.equal(tab.title, 'tab 2', 'Correct new tab title');
  33. assert.notEqual(window.tabs.activeTab, tab, 'Correct active tab');
  34. // end test
  35. tab.close(done);
  36. }
  37. });
  38. };
  39. // TEST: browserWindows.activeWindow
  40. exports.testWindowActivateMethod_simple = function(assert) {
  41. let window = browserWindows.activeWindow;
  42. let tab = window.tabs.activeTab;
  43. window.activate();
  44. assert.equal(browserWindows.activeWindow, window,
  45. 'Active window is active after window.activate() call');
  46. assert.equal(window.tabs.activeTab, tab,
  47. 'Active tab is active after window.activate() call');
  48. };
  49. require('sdk/test').run(exports);