diff options
Diffstat (limited to '')
18 files changed, 1571 insertions, 0 deletions
diff --git a/comm/suite/browser/test/mochitest/audio.ogg b/comm/suite/browser/test/mochitest/audio.ogg Binary files differnew file mode 100644 index 0000000000..7e6ef77ec4 --- /dev/null +++ b/comm/suite/browser/test/mochitest/audio.ogg diff --git a/comm/suite/browser/test/mochitest/bug364677-data.xml b/comm/suite/browser/test/mochitest/bug364677-data.xml new file mode 100644 index 0000000000..b48915c050 --- /dev/null +++ b/comm/suite/browser/test/mochitest/bug364677-data.xml @@ -0,0 +1,5 @@ +<rss version="2.0"> + <channel> + <title>t</title> + </channel> +</rss> diff --git a/comm/suite/browser/test/mochitest/bug364677-data.xml^headers^ b/comm/suite/browser/test/mochitest/bug364677-data.xml^headers^ new file mode 100644 index 0000000000..f203c6368e --- /dev/null +++ b/comm/suite/browser/test/mochitest/bug364677-data.xml^headers^ @@ -0,0 +1 @@ +Content-Type: text/xml diff --git a/comm/suite/browser/test/mochitest/bug395533-data.txt b/comm/suite/browser/test/mochitest/bug395533-data.txt new file mode 100644 index 0000000000..e0ed39850f --- /dev/null +++ b/comm/suite/browser/test/mochitest/bug395533-data.txt @@ -0,0 +1,6 @@ +<rss version="2.0"> + <channel> + <link>http://example.org/</link> + <title>t</title> + </channel> +</rss> diff --git a/comm/suite/browser/test/mochitest/bug436801-data.xml b/comm/suite/browser/test/mochitest/bug436801-data.xml new file mode 100644 index 0000000000..0e45c7ed8e --- /dev/null +++ b/comm/suite/browser/test/mochitest/bug436801-data.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom" xml:base="http://www.example.com/"> + + <title type="xhtml" xml:base="/foo/bar/"> + <div xmlns="http://www.w3.org/1999/xhtml">Example of a <em>special</em> feed (<img height="20px" src="baz.png" alt="base test sprite"/>)</div> + </title> + + <subtitle type="html" xml:base="/foo/bar/"> + <![CDATA[ + With a <em>special</em> subtitle (<img height="20px" src="baz.png" alt="base test sprite"/>) + ]]> + </subtitle> + + <link href="http://example.org/"/> + + <updated>2010-09-02T18:30:02Z</updated> + + <author> + <name>John Doe</name> + </author> + + <id>urn:uuid:22906062-ecbd-46e2-b6a7-3039506a398f</id> + + <entry> + <title type="xhtml" xml:base="/foo/bar/"> + <div xmlns="http://www.w3.org/1999/xhtml">Some <abbr title="Extensible Hyper-text Mark-up Language">XHTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>)</div> + </title> + <id>urn:uuid:b48083a7-71a7-4c9c-8515-b7c0d22955e7</id> + <updated>2010-09-02T18:30:02Z</updated> + <summary>Some text.</summary> + </entry> + + <entry> + <title type="html" xml:base="/foo/bar/"> + <![CDATA[ + Some <abbr title="Hyper-text Mark-up Language">HTML</abbr> examples (<img height="20px" src="baz.png" alt="base test sprite"/>) + ]]> + </title> + <id>urn:uuid:1424967a-280a-414d-b0ab-8b11c4ac1bb7</id> + <updated>2010-09-02T18:30:02Z</updated> + <summary>Some text.</summary> + </entry> + +</feed> diff --git a/comm/suite/browser/test/mochitest/ctxmenu-image.png b/comm/suite/browser/test/mochitest/ctxmenu-image.png Binary files differnew file mode 100644 index 0000000000..4c3be50847 --- /dev/null +++ b/comm/suite/browser/test/mochitest/ctxmenu-image.png diff --git a/comm/suite/browser/test/mochitest/feed_discovery.html b/comm/suite/browser/test/mochitest/feed_discovery.html new file mode 100644 index 0000000000..80c35d19ab --- /dev/null +++ b/comm/suite/browser/test/mochitest/feed_discovery.html @@ -0,0 +1,112 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=377611 +--> + <head> + <title>Test for feed discovery</title> + + <!-- Straight up standard --> + <link rel="alternate" type="application/atom+xml" title="1" href="/1.atom" /> + <link rel="alternate" type="application/rss+xml" title="2" href="/2.rss" /> + <link rel="feed" title="3" href="/3.xml" /> + + <!-- rel is a space-separated list --> + <link rel=" alternate " type="application/atom+xml" title="4" href="/4.atom" /> + <link rel="foo alternate" type="application/atom+xml" title="5" href="/5.atom" /> + <link rel="alternate foo" type="application/atom+xml" title="6" href="/6.atom" /> + <link rel="foo alternate foo" type="application/atom+xml" title="7" href="/7.atom" /> + <link rel="meat feed cake" title="8" href="/8.atom" /> + + <!-- rel is case-insensitive --> + <link rel="ALTERNate" type="application/atom+xml" title="9" href="/9.atom" /> + <link rel="fEEd" title="10" href="/10.atom" /> + + <!-- type can have leading and trailing whitespace --> + <link rel="alternate" type=" application/atom+xml " title="11" href="/11.atom" /> + + <!-- type is case-insensitive --> + <link rel="alternate" type="aPPliCAtion/ATom+xML" title="12" href="/12.atom" /> + + <!-- "feed stylesheet" is a feed, though "alternate stylesheet" isn't --> + <link rel="feed stylesheet" title="13" href="/13.atom" /> + + <!-- hyphens or letters around rel not allowed --> + <link rel="disabled-alternate" type="application/atom+xml" title="Bogus1" href="/Bogus1" /> + <link rel="alternates" type="application/atom+xml" title="Bogus2" href="/Bogus2" /> + <link rel=" alternate-like" type="application/atom+xml" title="Bogus3" href="/Bogus3" /> + + <!-- don't tolerate text/xml if title includes 'rss' not as a word --> + <link rel="alternate" type="text/xml" title="Bogus4 scissorsshaped" href="/Bogus4" /> + + <!-- don't tolerate application/xml if title includes 'rss' not as a word --> + <link rel="alternate" type="application/xml" title="Bogus5 scissorsshaped" href="/Bogus5" /> + + <!-- don't tolerate application/rdf+xml if title includes 'rss' not as a word --> + <link rel="alternate" type="application/rdf+xml" title="Bogus6 scissorsshaped" href="/Bogus6" /> + + <!-- don't tolerate random types --> + <link rel="alternate" type="text/plain" title="Bogus7 rss" href="/Bogus7" /> + + <!-- don't find Atom by title --> + <link rel="foopy" type="application/atom+xml" title="Bogus8 Atom and RSS" href="/Bogus8" /> + + <!-- don't find application/rss+xml by title --> + <link rel="goats" type="application/rss+xml" title="Bogus9 RSS and Atom" href="/Bogus9" /> + + <!-- don't find application/rdf+xml by title --> + <link rel="alternate" type="application/rdf+xml" title="Bogus10 RSS and Atom" href="/Bogus10" /> + + <!-- don't find application/xml by title --> + <link rel="alternate" type="application/xml" title="Bogus11 RSS and Atom" href="/Bogus11" /> + + <!-- don't find text/xml by title --> + <link rel="alternate" type="text/xml" title="Bogus12 RSS and Atom" href="/Bogus12" /> + + <!-- alternate and stylesheet isn't a feed --> + <link rel="alternate stylesheet" type="application/rss+xml" title="Bogus13 RSS" href="/Bogus13" /> + </head> + <body> + <script> + window.onload = function() { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + + var tests = new Array(); + + var currentWindow = + window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow); + var browserSH = currentWindow.XULBrowserWindow; + + var discovered = browserSH.feeds; + tests.push({ check: discovered.length > 0, + message: "some feeds should be discovered" }); + + var feeds = []; + + for (var aFeed of discovered) { + feeds[aFeed.href] = true; + } + + for (var aLink of document.getElementsByTagName("link")) { + // ignore real stylesheets, and anything without an href property + if (aLink.type != "text/css" && aLink.href) { + if (/bogus/i.test(aLink.title)) { + tests.push({ check: !feeds[aLink.href], todo: /todo/i.test(aLink.title), + message: "don't discover " + aLink.href }); + } else { + tests.push({ check: feeds[aLink.href], todo: /todo/i.test(aLink.title), + message: "should discover " + aLink.href }); + } + } + } + window.arguments[0].tests = tests; + window.close(); + } + </script> + </body> +</html> diff --git a/comm/suite/browser/test/mochitest/mochitest.ini b/comm/suite/browser/test/mochitest/mochitest.ini new file mode 100644 index 0000000000..99b25bba9d --- /dev/null +++ b/comm/suite/browser/test/mochitest/mochitest.ini @@ -0,0 +1,17 @@ +[DEFAULT] +support-files = + valid-feed.xml + valid-unsniffable-feed.xml + +[test_bug364677.html] +support-files = bug364677-data.xml bug364677-data.xml^headers^ +[test_bug395533.html] +support-files = bug395533-data.txt +[test_bug436801.html] +support-files = bug436801-data.xml +[test_contextmenu.html] +support-files = audio.ogg ctxmenu-image.png subtst_contextmenu.html video.ogg +skip-if = os != "win" # disabled on Linux due to bug 513558, on Mac after 10.6 due to bug 792304 +[test_feed_discovery.html] +support-files = feed_discovery.html +[test_registerHandler.html] diff --git a/comm/suite/browser/test/mochitest/subtst_contextmenu.html b/comm/suite/browser/test/mochitest/subtst_contextmenu.html new file mode 100644 index 0000000000..63cc70c84e --- /dev/null +++ b/comm/suite/browser/test/mochitest/subtst_contextmenu.html @@ -0,0 +1,70 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Subtest for browser context menu</title> +</head> +<body> +Browser context menu subtest. + +<div id="test-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</div> +<a id="test-link" href="http://mozilla.com">Click the monkey!</a> +<a id="test-mailto" href="mailto:codemonkey@mozilla.com">Mail the monkey!</a><br> +<input id="test-input"><br> +<input id="test-input-select"><br> +<img id="test-image" src="ctxmenu-image.png"> +<canvas id="test-canvas" width="100" height="100" style="background-color: blue"></canvas> +<video controls id="test-video-ok" src="video.ogg" width="100" height="100" style="background-color: green"></video> +<video id="test-audio-in-video" src="audio.ogg" width="100" height="100" style="background-color: red"></video> +<video controls id="test-video-bad" src="bogus.duh" width="100" height="100" style="background-color: orange"></video> +<video controls id="test-video-bad2" width="100" height="100" style="background-color: yellow"> + <source src="bogus.duh" type="video/durrrr;"> +</video> +<iframe id="test-iframe" width="98" height="98" style="border: 1px solid black"></iframe> +<iframe id="test-video-in-iframe" src="video.ogg" width="98" height="98" style="border: 1px solid black"></iframe> +<iframe id="test-image-in-iframe" src="ctxmenu-image.png" width="98" height="98" style="border: 1px solid black"></iframe> +<textarea id="test-textarea">chssseesbbbie</textarea> <!-- a weird word which generates only one suggestion --> +<textarea id="test-textarea-sel">test</textarea> +<div id="test-contenteditable" contenteditable="true">chssseefsbbbie</div> <!-- a more weird word which generates no suggestions --> +<input id="test-input-spellcheck" type="text" spellcheck="true" autofocus value="prodkjfgigrty"> <!-- this one also generates one suggestion --> +<div contextmenu="myMenu"> + <p id="test-pagemenu" hopeless="true">I've got a context menu!</p> + <menu id="myMenu" type="context"> + <menuitem label="Plain item" onclick="document.getElementById('test-pagemenu').removeAttribute('hopeless');"></menuitem> + <menuitem label="Disabled item" disabled></menuitem> + <menuitem> Item w/ textContent</menuitem> + <menu> + <menuitem type="checkbox" label="Checkbox" checked></menuitem> + </menu> + <menu> + <menuitem type="radio" label="Radio1" checked></menuitem> + <menuitem type="radio" label="Radio2"></menuitem> + <menuitem type="radio" label="Radio3"></menuitem> + </menu> + <menu> + <menuitem label="Item w/ icon" icon="favicon.ico"></menuitem> + <menuitem label="Item w/ bad icon" icon="data://www.mozilla.org/favicon.ico"></menuitem> + </menu> + <menu label="Submenu"> + <menuitem type="radio" label="Radio1" radiogroup="rg"></menuitem> + <menuitem type="radio" label="Radio2" checked radiogroup="rg"></menuitem> + <menuitem type="radio" label="Radio3" radiogroup="rg"></menuitem> + <menu> + <menuitem type="checkbox" label="Checkbox"></menuitem> + </menu> + </menu> + <menu hidden> + <menuitem label="Bogus item"></menuitem> + </menu> + <menu> + </menu> + <menuitem label="Hidden item" hidden></menuitem> + <menuitem></menuitem> + </menu> +</div> + +<!-- SeaMonkey specific elements --> +<a href="http://mozilla.com"><img id="test-image-link" alt="Click the monkey!" src="ctxmenu-image.png"></a> +<a href="mailto:codemonkey@mozilla.com"><img id="test-image-mailto" alt="Mail the monkey!" src="ctxmenu-image.png"></a><br> + +</body> +</html> diff --git a/comm/suite/browser/test/mochitest/test_bug364677.html b/comm/suite/browser/test/mochitest/test_bug364677.html new file mode 100644 index 0000000000..e08b1403f6 --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_bug364677.html @@ -0,0 +1,32 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=364677 +--> +<head> + <title>Test for Bug 364677</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=364677">Mozilla Bug 364677</a> +<p id="display"><iframe id="testFrame" src="bug364677-data.xml"></iframe></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody"> + +/** Test for Bug 364677 **/ +SimpleTest.waitForExplicitFinish(); + +addLoadEvent(function() { + is(SpecialPowers.wrap($("testFrame")).contentDocument.documentElement.id, "feedHandler", + "Feed served as text/xml without a channel/link should have been sniffed"); +}); +addLoadEvent(SimpleTest.finish); +</script> +</pre> +</body> +</html> + diff --git a/comm/suite/browser/test/mochitest/test_bug395533.html b/comm/suite/browser/test/mochitest/test_bug395533.html new file mode 100644 index 0000000000..5d3cfa0121 --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_bug395533.html @@ -0,0 +1,39 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=395533 +--> +<head> + <title>Test for Bug 395533</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=395533">Mozilla Bug 395533</a> +<p id="display"><iframe id="testFrame" src="bug395533-data.txt"></iframe></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody"> + +/** Test for Bug 395533 **/ +SimpleTest.waitForExplicitFinish(); + +addLoadEvent(function() { + // Need privs because the feed seems to have an about:feeds principal or some + // such. It's not same-origin with us in any case. + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + is($("testFrame").contentDocument.documentElement.id, "", + "Text got sniffed as a feed?"); +}); +addLoadEvent(SimpleTest.finish); + + + + +</script> +</pre> +</body> +</html> + diff --git a/comm/suite/browser/test/mochitest/test_bug436801.html b/comm/suite/browser/test/mochitest/test_bug436801.html new file mode 100644 index 0000000000..6ca1b83cf5 --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_bug436801.html @@ -0,0 +1,118 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=436801 +--> +<head> + <title>Test feed preview subscribe UI</title> + <script src="/MochiKit/packed.js"></script> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436801">Mozilla Bug 436801</a> +<p id="display"><iframe id="testFrame" src="bug436801-data.xml"></iframe></p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +<script class="testbody"> + +SimpleTest.waitForExplicitFinish(); + +addLoadEvent(function () { + var doc = SpecialPowers.wrap($("testFrame")).contentDocument; + + checkNode(doc.getElementById("feedTitleText"), [ + "ELEMENT", "h1", { "xml:base": "http://www.example.com/foo/bar/" }, [ + ["TEXT", "Example of a "], + ["ELEMENT", "em", [ + ["TEXT", "special"], + ]], + ["TEXT", " feed ("], + ["ELEMENT", "img", { "src": "baz.png" }], + ["TEXT", ")"], + ] + ]); + + checkNode(doc.getElementById("feedSubtitleText"), [ + "ELEMENT", "h2", { "xml:base": "http://www.example.com/foo/bar/" }, [ + ["TEXT", "With a "], + ["ELEMENT", "em", [ + ["TEXT", "special"], + ]], + ["TEXT", " subtitle ("], + ["ELEMENT", "img", { "src": "baz.png" }], + ["TEXT", ")"], + ] + ]); + + checkNode(doc.querySelector(".entry").firstChild.firstChild.firstChild, [ + "ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [ + ["TEXT", "Some "], + ["ELEMENT", "abbr", { title: "Extensible Hyper-text Mark-up Language" }, [ + ["TEXT", "XHTML"], + ]], + ["TEXT", " examples ("], + ["ELEMENT", "img", { "src": "baz.png" }], + ["TEXT", ")"], + ] + ]); + + checkNode(doc.querySelectorAll(".entry")[1].firstChild.firstChild.firstChild, [ + "ELEMENT", "span", { "xml:base": "http://www.example.com/foo/bar/" }, [ + ["TEXT", "Some "], + ["ELEMENT", "abbr", { title: "Hyper-text Mark-up Language" }, [ + ["TEXT", "HTML"], + ]], + ["TEXT", " examples ("], + ["ELEMENT", "img", { "src": "baz.png" }], + ["TEXT", ")"], + ] + ]); +}); + +addLoadEvent(SimpleTest.finish); + +function checkNode(node, schema) { + var typeName = schema.shift() + "_NODE"; + var type = Node[typeName]; + is(node.nodeType, type, "Node should be expected type " + typeName); + if (type == Node.TEXT_NODE) { + var text = schema.shift(); + is(node.data, text, "Text should match"); + return; + } + // type == Node.ELEMENT_NODE + var tag = schema.shift(); + is(node.localName, tag, "Element should have expected tag"); + while (schema.length) { + var val = schema.shift(); + if (Array.isArray(val)) + var childSchema = val; + else + var attrSchema = val; + } + if (attrSchema) { + var nsTable = { + xml: "http://www.w3.org/XML/1998/namespace", + }; + for (var name in attrSchema) { + var [ns, nsName] = name.split(":"); + var val = nsName ? node.getAttributeNS(nsTable[ns], nsName) : + node.getAttribute(name); + is(val, attrSchema[name], "Attribute " + name + " should match"); + } + } + if (childSchema) { + var numChildren = node.childNodes.length; + is(childSchema.length, numChildren, + "Element should have expected number of children"); + for (var i = 0; i < numChildren; i++) + checkNode(node.childNodes[i], childSchema[i]); + } +} + +</script> +</pre> +</body> +</html> diff --git a/comm/suite/browser/test/mochitest/test_contextmenu.html b/comm/suite/browser/test/mochitest/test_contextmenu.html new file mode 100644 index 0000000000..0dea49c925 --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_contextmenu.html @@ -0,0 +1,931 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Tests for browser context menu</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script src="/tests/SimpleTest/EventUtils.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +Browser context menu tests. +<p id="display"></p> + +<div id="content"> +</div> + +<pre id="test"> +<script class="testbody"> + +/** Test for Login Manager: multiple login autocomplete. **/ + +SpecialPowers.ChromeUtils.import("resource://gre/modules/InlineSpellChecker.jsm", window); +SpecialPowers.ChromeUtils.import("resource://gre/modules/AsyncSpellCheckTestHelper.jsm", window); + +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; + +function openContextMenuFor(element, shiftkey, waitForSpellCheck) { + // Context menu should be closed before we open it again. + is(SpecialPowers.wrap(contextMenu).state, "closed", "checking if popup is closed"); + + if (lastElement) + lastElement.blur(); + element.focus(); + + // Some elements need time to focus and spellcheck before any tests are + // run on them. + function actuallyOpenContextMenuFor() { + lastElement = element; + var eventDetails = { type : "contextmenu", button : 2, shiftKey : shiftkey }; + synthesizeMouse(element, 2, 2, eventDetails, element.ownerDocument.defaultView); + } + + if (waitForSpellCheck) + onSpellCheck(element, actuallyOpenContextMenuFor); + else + actuallyOpenContextMenuFor(); +} + +function closeContextMenu() { + contextMenu.hidePopup(); +} + +function executeCopyCommand(command, expectedValue) +{ + // Just execute the command directly rather than simulating a context menu + // press to avoid having to deal with its asynchronous nature + SpecialPowers.wrap(subwindow).controllers.getControllerForCommand(command).doCommand(command); + + // The easiest way to check the clipboard is to paste the contents into a + // textbox + input.focus(); + input.value = ""; + SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste"); + is(input.value, expectedValue, "paste for command " + command); +} + +function invokeItemAction(generatedItemId) +{ + var item = contextMenu.getElementsByAttribute("generateditemid", + generatedItemId)[0]; + ok(item, "Got generated XUL menu item"); + item.doCommand(); + is(pagemenu.hasAttribute("hopeless"), false, "attribute got removed"); +} + +function getVisibleMenuItems(aMenu, aData) { + var items = []; + var accessKeys = {}; + for (var i = 0; i < aMenu.childNodes.length; i++) { + var item = aMenu.childNodes[i]; + if (item.hidden) + continue; + + var key = item.accessKey; + if (key) + key = key.toLowerCase(); + + var isGenerated = item.hasAttribute("generateditemid"); + + if (item.nodeName == "menuitem") { + var isSpellSuggestion = item.className == "spell-suggestion"; + if (isSpellSuggestion) { + is(item.id, "", "child menuitem #" + i + " is a spelling suggestion"); + } else if (isGenerated) { + is(item.id, "", "child menuitem #" + i + " is a generated item"); + } else { + ok(item.id, "child menuitem #" + i + " has an ID"); + } + var label = item.getAttribute("label"); + ok(label.length, "menuitem " + item.id + " has a label"); + if (isSpellSuggestion) { + is(key, "", "Spell suggestions shouldn't have an access key"); + items.push("*" + label); + } else if (isGenerated) { + items.push("+" + label); + } else if (item.id.indexOf("spell-check-dictionary-") != 0 && + item.id != "spell-no-suggestions") { + ok(key, "menuitem " + item.id + " has an access key"); + if (accessKeys[key]) + ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]); + else + accessKeys[key] = item.id; + } + if (!isSpellSuggestion && !isGenerated) { + items.push(item.id); + } + if (isGenerated) { + var p = {}; + p.type = item.getAttribute("type"); + p.icon = item.getAttribute("image"); + p.checked = item.hasAttribute("checked"); + p.disabled = item.hasAttribute("disabled"); + items.push(p); + } else { + items.push(!item.disabled); + } + } else if (item.nodeName == "menuseparator") { + ok(true, "--- seperator id is " + item.id); + items.push("---"); + items.push(null); + } else if (item.nodeName == "menu") { + if (isGenerated) { + item.id = "generated-submenu-" + aData.generatedSubmenuId++; + } + ok(item.id, "child menu #" + i + " has an ID"); + if (!isGenerated) { + ok(key, "menu has an access key"); + if (accessKeys[key]) + ok(false, "menu " + item.id + " has same accesskey as " + accessKeys[key]); + else + accessKeys[key] = item.id; + } + items.push(item.id); + items.push(!item.disabled); + // Add a dummy item to that the indexes in checkMenu are the same + // for expectedItems and actualItems. + items.push([]); + items.push(null); + } else { + ok(false, "child #" + i + " of menu ID " + aMenu.id + + " has an unknown type (" + item.nodeName + ")"); + } + } + return items; +} + +function checkContextMenu(expectedItems) { + is(contextMenu.state, "open", "checking if popup is open"); + var data = { generatedSubmenuId: 1 }; + checkMenu(contextMenu, expectedItems, data); +} + +/* + * checkMenu - checks to see if the specified <menupopup> contains the + * expected items and state. + * expectedItems is a array of (1) item IDs and (2) a boolean specifying if + * the item is enabled or not (or null to ignore it). Submenus can be checked + * by providing a nested array entry after the expected <menu> ID. + * For example: ["blah", true, // item enabled + * "submenu", null, // submenu + * ["sub1", true, // submenu contents + * "sub2", false], null, // submenu contents + * "lol", false] // item disabled + * + */ +function checkMenu(menu, expectedItems, data) { + var actualItems = getVisibleMenuItems(menu, data); + //ok(false, "Items are: " + actualItems); + for (var i = 0; i < expectedItems.length; i+=2) { + var actualItem = actualItems[i]; + var actualEnabled = actualItems[i + 1]; + var expectedItem = expectedItems[i]; + var expectedEnabled = expectedItems[i + 1]; + if (expectedItem instanceof Array) { + ok(true, "Checking submenu..."); + var menuID = expectedItems[i - 2]; // The last item was the menu ID. + var submenu = menu.getElementsByAttribute("id", menuID)[0]; + ok(submenu && submenu.nodeName == "menu", "got expected submenu element"); + checkMenu(submenu.menupopup, expectedItem, data); + } else { + is(actualItem, expectedItem, + "checking item #" + i/2 + " (" + expectedItem + ") name"); + + if (typeof expectedEnabled == "object" && expectedEnabled != null || + typeof actualEnabled == "object" && actualEnabled != null) { + + ok(!(actualEnabled == null), "actualEnabled is not null"); + ok(!(expectedEnabled == null), "expectedEnabled is not null"); + is(typeof actualEnabled, typeof expectedEnabled, "checking types"); + + if (typeof actualEnabled != typeof expectedEnabled || + actualEnabled == null || expectedEnabled == null) + continue; + + is(actualEnabled.type, expectedEnabled.type, + "checking item #" + i/2 + " (" + expectedItem + ") type attr value"); + var icon = actualEnabled.icon; + if (icon) { + var tmp = ""; + var j = icon.length - 1; + while (j && icon[j] != "/") { + tmp = icon[j--] + tmp; + } + icon = tmp; + } + is(icon, expectedEnabled.icon, + "checking item #" + i/2 + " (" + expectedItem + ") icon attr value"); + is(actualEnabled.checked, expectedEnabled.checked, + "checking item #" + i/2 + " (" + expectedItem + ") has checked attr"); + is(actualEnabled.disabled, expectedEnabled.disabled, + "checking item #" + i/2 + " (" + expectedItem + ") has disabled attr"); + } else if (expectedEnabled != null) + is(actualEnabled, expectedEnabled, + "checking item #" + i/2 + " (" + expectedItem + ") enabled state"); + } + } + // Could find unexpected extra items at the end... + is(actualItems.length, expectedItems.length, "checking expected number of menu entries"); +} + +/* + * runTest + * + * Called by a popupshowing event handler. Each test checks for expected menu + * contents, closes the popup, and finally triggers the popup on a new element + * (thus kicking off another cycle). + * + */ +function runTest(testNum) { + ok(true, "Starting test #" + testNum); + + switch (testNum) { + case 1: + // Invoke context menu for next test. + openContextMenuFor(text); + break; + + case 2: + // Context menu for plain text + plainTextItems = ["context-back", false, + "context-forward", false, + "context-reload", true, + "context-stop", false, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "context-sendpage", true, + "---", null, + "context-viewbgimage", false, + "context-selectall", true, + "---", null, + "context-viewsource", true, + "context-viewinfo", true]; + checkContextMenu(plainTextItems); + closeContextMenu(); + openContextMenuFor(link); // Invoke context menu for next test. + break; + + case 3: + // Context menu for text link + checkContextMenu(["context-openlinkintab", true, + "context-openlink", true, + "context-openlinkinprivatewindow", true, + "---", null, + "context-bookmarklink", true, + "context-savelink", true, + "context-sendlink", true, + "context-copylink", true, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "---", null, + "context-metadata", true]); + closeContextMenu(); + openContextMenuFor(mailto); // Invoke context menu for next test. + break; + + case 4: + // Context menu for text mailto-link + checkContextMenu(["context-copyemail", true, + "context-copylink", true, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "---", null, + "context-metadata", true]); + closeContextMenu(); + openContextMenuFor(input); // Invoke context menu for next test. + break; + + case 5: + // Context menu for text input field + checkContextMenu(["context-undo", false, + "context-redo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", false, + "---", null, + "spell-check-enabled", true]); + closeContextMenu(); + input_sel.value = "test"; + input_sel.select(); + openContextMenuFor(input_sel); // Invoke context menu for next test. + break; + + case 6: + // Context menu for text input field with text + checkContextMenu(["context-undo", false, + "context-redo", false, + "---", null, + "context-cut", true, + "context-copy", true, + "context-paste", null, // ignore clipboard state + "context-delete", true, + "---", null, + "context-selectall", true, + "context-searchselect", true, + "---", null, + "spell-check-enabled", true]); + closeContextMenu(); + openContextMenuFor(img); // Invoke context menu for next test. + break; + + case 7: + // Context menu for an image + checkContextMenu(["context-reloadimage", true, + "context-viewimage", true, + "context-blockimage", true, + "context-copyimage", true, + "---", null, + "context-saveimage", true, + "context-sendimage", true].concat( + ("@mozilla.org/suite/shell-service;1" in Cc) ? + ["context-setDesktopBackground", true] : []).concat( + ["---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "context-sendpage", true, + "---", null, + "context-metadata", true])); + closeContextMenu(); + openContextMenuFor(canvas); // Invoke context menu for next test. + break; + + case 8: + // Context menu for a canvas + checkContextMenu(["context-viewimage", true, + "context-saveimage", true, + "context-bookmarkpage", true, + "context-sendpage", true, + "context-selectall", true]); + closeContextMenu(); + openContextMenuFor(video_ok); // Invoke context menu for next test. + break; + + case 9: + // Context menu for a video (with a VALID media source) + checkContextMenu(["context-media-play", true, + "context-media-mute", true, + "context-media-playbackrate", true, + ["context-media-playbackrate-050", true, + "context-media-playbackrate-100", true, + "context-media-playbackrate-150", true, + "context-media-playbackrate-200", true], null, + "context-media-hidecontrols", true, + "context-video-showstats", true, + "context-video-fullscreen", true, + "---", null, + "context-viewvideo", true, + "context-copyvideourl", true, + "---", null, + "context-savevideo", true, + "context-sendvideo", true, + "context-video-saveimage", true]); + closeContextMenu(); + openContextMenuFor(audio_in_video); // Invoke context menu for next test. + break; + + case 10: + // Context menu for a video (with an audio-only file) + checkContextMenu(["context-media-play", true, + "context-media-mute", true, + "context-media-playbackrate", true, + ["context-media-playbackrate-050", true, + "context-media-playbackrate-100", true, + "context-media-playbackrate-150", true, + "context-media-playbackrate-200", true], null, + "context-media-showcontrols", true, + "---", null, + "context-copyaudiourl", true, + "---", null, + "context-saveaudio", true, + "context-sendaudio", true]); + closeContextMenu(); + openContextMenuFor(video_bad); // Invoke context menu for next test. + break; + + case 11: + // Context menu for a video (with an INVALID media source) + checkContextMenu(["context-media-play", false, + "context-media-mute", false, + "context-media-playbackrate", false, + ["context-media-playbackrate-050", null, + "context-media-playbackrate-100", null, + "context-media-playbackrate-150", null, + "context-media-playbackrate-200", null], null, + "context-media-hidecontrols", false, + "context-video-showstats", false, + "context-video-fullscreen", false, + "---", null, + "context-viewvideo", true, + "context-copyvideourl", true, + "---", null, + "context-savevideo", true, + "context-sendvideo", true, + "context-video-saveimage", false]); + closeContextMenu(); + openContextMenuFor(video_bad2); // Invoke context menu for next test. + break; + + case 12: + // Context menu for a video (with an INVALID media source) + checkContextMenu(["context-media-play", false, + "context-media-mute", false, + "context-media-playbackrate", false, + ["context-media-playbackrate-050", null, + "context-media-playbackrate-100", null, + "context-media-playbackrate-150", null, + "context-media-playbackrate-200", null], null, + "context-media-hidecontrols", false, + "context-video-showstats", false, + "context-video-fullscreen", false, + "---", null, + "context-viewvideo", false, + "context-copyvideourl", false, + "---", null, + "context-savevideo", false, + "context-sendvideo", false, + "context-video-saveimage", false]); + closeContextMenu(); + openContextMenuFor(iframe); // Invoke context menu for next test. + break; + + case 13: + // Context menu for an iframe + checkContextMenu(["context-back", false, + "context-forward", false, + "context-reload", true, + "context-stop", false, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "context-sendpage", true, + "---", null, + "context-viewbgimage", false, + "context-selectall", true, + "---", null, + "context-viewsource", true, + "context-viewinfo", true, + "---", null, + "frame", null, + ["context-showonlythisframe", true, + "context-openframeintab", true, + "context-openframe", true, + "---", null, + "context-reloadframe", true, + "---", null, + "context-bookmarkframe", true, + "context-saveframe", true, + "context-sendframe", true, + "---", null, + "context-viewframesource", true, + "context-viewframeinfo", true], null]); + closeContextMenu(); + openContextMenuFor(video_in_iframe); // Invoke context menu for next test. + break; + + case 14: + // Context menu for a video in an iframe + checkContextMenu(["context-media-play", true, + "context-media-mute", true, + "context-media-playbackrate", true, + ["context-media-playbackrate-050", true, + "context-media-playbackrate-100", true, + "context-media-playbackrate-150", true, + "context-media-playbackrate-200", true], null, + "context-media-hidecontrols", true, + "context-video-showstats", true, + "context-video-fullscreen", true, + "---", null, + "context-viewvideo", true, + "context-copyvideourl", true, + "---", null, + "context-savevideo", true, + "context-sendvideo", true, + "context-video-saveimage", true, + "---", null, + "frame", null, + ["context-showonlythisframe", true, + "context-openframeintab", true, + "context-openframe", true, + "---", null, + "context-reloadframe", true, + "---", null, + "context-bookmarkframe", true, + "context-saveframe", true, + "context-sendframe", true, + "---", null, + "context-viewframesource", true, + "context-viewframeinfo", true], null]); + closeContextMenu(); + openContextMenuFor(image_in_iframe); // Invoke context menu for next test. + break; + + case 15: + // Context menu for an image in an iframe + checkContextMenu(["context-reloadimage", true, + "context-viewimage", true, + "context-blockimage", true, + "context-copyimage", true, + "---", null, + "context-saveimage", true, + "context-sendimage", true, + ].concat( + ("@mozilla.org/suite/shell-service;1" in Cc) ? + ["context-setDesktopBackground", true] : []) + .concat( + ["---", null, + "context-sendpage", true, + "---", null, + "context-metadata", true, + "---", null, + "frame", null, + ["context-showonlythisframe", true, + "context-openframeintab", true, + "context-openframe", true, + "---", null, + "context-reloadframe", true, + "---", null, + "context-bookmarkframe", true, + "context-saveframe", true, + "context-sendframe", true, + "---", null, + "context-viewframesource", true, + "context-viewframeinfo", true], null])); + closeContextMenu(); + openContextMenuFor(text); // Invoke context menu for next test. + break; + + case 16: + // Re-check context menu for plain text to make sure it hasn't changed + checkContextMenu(plainTextItems); + closeContextMenu(); + textarea_sel.select(); + openContextMenuFor(textarea_sel, false, true); + break; + + case 17: + // search for text with text area's selected value + checkContextMenu(["context-undo", false, + "context-redo", false, + "---", null, + "context-cut", true, + "context-copy", true, + "context-paste", null, // ignore clipboard state + "context-delete", true, + "---", null, + "context-selectall", true, + "context-searchselect", true, + "---", null, + "spell-check-enabled", true, + "spell-dictionaries", true, + ["spell-check-dictionary-en-US", true, + "---", null, + "spell-add-dictionaries", true], null]); + closeContextMenu(); + openContextMenuFor(textarea, false, true); // Invoke context menu for next test, but wait for the spellcheck. + break; + + case 18: + // Context menu for textarea + checkContextMenu(["*chubbiness", true, // spelling suggestion + "---", null, + "spell-add-to-dictionary", true, + "spell-ignore-word", true, + "---", null, + "context-undo", false, + "context-redo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", true, + "---", null, + "spell-check-enabled", true, + "spell-dictionaries", true, + ["spell-check-dictionary-en-US", true, + "---", null, + "spell-add-dictionaries", true], null]); + + contextMenu.ownerDocument.getElementById("spell-add-to-dictionary").doCommand(); // Add to dictionary + closeContextMenu(); + openContextMenuFor(textarea, false, true); // Invoke context menu for next test. + break; + + case 19: + // Context menu for textarea after a word has been added + // to the dictionary + checkContextMenu(["spell-undo-add-to-dictionary", true, + "---", null, + "context-undo", false, + "context-redo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", true, + "---", null, + "spell-check-enabled", true, + "spell-dictionaries", true, + ["spell-check-dictionary-en-US", true, + "---", null, + "spell-add-dictionaries", true], null, + ]); + + contextMenu.ownerDocument.getElementById("spell-undo-add-to-dictionary").doCommand(); // Undo add to dictionary + closeContextMenu(); + openContextMenuFor(contenteditable, false, true); + break; + + case 20: + // Context menu for contenteditable + checkContextMenu(["spell-no-suggestions", false, + "---", null, + "spell-add-to-dictionary", true, + "spell-ignore-word", true, + "---", null, + "context-undo", false, + "context-redo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", true, + "---", null, + "spell-check-enabled", true, + "spell-dictionaries", true, + ["spell-check-dictionary-en-US", true, + "---", null, + "spell-add-dictionaries", true], null]); + + closeContextMenu(); + openContextMenuFor(inputspell, false, true); // Invoke context menu for next test. + break; + + case 21: + // Context menu for spell-check input + checkContextMenu(["*prodigality", true, // spelling suggestion + "---", null, + "spell-add-to-dictionary", true, + "spell-ignore-word", true, + "---", null, + "context-undo", false, + "context-redo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", true, + "---", null, + "spell-check-enabled", true, + "spell-dictionaries", true, + ["spell-check-dictionary-en-US", true, + "---", null, + "spell-add-dictionaries", true], null]); + + closeContextMenu(); + openContextMenuFor(link); // Invoke context menu for next test. + break; + + case 22: + executeCopyCommand("cmd_copyLink", "http://mozilla.com/"); + closeContextMenu(); + openContextMenuFor(pagemenu); // Invoke context menu for next test. + break; + + case 23: + // Context menu for element with assigned content context menu + checkContextMenu(["+Plain item", {type: "", icon: "", checked: false, disabled: false}, + "+Disabled item", {type: "", icon: "", checked: false, disabled: true}, + "+Item w/ textContent", {type: "", icon: "", checked: false, disabled: false}, + "---", null, + "+Checkbox", {type: "checkbox", icon: "", checked: true, disabled: false}, + "---", null, + "+Radio1", {type: "checkbox", icon: "", checked: true, disabled: false}, + "+Radio2", {type: "checkbox", icon: "", checked: false, disabled: false}, + "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false}, + "---", null, + "+Item w/ icon", {type: "", icon: "favicon.ico", checked: false, disabled: false}, + "+Item w/ bad icon", {type: "", icon: "", checked: false, disabled: false}, + "---", null, + "generated-submenu-1", true, + ["+Radio1", {type: "checkbox", icon: "", checked: false, disabled: false}, + "+Radio2", {type: "checkbox", icon: "", checked: true, disabled: false}, + "+Radio3", {type: "checkbox", icon: "", checked: false, disabled: false}, + "---", null, + "+Checkbox", {type: "checkbox", icon: "", checked: false, disabled: false}], null, + "---", null, + "context-back", false, + "context-forward", false, + "context-reload", true, + "context-stop", false, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "context-sendpage", true, + "---", null, + "context-viewbgimage", false, + "context-selectall", true, + "---", null, + "context-viewsource", true, + "context-viewinfo", true]); + + invokeItemAction("0"); + closeContextMenu(); + openContextMenuFor(pagemenu, true); // Invoke context menu for next test. + break; + + case 24: + // Context menu for element with assigned content context menu + // The shift key should bypass content context menu processing + checkContextMenu(["context-back", false, + "context-forward", false, + "context-reload", true, + "context-stop", false, + "---", null, + "context-bookmarkpage", true, + "context-savepage", true, + "context-sendpage", true, + "---", null, + "context-viewbgimage", false, + "context-selectall", true, + "---", null, + "context-viewsource", true, + "context-viewinfo", true]); + closeContextMenu(); + + // Continue with SeaMonkey specific cases. + openContextMenuFor(img_link); // Invoke context menu for next test. + break; + + case 25: + // Context menu for an image with a link + checkContextMenu(["context-openlinkintab", true, + "context-openlink", true, + "context-openlinkinprivatewindow", true, + "---", null, + "context-bookmarklink", true, + "context-savelink", true, + "context-sendlink", true, + "context-copylink", true, + "---", null, + "context-reloadimage", true, + "context-viewimage", true, + "context-blockimage", true, + "context-copyimage", true, + "---", null, + "context-saveimage", true, + "context-sendimage", true].concat( + ("@mozilla.org/suite/shell-service;1" in Cc) ? + ["context-setDesktopBackground", true] : []).concat( + ["---", null, + "context-bookmarkpage", true, + "---", null, + "context-metadata", true])); + closeContextMenu(); + openContextMenuFor(img_mailto); // Invoke context menu for next test. + break; + + case 26: + // Context menu for an image with a mailto: link + checkContextMenu(["context-copyemail", true, + "context-copylink", true, + "---", null, + "context-reloadimage", true, + "context-viewimage", true, + "context-blockimage", true, + "context-copyimage", true, + "---", null, + "context-saveimage", true, + "context-sendimage", true].concat( + ("@mozilla.org/suite/shell-service;1" in Cc) ? + ["context-setDesktopBackground", true] : []).concat( + ["---", null, + "context-bookmarkpage", true, + "---", null, + "context-metadata", true])); + closeContextMenu(); + + subwindow.close(); + SimpleTest.finish(); + return; + + /* + * Other things that would be nice to test: + * - selected text + * - spelling / misspelled word (in text input?) + * - check state of disabled items + * - test execution of menu items (maybe as a separate test?) + */ + + default: + ok(false, "Unexpected invocation of test #" + testNum); + subwindow.close(); + SimpleTest.finish(); + return; + } + +} + + +var testNum = 1; +var subwindow, chromeWin, contextMenu, lastElement; +var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2, + iframe, video_in_iframe, image_in_iframe, textarea, contenteditable, + inputspell, pagemenu, audio_in_video; + +// SeaMonkey specific variables. +var img_link, img_mailto; + +function startTest() { + chromeWin = SpecialPowers.wrap(subwindow) + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsIDocShellTreeItem) + .rootTreeItem + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindow) + .QueryInterface(Ci.nsIDOMChromeWindow); + contextMenu = chromeWin.document.getElementById("contentAreaContextMenu"); + ok(contextMenu, "Got context menu XUL"); + + if (chromeWin.document.getElementById("context-stop").getAttribute("disabled") != "true") { + isnot(false, "Document still loading"); + SimpleTest.executeSoon(startTest); + return; + } + + lastElement = null; + + text = subwindow.document.getElementById("test-text"); + link = subwindow.document.getElementById("test-link"); + mailto = subwindow.document.getElementById("test-mailto"); + input = subwindow.document.getElementById("test-input"); + input_sel = subwindow.document.getElementById("test-input-select"); + img = subwindow.document.getElementById("test-image"); + canvas = subwindow.document.getElementById("test-canvas"); + video_ok = subwindow.document.getElementById("test-video-ok"); + audio_in_video = subwindow.document.getElementById("test-audio-in-video"); + video_bad = subwindow.document.getElementById("test-video-bad"); + video_bad2 = subwindow.document.getElementById("test-video-bad2"); + iframe = subwindow.document.getElementById("test-iframe"); + video_in_iframe = subwindow.document.getElementById("test-video-in-iframe").contentDocument.getElementsByTagName("video")[0]; + // Ensure that contextmenu has 'context-media-play' item when check runs. + video_in_iframe.pause(); + image_in_iframe = subwindow.document.getElementById("test-image-in-iframe").contentDocument.getElementsByTagName("img")[0]; + textarea = subwindow.document.getElementById("test-textarea"); + textarea_sel = subwindow.document.getElementById("test-textarea-sel"); + contenteditable = subwindow.document.getElementById("test-contenteditable"); + contenteditable.focus(); // content editable needs to be focused to enable spellcheck + inputspell = subwindow.document.getElementById("test-input-spellcheck"); + pagemenu = subwindow.document.getElementById("test-pagemenu"); + + // SeaMonkey specific elements. + img_link = subwindow.document.getElementById("test-image-link"); + img_mailto = subwindow.document.getElementById("test-image-mailto"); + + contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }); + runTest(1); +} + +// We open this in a separate window, because the Mochitests run inside a frame. +// The frame causes an extra menu item, and prevents running the test +// standalone (ie, clicking the test name in the Mochitest window) to see +// success/failure messages. +var painted = false, loaded = false; + +function waitForEvents(event) +{ + if (event.type == "MozAfterPaint") + painted = true; + else if (event.type == "load") + loaded = true; + if (painted && loaded) { + subwindow.removeEventListener("MozAfterPaint", waitForEvents); + subwindow.onload = null; + startTest(); + } +} + +var subwindow = window.open("./subtst_contextmenu.html", "contextmenu-subtext", "width=600,height=700"); +subwindow.addEventListener("MozAfterPaint", waitForEvents); +subwindow.onload = waitForEvents; + +SimpleTest.waitForExplicitFinish(); +</script> +</pre> +</body> +</html> diff --git a/comm/suite/browser/test/mochitest/test_feed_discovery.html b/comm/suite/browser/test/mochitest/test_feed_discovery.html new file mode 100644 index 0000000000..2f2a0a459e --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_feed_discovery.html @@ -0,0 +1,56 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=240393 +--> +<head> + <title>Test for feed discovery</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377611">Mozilla Bug 377611</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody"> + +/** Tests for bug 240393 (from bug 377611 on Firefox side) **/ + +var rv = { tests: null }; +var testCheckInterval = null; + +function startTest() { + var url = window.location.href.replace(/test_feed_discovery\.html/, + 'feed_discovery.html'); + SpecialPowers.openDialog(window, [url, '', 'dialog=no,width=10,height=10', rv]); + testCheckInterval = window.setInterval(tryIfTestIsFinished, 500); +} + +function tryIfTestIsFinished() { + if (rv.tests) { + window.clearInterval(testCheckInterval); + checkTest(); + } +} + +function checkTest() { + for (var i = 0; i < rv.tests.length; ++ i) { + var test = rv.tests[i]; + if (test.todo) + todo(test.check, test.message); + else + ok(test.check, test.message); + } + SimpleTest.finish(); +} + +window.onload = startTest; + +SimpleTest.waitForExplicitFinish(); +</script> +</pre> +</body> +</html> diff --git a/comm/suite/browser/test/mochitest/test_registerHandler.html b/comm/suite/browser/test/mochitest/test_registerHandler.html new file mode 100644 index 0000000000..20952ca9ee --- /dev/null +++ b/comm/suite/browser/test/mochitest/test_registerHandler.html @@ -0,0 +1,85 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=402788 +--> +<head> + <title>Test for Bug 402788</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody"> + +/** Test for Bug 402788 **/ + + // return false if an exception has been catched, true otherwise + function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) + { + try { + if (aIsProtocol) + navigator.registerProtocolHandler(aTxt, aUri, aTitle); + else + navigator.registerContentHandler(aTxt, aUri, aTitle); + } + catch(e) { + return false; + } + + return true; + } + + ok(navigator.registerProtocolHandler, "navigator.registerProtocolHandler should be defined"); + ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined"); + + // testing a generic case + is(true, testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler should work"); + is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler should work"); + + // testing with wrong uris + is(false, testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), "a protocol handler uri should contain %s"); + is(false, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), "a content handler uri should contain %s"); + + // the spec says we should not throw here, but it probably needs to be changed + is(false, testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), "a protocol handler uri should be valid"); + is(false, testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), "a content handler uri should be valid"); + + // we should only accept to register when the handler has the same host as the current page (bug 402287) + is(false, testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), "registering a foo protocol handler with a different host should not work"); + is(false, testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), "registering a foo content handler with a different host should not work"); + + // restriction to http(s) for the uri of the handler (bug 401343) + // https should work (http already tested in the generic case) + is(true, testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with https scheme should work"); + is(true, testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with https scheme should work"); + // ftp should not work + is(false, testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with ftp scheme should not work"); + is(false, testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with ftp scheme should not work"); + // chrome should not work + is(false, testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with chrome scheme should not work"); + is(false, testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with chrome scheme should not work"); + // foo should not work + is(false, testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with foo scheme should not work"); + is(false, testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with foo scheme should not work"); + + // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788) + is(false, testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), "registering a chrome protocol handler should not work"); + is(false, testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), "registering a vbscript protocol handler should not work"); + is(false, testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), "registering a javascript protocol handler should not work"); + is(false, testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), "registering a moz-icon protocol handler should not work"); + + // for security reasons, content handlers should never be registered for some types (html, ...) + is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering rss content handlers should work"); + is(true, testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering atom content handlers should work"); + todo(false, testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), "registering html content handlers should not work"); // bug 403798 + +</script> +</pre> +</body> +</html> diff --git a/comm/suite/browser/test/mochitest/valid-feed.xml b/comm/suite/browser/test/mochitest/valid-feed.xml new file mode 100644 index 0000000000..0e700b6d8d --- /dev/null +++ b/comm/suite/browser/test/mochitest/valid-feed.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + + <title>Example Feed</title> + <link href="http://example.org/"/> + <updated>2010-08-22T18:30:02Z</updated> + + <author> + <name>John Doe</name> + </author> + <id>urn:uuid:e2df8375-99be-4848-b05e-b9d407555267</id> + + <entry> + + <title>Item</title> + <link href="http://example.org/first"/> + <id>urn:uuid:9e0f4bed-33d3-4a9d-97ab-ecaa31b3f14a</id> + <updated>2010-08-22T18:30:02Z</updated> + + <summary>Some text.</summary> + </entry> + +</feed> diff --git a/comm/suite/browser/test/mochitest/valid-unsniffable-feed.xml b/comm/suite/browser/test/mochitest/valid-unsniffable-feed.xml new file mode 100644 index 0000000000..e753157395 --- /dev/null +++ b/comm/suite/browser/test/mochitest/valid-unsniffable-feed.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 512 bytes! +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + --> +<feed xmlns="http://www.w3.org/2005/Atom"> + + <title>Example Feed</title> + <link href="http://example.org/"/> + <updated>2010-08-22T18:30:02Z</updated> + + <author> + <name>John Doe</name> + </author> + <id>urn:uuid:e2df8375-99be-4848-b05e-b9d407555267</id> + + <entry> + + <title>Item</title> + <link href="http://example.org/first"/> + <id>urn:uuid:9e0f4bed-33d3-4a9d-97ab-ecaa31b3f14a</id> + <updated>2010-08-22T18:30:02Z</updated> + + <summary>Some text.</summary> + </entry> + +</feed> diff --git a/comm/suite/browser/test/mochitest/video.ogg b/comm/suite/browser/test/mochitest/video.ogg Binary files differnew file mode 100644 index 0000000000..ac7ece3519 --- /dev/null +++ b/comm/suite/browser/test/mochitest/video.ogg |