1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/viewsource/test/browser/browser_contextmenu.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +let source = "data:text/html,text<link%20href='http://example.com/'%20/>more%20text<a%20href='mailto:abc@def.ghi'>email</a>"; 1.9 +let gViewSourceWindow, gContextMenu, gCopyLinkMenuItem, gCopyEmailMenuItem; 1.10 + 1.11 +let expectedData = []; 1.12 +let currentTest = 0; 1.13 +let partialTestRunning = false; 1.14 + 1.15 +function test() { 1.16 + waitForExplicitFinish(); 1.17 + openViewSourceWindow(source, onViewSourceWindowOpen); 1.18 +} 1.19 + 1.20 +function onViewSourceWindowOpen(aWindow) { 1.21 + gViewSourceWindow = aWindow; 1.22 + 1.23 + gContextMenu = aWindow.document.getElementById("viewSourceContextMenu"); 1.24 + gCopyLinkMenuItem = aWindow.document.getElementById("context-copyLink"); 1.25 + gCopyEmailMenuItem = aWindow.document.getElementById("context-copyEmail"); 1.26 + 1.27 + let aTags = aWindow.gBrowser.contentDocument.querySelectorAll("a[href]"); 1.28 + is(aTags[0].href, "view-source:http://example.com/", "Link has correct href"); 1.29 + is(aTags[1].href, "mailto:abc@def.ghi", "Link has correct href"); 1.30 + let spanTag = aWindow.gBrowser.contentDocument.querySelector("span"); 1.31 + 1.32 + expectedData.push([aTags[0], true, false, "http://example.com/"]); 1.33 + expectedData.push([aTags[1], false, true, "abc@def.ghi"]); 1.34 + expectedData.push([spanTag, false, false, null]); 1.35 + 1.36 + waitForFocus(runNextTest, aWindow); 1.37 +} 1.38 + 1.39 +function runNextTest() { 1.40 + if (currentTest == expectedData.length) { 1.41 + closeViewSourceWindow(gViewSourceWindow, function() { 1.42 + if (partialTestRunning) { 1.43 + finish(); 1.44 + return; 1.45 + } 1.46 + partialTestRunning = true; 1.47 + currentTest = 0; 1.48 + expectedData = []; 1.49 + openDocumentSelect(source, "body", onViewSourceWindowOpen); 1.50 + }); 1.51 + return; 1.52 + } 1.53 + let test = expectedData[currentTest++]; 1.54 + checkMenuItems(test[0], test[1], test[2], test[3]); 1.55 +} 1.56 + 1.57 +function checkMenuItems(popupNode, copyLinkExpected, copyEmailExpected, expectedClipboardContent) { 1.58 + popupNode.scrollIntoView(); 1.59 + 1.60 + let cachedEvent = null; 1.61 + let mouseFn = function(event) { 1.62 + cachedEvent = event; 1.63 + }; 1.64 + 1.65 + gViewSourceWindow.gBrowser.contentWindow.addEventListener("mousedown", mouseFn, false); 1.66 + EventUtils.synthesizeMouseAtCenter(popupNode, { button: 2 }, gViewSourceWindow.gBrowser.contentWindow); 1.67 + gViewSourceWindow.gBrowser.contentWindow.removeEventListener("mousedown", mouseFn, false); 1.68 + 1.69 + gContextMenu.openPopup(popupNode, "after_start", 0, 0, false, false, cachedEvent); 1.70 + 1.71 + is(gCopyLinkMenuItem.hidden, !copyLinkExpected, "Copy link menuitem is " + (copyLinkExpected ? "not hidden" : "hidden")); 1.72 + is(gCopyEmailMenuItem.hidden, !copyEmailExpected, "Copy email menuitem is " + (copyEmailExpected ? "not hidden" : "hidden")); 1.73 + 1.74 + if (!copyLinkExpected && !copyEmailExpected) { 1.75 + runNextTest(); 1.76 + return; 1.77 + } 1.78 + 1.79 + waitForClipboard(expectedClipboardContent, function() { 1.80 + if (copyLinkExpected) 1.81 + gCopyLinkMenuItem.doCommand(); 1.82 + else 1.83 + gCopyEmailMenuItem.doCommand(); 1.84 + gContextMenu.hidePopup(); 1.85 + }, runNextTest, runNextTest); 1.86 +}