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