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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | let source = "data:text/html,text<link%20href='http://example.com/'%20/>more%20text<a%20href='mailto:abc@def.ghi'>email</a>"; |
michael@0 | 6 | let gViewSourceWindow, gContextMenu, gCopyLinkMenuItem, gCopyEmailMenuItem; |
michael@0 | 7 | |
michael@0 | 8 | let expectedData = []; |
michael@0 | 9 | let currentTest = 0; |
michael@0 | 10 | let partialTestRunning = false; |
michael@0 | 11 | |
michael@0 | 12 | function test() { |
michael@0 | 13 | waitForExplicitFinish(); |
michael@0 | 14 | openViewSourceWindow(source, onViewSourceWindowOpen); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | function onViewSourceWindowOpen(aWindow) { |
michael@0 | 18 | gViewSourceWindow = aWindow; |
michael@0 | 19 | |
michael@0 | 20 | gContextMenu = aWindow.document.getElementById("viewSourceContextMenu"); |
michael@0 | 21 | gCopyLinkMenuItem = aWindow.document.getElementById("context-copyLink"); |
michael@0 | 22 | gCopyEmailMenuItem = aWindow.document.getElementById("context-copyEmail"); |
michael@0 | 23 | |
michael@0 | 24 | let aTags = aWindow.gBrowser.contentDocument.querySelectorAll("a[href]"); |
michael@0 | 25 | is(aTags[0].href, "view-source:http://example.com/", "Link has correct href"); |
michael@0 | 26 | is(aTags[1].href, "mailto:abc@def.ghi", "Link has correct href"); |
michael@0 | 27 | let spanTag = aWindow.gBrowser.contentDocument.querySelector("span"); |
michael@0 | 28 | |
michael@0 | 29 | expectedData.push([aTags[0], true, false, "http://example.com/"]); |
michael@0 | 30 | expectedData.push([aTags[1], false, true, "abc@def.ghi"]); |
michael@0 | 31 | expectedData.push([spanTag, false, false, null]); |
michael@0 | 32 | |
michael@0 | 33 | waitForFocus(runNextTest, aWindow); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function runNextTest() { |
michael@0 | 37 | if (currentTest == expectedData.length) { |
michael@0 | 38 | closeViewSourceWindow(gViewSourceWindow, function() { |
michael@0 | 39 | if (partialTestRunning) { |
michael@0 | 40 | finish(); |
michael@0 | 41 | return; |
michael@0 | 42 | } |
michael@0 | 43 | partialTestRunning = true; |
michael@0 | 44 | currentTest = 0; |
michael@0 | 45 | expectedData = []; |
michael@0 | 46 | openDocumentSelect(source, "body", onViewSourceWindowOpen); |
michael@0 | 47 | }); |
michael@0 | 48 | return; |
michael@0 | 49 | } |
michael@0 | 50 | let test = expectedData[currentTest++]; |
michael@0 | 51 | checkMenuItems(test[0], test[1], test[2], test[3]); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function checkMenuItems(popupNode, copyLinkExpected, copyEmailExpected, expectedClipboardContent) { |
michael@0 | 55 | popupNode.scrollIntoView(); |
michael@0 | 56 | |
michael@0 | 57 | let cachedEvent = null; |
michael@0 | 58 | let mouseFn = function(event) { |
michael@0 | 59 | cachedEvent = event; |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | gViewSourceWindow.gBrowser.contentWindow.addEventListener("mousedown", mouseFn, false); |
michael@0 | 63 | EventUtils.synthesizeMouseAtCenter(popupNode, { button: 2 }, gViewSourceWindow.gBrowser.contentWindow); |
michael@0 | 64 | gViewSourceWindow.gBrowser.contentWindow.removeEventListener("mousedown", mouseFn, false); |
michael@0 | 65 | |
michael@0 | 66 | gContextMenu.openPopup(popupNode, "after_start", 0, 0, false, false, cachedEvent); |
michael@0 | 67 | |
michael@0 | 68 | is(gCopyLinkMenuItem.hidden, !copyLinkExpected, "Copy link menuitem is " + (copyLinkExpected ? "not hidden" : "hidden")); |
michael@0 | 69 | is(gCopyEmailMenuItem.hidden, !copyEmailExpected, "Copy email menuitem is " + (copyEmailExpected ? "not hidden" : "hidden")); |
michael@0 | 70 | |
michael@0 | 71 | if (!copyLinkExpected && !copyEmailExpected) { |
michael@0 | 72 | runNextTest(); |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | waitForClipboard(expectedClipboardContent, function() { |
michael@0 | 77 | if (copyLinkExpected) |
michael@0 | 78 | gCopyLinkMenuItem.doCommand(); |
michael@0 | 79 | else |
michael@0 | 80 | gCopyEmailMenuItem.doCommand(); |
michael@0 | 81 | gContextMenu.hidePopup(); |
michael@0 | 82 | }, runNextTest, runNextTest); |
michael@0 | 83 | } |