This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); | |||
}); | |||
} | |||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters