test-fennec-windows.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 { Cc, Ci } = require('chrome');
  6. const { setTimeout } = require('sdk/timers');
  7. const { Loader } = require('sdk/test/loader');
  8. const WM = Cc['@mozilla.org/appshell/window-mediator;1'].
  9. getService(Ci.nsIWindowMediator);
  10. const { browserWindows } = require('sdk/windows');
  11. const ERR_MSG = 'This method is not yet supported by Fennec, consider using require("sdk/tabs") instead';
  12. // TEST: browserWindows.length for Fennec
  13. exports.testBrowserWindowsLength = function(assert) {
  14. assert.equal(browserWindows.length, 1, "Only one window open");
  15. };
  16. // TEST: open & close window
  17. exports.testOpenWindow = function(assert) {
  18. let tabCount = browserWindows.activeWindow.tabs.length;
  19. let url = "data:text/html;charset=utf-8,<title>windows%20API%20test</title>";
  20. try {
  21. browserWindows.open({url: url});
  22. assert.fail('Error was not thrown');
  23. }
  24. catch(e) {
  25. assert.equal(e.message, ERR_MSG, 'Error is thrown on windows.open');
  26. assert.equal(browserWindows.length, 1, "Only one window open");
  27. }
  28. };
  29. exports.testCloseWindow = function(assert) {
  30. let window = browserWindows.activeWindow;
  31. try {
  32. window.close();
  33. assert.fail('Error was not thrown');
  34. }
  35. catch(e) {
  36. assert.equal(e.message, ERR_MSG, 'Error is thrown on windows.close');
  37. assert.equal(browserWindows.length, 1, "Only one window open");
  38. }
  39. };
  40. require('sdk/test').run(exports);