Permalink
Browse files

Bug 842702: Add tests for empty data and label properties and address…

… review comments.
  • Loading branch information...
1 parent 9a03551 commit 3bacd9fffd2d33cc2c68c1ce2671f82e96621550 @Mossop committed Feb 19, 2013
Showing with 100 additions and 3 deletions.
  1. +100 −3 test/test-context-menu.js
View
@@ -2477,6 +2477,103 @@ exports.testAlreadyOpenIframe = function (test) {
};
+// Tests that a missing label throws an exception
+exports.testItemNoLabel = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ try {
+ new loader.cm.Item({});
+ test.assert(false, "Should have seen exception");
+ }
+ catch (e) {
+ test.assert(true, "Should have seen exception");
+ }
+
+ try {
+ new loader.cm.Item({ label: null });
+ test.assert(false, "Should have seen exception");
+ }
+ catch (e) {
+ test.assert(true, "Should have seen exception");
+ }
+
+ try {
+ new loader.cm.Item({ label: undefined });
+ test.assert(false, "Should have seen exception");
+ }
+ catch (e) {
+ test.assert(true, "Should have seen exception");
+ }
+
+ try {
+ new loader.cm.Item({ label: "" });
+ test.assert(false, "Should have seen exception");
+ }
+ catch (e) {
+ test.assert(true, "Should have seen exception");
+ }
+
+ test.done();
+}
+
+
+// Tests that items can have an empty data property
+exports.testItemNoData = function (test) {
+ test = new TestHelper(test);
+ let loader = test.newLoader();
+
+ function checkData(data) {
+ test.assertEqual(data, undefined, "Data should be undefined");
+ }
+
+ 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
+ });
+
+ test.assertEqual(item1.data, undefined, "Should be no defined data");
+ test.assertEqual(item2.data, null, "Should be no defined data");
+ test.assertEqual(item3.data, undefined, "Should be no defined data");
+
+ 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();
+ });
+ });
+ });
+ });
+ });
+}
+
+
// Tests that items without an image don't attempt to show one
exports.testItemNoImage = function (test) {
test = new TestHelper(test);
@@ -2486,9 +2583,9 @@ exports.testItemNoImage = function (test) {
let item2 = new loader.cm.Item({ label: "item 2", image: null });
let item3 = new loader.cm.Item({ label: "item 3", image: undefined });
- test.assert(!item1.image, "Should be no defined image");
- test.assert(!item2.image, "Should be no defined image");
- test.assert(!item3.image, "Should be no defined image");
+ test.assertEqual(item1.image, undefined, "Should be no defined image");
+ test.assertEqual(item2.image, null, "Should be no defined image");
+ test.assertEqual(item3.image, undefined, "Should be no defined image");
test.showMenu(null, function (popup) {
test.checkMenu([item1, item2, item3], [], []);

0 comments on commit 3bacd9f

Please sign in to comment.