|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
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; |
|
7 |
|
8 let expectedData = []; |
|
9 let currentTest = 0; |
|
10 let partialTestRunning = false; |
|
11 |
|
12 function test() { |
|
13 waitForExplicitFinish(); |
|
14 openViewSourceWindow(source, onViewSourceWindowOpen); |
|
15 } |
|
16 |
|
17 function onViewSourceWindowOpen(aWindow) { |
|
18 gViewSourceWindow = aWindow; |
|
19 |
|
20 gContextMenu = aWindow.document.getElementById("viewSourceContextMenu"); |
|
21 gCopyLinkMenuItem = aWindow.document.getElementById("context-copyLink"); |
|
22 gCopyEmailMenuItem = aWindow.document.getElementById("context-copyEmail"); |
|
23 |
|
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"); |
|
28 |
|
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]); |
|
32 |
|
33 waitForFocus(runNextTest, aWindow); |
|
34 } |
|
35 |
|
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 } |
|
53 |
|
54 function checkMenuItems(popupNode, copyLinkExpected, copyEmailExpected, expectedClipboardContent) { |
|
55 popupNode.scrollIntoView(); |
|
56 |
|
57 let cachedEvent = null; |
|
58 let mouseFn = function(event) { |
|
59 cachedEvent = event; |
|
60 }; |
|
61 |
|
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); |
|
65 |
|
66 gContextMenu.openPopup(popupNode, "after_start", 0, 0, false, false, cachedEvent); |
|
67 |
|
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")); |
|
70 |
|
71 if (!copyLinkExpected && !copyEmailExpected) { |
|
72 runNextTest(); |
|
73 return; |
|
74 } |
|
75 |
|
76 waitForClipboard(expectedClipboardContent, function() { |
|
77 if (copyLinkExpected) |
|
78 gCopyLinkMenuItem.doCommand(); |
|
79 else |
|
80 gCopyEmailMenuItem.doCommand(); |
|
81 gContextMenu.hidePopup(); |
|
82 }, runNextTest, runNextTest); |
|
83 } |