1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<!DOCTYPE HTML>
<html>
<head>
<title>PageAction Test</title>
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
<script src="chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script type="text/javascript" src="head.js"></script>
<link rel="stylesheet" href="chrome://mochikit/contents/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="text/javascript">
"use strict";
let dataURI = "iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAC4klEQVRYhdWXLWzbQBSADQtDAwsHC1tUhUxqfL67lk2tdn+OJg0ODU0rLByqgqINBY6tmlbn7LMTJ5FaFVVBk1G0oUGjG2jT2Y7jxmmcbU/6iJ+f36fz+e5sGP9riCGm9hB37RG+scd4Yo/wsDXCZyIE2xuXsce4bY+wXkAsQtzYmExrfFgvkJkRbkzo1ehoxx5iXcgI/9iYUGt8WH9MqDXEcmNChmEYrRCf2SHWeYgQx3x0tLNRIeKQLTtEFyJEep4NTuhk8BC+yMrwEE3+iozo42d8gK7FAOkMsRiiN8QhW2ttSK5QTfRRV4QoymVeJMvPvDp7gCZigD613MN6yRFA3SWarow9QB9LCfG+NeF9qCtjAKOSQjCqVKhfVsiHEQ+grgx/lRGqUihAc1uL8EFD+KCRO+GrF4J61phcoRoPoEzkYhZYpykh5sMb7kOdIeY+jHKur4QI4Feh4AFX1nVeLxrAvQchGsBz5ls6wa2QdwcvIcE2863bTH79KOvsz/uUYJsp+J0pSzNlDckVqqVGUAF+n6uS7txcOl6wot4JVy70ufDLy4pWLUQVPE81pRI0mGe9oxLMHSeohHvMs/STUNaUK6vDPCvOyxMFDx4achehRDJmHnydnkPww5OFfLxrGIZBFDyYl4LpMzlTQFIP6AQx86w2UeYBccFpJrcKv5L9eGDtUAU6RIELqsB74uynjy/UBRF1gS5BTFxwQT1wTiXoUg9MH7m/3NZRRoi5IJytUbMgzv4Wc832+oQkiKgEehmyMkkpKsFkQV11QsRJL5rJYBLItQgRaUZEmnoZXsomz3vGiWw+I9KMF9SVFOqZEemZekli1jN3U/UOqhHHvC6oWWGElhfSpGdOk6+O9prdwvtLj5BjRsQxdRnot+Zeifpy/2/0stktKTRNLmbk0mwXyl8253fyojj+8rxOHNAhjjm5n0/5OOCGOKBzkrMO0Z75lvSAzKlrF32Z/3z8BqLAn+yMV7VhAAAAAElFTkSuQmCC";
let image = atob(dataURI);
const IMAGE_ARRAYBUFFER = Uint8Array.from(image, byte => byte.charCodeAt(0)).buffer;
function background() {
browser.test.assertTrue("pageAction" in browser, "Namespace 'pageAction' exists in browser");
browser.test.assertTrue("show" in browser.pageAction, "API method 'show' exists in browser.pageAction");
// TODO: Use the Tabs API to obtain the tab ids for showing pageActions.
let tabId = 1;
browser.test.onMessage.addListener(msg => {
if (msg === "pageAction-show") {
browser.pageAction.show(tabId).then(() => {
browser.test.sendMessage("page-action-shown");
});
} else if (msg === "pageAction-hide") {
browser.pageAction.hide(tabId).then(() => {
browser.test.sendMessage("page-action-hidden");
});
}
});
browser.pageAction.onClicked.addListener(tab => {
// TODO: Make sure we get the correct tab once basic tabs support is added.
browser.test.sendMessage("page-action-clicked");
});
let extensionInfo = {
// Extract the assigned uuid from the background page url.
uuid: `{${window.location.hostname}}`,
};
browser.test.sendMessage("ready", extensionInfo);
}
add_task(function* test_pageAction() {
let extension = ExtensionTestUtils.loadExtension({
background,
manifest: {
"name": "PageAction Extension",
"page_action": {
"default_title": "Page Action",
"default_icon": {
"18": "extension.png",
},
},
"applications": {
"gecko": {
"id": "foo@bar.com",
},
},
},
files: {
"extension.png": IMAGE_ARRAYBUFFER,
},
});
yield extension.startup();
let {uuid} = yield extension.awaitMessage("ready");
extension.sendMessage("pageAction-show");
yield extension.awaitMessage("page-action-shown");
ok(isPageActionShown(uuid), "The PageAction should be shown");
extension.sendMessage("pageAction-hide");
yield extension.awaitMessage("page-action-hidden");
ok(!isPageActionShown(uuid), "The PageAction should be hidden");
extension.sendMessage("pageAction-show");
yield extension.awaitMessage("page-action-shown");
ok(isPageActionShown(uuid), "The PageAction should be shown");
clickPageAction(uuid);
yield extension.awaitMessage("page-action-clicked");
ok(isPageActionShown(uuid), "The PageAction should still be shown after being clicked");
yield extension.unload();
ok(!isPageActionShown(uuid), "The PageAction should be removed after unload");
});
</script>
</body>
</html>
|