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 let doc, range, selection;
2 function setSelection(el1, el2, index1, index2) {
3 while (el1.nodeType != Node.TEXT_NODE)
4 el1 = el1.firstChild;
5 while (el2.nodeType != Node.TEXT_NODE)
6 el2 = el2.firstChild;
8 selection.removeAllRanges();
9 range.setStart(el1, index1);
10 range.setEnd(el2, index2);
11 selection.addRange(range);
12 }
14 function initContextMenu(aNode) {
15 document.popupNode = aNode;
16 let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
17 let contextMenu = new nsContextMenu(contentAreaContextMenu);
18 return contextMenu;
19 }
21 function testExpected(expected, msg, aNode) {
22 let popupNode = aNode || doc.getElementsByTagName("DIV")[0];
23 initContextMenu(popupNode);
24 let linkMenuItem = document.getElementById("context-openlinkincurrent");
25 is(linkMenuItem.hidden, expected, msg);
26 }
28 function testLinkExpected(expected, msg, aNode) {
29 let popupNode = aNode || doc.getElementsByTagName("DIV")[0];
30 let contextMenu = initContextMenu(popupNode);
31 is(contextMenu.linkURL, expected, msg);
32 }
34 function runSelectionTests() {
35 let mainDiv = doc.createElement("div");
36 let div = doc.createElement("div");
37 let div2 = doc.createElement("div");
38 let span1 = doc.createElement("span");
39 let span2 = doc.createElement("span");
40 let span3 = doc.createElement("span");
41 let span4 = doc.createElement("span");
42 let p1 = doc.createElement("p");
43 let p2 = doc.createElement("p");
44 span1.textContent = "http://index.";
45 span2.textContent = "example.com example.com";
46 span3.textContent = " - Test";
47 span4.innerHTML = "<a href='http://www.example.com'>http://www.example.com/example</a>";
48 p1.textContent = "mailto:test.com ftp.example.com";
49 p2.textContent = "example.com -";
50 div.appendChild(span1);
51 div.appendChild(span2);
52 div.appendChild(span3);
53 div.appendChild(span4);
54 div.appendChild(p1);
55 div.appendChild(p2);
56 let p3 = doc.createElement("p");
57 p3.textContent = "main.example.com";
58 div2.appendChild(p3);
59 mainDiv.appendChild(div);
60 mainDiv.appendChild(div2);
61 doc.body.appendChild(mainDiv);
62 setSelection(span1.firstChild, span2.firstChild, 0, 11);
63 testExpected(false, "The link context menu should show for http://www.example.com");
64 setSelection(span1.firstChild, span2.firstChild, 7, 11);
65 testExpected(false, "The link context menu should show for www.example.com");
66 setSelection(span1.firstChild, span2.firstChild, 8, 11);
67 testExpected(true, "The link context menu should not show for ww.example.com");
68 setSelection(span2.firstChild, span2.firstChild, 0, 11);
69 testExpected(false, "The link context menu should show for example.com");
70 testLinkExpected("http://example.com/", "url for example.com selection should not prepend www");
71 setSelection(span2.firstChild, span2.firstChild, 11, 23);
72 testExpected(false, "The link context menu should show for example.com");
73 setSelection(span2.firstChild, span2.firstChild, 0, 10);
74 testExpected(true, "Link options should not show for selection that's not at a word boundary");
75 setSelection(span2.firstChild, span3.firstChild, 12, 7);
76 testExpected(true, "Link options should not show for selection that has whitespace");
77 setSelection(span2.firstChild, span2.firstChild, 12, 19);
78 testExpected(true, "Link options should not show unless a url is selected");
79 setSelection(p1.firstChild, p1.firstChild, 0, 15);
80 testExpected(true, "Link options should not show for mailto: links");
81 setSelection(p1.firstChild, p1.firstChild, 16, 31);
82 testExpected(false, "Link options should show for ftp.example.com");
83 testLinkExpected("ftp://ftp.example.com/", "ftp.example.com should be preceeded with ftp://");
84 setSelection(p2.firstChild, p2.firstChild, 0, 14);
85 testExpected(false, "Link options should show for www.example.com ");
86 selection.selectAllChildren(div2);
87 testExpected(false, "Link options should show for triple-click selections");
88 selection.selectAllChildren(span4);
89 testLinkExpected("http://www.example.com/", "Linkified text should open the correct link", span4.firstChild);
91 mainDiv.innerHTML = "(open-suse.ru)";
92 setSelection(mainDiv, mainDiv, 1, 13);
93 testExpected(false, "Link options should show for open-suse.ru");
94 testLinkExpected("http://open-suse.ru/", "Linkified text should open the correct link");
95 setSelection(mainDiv, mainDiv, 1, 14);
96 testExpected(true, "Link options should not show for 'open-suse.ru)'");
98 gBrowser.removeCurrentTab();
99 finish();
100 }
102 function test() {
103 waitForExplicitFinish();
104 gBrowser.selectedTab = gBrowser.addTab();
105 gBrowser.selectedBrowser.addEventListener("load", function() {
106 gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
107 doc = content.document;
108 range = doc.createRange();
109 selection = content.getSelection();
110 waitForFocus(runSelectionTests, content);
111 }, true);
113 content.location =
114 "data:text/html;charset=UTF-8,Test For Non-Hyperlinked url selection";
115 }