2013-02-02 01:17:34 +04:00
|
|
|
/* 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/. */
|
2013-02-14 22:03:26 +04:00
|
|
|
'use strict';
|
|
|
|
|
2013-07-30 01:37:44 +04:00
|
|
|
require("sdk/context-menu");
|
|
|
|
|
2014-09-26 19:32:55 +04:00
|
|
|
const { defer } = require("sdk/core/promise");
|
2015-02-03 20:51:16 +03:00
|
|
|
const packaging = require('@loader/options');
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// These should match the same constants in the module.
|
|
|
|
const OVERFLOW_THRESH_DEFAULT = 10;
|
|
|
|
const OVERFLOW_THRESH_PREF =
|
|
|
|
"extensions.addon-sdk.context-menu.overflowThreshold";
|
|
|
|
|
|
|
|
const TEST_DOC_URL = module.uri.replace(/\.js$/, ".html");
|
2013-11-06 01:51:58 +04:00
|
|
|
const data = require("./fixtures");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
2015-02-03 20:51:16 +03:00
|
|
|
const { TestHelper } = require("./context-menu/test-helper.js")
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Tests that when present the separator is placed before the separator from
|
|
|
|
// the old context-menu module
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSeparatorPosition = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
// Create the old separator
|
|
|
|
let oldSeparator = test.contextMenuPopup.ownerDocument.createElement("menuseparator");
|
|
|
|
oldSeparator.id = "jetpack-context-menu-separator";
|
|
|
|
test.contextMenuPopup.appendChild(oldSeparator);
|
|
|
|
|
|
|
|
// Create an item.
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(test.contextMenuSeparator.nextSibling.nextSibling, oldSeparator,
|
2013-02-02 01:17:34 +04:00
|
|
|
"New separator should appear before the old one");
|
|
|
|
test.contextMenuPopup.removeChild(oldSeparator);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Destroying items that were previously created should cause them to be absent
|
|
|
|
// from the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testConstructDestroy = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
// Create an item.
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.parentMenu, loader.cm.contentContextMenu,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// It should be present when the menu is shown.
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Destroy the item. Multiple destroys should be harmless.
|
|
|
|
item.destroy();
|
|
|
|
item.destroy();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// It should be removed from the menu.
|
|
|
|
test.checkMenu([item], [], [item]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Destroying an item twice should not cause an error.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testDestroyTwice = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
item.destroy();
|
|
|
|
item.destroy();
|
|
|
|
|
|
|
|
test.pass("Destroying an item twice should not cause an error.");
|
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CSS selector contexts should cause their items to be present in the menu
|
|
|
|
// when the menu is invoked on nodes that match the selectors.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectorContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
data: "item",
|
|
|
|
context: loader.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CSS selector contexts should cause their items to be present in the menu
|
|
|
|
// when the menu is invoked on nodes that have ancestors that match the
|
|
|
|
// selectors.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectorAncestorContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
data: "item",
|
|
|
|
context: loader.cm.SelectorContext("a[href]")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#span-link", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// CSS selector contexts should cause their items to be absent from the menu
|
|
|
|
// when the menu is not invoked on nodes that match or have ancestors that
|
|
|
|
// match the selectors.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectorContextNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
data: "item",
|
|
|
|
context: loader.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Page contexts should cause their items to be present in the menu when the
|
|
|
|
// menu is not invoked on an active element.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testPageContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 0"
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: undefined
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.PageContext()
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: [loader.cm.PageContext()]
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Page contexts should cause their items to be absent from the menu when the
|
|
|
|
// menu is invoked on an active element.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testPageContextNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 0"
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: undefined
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.PageContext()
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: [loader.cm.PageContext()]
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should cause items to appear when a selection exists.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
window.getSelection().selectAllChildren(doc.body);
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should cause items to appear when a selection exists in
|
|
|
|
// a text field.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextMatchInTextField = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.selectRange("#textfield", 0, null);
|
|
|
|
test.showMenu("#textfield", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should not cause items to appear when a selection does
|
|
|
|
// not exist in a text field.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextNoMatchInTextField = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.selectRange("#textfield", 0, 0);
|
|
|
|
test.showMenu("#textfield", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should not cause items to appear when a selection does
|
|
|
|
// not exist.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should cause items to appear when a selection exists even
|
|
|
|
// for newly opened pages
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextInNewTab = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let link = doc.getElementById("targetlink");
|
|
|
|
link.click();
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
let tablistener = event => {
|
|
|
|
this.tabBrowser.tabContainer.removeEventListener("TabOpen", tablistener, false);
|
|
|
|
let tab = event.target;
|
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
this.loadFrameScript(browser);
|
|
|
|
this.delayedEventListener(browser, "load", () => {
|
|
|
|
let window = browser.contentWindow;
|
|
|
|
let doc = browser.contentDocument;
|
|
|
|
window.getSelection().selectAllChildren(doc.body);
|
2013-02-02 01:17:34 +04:00
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
2013-02-02 01:17:34 +04:00
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.tabBrowser.removeTab(test.tabBrowser.selectedTab);
|
|
|
|
test.tabBrowser.selectedTab = test.tab;
|
2013-02-02 01:17:34 +04:00
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
2013-02-02 01:17:34 +04:00
|
|
|
});
|
2014-11-18 01:08:07 +03:00
|
|
|
}, true);
|
|
|
|
};
|
|
|
|
this.tabBrowser.tabContainer.addEventListener("TabOpen", tablistener, false);
|
2013-02-02 01:17:34 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Selection contexts should work when right clicking a form button
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextButtonMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
window.getSelection().selectAllChildren(doc.body);
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#button", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//Selection contexts should work when right clicking a form button
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionContextButtonNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#button", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// URL contexts should cause items to appear on pages that match.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testURLContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader.cm.URLContext(TEST_DOC_URL)
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader.cm.URLContext([TEST_DOC_URL, "*.bogus.com"])
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.URLContext([new RegExp(".*\\.html")])
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// URL contexts should not cause items to appear on pages that do not match.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testURLContextNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader.cm.URLContext("*.bogus.com")
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader.cm.URLContext(["*.bogus.com", "*.gnarly.com"])
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.URLContext([new RegExp(".*\\.js")])
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Loading a new page in the same tab should correctly start a new worker for
|
|
|
|
// any content scripts
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testPageReload = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "Item",
|
|
|
|
contentScript: "var doc = document; self.on('context', function(node) doc.body.getAttribute('showItem') == 'true');"
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
// Set a flag on the document that the item uses
|
|
|
|
doc.body.setAttribute("showItem", "true");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// With the attribute true the item should be visible in the menu
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.hideMenu(function() {
|
|
|
|
let browser = this.tabBrowser.getBrowserForTab(this.tab)
|
|
|
|
test.delayedEventListener(browser, "load", function() {
|
|
|
|
test.delayedEventListener(browser, "load", function() {
|
|
|
|
window = browser.contentWindow;
|
|
|
|
doc = window.document;
|
|
|
|
|
|
|
|
// Set a flag on the document that the item uses
|
|
|
|
doc.body.setAttribute("showItem", "false");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// In the new document with the attribute false the item should be
|
|
|
|
// hidden, but if the contentScript hasn't been reloaded it will
|
|
|
|
// still see the old value
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
}, true);
|
|
|
|
browser.loadURI(TEST_DOC_URL, null, null);
|
|
|
|
}, true);
|
|
|
|
// Required to make sure we load a new page in history rather than
|
|
|
|
// just reloading the current page which would unload it
|
|
|
|
browser.loadURI("about:blank", null, null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// Closing a page after it's been used with a worker should cause the worker
|
|
|
|
// to be destroyed
|
2013-10-05 03:48:52 +04:00
|
|
|
/*exports.testWorkerDestroy = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let loadExpected = false;
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.postMessage("loaded"); self.on("detach", function () { console.log("saw detach"); self.postMessage("detach") });',
|
|
|
|
onMessage: function (msg) {
|
|
|
|
switch (msg) {
|
|
|
|
case "loaded":
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(loadExpected, "Should have seen the load event at the right time");
|
2013-02-02 01:17:34 +04:00
|
|
|
loadExpected = false;
|
|
|
|
break;
|
|
|
|
case "detach":
|
|
|
|
test.done();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
loadExpected = true;
|
|
|
|
test.showMenu(null, function (popup) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(!loadExpected, "Should have seen a message");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
|
|
|
|
test.closeTab();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};*/
|
|
|
|
|
|
|
|
|
|
|
|
// Content contexts that return true should cause their items to be present
|
|
|
|
// in the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Content contexts that return false should cause their items to be absent
|
|
|
|
// from the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Content contexts that return undefined should cause their items to be absent
|
|
|
|
// from the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextUndefined = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () {});'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Content contexts that return an empty string should cause their items to be
|
|
|
|
// absent from the menu and shouldn't wipe the label
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextEmptyString = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () "");'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.label, "item", "Label should still be correct");
|
2013-02-14 22:03:26 +04:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If any content contexts returns true then their items should be present in
|
|
|
|
// the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContentContextMatch1 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () true); ' +
|
|
|
|
'self.on("context", function () false);',
|
|
|
|
onMessage: function() {
|
|
|
|
test.fail("Should not have called the second context listener");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If any content contexts returns true then their items should be present in
|
|
|
|
// the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContentContextMatch2 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () false); ' +
|
|
|
|
'self.on("context", function () true);'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If any content contexts returns a string then their items should be present
|
|
|
|
// in the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContentContextString1 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () "new label"); ' +
|
|
|
|
'self.on("context", function () false);'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.label, "new label", "Label should have changed");
|
2013-02-14 22:03:26 +04:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If any content contexts returns a string then their items should be present
|
|
|
|
// in the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContentContextString2 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () false); ' +
|
|
|
|
'self.on("context", function () "new label");'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.label, "new label", "Label should have changed");
|
2013-02-14 22:03:26 +04:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If many content contexts returns a string then the first should take effect
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContentContextString3 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function () "new label 1"); ' +
|
|
|
|
'self.on("context", function () "new label 2");'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.label, "new label 1", "Label should have changed");
|
2013-02-14 22:03:26 +04:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Content contexts that return true should cause their items to be present
|
|
|
|
// in the menu when context clicking an active element.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextMatchActiveElement = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: undefined,
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
}),
|
|
|
|
// These items will always be hidden by the declarative usage of PageContext
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader.cm.PageContext(),
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 4",
|
|
|
|
context: [loader.cm.PageContext()],
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, [items[2], items[3]], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Content contexts that return false should cause their items to be absent
|
|
|
|
// from the menu when context clicking an active element.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextNoMatchActiveElement = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: undefined,
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
}),
|
|
|
|
// These items will always be hidden by the declarative usage of PageContext
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader.cm.PageContext(),
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 4",
|
|
|
|
context: [loader.cm.PageContext()],
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Content contexts that return undefined should cause their items to be absent
|
|
|
|
// from the menu when context clicking an active element.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextNoMatchActiveElement = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
contentScript: 'self.on("context", function () {});'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: undefined,
|
|
|
|
contentScript: 'self.on("context", function () {});'
|
|
|
|
}),
|
|
|
|
// These items will always be hidden by the declarative usage of PageContext
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader.cm.PageContext(),
|
|
|
|
contentScript: 'self.on("context", function () {});'
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 4",
|
|
|
|
context: [loader.cm.PageContext()],
|
|
|
|
contentScript: 'self.on("context", function () {});'
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Content contexts that return a string should cause their items to be present
|
|
|
|
// in the menu and the items' labels to be updated.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextMatchString = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "first label",
|
|
|
|
contentScript: 'self.on("context", function () "second label");'
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.label, "second label",
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's label should be updated");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that contentScriptFile is working correctly
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentScriptFile = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
2014-07-18 00:54:21 +04:00
|
|
|
let { defer, all } = require("sdk/core/promise");
|
|
|
|
let itemScript = [defer(), defer()];
|
|
|
|
let menuShown = defer();
|
|
|
|
let menuPromises = itemScript.concat(menuShown).map(({promise}) => promise);
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// Reject remote files
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.throws(function() {
|
2013-02-02 01:17:34 +04:00
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScriptFile: "http://mozilla.com/context-menu.js"
|
|
|
|
});
|
|
|
|
},
|
2014-07-18 00:54:21 +04:00
|
|
|
/The `contentScriptFile` option must be a local URL or an array of URLs/,
|
2013-02-02 01:17:34 +04:00
|
|
|
"Item throws when contentScriptFile is a remote URL");
|
|
|
|
|
|
|
|
// But accept files from data folder
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
2014-07-18 00:54:21 +04:00
|
|
|
contentScriptFile: data.url("test-contentScriptFile.js"),
|
|
|
|
onMessage: (message) => {
|
|
|
|
assert.equal(message, "msg from contentScriptFile",
|
|
|
|
"contentScriptFile loaded with absolute url");
|
|
|
|
itemScript[0].resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let item2 = new loader.cm.Item({
|
|
|
|
label: "item2",
|
|
|
|
contentScriptFile: "./test-contentScriptFile.js",
|
|
|
|
onMessage: (message) => {
|
|
|
|
assert.equal(message, "msg from contentScriptFile",
|
|
|
|
"contentScriptFile loaded with relative url");
|
|
|
|
itemScript[1].resolve();
|
|
|
|
}
|
2013-02-02 01:17:34 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
2014-07-18 00:54:21 +04:00
|
|
|
test.checkMenu([item, item2], [], []);
|
|
|
|
menuShown.resolve();
|
2013-02-02 01:17:34 +04:00
|
|
|
});
|
2014-07-18 00:54:21 +04:00
|
|
|
|
|
|
|
all(menuPromises).then(() => test.done());
|
2013-02-02 01:17:34 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The args passed to context listeners should be correct.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentContextArgs = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
let callbacks = 0;
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'self.on("context", function (node) {' +
|
|
|
|
' self.postMessage(node.tagName);' +
|
|
|
|
' return false;' +
|
|
|
|
'});',
|
|
|
|
onMessage: function (tagName) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(tagName, "HTML", "node should be an HTML element");
|
2013-02-02 01:17:34 +04:00
|
|
|
if (++callbacks == 2) test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function () {
|
|
|
|
if (++callbacks == 2) test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
// Multiple contexts imply intersection, not union.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleContexts = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: [loader.cm.SelectorContext("a[href]"), loader.cm.PageContext()],
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#span-link", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Once a context is removed, it should no longer cause its item to appear.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testRemoveContext = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let ctxt = loader.cm.SelectorContext("img");
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: ctxt
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// The item should be present at first.
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Remove the img context and check again.
|
|
|
|
item.context.remove(ctxt);
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Once a context is removed, it should no longer cause its item to appear.
|
|
|
|
exports.testSetContextRemove = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let ctxt = loader.cm.SelectorContext("img");
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: ctxt
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
|
|
|
|
// The item should be present at first.
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Remove the img context and check again.
|
|
|
|
item.context = [];
|
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
// Once a context is added, it should affect whether the item appears.
|
|
|
|
exports.testAddContext = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let ctxt = loader.cm.SelectorContext("img");
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item"
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
|
|
|
|
// The item should not be present at first.
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Add the img context and check again.
|
|
|
|
item.context.add(ctxt);
|
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Once a context is added, it should affect whether the item appears.
|
|
|
|
exports.testSetContextAdd = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let ctxt = loader.cm.SelectorContext("img");
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item"
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
|
|
|
|
// The item should not be present at first.
|
|
|
|
test.checkMenu([item], [item], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Add the img context and check again.
|
|
|
|
item.context = [ctxt];
|
|
|
|
test.showMenu("#image", function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// Lots of items should overflow into the overflow submenu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [];
|
|
|
|
for (let i = 0; i < OVERFLOW_THRESH_DEFAULT + 1; i++) {
|
|
|
|
let item = new loader.cm.Item({ label: "item " + i });
|
|
|
|
items.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Module unload should cause all items to be removed.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testUnload = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain the item.
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload the module.
|
|
|
|
loader.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The item should be removed from the menu.
|
|
|
|
test.checkMenu([item], [], [item]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to add items without causing overflow should
|
2013-02-14 22:03:26 +04:00
|
|
|
// work OK. Assumes OVERFLOW_THRESH_DEFAULT >= 2.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesAdd = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
// Use each module to add an item, then unload each module in turn.
|
|
|
|
let item0 = new loader0.cm.Item({ label: "item 0" });
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain both items.
|
|
|
|
test.checkMenu([item0, item1], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload the first module.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The first item should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload the second module.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Both items should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0, item1]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to add items causing overflow should work OK.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesAddOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
// Use module 0 to add OVERFLOW_THRESH_DEFAULT items.
|
|
|
|
let items0 = [];
|
|
|
|
for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
|
|
|
|
let item = new loader0.cm.Item({ label: "item 0 " + i });
|
|
|
|
items0.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use module 1 to add one item.
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
let allItems = items0.concat(item1);
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain all items in overflow.
|
|
|
|
test.checkMenu(allItems, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload the first module.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The first items should be removed from the menu, which should not
|
|
|
|
// overflow.
|
|
|
|
test.checkMenu(allItems, [], items0);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload the second module.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// All items should be removed from the menu.
|
|
|
|
test.checkMenu(allItems, [], allItems);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to modify the menu without causing overflow
|
|
|
|
// should work OK. This test creates two loaders and:
|
|
|
|
// loader0 create item -> loader1 create item -> loader0.unload ->
|
|
|
|
// loader1.unload
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesDiffContexts1 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item0 = new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain item1.
|
|
|
|
test.checkMenu([item0, item1], [item0], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 0.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// item0 should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 1.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Both items should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0, item1]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to modify the menu without causing overflow
|
|
|
|
// should work OK. This test creates two loaders and:
|
|
|
|
// loader1 create item -> loader0 create item -> loader0.unload ->
|
|
|
|
// loader1.unload
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesDiffContexts2 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
let item0 = new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain item1.
|
|
|
|
test.checkMenu([item0, item1], [item0], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 0.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// item0 should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 1.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Both items should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0, item1]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to modify the menu without causing overflow
|
|
|
|
// should work OK. This test creates two loaders and:
|
|
|
|
// loader0 create item -> loader1 create item -> loader1.unload ->
|
|
|
|
// loader0.unload
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesDiffContexts3 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item0 = new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain item1.
|
|
|
|
test.checkMenu([item0, item1], [item0], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 1.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// item1 should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [item0], [item1]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 0.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Both items should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0, item1]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Using multiple module instances to modify the menu without causing overflow
|
|
|
|
// should work OK. This test creates two loaders and:
|
|
|
|
// loader1 create item -> loader0 create item -> loader1.unload ->
|
|
|
|
// loader0.unload
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesDiffContexts4 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
let item0 = new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("img")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain item1.
|
|
|
|
test.checkMenu([item0, item1], [item0], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 1.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// item1 should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [item0], [item1]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 0.
|
|
|
|
loader0.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Both items should be removed from the menu.
|
|
|
|
test.checkMenu([item0, item1], [], [item0, item1]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test interactions between a loaded module, unloading another module, and the
|
|
|
|
// menu separator and overflow submenu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesAddRemove = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader0.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain the item.
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Remove the item.
|
|
|
|
item.destroy();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The item should be removed from the menu.
|
|
|
|
test.checkMenu([item], [], [item]);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
// Unload module 1.
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// There shouldn't be any errors involving the menu separator or
|
|
|
|
// overflow submenu.
|
|
|
|
test.checkMenu([item], [], [item]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that the order of menu items is correct when adding/removing across
|
|
|
|
// multiple modules. All items from a single module should remain in a group
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesOrder = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
// Use each module to add an item, then unload each module in turn.
|
|
|
|
let item0 = new loader0.cm.Item({ label: "item 0" });
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain both items.
|
|
|
|
test.checkMenu([item0, item1], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
let item2 = new loader0.cm.Item({ label: "item 2" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The new item should be grouped with the same items from loader0.
|
|
|
|
test.checkMenu([item0, item2, item1], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
let item3 = new loader1.cm.Item({ label: "item 3" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Same again
|
|
|
|
test.checkMenu([item0, item2, item1, item3], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that the order of menu items is correct when adding/removing across
|
|
|
|
// multiple modules when overflowing. All items from a single module should
|
|
|
|
// remain in a group
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesOrderOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-02 01:17:34 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 0);
|
|
|
|
|
|
|
|
// Use each module to add an item, then unload each module in turn.
|
|
|
|
let item0 = new loader0.cm.Item({ label: "item 0" });
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The menu should contain both items.
|
|
|
|
test.checkMenu([item0, item1], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
let item2 = new loader0.cm.Item({ label: "item 2" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// The new item should be grouped with the same items from loader0.
|
|
|
|
test.checkMenu([item0, item2, item1], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
let item3 = new loader1.cm.Item({ label: "item 3" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// Same again
|
|
|
|
test.checkMenu([item0, item2, item1, item3], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Checks that if a module's items are all hidden then the overflow menu doesn't
|
|
|
|
// get hidden
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesOverflowHidden = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 0);
|
|
|
|
|
|
|
|
// Use each module to add an item, then unload each module in turn.
|
|
|
|
let item0 = new loader0.cm.Item({ label: "item 0" });
|
|
|
|
let item1 = new loader1.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader1.cm.SelectorContext("a")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu([item0, item1], [item1], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that if a module's items are all hidden then the overflow menu doesn't
|
|
|
|
// get hidden (reverse order to above)
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMultipleModulesOverflowHidden2 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 0);
|
|
|
|
|
|
|
|
// Use each module to add an item, then unload each module in turn.
|
|
|
|
let item0 = new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("a")
|
|
|
|
});
|
|
|
|
let item1 = new loader1.cm.Item({ label: "item 1" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu([item0, item1], [item0], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that we don't overflow if there are more items than the overflow
|
|
|
|
// threshold but not all of them are visible
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflowIgnoresHidden = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 2);
|
|
|
|
|
|
|
|
let allItems = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 0"
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1"
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu(allItems, [allItems[2]], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that we don't overflow if there are more items than the overflow
|
|
|
|
// threshold but not all of them are visible
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflowIgnoresHiddenMultipleModules1 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 2);
|
|
|
|
|
|
|
|
let allItems = [
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 0"
|
|
|
|
}),
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 1"
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader1.cm.SelectorContext("a")
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader1.cm.SelectorContext("a")
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu(allItems, [allItems[2], allItems[3]], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that we don't overflow if there are more items than the overflow
|
|
|
|
// threshold but not all of them are visible
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflowIgnoresHiddenMultipleModules2 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 2);
|
|
|
|
|
|
|
|
let allItems = [
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 0"
|
|
|
|
}),
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader0.cm.SelectorContext("a")
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 2"
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader1.cm.SelectorContext("a")
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu(allItems, [allItems[1], allItems[3]], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that we don't overflow if there are more items than the overflow
|
|
|
|
// threshold but not all of them are visible
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflowIgnoresHiddenMultipleModules3 = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader0.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 2);
|
|
|
|
|
|
|
|
let allItems = [
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader0.cm.SelectorContext("a")
|
|
|
|
}),
|
|
|
|
new loader0.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader0.cm.SelectorContext("a")
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 2"
|
|
|
|
}),
|
|
|
|
new loader1.cm.Item({
|
|
|
|
label: "item 3"
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// One should be hidden
|
|
|
|
test.checkMenu(allItems, [allItems[0], allItems[1]], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Tests that we transition between overflowing to non-overflowing to no items
|
|
|
|
// and back again
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testOverflowTransition = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
let prefs = loader.loader.require("sdk/preferences/service");
|
2013-02-14 22:03:26 +04:00
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 2);
|
|
|
|
|
|
|
|
let pItems = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 0",
|
|
|
|
context: loader.cm.SelectorContext("p")
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
context: loader.cm.SelectorContext("p")
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
let aItems = [
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
}),
|
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
let allItems = pItems.concat(aItems);
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#link", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// The menu should contain all items and will overflow
|
|
|
|
test.checkMenu(allItems, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#text", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// Only contains hald the items and will not overflow
|
|
|
|
test.checkMenu(allItems, aItems, []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// None of the items will be visible
|
|
|
|
test.checkMenu(allItems, allItems, []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#text", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// Only contains hald the items and will not overflow
|
|
|
|
test.checkMenu(allItems, aItems, []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#link", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// The menu should contain all items and will overflow
|
|
|
|
test.checkMenu(allItems, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
// None of the items will be visible
|
|
|
|
test.checkMenu(allItems, allItems, []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#link", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// The menu should contain all items and will overflow
|
|
|
|
test.checkMenu(allItems, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// An item's command listener should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemCommand = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
data: "item data",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function (data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(this, item, "`this` inside onMessage should be item");
|
|
|
|
assert.equal(data.tagName, "HTML", "node should be an HTML element");
|
|
|
|
assert.equal(data.data, item.data, "data should be item data");
|
2013-02-14 22:03:26 +04:00
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
let elt = test.getItemElt(popup, item);
|
|
|
|
|
|
|
|
// create a command event
|
|
|
|
let evt = elt.ownerDocument.createEvent('Event');
|
|
|
|
evt.initEvent('command', true, true);
|
|
|
|
elt.dispatchEvent(evt);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A menu's click listener should work and receive bubbling 'command' events from
|
|
|
|
// sub-items appropriately. This also tests menus and ensures that when a CSS
|
|
|
|
// selector context matches the clicked node's ancestor, the matching ancestor
|
|
|
|
// is passed to listeners as the clicked node.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuCommand = function (assert, done) {
|
2013-02-14 22:03:26 +04:00
|
|
|
// Create a top-level menu, submenu, and item, like this:
|
|
|
|
// topMenu -> submenu -> item
|
|
|
|
// Click the item and make sure the click bubbles.
|
2013-10-05 03:48:52 +04:00
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "submenu item",
|
|
|
|
data: "submenu item data",
|
|
|
|
context: loader.cm.SelectorContext("a"),
|
|
|
|
});
|
|
|
|
|
|
|
|
let submenu = new loader.cm.Menu({
|
|
|
|
label: "submenu",
|
|
|
|
context: loader.cm.SelectorContext("a"),
|
|
|
|
items: [item]
|
|
|
|
});
|
|
|
|
|
|
|
|
let topMenu = new loader.cm.Menu({
|
|
|
|
label: "top menu",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function (data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(this, topMenu, "`this` inside top menu should be menu");
|
|
|
|
assert.equal(data.tagName, "A", "Clicked node should be anchor");
|
|
|
|
assert.equal(data.data, item.data,
|
2013-02-14 22:03:26 +04:00
|
|
|
"Clicked item data should be correct");
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
items: [submenu],
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#span-link", function (popup) {
|
2013-02-14 22:03:26 +04:00
|
|
|
test.checkMenu([topMenu], [], []);
|
|
|
|
let topMenuElt = test.getItemElt(popup, topMenu);
|
|
|
|
let topMenuPopup = topMenuElt.firstChild;
|
|
|
|
let submenuElt = test.getItemElt(topMenuPopup, submenu);
|
|
|
|
let submenuPopup = submenuElt.firstChild;
|
|
|
|
let itemElt = test.getItemElt(submenuPopup, item);
|
|
|
|
|
|
|
|
// create a command event
|
|
|
|
let evt = itemElt.ownerDocument.createEvent('Event');
|
|
|
|
evt.initEvent('command', true, true);
|
|
|
|
itemElt.dispatchEvent(evt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Click listeners should work when multiple modules are loaded.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemCommandMultipleModules = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item0 = loader0.cm.Item({
|
|
|
|
label: "loader 0 item",
|
|
|
|
contentScript: 'self.on("click", self.postMessage);',
|
|
|
|
onMessage: function () {
|
|
|
|
test.fail("loader 0 item should not emit click event");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let item1 = loader1.cm.Item({
|
|
|
|
label: "loader 1 item",
|
|
|
|
contentScript: 'self.on("click", self.postMessage);',
|
|
|
|
onMessage: function () {
|
|
|
|
test.pass("loader 1 item clicked as expected");
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item0, item1], [], []);
|
|
|
|
let item1Elt = test.getItemElt(popup, item1);
|
|
|
|
|
|
|
|
// create a command event
|
|
|
|
let evt = item1Elt.ownerDocument.createEvent('Event');
|
|
|
|
evt.initEvent('command', true, true);
|
|
|
|
item1Elt.dispatchEvent(evt);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// An item's click listener should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemClick = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
data: "item data",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function (data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(this, item, "`this` inside onMessage should be item");
|
|
|
|
assert.equal(data.tagName, "HTML", "node should be an HTML element");
|
|
|
|
assert.equal(data.data, item.data, "data should be item data");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
let elt = test.getItemElt(popup, item);
|
|
|
|
elt.click();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A menu's click listener should work and receive bubbling clicks from
|
|
|
|
// sub-items appropriately. This also tests menus and ensures that when a CSS
|
|
|
|
// selector context matches the clicked node's ancestor, the matching ancestor
|
|
|
|
// is passed to listeners as the clicked node.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuClick = function (assert, done) {
|
2013-02-02 01:17:34 +04:00
|
|
|
// Create a top-level menu, submenu, and item, like this:
|
|
|
|
// topMenu -> submenu -> item
|
|
|
|
// Click the item and make sure the click bubbles.
|
2013-10-05 03:48:52 +04:00
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "submenu item",
|
|
|
|
data: "submenu item data",
|
|
|
|
context: loader.cm.SelectorContext("a"),
|
|
|
|
});
|
|
|
|
|
|
|
|
let submenu = new loader.cm.Menu({
|
|
|
|
label: "submenu",
|
|
|
|
context: loader.cm.SelectorContext("a"),
|
|
|
|
items: [item]
|
|
|
|
});
|
|
|
|
|
|
|
|
let topMenu = new loader.cm.Menu({
|
|
|
|
label: "top menu",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function (data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(this, topMenu, "`this` inside top menu should be menu");
|
|
|
|
assert.equal(data.tagName, "A", "Clicked node should be anchor");
|
|
|
|
assert.equal(data.data, item.data,
|
2013-02-02 01:17:34 +04:00
|
|
|
"Clicked item data should be correct");
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
items: [submenu],
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
});
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#span-link", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([topMenu], [], []);
|
|
|
|
let topMenuElt = test.getItemElt(popup, topMenu);
|
|
|
|
let topMenuPopup = topMenuElt.firstChild;
|
|
|
|
let submenuElt = test.getItemElt(topMenuPopup, submenu);
|
|
|
|
let submenuPopup = submenuElt.firstChild;
|
|
|
|
let itemElt = test.getItemElt(submenuPopup, item);
|
|
|
|
itemElt.click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Click listeners should work when multiple modules are loaded.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemClickMultipleModules = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let item0 = loader0.cm.Item({
|
|
|
|
label: "loader 0 item",
|
|
|
|
contentScript: 'self.on("click", self.postMessage);',
|
|
|
|
onMessage: function () {
|
|
|
|
test.fail("loader 0 item should not emit click event");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let item1 = loader1.cm.Item({
|
|
|
|
label: "loader 1 item",
|
|
|
|
contentScript: 'self.on("click", self.postMessage);',
|
|
|
|
onMessage: function () {
|
|
|
|
test.pass("loader 1 item clicked as expected");
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item0, item1], [], []);
|
|
|
|
let item1Elt = test.getItemElt(popup, item1);
|
|
|
|
item1Elt.click();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Adding a separator to a submenu should work OK.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSeparator = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = new loader.cm.Menu({
|
|
|
|
label: "submenu",
|
|
|
|
items: [new loader.cm.Separator()]
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The parentMenu option should work
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testParentMenu = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = new loader.cm.Menu({
|
|
|
|
label: "submenu",
|
|
|
|
items: [loader.cm.Item({ label: "item 1" })],
|
|
|
|
parentMenu: loader.cm.contentContextMenu
|
|
|
|
});
|
|
|
|
|
|
|
|
let item = loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
parentMenu: menu,
|
|
|
|
});
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[1], item, "Item should be in the sub menu");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-04-26 13:04:23 +04:00
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Existing context menu modifications should apply to new windows.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testNewWindow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.withNewWindow(function () {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// When a new window is opened, items added by an unloaded module should not
|
|
|
|
// be present in the menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testNewWindowMultipleModules = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
loader.unload();
|
|
|
|
test.withNewWindow(function () {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], [item]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-04-26 13:04:23 +04:00
|
|
|
// Existing context menu modifications should not apply to new private windows.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testNewPrivateWindow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-04-26 13:04:23 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
test.withNewPrivateWindow(function () {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Existing context menu modifications should apply to new private windows when
|
|
|
|
// private browsing support is enabled.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testNewPrivateEnabledWindow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-04-26 13:04:23 +04:00
|
|
|
let loader = test.newPrivateLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
test.withNewPrivateWindow(function () {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Existing context menu modifications should apply to new private windows when
|
|
|
|
// private browsing support is enabled unless unloaded.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testNewPrivateEnabledWindowUnloaded = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-04-26 13:04:23 +04:00
|
|
|
let loader = test.newPrivateLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item" });
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
loader.unload();
|
|
|
|
|
|
|
|
test.withNewPrivateWindow(function () {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Items in the context menu should be sorted according to locale.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSorting = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
// Make an unsorted items list. It'll look like this:
|
|
|
|
// item 1, item 0, item 3, item 2, item 5, item 4, ...
|
|
|
|
let items = [];
|
|
|
|
for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i += 2) {
|
|
|
|
items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
|
|
|
|
items.push(new loader.cm.Item({ label: "item " + i }));
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Items in the overflow menu should be sorted according to locale.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSortingOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
// Make an unsorted items list. It'll look like this:
|
|
|
|
// item 1, item 0, item 3, item 2, item 5, item 4, ...
|
|
|
|
let items = [];
|
|
|
|
for (let i = 0; i < OVERFLOW_THRESH_DEFAULT * 2; i += 2) {
|
|
|
|
items.push(new loader.cm.Item({ label: "item " + (i + 1) }));
|
|
|
|
items.push(new loader.cm.Item({ label: "item " + i }));
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Multiple modules shouldn't interfere with sorting.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSortingMultipleModules = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader0 = test.newLoader();
|
|
|
|
let loader1 = test.newLoader();
|
|
|
|
|
|
|
|
let items0 = [];
|
|
|
|
let items1 = [];
|
|
|
|
for (let i = 0; i < OVERFLOW_THRESH_DEFAULT; i++) {
|
|
|
|
if (i % 2) {
|
|
|
|
let item = new loader0.cm.Item({ label: "item " + i });
|
|
|
|
items0.push(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let item = new loader1.cm.Item({ label: "item " + i });
|
|
|
|
items1.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let allItems = items0.concat(items1);
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// All items should be present and sorted.
|
|
|
|
test.checkMenu(allItems, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
loader0.unload();
|
|
|
|
loader1.unload();
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
|
|
|
|
// All items should be removed.
|
|
|
|
test.checkMenu(allItems, [], allItems);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Content click handlers and context handlers should be able to communicate,
|
|
|
|
// i.e., they're eval'ed in the same worker and sandbox.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testContentCommunication = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript: 'var potato;' +
|
|
|
|
'self.on("context", function () {' +
|
|
|
|
' potato = "potato";' +
|
|
|
|
' return true;' +
|
|
|
|
'});' +
|
|
|
|
'self.on("click", function () {' +
|
|
|
|
' self.postMessage(potato);' +
|
|
|
|
'});',
|
|
|
|
});
|
|
|
|
|
|
|
|
item.on("message", function (data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(data, "potato", "That's a lot of potatoes!");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
let elt = test.getItemElt(popup, item);
|
|
|
|
elt.click();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// When the context menu is invoked on a tab that was already open when the
|
|
|
|
// module was loaded, it should contain the expected items and content workers
|
|
|
|
// should function as expected.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testLoadWithOpenTab = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
contentScript:
|
|
|
|
'self.on("click", function () self.postMessage("click"));',
|
|
|
|
onMessage: function (msg) {
|
|
|
|
if (msg === "click")
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.getItemElt(popup, item).click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Bug 732716: Ensure that the node given in `click` event works fine
|
|
|
|
// (i.e. is correctly wrapped)
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testDrawImageOnClickNode = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.SelectorContext("img"),
|
|
|
|
contentScript: "new " + function() {
|
|
|
|
self.on("click", function (img, data) {
|
|
|
|
let ctx = document.createElement("canvas").getContext("2d");
|
|
|
|
ctx.drawImage(img, 1, 1, 1, 1);
|
|
|
|
self.postMessage("done");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onMessage: function (msg) {
|
|
|
|
if (msg === "done")
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
});
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.getItemElt(popup, item).click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Setting an item's label before the menu is ever shown should correctly change
|
|
|
|
// its label.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSetLabelBeforeShow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({ label: "a" }),
|
|
|
|
new loader.cm.Item({ label: "b" })
|
|
|
|
]
|
|
|
|
items[0].label = "z";
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(items[0].label, "z");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting an item's label after the menu is shown should correctly change its
|
|
|
|
// label.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSetLabelAfterShow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({ label: "a" }),
|
|
|
|
new loader.cm.Item({ label: "b" })
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
items[0].label = "z";
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(items[0].label, "z");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting an item's label before the menu is ever shown should correctly change
|
|
|
|
// its label.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSetLabelBeforeShowOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let prefs = loader.loader.require("sdk/preferences/service");
|
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 0);
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({ label: "a" }),
|
|
|
|
new loader.cm.Item({ label: "b" })
|
|
|
|
]
|
|
|
|
items[0].label = "z";
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(items[0].label, "z");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting an item's label after the menu is shown should correctly change its
|
|
|
|
// label.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSetLabelAfterShowOverflow = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let prefs = loader.loader.require("sdk/preferences/service");
|
|
|
|
prefs.set(OVERFLOW_THRESH_PREF, 0);
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
new loader.cm.Item({ label: "a" }),
|
|
|
|
new loader.cm.Item({ label: "b" })
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
popup.hidePopup();
|
|
|
|
|
|
|
|
items[0].label = "z";
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(items[0].label, "z");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting the label of an item in a Menu should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSetLabelMenuItem = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [loader.cm.Item({ label: "a" })]
|
|
|
|
});
|
|
|
|
menu.items[0].label = "z";
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[0].label, "z");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Menu.addItem() should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuAddItem = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({ label: "item 0" })
|
|
|
|
]
|
|
|
|
});
|
|
|
|
menu.addItem(loader.cm.Item({ label: "item 1" }));
|
|
|
|
menu.addItem(loader.cm.Item({ label: "item 2" }));
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items.length, 3,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[i].label, "item " + i,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[i].parentMenu, menu,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Adding the same item twice to a menu should work as expected.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuAddItemTwice = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: []
|
|
|
|
});
|
|
|
|
let subitem = loader.cm.Item({ label: "item 1" })
|
|
|
|
menu.addItem(subitem);
|
|
|
|
menu.addItem(loader.cm.Item({ label: "item 0" }));
|
|
|
|
menu.addItem(subitem);
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items.length, 2,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
|
|
|
for (let i = 0; i < 2; i++) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[i].label, "item " + i,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Menu.removeItem() should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuRemoveItem = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let subitem = loader.cm.Item({ label: "item 1" });
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({ label: "item 0" }),
|
|
|
|
subitem,
|
|
|
|
loader.cm.Item({ label: "item 2" })
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
// Removing twice should be harmless.
|
|
|
|
menu.removeItem(subitem);
|
|
|
|
menu.removeItem(subitem);
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(subitem.parentMenu, null,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items.length, 2,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[0].label, "item 0",
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[1].label, "item 2",
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Adding an item currently contained in one menu to another menu should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuItemSwap = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let subitem = loader.cm.Item({ label: "item" });
|
|
|
|
let menu0 = loader.cm.Menu({
|
|
|
|
label: "menu 0",
|
|
|
|
items: [subitem]
|
|
|
|
});
|
|
|
|
let menu1 = loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
items: []
|
|
|
|
});
|
|
|
|
menu1.addItem(subitem);
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu0.items.length, 0,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu1.items.length, 1,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu1.items[0].label, "item",
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(subitem.parentMenu, menu1,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu0, menu1], [menu0], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Destroying an item should remove it from its parent menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuItemDestroy = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let subitem = loader.cm.Item({ label: "item" });
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [subitem]
|
|
|
|
});
|
|
|
|
subitem.destroy();
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items.length, 0,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(subitem.parentMenu, null,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [menu], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting Menu.items should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuItemsSetter = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({ label: "old item 0" }),
|
|
|
|
loader.cm.Item({ label: "old item 1" })
|
|
|
|
]
|
|
|
|
});
|
|
|
|
menu.items = [
|
|
|
|
loader.cm.Item({ label: "new item 0" }),
|
|
|
|
loader.cm.Item({ label: "new item 1" }),
|
|
|
|
loader.cm.Item({ label: "new item 2" })
|
|
|
|
];
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items.length, 3,
|
2013-02-02 01:17:34 +04:00
|
|
|
"menu should have correct number of items");
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[i].label, "new item " + i,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item label should be correct");
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(menu.items[i].parentMenu, menu,
|
2013-02-02 01:17:34 +04:00
|
|
|
"item's parent menu should be correct");
|
|
|
|
}
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Setting Item.data should work.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemDataSetter = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = loader.cm.Item({ label: "old item 0", data: "old" });
|
|
|
|
item.data = "new";
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.data, "new", "item should have correct data");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Open the test doc, load the module, make sure items appear when context-
|
|
|
|
// clicking the iframe.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testAlreadyOpenIframe = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let item = new loader.cm.Item({
|
|
|
|
label: "item"
|
|
|
|
});
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#iframe", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item], [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
// Tests that a missing label throws an exception
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemNoLabel = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-21 19:54:55 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
try {
|
|
|
|
new loader.cm.Item({});
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(false, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(true, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
new loader.cm.Item({ label: null });
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(false, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(true, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
new loader.cm.Item({ label: undefined });
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(false, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(true, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
new loader.cm.Item({ label: "" });
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(false, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
catch (e) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.ok(true, "Should have seen exception");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Tests that items can have an empty data property
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemNoData = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-21 19:54:55 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
function checkData(data) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(data, undefined, "Data should be undefined");
|
2013-02-21 19:54:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
let item1 = new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
|
|
|
|
onMessage: checkData
|
|
|
|
});
|
|
|
|
let item2 = new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
data: null,
|
|
|
|
contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
|
|
|
|
onMessage: checkData
|
|
|
|
});
|
|
|
|
let item3 = new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
data: undefined,
|
|
|
|
contentScript: 'self.on("click", function(node, data) self.postMessage(data))',
|
|
|
|
onMessage: checkData
|
|
|
|
});
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item1.data, undefined, "Should be no defined data");
|
|
|
|
assert.equal(item2.data, null, "Should be no defined data");
|
|
|
|
assert.equal(item3.data, undefined, "Should be no defined data");
|
2013-02-21 19:54:55 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item1, item2, item3], [], []);
|
|
|
|
|
|
|
|
let itemElt = test.getItemElt(popup, item1);
|
|
|
|
itemElt.click();
|
|
|
|
|
|
|
|
test.hideMenu(function() {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
let itemElt = test.getItemElt(popup, item2);
|
|
|
|
itemElt.click();
|
|
|
|
|
|
|
|
test.hideMenu(function() {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
let itemElt = test.getItemElt(popup, item3);
|
|
|
|
itemElt.click();
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-26 19:32:55 +04:00
|
|
|
exports.testItemNoAccessKey = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item1 = new loader.cm.Item({ label: "item 1" });
|
|
|
|
let item2 = new loader.cm.Item({ label: "item 2", accesskey: null });
|
|
|
|
let item3 = new loader.cm.Item({ label: "item 3", accesskey: undefined });
|
|
|
|
|
|
|
|
assert.equal(item1.accesskey, undefined, "Should be no defined image");
|
|
|
|
assert.equal(item2.accesskey, null, "Should be no defined image");
|
|
|
|
assert.equal(item3.accesskey, undefined, "Should be no defined image");
|
|
|
|
|
|
|
|
test.showMenu().
|
|
|
|
then((popup) => test.checkMenu([item1, item2, item3], [], [])).
|
|
|
|
then(test.done).
|
|
|
|
catch(assert.fail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test accesskey support.
|
|
|
|
exports.testItemAccessKey = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item = new loader.cm.Item({ label: "item", accesskey: "i" });
|
|
|
|
assert.equal(item.accesskey, "i", "Should have set the image to i");
|
|
|
|
|
|
|
|
let menu = new loader.cm.Menu({ label: "menu", accesskey: "m", items: [
|
|
|
|
loader.cm.Item({ label: "subitem" })
|
|
|
|
]});
|
|
|
|
assert.equal(menu.accesskey, "m", "Should have set the accesskey to m");
|
|
|
|
|
|
|
|
test.showMenu().then((popup) => {
|
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
|
|
|
|
let accesskey = "e";
|
|
|
|
menu.accesskey = item.accesskey = accesskey;
|
|
|
|
assert.equal(item.accesskey, accesskey, "Should have set the accesskey to " + accesskey);
|
|
|
|
assert.equal(menu.accesskey, accesskey, "Should have set the accesskey to " + accesskey);
|
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
|
|
|
|
item.accesskey = null;
|
|
|
|
menu.accesskey = null;
|
|
|
|
assert.equal(item.accesskey, null, "Should have set the accesskey to " + accesskey);
|
|
|
|
assert.equal(menu.accesskey, null, "Should have set the accesskey to " + accesskey);
|
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
}).
|
|
|
|
then(test.done).
|
|
|
|
catch(assert.fail);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-21 19:54:55 +04:00
|
|
|
// Tests that items without an image don't attempt to show one
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemNoImage = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-21 19:54:55 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let item1 = new loader.cm.Item({ label: "item 1" });
|
|
|
|
let item2 = new loader.cm.Item({ label: "item 2", image: null });
|
|
|
|
let item3 = new loader.cm.Item({ label: "item 3", image: undefined });
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item1.image, undefined, "Should be no defined image");
|
|
|
|
assert.equal(item2.image, null, "Should be no defined image");
|
|
|
|
assert.equal(item3.image, undefined, "Should be no defined image");
|
2013-02-21 19:54:55 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item1, item2, item3], [], []);
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Test image support.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemImage = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
2013-11-06 01:51:58 +04:00
|
|
|
let imageURL = data.url("moz_favicon.ico");
|
2013-02-02 01:17:34 +04:00
|
|
|
let item = new loader.cm.Item({ label: "item", image: imageURL });
|
|
|
|
let menu = new loader.cm.Menu({ label: "menu", image: imageURL, items: [
|
|
|
|
loader.cm.Item({ label: "subitem" })
|
|
|
|
]});
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.image, imageURL, "Should have set the image correctly");
|
|
|
|
assert.equal(menu.image, imageURL, "Should have set the image correctly");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
|
2013-11-06 01:51:58 +04:00
|
|
|
let imageURL2 = data.url("dummy.ico");
|
2013-02-02 01:17:34 +04:00
|
|
|
item.image = imageURL2;
|
|
|
|
menu.image = imageURL2;
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.image, imageURL2, "Should have set the image correctly");
|
|
|
|
assert.equal(menu.image, imageURL2, "Should have set the image correctly");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
|
|
|
|
item.image = null;
|
|
|
|
menu.image = null;
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item.image, null, "Should have set the image correctly");
|
|
|
|
assert.equal(menu.image, null, "Should have set the image correctly");
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu([item, menu], [], []);
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-05-08 06:30:52 +04:00
|
|
|
// Test image URL validation.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testItemImageValidURL = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-05-08 06:30:52 +04:00
|
|
|
let loader = test.newLoader();
|
2013-11-06 01:51:58 +04:00
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.throws(function(){
|
2013-05-08 06:30:52 +04:00
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 1",
|
|
|
|
image: "foo"
|
|
|
|
})
|
2013-10-05 03:48:52 +04:00
|
|
|
}, /Image URL validation failed/
|
2013-05-08 06:30:52 +04:00
|
|
|
);
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.throws(function(){
|
2013-05-08 06:30:52 +04:00
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 2",
|
|
|
|
image: false
|
|
|
|
})
|
2013-10-05 03:48:52 +04:00
|
|
|
}, /Image URL validation failed/
|
2013-05-08 06:30:52 +04:00
|
|
|
);
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.throws(function(){
|
2013-05-08 06:30:52 +04:00
|
|
|
new loader.cm.Item({
|
|
|
|
label: "item 3",
|
|
|
|
image: 0
|
|
|
|
})
|
2013-10-05 03:48:52 +04:00
|
|
|
}, /Image URL validation failed/
|
2013-05-08 06:30:52 +04:00
|
|
|
);
|
2013-11-06 01:51:58 +04:00
|
|
|
|
|
|
|
let imageURL = data.url("moz_favicon.ico");
|
2013-05-08 06:30:52 +04:00
|
|
|
let item4 = new loader.cm.Item({ label: "item 4", image: imageURL });
|
|
|
|
let item5 = new loader.cm.Item({ label: "item 5", image: null });
|
|
|
|
let item6 = new loader.cm.Item({ label: "item 6", image: undefined });
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(item4.image, imageURL, "Should be proper image URL");
|
|
|
|
assert.equal(item5.image, null, "Should be null image");
|
|
|
|
assert.equal(item6.image, undefined, "Should be undefined image");
|
2013-05-08 06:30:52 +04:00
|
|
|
|
|
|
|
test.done();
|
2013-10-05 03:48:52 +04:00
|
|
|
};
|
2013-05-08 06:30:52 +04:00
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
// Menu.destroy should destroy the item tree rooted at that menu.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testMenuDestroy = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let menu = loader.cm.Menu({
|
|
|
|
label: "menu",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({ label: "item 0" }),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "item 1",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({ label: "subitem 0" }),
|
|
|
|
loader.cm.Item({ label: "subitem 1" }),
|
|
|
|
loader.cm.Item({ label: "subitem 2" })
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Item({ label: "item 2" })
|
|
|
|
]
|
|
|
|
});
|
|
|
|
menu.destroy();
|
|
|
|
|
|
|
|
/*let numRegistryEntries = 0;
|
|
|
|
loader.globalScope.browserManager.browserWins.forEach(function (bwin) {
|
|
|
|
for (let itemID in bwin.items)
|
|
|
|
numRegistryEntries++;
|
|
|
|
});
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(numRegistryEntries, 0, "All items should be unregistered.");*/
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([menu], [], [menu]);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Checks that if a menu contains sub items that are hidden then the menu is
|
|
|
|
// hidden too. Also checks that content scripts and contexts work for sub items.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSubItemContextNoMatchHideMenu = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 1",
|
|
|
|
context: loader.cm.SelectorContext(".foo")
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 2",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 2",
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 3",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 3",
|
|
|
|
context: loader.cm.SelectorContext(".foo")
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 4",
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Checks that if a menu contains a combination of hidden and visible sub items
|
|
|
|
// then the menu is still visible too.
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSubItemContextMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let hiddenItems = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 3",
|
|
|
|
context: loader.cm.SelectorContext(".foo")
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 6",
|
|
|
|
contentScript: 'self.on("context", function () false);'
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 1",
|
|
|
|
context: loader.cm.URLContext(TEST_DOC_URL)
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 2",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 2",
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 3",
|
|
|
|
items: [
|
|
|
|
hiddenItems[0],
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 4",
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 4",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 5",
|
|
|
|
context: loader.cm.URLContext(TEST_DOC_URL)
|
|
|
|
}),
|
|
|
|
hiddenItems[1]
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 5",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 7",
|
|
|
|
context: loader.cm.URLContext(TEST_DOC_URL)
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 8",
|
|
|
|
contentScript: 'self.on("context", function () true);'
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, hiddenItems, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Child items should default to visible, not to PageContext
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSubItemDefaultVisible = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
context: loader.cm.SelectorContext("img"),
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 1"
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 2",
|
|
|
|
context: loader.cm.SelectorContext("img")
|
|
|
|
}),
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 3",
|
|
|
|
context: loader.cm.SelectorContext("a")
|
|
|
|
})
|
|
|
|
]
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
// subitem 3 will be hidden
|
|
|
|
let hiddenItems = [items[0].items[2]];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, hiddenItems, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Tests that the click event on sub menuitem
|
|
|
|
// tiggers the click event for the sub menuitem and the parent menu
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSubItemClick = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let state = 0;
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 1",
|
|
|
|
data: "foobar",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function(msg) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(msg.tagName, "HTML", "should have seen the right node");
|
|
|
|
assert.equal(msg.data, "foobar", "should have seen the right data");
|
|
|
|
assert.equal(state, 0, "should have seen the event at the right time");
|
2013-02-02 01:17:34 +04:00
|
|
|
state++;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function(msg) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(msg.tagName, "HTML", "should have seen the right node");
|
|
|
|
assert.equal(msg.data, "foobar", "should have seen the right data");
|
|
|
|
assert.equal(state, 1, "should have seen the event at the right time");
|
2013-02-02 01:17:34 +04:00
|
|
|
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
|
|
|
|
let topMenuElt = test.getItemElt(popup, items[0]);
|
|
|
|
let topMenuPopup = topMenuElt.firstChild;
|
|
|
|
let itemElt = test.getItemElt(topMenuPopup, items[0].items[0]);
|
|
|
|
itemElt.click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-02-14 22:03:26 +04:00
|
|
|
// Tests that the command event on sub menuitem
|
|
|
|
// tiggers the click event for the sub menuitem and the parent menu
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSubItemCommand = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-14 22:03:26 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let state = 0;
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Menu({
|
|
|
|
label: "menu 1",
|
|
|
|
items: [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "subitem 1",
|
|
|
|
data: "foobar",
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function(msg) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(msg.tagName, "HTML", "should have seen the right node");
|
|
|
|
assert.equal(msg.data, "foobar", "should have seen the right data");
|
|
|
|
assert.equal(state, 0, "should have seen the event at the right time");
|
2013-02-14 22:03:26 +04:00
|
|
|
state++;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
contentScript: 'self.on("click", function (node, data) {' +
|
|
|
|
' self.postMessage({' +
|
|
|
|
' tagName: node.tagName,' +
|
|
|
|
' data: data' +
|
|
|
|
' });' +
|
|
|
|
'});',
|
|
|
|
onMessage: function(msg) {
|
2013-10-05 03:48:52 +04:00
|
|
|
assert.equal(msg.tagName, "HTML", "should have seen the right node");
|
|
|
|
assert.equal(msg.data, "foobar", "should have seen the right data");
|
|
|
|
assert.equal(state, 1, "should have seen the event at the right time");
|
2013-02-14 22:03:26 +04:00
|
|
|
state++
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
|
|
|
|
let topMenuElt = test.getItemElt(popup, items[0]);
|
|
|
|
let topMenuPopup = topMenuElt.firstChild;
|
|
|
|
let itemElt = test.getItemElt(topMenuPopup, items[0].items[0]);
|
|
|
|
|
|
|
|
// create a command event
|
|
|
|
let evt = itemElt.ownerDocument.createEvent('Event');
|
|
|
|
evt.initEvent('command', true, true);
|
|
|
|
itemElt.dispatchEvent(evt);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-02-02 01:17:34 +04:00
|
|
|
// Tests that opening a context menu for an outer frame when an inner frame
|
|
|
|
// has a selection doesn't activate the SelectionContext
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionInInnerFrameNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let state = 0;
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "test item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let frame = doc.getElementById("iframe");
|
|
|
|
frame.contentWindow.getSelection().selectAllChildren(frame.contentDocument.body);
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Tests that opening a context menu for an inner frame when the inner frame
|
|
|
|
// has a selection does activate the SelectionContext
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionInInnerFrameMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let state = 0;
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "test item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let frame = doc.getElementById("iframe");
|
|
|
|
frame.contentWindow.getSelection().selectAllChildren(frame.contentDocument.body);
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(["#iframe", "#text"], function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Tests that opening a context menu for an inner frame when the outer frame
|
|
|
|
// has a selection doesn't activate the SelectionContext
|
2013-10-05 03:48:52 +04:00
|
|
|
exports.testSelectionInOuterFrameNoMatch = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
2013-02-02 01:17:34 +04:00
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let state = 0;
|
|
|
|
|
|
|
|
let items = [
|
|
|
|
loader.cm.Item({
|
|
|
|
label: "test item",
|
|
|
|
context: loader.cm.SelectionContext()
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let frame = doc.getElementById("iframe");
|
|
|
|
window.getSelection().selectAllChildren(doc.body);
|
|
|
|
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(["#iframe", "#text"], function (popup) {
|
2013-02-02 01:17:34 +04:00
|
|
|
test.checkMenu(items, items, []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
|
|
|
|
// Test that the return value of the predicate function determines if
|
|
|
|
// item is shown
|
|
|
|
exports.testPredicateContextControl = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let itemTrue = loader.cm.Item({
|
|
|
|
label: "visible",
|
|
|
|
context: loader.cm.PredicateContext(function () { return true; })
|
|
|
|
});
|
|
|
|
|
|
|
|
let itemFalse = loader.cm.Item({
|
|
|
|
label: "hidden",
|
|
|
|
context: loader.cm.PredicateContext(function () { return false; })
|
|
|
|
});
|
|
|
|
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu([itemTrue, itemFalse], [itemFalse], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has the correct document type
|
|
|
|
exports.testPredicateContextDocumentType = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.equal(data.documentType, 'text/html');
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has the correct document URL
|
|
|
|
exports.testPredicateContextDocumentURL = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.equal(data.documentURL, TEST_DOC_URL);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object has the correct element name
|
|
|
|
exports.testPredicateContextTargetName = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.targetName, "input");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#button", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object has the correct ID
|
|
|
|
exports.testPredicateContextTargetIDSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.targetID, "button");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#button", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has the correct ID
|
|
|
|
exports.testPredicateContextTargetIDNotSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.targetID, null);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(".predicate-test-a", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly for regular text inputs
|
|
|
|
exports.testPredicateContextTextBoxIsEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, true);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#textbox", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly for readonly text inputs
|
|
|
|
exports.testPredicateContextReadonlyTextBoxIsNotEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, false);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#readonly-textbox", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly for disabled text inputs
|
|
|
|
exports.testPredicateContextDisabledTextBoxIsNotEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, false);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#disabled-textbox", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly for text areas
|
|
|
|
exports.testPredicateContextTextAreaIsEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, true);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#textfield", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that non-text inputs are not considered editable
|
|
|
|
exports.testPredicateContextButtonIsNotEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, false);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#button", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly
|
|
|
|
exports.testPredicateContextNonInputIsNotEditable = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, false);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object is showing editable correctly for HTML contenteditable elements
|
|
|
|
exports.testPredicateContextEditableElement = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.isEditable, true);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#editable", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object does not have a selection when there is none
|
|
|
|
exports.testPredicateContextNoSelectionInPage = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.selectionText, null);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object includes the selected page text
|
|
|
|
exports.testPredicateContextSelectionInPage = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
// since we might get whitespace
|
|
|
|
assert.ok(data.selectionText && data.selectionText.search(/^\s*Some text.\s*$/) != -1,
|
|
|
|
'Expected "Some text.", got "' + data.selectionText + '"');
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
window.getSelection().selectAllChildren(doc.getElementById("text"));
|
|
|
|
test.showMenu(null, function (popup) {
|
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object includes the selected input text
|
|
|
|
exports.testPredicateContextSelectionInTextBox = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
// since we might get whitespace
|
|
|
|
assert.strictEqual(data.selectionText, "t v");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
let textbox = doc.getElementById("textbox");
|
2014-11-18 01:08:07 +03:00
|
|
|
test.selectRange("#textbox", 3, 6);
|
|
|
|
test.showMenu("#textbox", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has the correct src for an image
|
|
|
|
exports.testPredicateContextTargetSrcSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let image;
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.srcURL, image.src);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
|
|
|
image = doc.getElementById("image");
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has no src for a link
|
|
|
|
exports.testPredicateContextTargetSrcNotSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.srcURL, null);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#link", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Test that the data object has the correct link set
|
|
|
|
exports.testPredicateContextTargetLinkSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let image;
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.linkURL, TEST_DOC_URL + "#test");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu(".predicate-test-a", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has no link for an image
|
|
|
|
exports.testPredicateContextTargetLinkNotSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.linkURL, null);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-07-03 01:37:05 +04:00
|
|
|
// Test that the data object has the correct link for a nested image
|
|
|
|
exports.testPredicateContextTargetLinkSetNestedImage = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.linkURL, TEST_DOC_URL + "#nested-image");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#predicate-test-nested-image", function (popup) {
|
2014-07-03 01:37:05 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has the correct link for a complex nested structure
|
|
|
|
exports.testPredicateContextTargetLinkSetNestedStructure = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
|
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.linkURL, TEST_DOC_URL + "#nested-structure");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#predicate-test-nested-structure", function (popup) {
|
2014-07-03 01:37:05 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
// Test that the data object has the value for an input textbox
|
|
|
|
exports.testPredicateContextTargetValueSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
|
|
|
let image;
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.value, "test value");
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#textbox", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Test that the data object has no value for an image
|
|
|
|
exports.testPredicateContextTargetValueNotSet = function (assert, done) {
|
|
|
|
let test = new TestHelper(assert, done);
|
|
|
|
let loader = test.newLoader();
|
2014-03-20 19:07:16 +04:00
|
|
|
|
2013-12-20 02:50:18 +04:00
|
|
|
let items = [loader.cm.Item({
|
|
|
|
label: "item",
|
|
|
|
context: loader.cm.PredicateContext(function (data) {
|
|
|
|
assert.strictEqual(data.value, null);
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
})];
|
|
|
|
|
|
|
|
test.withTestDoc(function (window, doc) {
|
2014-11-18 01:08:07 +03:00
|
|
|
test.showMenu("#image", function (popup) {
|
2013-12-20 02:50:18 +04:00
|
|
|
test.checkMenu(items, [], []);
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-02-03 20:51:16 +03:00
|
|
|
if (packaging.isNative) {
|
|
|
|
module.exports = {
|
|
|
|
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
|
|
|
|
};
|
2013-02-02 01:17:34 +04:00
|
|
|
}
|
|
|
|
|
2013-10-05 03:48:52 +04:00
|
|
|
require('sdk/test').run(exports);
|