main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. module.metadata = {
  6. engines: {
  7. 'Firefox': '*'
  8. }
  9. };
  10. const { isTabOpen, activateTab, openTab,
  11. closeTab, getURI } = require('sdk/tabs/utils');
  12. const windows = require('sdk/deprecated/window-utils');
  13. const { LoaderWithHookedConsole } = require('sdk/test/loader');
  14. const { setTimeout } = require('sdk/timers');
  15. const { is } = require('sdk/system/xul-app');
  16. const tabs = require('sdk/tabs');
  17. const isAustralis = "gCustomizeMode" in windows.activeBrowserWindow;
  18. const { set: setPref } = require("sdk/preferences/service");
  19. const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings";
  20. let uri = require('sdk/self').data.url('index.html');
  21. function isChromeVisible(window) {
  22. let x = window.document.documentElement.getAttribute('disablechrome')
  23. return x !== 'true';
  24. }
  25. exports['test add-on page deprecation message'] = function(assert) {
  26. let { loader, messages } = LoaderWithHookedConsole(module);
  27. loader.require('sdk/addon-page');
  28. setPref(DEPRECATE_PREF, true);
  29. assert.equal(messages.length, 1, "only one error is dispatched");
  30. assert.equal(messages[0].type, "error", "the console message is an error");
  31. let msg = messages[0].msg;
  32. assert.ok(msg.indexOf("DEPRECATED") === 0,
  33. "The message is deprecation message");
  34. loader.unload();
  35. };
  36. exports['test that add-on page has no chrome'] = function(assert, done) {
  37. let { loader } = LoaderWithHookedConsole(module);
  38. loader.require('sdk/addon-page');
  39. let window = windows.activeBrowserWindow;
  40. let tab = openTab(window, uri);
  41. assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
  42. // need to do this in another turn to make sure event listener
  43. // that sets property has time to do that.
  44. setTimeout(function() {
  45. activateTab(tab);
  46. assert.equal(isChromeVisible(window), is('Fennec') || isAustralis,
  47. 'chrome is not visible for addon page');
  48. closeTab(tab);
  49. assert.ok(isChromeVisible(window), 'chrome is visible again');
  50. loader.unload();
  51. assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
  52. done();
  53. });
  54. };
  55. exports['test that add-on page with hash has no chrome'] = function(assert, done) {
  56. let { loader } = LoaderWithHookedConsole(module);
  57. loader.require('sdk/addon-page');
  58. let window = windows.activeBrowserWindow;
  59. let tab = openTab(window, uri + "#foo");
  60. assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
  61. // need to do this in another turn to make sure event listener
  62. // that sets property has time to do that.
  63. setTimeout(function() {
  64. activateTab(tab);
  65. assert.equal(isChromeVisible(window), is('Fennec') || isAustralis,
  66. 'chrome is not visible for addon page');
  67. closeTab(tab);
  68. assert.ok(isChromeVisible(window), 'chrome is visible again');
  69. loader.unload();
  70. assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
  71. done();
  72. });
  73. };
  74. exports['test that add-on page with querystring has no chrome'] = function(assert, done) {
  75. let { loader } = LoaderWithHookedConsole(module);
  76. loader.require('sdk/addon-page');
  77. let window = windows.activeBrowserWindow;
  78. let tab = openTab(window, uri + '?foo=bar');
  79. assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
  80. // need to do this in another turn to make sure event listener
  81. // that sets property has time to do that.
  82. setTimeout(function() {
  83. activateTab(tab);
  84. assert.equal(isChromeVisible(window), is('Fennec') || isAustralis,
  85. 'chrome is not visible for addon page');
  86. closeTab(tab);
  87. assert.ok(isChromeVisible(window), 'chrome is visible again');
  88. loader.unload();
  89. assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
  90. done();
  91. });
  92. };
  93. exports['test that add-on page with hash and querystring has no chrome'] = function(assert, done) {
  94. let { loader } = LoaderWithHookedConsole(module);
  95. loader.require('sdk/addon-page');
  96. let window = windows.activeBrowserWindow;
  97. let tab = openTab(window, uri + '#foo?foo=bar');
  98. assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
  99. // need to do this in another turn to make sure event listener
  100. // that sets property has time to do that.
  101. setTimeout(function() {
  102. activateTab(tab);
  103. assert.equal(isChromeVisible(window), is('Fennec') || isAustralis,
  104. 'chrome is not visible for addon page');
  105. closeTab(tab);
  106. assert.ok(isChromeVisible(window), 'chrome is visible again');
  107. loader.unload();
  108. assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload');
  109. done();
  110. });
  111. };
  112. exports['test that malformed uri is not an addon-page'] = function(assert, done) {
  113. let { loader } = LoaderWithHookedConsole(module);
  114. loader.require('sdk/addon-page');
  115. let window = windows.activeBrowserWindow;
  116. let tab = openTab(window, uri + 'anguage');
  117. // need to do this in another turn to make sure event listener
  118. // that sets property has time to do that.
  119. setTimeout(function() {
  120. activateTab(tab);
  121. assert.ok(isChromeVisible(window), 'chrome is visible for malformed uri');
  122. closeTab(tab);
  123. loader.unload();
  124. done();
  125. });
  126. };
  127. require('sdk/test/runner').runTestsFromModule(module);