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