Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Make sure context menu includes option to search hyperlink text on search engine */ |
michael@0 | 2 | |
michael@0 | 3 | function test() { |
michael@0 | 4 | waitForExplicitFinish(); |
michael@0 | 5 | |
michael@0 | 6 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 7 | |
michael@0 | 8 | gBrowser.selectedBrowser.addEventListener("load", function() { |
michael@0 | 9 | gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 10 | |
michael@0 | 11 | let doc = gBrowser.contentDocument; |
michael@0 | 12 | let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); |
michael@0 | 13 | let ellipsis = "\u2026"; |
michael@0 | 14 | |
michael@0 | 15 | // Tests if the "Search <engine> for '<some terms>'" context menu item is shown for the |
michael@0 | 16 | // given query string of an element. Tests to make sure label includes the proper search terms. |
michael@0 | 17 | // |
michael@0 | 18 | // Options: |
michael@0 | 19 | // |
michael@0 | 20 | // id: The id of the element to test. |
michael@0 | 21 | // isSelected: Flag to enable selection (text hilight) the contents of the element |
michael@0 | 22 | // shouldBeShown: The display state of the menu item |
michael@0 | 23 | // expectedLabelContents: The menu item label should contain a portion of this string. |
michael@0 | 24 | // Will only be tested if shouldBeShown is true. |
michael@0 | 25 | |
michael@0 | 26 | let testElement = function(opts) { |
michael@0 | 27 | let element = doc.getElementById(opts.id); |
michael@0 | 28 | document.popupNode = element; |
michael@0 | 29 | |
michael@0 | 30 | let selection = content.getSelection(); |
michael@0 | 31 | selection.removeAllRanges(); |
michael@0 | 32 | |
michael@0 | 33 | if(opts.isSelected) { |
michael@0 | 34 | selection.selectAllChildren(element); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | let contextMenu = new nsContextMenu(contentAreaContextMenu); |
michael@0 | 38 | let menuItem = document.getElementById("context-searchselect"); |
michael@0 | 39 | |
michael@0 | 40 | is(document.getElementById("context-searchselect").hidden, !opts.shouldBeShown, "search context menu item is shown for '#" + opts.id + "' and selected is '" + opts.isSelected + "'"); |
michael@0 | 41 | |
michael@0 | 42 | if(opts.shouldBeShown) { |
michael@0 | 43 | ok(menuItem.label.contains(opts.expectedLabelContents), "Menu item text '" + menuItem.label + "' contains the correct search terms '" + opts.expectedLabelContents + "'"); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | testElement({ |
michael@0 | 48 | id: "link", |
michael@0 | 49 | isSelected: true, |
michael@0 | 50 | shouldBeShown: true, |
michael@0 | 51 | expectedLabelContents: "I'm a link!", |
michael@0 | 52 | }); |
michael@0 | 53 | testElement({ |
michael@0 | 54 | id: "link", |
michael@0 | 55 | isSelected: false, |
michael@0 | 56 | shouldBeShown: true, |
michael@0 | 57 | expectedLabelContents: "I'm a link!", |
michael@0 | 58 | }); |
michael@0 | 59 | |
michael@0 | 60 | testElement({ |
michael@0 | 61 | id: "longLink", |
michael@0 | 62 | isSelected: true, |
michael@0 | 63 | shouldBeShown: true, |
michael@0 | 64 | expectedLabelContents: "I'm a really lo" + ellipsis, |
michael@0 | 65 | }); |
michael@0 | 66 | testElement({ |
michael@0 | 67 | id: "longLink", |
michael@0 | 68 | isSelected: false, |
michael@0 | 69 | shouldBeShown: true, |
michael@0 | 70 | expectedLabelContents: "I'm a really lo" + ellipsis, |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | testElement({ |
michael@0 | 74 | id: "plainText", |
michael@0 | 75 | isSelected: true, |
michael@0 | 76 | shouldBeShown: true, |
michael@0 | 77 | expectedLabelContents: "Right clicking " + ellipsis, |
michael@0 | 78 | }); |
michael@0 | 79 | testElement({ |
michael@0 | 80 | id: "plainText", |
michael@0 | 81 | isSelected: false, |
michael@0 | 82 | shouldBeShown: false, |
michael@0 | 83 | }); |
michael@0 | 84 | |
michael@0 | 85 | testElement({ |
michael@0 | 86 | id: "mixedContent", |
michael@0 | 87 | isSelected: true, |
michael@0 | 88 | shouldBeShown: true, |
michael@0 | 89 | expectedLabelContents: "I'm some text, " + ellipsis, |
michael@0 | 90 | }); |
michael@0 | 91 | testElement({ |
michael@0 | 92 | id: "mixedContent", |
michael@0 | 93 | isSelected: false, |
michael@0 | 94 | shouldBeShown: false, |
michael@0 | 95 | }); |
michael@0 | 96 | |
michael@0 | 97 | testElement({ |
michael@0 | 98 | id: "partialLink", |
michael@0 | 99 | isSelected: true, |
michael@0 | 100 | shouldBeShown: true, |
michael@0 | 101 | expectedLabelContents: "link selection", |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | testElement({ |
michael@0 | 105 | id: "partialLink", |
michael@0 | 106 | isSelected: false, |
michael@0 | 107 | shouldBeShown: true, |
michael@0 | 108 | expectedLabelContents: "A partial link " + ellipsis, |
michael@0 | 109 | }); |
michael@0 | 110 | |
michael@0 | 111 | // cleanup |
michael@0 | 112 | document.popupNode = null; |
michael@0 | 113 | gBrowser.removeCurrentTab(); |
michael@0 | 114 | finish(); |
michael@0 | 115 | }, true); |
michael@0 | 116 | |
michael@0 | 117 | content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug970746.xhtml"; |
michael@0 | 118 | } |