michael@0: /* Make sure context menu includes option to search hyperlink text on search engine */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); michael@0: michael@0: let doc = gBrowser.contentDocument; michael@0: let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); michael@0: let ellipsis = "\u2026"; michael@0: michael@0: // Tests if the "Search for ''" context menu item is shown for the michael@0: // given query string of an element. Tests to make sure label includes the proper search terms. michael@0: // michael@0: // Options: michael@0: // michael@0: // id: The id of the element to test. michael@0: // isSelected: Flag to enable selection (text hilight) the contents of the element michael@0: // shouldBeShown: The display state of the menu item michael@0: // expectedLabelContents: The menu item label should contain a portion of this string. michael@0: // Will only be tested if shouldBeShown is true. michael@0: michael@0: let testElement = function(opts) { michael@0: let element = doc.getElementById(opts.id); michael@0: document.popupNode = element; michael@0: michael@0: let selection = content.getSelection(); michael@0: selection.removeAllRanges(); michael@0: michael@0: if(opts.isSelected) { michael@0: selection.selectAllChildren(element); michael@0: } michael@0: michael@0: let contextMenu = new nsContextMenu(contentAreaContextMenu); michael@0: let menuItem = document.getElementById("context-searchselect"); michael@0: michael@0: is(document.getElementById("context-searchselect").hidden, !opts.shouldBeShown, "search context menu item is shown for '#" + opts.id + "' and selected is '" + opts.isSelected + "'"); michael@0: michael@0: if(opts.shouldBeShown) { michael@0: ok(menuItem.label.contains(opts.expectedLabelContents), "Menu item text '" + menuItem.label + "' contains the correct search terms '" + opts.expectedLabelContents + "'"); michael@0: } michael@0: } michael@0: michael@0: testElement({ michael@0: id: "link", michael@0: isSelected: true, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "I'm a link!", michael@0: }); michael@0: testElement({ michael@0: id: "link", michael@0: isSelected: false, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "I'm a link!", michael@0: }); michael@0: michael@0: testElement({ michael@0: id: "longLink", michael@0: isSelected: true, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "I'm a really lo" + ellipsis, michael@0: }); michael@0: testElement({ michael@0: id: "longLink", michael@0: isSelected: false, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "I'm a really lo" + ellipsis, michael@0: }); michael@0: michael@0: testElement({ michael@0: id: "plainText", michael@0: isSelected: true, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "Right clicking " + ellipsis, michael@0: }); michael@0: testElement({ michael@0: id: "plainText", michael@0: isSelected: false, michael@0: shouldBeShown: false, michael@0: }); michael@0: michael@0: testElement({ michael@0: id: "mixedContent", michael@0: isSelected: true, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "I'm some text, " + ellipsis, michael@0: }); michael@0: testElement({ michael@0: id: "mixedContent", michael@0: isSelected: false, michael@0: shouldBeShown: false, michael@0: }); michael@0: michael@0: testElement({ michael@0: id: "partialLink", michael@0: isSelected: true, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "link selection", michael@0: }); michael@0: michael@0: testElement({ michael@0: id: "partialLink", michael@0: isSelected: false, michael@0: shouldBeShown: true, michael@0: expectedLabelContents: "A partial link " + ellipsis, michael@0: }); michael@0: michael@0: // cleanup michael@0: document.popupNode = null; michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }, true); michael@0: michael@0: content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug970746.xhtml"; michael@0: }