const assertEq = chrome.test.assertEq;
const assertTrue = chrome.test.assertTrue;
var popupWindowId = 0;
var optionsTabId = 0;
function popupCallback() {
assertEq(2, chrome.extension.getViews().length);
assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length);
chrome.tabs.create({url: chrome.runtime.getURL("options.html")},
function(tab) {
optionsTabId = tab.id;
});
}
function optionsPageCallback() {
assertEq(3, chrome.extension.getViews().length);
assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length);
assertEq(
2, chrome.extension.getViews({type: "tab", windowId: window.id}).length);
chrome.tabs.query({windowId: window.id}, function(tabs) {
assertEq(3, tabs.length);
assertEq(2, chrome.extension.getViews({type: "tab"}).length);
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].windowId == popupWindowId) {
assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length);
assertEq(1, chrome.extension.getViews({windowId: popupWindowId,
tabId: tabs[i].id}).length);
assertEq(1, chrome.extension.getViews({type: "tab",
tabId: tabs[i].id}).length);
} else if (tabs[i].id == optionsTabId) {
assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length);
}
}
});
chrome.test.notifyPass();
}
var tests = [
function getViews() {
assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined");
assertEq(1, chrome.extension.getViews().length);
assertEq(0, chrome.extension.getViews({type: "tab"}).length);
assertEq(0, chrome.extension.getViews({type: "popup"}).length);
chrome.windows.getAll({populate: true}, function(windows) {
assertEq(1, windows.length);
chrome.windows.create({url: chrome.runtime.getURL("popup.html"),
type: "popup"}, function(window) {
assertTrue(window.id > 0);
popupWindowId = window.id;
});
});
}
];
chrome.test.runTests(tests);