browser/base/content/test/general/browser_bug970746.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:307666a3e07d
1 /* Make sure context menu includes option to search hyperlink text on search engine */
2
3 function test() {
4 waitForExplicitFinish();
5
6 gBrowser.selectedTab = gBrowser.addTab();
7
8 gBrowser.selectedBrowser.addEventListener("load", function() {
9 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
10
11 let doc = gBrowser.contentDocument;
12 let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
13 let ellipsis = "\u2026";
14
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.
25
26 let testElement = function(opts) {
27 let element = doc.getElementById(opts.id);
28 document.popupNode = element;
29
30 let selection = content.getSelection();
31 selection.removeAllRanges();
32
33 if(opts.isSelected) {
34 selection.selectAllChildren(element);
35 }
36
37 let contextMenu = new nsContextMenu(contentAreaContextMenu);
38 let menuItem = document.getElementById("context-searchselect");
39
40 is(document.getElementById("context-searchselect").hidden, !opts.shouldBeShown, "search context menu item is shown for '#" + opts.id + "' and selected is '" + opts.isSelected + "'");
41
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 }
46
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 });
59
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 });
72
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 });
84
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 });
96
97 testElement({
98 id: "partialLink",
99 isSelected: true,
100 shouldBeShown: true,
101 expectedLabelContents: "link selection",
102 });
103
104 testElement({
105 id: "partialLink",
106 isSelected: false,
107 shouldBeShown: true,
108 expectedLabelContents: "A partial link " + ellipsis,
109 });
110
111 // cleanup
112 document.popupNode = null;
113 gBrowser.removeCurrentTab();
114 finish();
115 }, true);
116
117 content.location = "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug970746.xhtml";
118 }

mercurial