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