1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_bug970746.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* Make sure context menu includes option to search hyperlink text on search engine */ 1.5 + 1.6 +function test() { 1.7 + waitForExplicitFinish(); 1.8 + 1.9 + gBrowser.selectedTab = gBrowser.addTab(); 1.10 + 1.11 + gBrowser.selectedBrowser.addEventListener("load", function() { 1.12 + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); 1.13 + 1.14 + let doc = gBrowser.contentDocument; 1.15 + let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); 1.16 + let ellipsis = "\u2026"; 1.17 + 1.18 + // Tests if the "Search <engine> for '<some terms>'" context menu item is shown for the 1.19 + // given query string of an element. Tests to make sure label includes the proper search terms. 1.20 + // 1.21 + // Options: 1.22 + // 1.23 + // id: The id of the element to test. 1.24 + // isSelected: Flag to enable selection (text hilight) the contents of the element 1.25 + // shouldBeShown: The display state of the menu item 1.26 + // expectedLabelContents: The menu item label should contain a portion of this string. 1.27 + // Will only be tested if shouldBeShown is true. 1.28 + 1.29 + let testElement = function(opts) { 1.30 + let element = doc.getElementById(opts.id); 1.31 + document.popupNode = element; 1.32 + 1.33 + let selection = content.getSelection(); 1.34 + selection.removeAllRanges(); 1.35 + 1.36 + if(opts.isSelected) { 1.37 + selection.selectAllChildren(element); 1.38 + } 1.39 + 1.40 + let contextMenu = new nsContextMenu(contentAreaContextMenu); 1.41 + let menuItem = document.getElementById("context-searchselect"); 1.42 + 1.43 + is(document.getElementById("context-searchselect").hidden, !opts.shouldBeShown, "search context menu item is shown for '#" + opts.id + "' and selected is '" + opts.isSelected + "'"); 1.44 + 1.45 + if(opts.shouldBeShown) { 1.46 + ok(menuItem.label.contains(opts.expectedLabelContents), "Menu item text '" + menuItem.label + "' contains the correct search terms '" + opts.expectedLabelContents + "'"); 1.47 + } 1.48 + } 1.49 + 1.50 + testElement({ 1.51 + id: "link", 1.52 + isSelected: true, 1.53 + shouldBeShown: true, 1.54 + expectedLabelContents: "I'm a link!", 1.55 + }); 1.56 + testElement({ 1.57 + id: "link", 1.58 + isSelected: false, 1.59 + shouldBeShown: true, 1.60 + expectedLabelContents: "I'm a link!", 1.61 + }); 1.62 + 1.63 + testElement({ 1.64 + id: "longLink", 1.65 + isSelected: true, 1.66 + shouldBeShown: true, 1.67 + expectedLabelContents: "I'm a really lo" + ellipsis, 1.68 + }); 1.69 + testElement({ 1.70 + id: "longLink", 1.71 + isSelected: false, 1.72 + shouldBeShown: true, 1.73 + expectedLabelContents: "I'm a really lo" + ellipsis, 1.74 + }); 1.75 + 1.76 + testElement({ 1.77 + id: "plainText", 1.78 + isSelected: true, 1.79 + shouldBeShown: true, 1.80 + expectedLabelContents: "Right clicking " + ellipsis, 1.81 + }); 1.82 + testElement({ 1.83 + id: "plainText", 1.84 + isSelected: false, 1.85 + shouldBeShown: false, 1.86 + }); 1.87 + 1.88 + testElement({ 1.89 + id: "mixedContent", 1.90 + isSelected: true, 1.91 + shouldBeShown: true, 1.92 + expectedLabelContents: "I'm some text, " + ellipsis, 1.93 + }); 1.94 + testElement({ 1.95 + id: "mixedContent", 1.96 + isSelected: false, 1.97 + shouldBeShown: false, 1.98 + }); 1.99 + 1.100 + testElement({ 1.101 + id: "partialLink", 1.102 + isSelected: true, 1.103 + shouldBeShown: true, 1.104 + expectedLabelContents: "link selection", 1.105 + }); 1.106 + 1.107 + testElement({ 1.108 + id: "partialLink", 1.109 + isSelected: false, 1.110 + shouldBeShown: true, 1.111 + expectedLabelContents: "A partial link " + ellipsis, 1.112 + }); 1.113 + 1.114 + // cleanup 1.115 + document.popupNode = null; 1.116 + gBrowser.removeCurrentTab(); 1.117 + finish(); 1.118 + }, true); 1.119 + 1.120 + content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug970746.xhtml"; 1.121 +}