forked from bholley/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1190321: [webext] Complete test coverage for the browserAction AP…
…I. r=gabor --HG-- rename : browser/components/extensions/test/browser/browser_ext_pageAction_popup.js => browser/components/extensions/test/browser/browser_ext_browserAction_popup.js extra : commitid : KNrOPlO2bOP extra : rebase_source : 367ab2d367b76512485920a17c8f979b0668beb3 extra : histedit_source : 2d114fc7778b21a9e5cd085a1b78d21b172376bd
- Loading branch information
Showing
3 changed files
with
201 additions
and
33 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
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
147 changes: 147 additions & 0 deletions
147
browser/components/extensions/test/browser/browser_ext_browserAction_popup.js
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ | ||
/* vim: set sts=2 sw=2 et tw=80: */ | ||
"use strict"; | ||
|
||
function promisePopupShown(popup) { | ||
return new Promise(resolve => { | ||
if (popup.popupOpen) { | ||
resolve(); | ||
} else { | ||
let onPopupShown = event => { | ||
popup.removeEventListener("popupshown", onPopupShown); | ||
resolve(); | ||
}; | ||
popup.addEventListener("popupshown", onPopupShown); | ||
} | ||
}); | ||
} | ||
|
||
add_task(function* testPageActionPopup() { | ||
let extension = ExtensionTestUtils.loadExtension({ | ||
manifest: { | ||
"background": { | ||
"page": "data/background.html" | ||
}, | ||
"browser_action": { | ||
"default_popup": "popup-a.html" | ||
} | ||
}, | ||
|
||
files: { | ||
"popup-a.html": `<script src="popup-a.js"></script>`, | ||
"popup-a.js": function() { | ||
browser.runtime.sendMessage("from-popup-a"); | ||
}, | ||
|
||
"data/popup-b.html": `<script src="popup-b.js"></script>`, | ||
"data/popup-b.js": function() { | ||
browser.runtime.sendMessage("from-popup-b"); | ||
}, | ||
|
||
"data/background.html": `<script src="background.js"></script>`, | ||
|
||
"data/background.js": function() { | ||
var tests = [ | ||
() => { | ||
sendClick({ expectEvent: false, expectPopup: "a" }); | ||
}, | ||
() => { | ||
sendClick({ expectEvent: false, expectPopup: "a" }); | ||
}, | ||
() => { | ||
browser.browserAction.setPopup({ popup: "popup-b.html" }); | ||
sendClick({ expectEvent: false, expectPopup: "b" }); | ||
}, | ||
() => { | ||
sendClick({ expectEvent: false, expectPopup: "b" }); | ||
}, | ||
() => { | ||
browser.browserAction.setPopup({ popup: "" }); | ||
sendClick({ expectEvent: true, expectPopup: null }); | ||
}, | ||
() => { | ||
sendClick({ expectEvent: true, expectPopup: null }); | ||
}, | ||
() => { | ||
browser.browserAction.setPopup({ popup: "/popup-a.html" }); | ||
sendClick({ expectEvent: false, expectPopup: "a" }); | ||
}, | ||
]; | ||
|
||
var expect = {}; | ||
function sendClick({ expectEvent, expectPopup }) { | ||
expect = { event: expectEvent, popup: expectPopup }; | ||
browser.test.sendMessage("send-click"); | ||
} | ||
|
||
browser.runtime.onMessage.addListener(msg => { | ||
if (expect.popup) { | ||
browser.test.assertEq(msg, `from-popup-${expect.popup}`, | ||
"expected popup opened"); | ||
} else { | ||
browser.test.fail("unexpected popup"); | ||
} | ||
|
||
expect.popup = null; | ||
browser.test.sendMessage("next-test"); | ||
}); | ||
|
||
browser.browserAction.onClicked.addListener(() => { | ||
if (expect.event) { | ||
browser.test.succeed("expected click event received"); | ||
} else { | ||
browser.test.fail("unexpected click event"); | ||
} | ||
|
||
expect.event = false; | ||
browser.test.sendMessage("next-test"); | ||
}); | ||
|
||
browser.test.onMessage.addListener((msg) => { | ||
if (msg != "next-test") { | ||
browser.test.fail("Expecting 'next-test' message"); | ||
} | ||
|
||
if (tests.length) { | ||
var test = tests.shift(); | ||
test(); | ||
} else { | ||
browser.test.notifyPass("browseraction-tests-done"); | ||
} | ||
}); | ||
|
||
browser.test.sendMessage("next-test"); | ||
}, | ||
}, | ||
}); | ||
|
||
let browserActionId = makeWidgetId(extension.id) + "-browser-action"; | ||
let panelId = makeWidgetId(extension.id) + "-panel"; | ||
|
||
extension.onMessage("send-click", () => { | ||
let button = document.getElementById(browserActionId); | ||
|
||
EventUtils.synthesizeMouseAtCenter(button, {}, window); | ||
}); | ||
|
||
extension.onMessage("next-test", Task.async(function* () { | ||
let panel = document.getElementById(panelId); | ||
if (panel) { | ||
yield promisePopupShown(panel); | ||
panel.hidePopup(); | ||
|
||
panel = document.getElementById(panelId); | ||
is(panel, undefined, "panel successfully removed from document after hiding"); | ||
} | ||
|
||
extension.sendMessage("next-test"); | ||
})); | ||
|
||
|
||
yield Promise.all([extension.startup(), extension.awaitFinish("browseraction-tests-done")]); | ||
|
||
yield extension.unload(); | ||
|
||
let panel = document.getElementById(panelId); | ||
is(panel, undefined, "browserAction panel removed from document"); | ||
}); |