Permalink
Browse files

Merge pull request #338 from Gozala/bug/simple-addon-page@644595

Bug 644595 - Implement very minimal support of add-on page API. r=@ochameau
  • Loading branch information...
2 parents 03d0556 + e4db2a3 commit 8d34075d1c1feffa41f60670c7778d49725ac8aa @Gozala Gozala committed Feb 12, 2012
@@ -0,0 +1,12 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+ - License, v. 2.0. If a copy of the MPL was not distributed with this
+ - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<html>
+ <head>
+ <title>Add-on Page</title>
+ </head>
+ <body>
+ <p>This is an add-on page test!</p>
+ </body>
+</html>
@@ -0,0 +1,33 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { uriPrefix, name } = require('@packaging');
+const { WindowTracker, isBrowser } = require('api-utils/window-utils');
+const { add, remove } = require('api-utils/array');
+const { getTabs, closeTab } = require('api-utils/tabs/utils');
+
+// Note: This is an URL that will be returned by calling
+// `require('self').data.url('index.html')` from the add-on modules.
+// We could not use this expression as in this module it would have
+// returned "addon-kit/data/index.html" instead.
+const addonURL = uriPrefix + name + '/data/index.html';
+
+WindowTracker({
+ onTrack: function onTrack(window) {
+ if (isBrowser(window))
+ add(window.XULBrowserWindow.inContentWhitelist, addonURL);
+ },
+ onUntrack: function onUntrack(window) {
+ getTabs(window).
+ filter(function(tab) tab.linkedBrowser.currentURI.spec === addonURL).
+ forEach(function(tab) {
+ // Note: `onUntrack` will be called for all windows on add-on unloads,
+ // so we want to clean them up from these URLs.
+ remove(window.XULBrowserWindow.inContentWhitelist, addonURL);
+ closeTab(tab);
+ });
+ }
+});
@@ -0,0 +1,51 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+'use strict';
+
+const { isTabOpen, activateTab, openTab, closeTab } = require('api-utils/tabs/utils');
+const windows = require('api-utils/window-utils');
+const { Loader } = require('./helpers');
+const { setTimeout } = require('api-utils/timer');
+
+let uri = require('self').data.url('index.html');
+
+function isChromeVisible(window)
+ window.document.documentElement.getAttribute('disablechrome') !== 'true'
+
+exports['test that add-on page has no chrome'] = function(assert, done) {
+ let loader = Loader(module);
+ loader.require('addon-kit/addon-page');
+
+ let window = windows.activeBrowserWindow;
+ let tab = openTab(window, uri);
+
+ assert.ok(isChromeVisible(window), 'chrome is visible for non addon page');
+
+ // need to do this in another turn to make sure event listener
+ // that sets property has time to do that.
+ setTimeout(function() {
+ activateTab(tab);
+
+ assert.ok(!isChromeVisible(window), 'chrome is not visible for addon page');
+
+ closeTab(tab);
+ assert.ok(isChromeVisible(window), 'chrome is visible again');
+ loader.unload();
+ done();
+ });
+};
+
+exports['test that add-on pages is closed on unload'] = function(assert) {
+ let loader = Loader(module);
+ loader.require('addon-kit/addon-page');
+
+ let tab = openTab(windows.activeBrowserWindow, uri);
+ loader.unload();
+
+ assert.ok(isTabOpen(tab), 'add-on page tabs are closed on unload');
+};
+
+
+require('test').run(exports);
@@ -43,6 +43,11 @@ function openTab(window, url) {
}
exports.openTab = openTab;
+function isTabOpen(tab) {
+ return !!tab.linkedBrowser;
+}
+exports.isTabOpen = isTabOpen;
+
function closeTab(tab) {
return getOwnerWindow(tab).gBrowser.removeTab(tab);
}

0 comments on commit 8d34075

Please sign in to comment.