diff options
Diffstat (limited to 'editor/composer/test')
-rw-r--r-- | editor/composer/test/chrome.ini | 5 | ||||
-rw-r--r-- | editor/composer/test/file_bug1453190.html | 12 | ||||
-rw-r--r-- | editor/composer/test/mochitest.ini | 11 | ||||
-rw-r--r-- | editor/composer/test/test_bug1266815.html | 95 | ||||
-rw-r--r-- | editor/composer/test/test_bug1453190.html | 36 | ||||
-rw-r--r-- | editor/composer/test/test_bug348497.html | 36 | ||||
-rw-r--r-- | editor/composer/test/test_bug384147.html | 203 | ||||
-rw-r--r-- | editor/composer/test/test_bug389350.html | 33 | ||||
-rw-r--r-- | editor/composer/test/test_bug434998.xhtml | 106 | ||||
-rw-r--r-- | editor/composer/test/test_bug519928.html | 119 | ||||
-rw-r--r-- | editor/composer/test/test_bug738440.html | 37 |
11 files changed, 693 insertions, 0 deletions
diff --git a/editor/composer/test/chrome.ini b/editor/composer/test/chrome.ini new file mode 100644 index 0000000000..cd25f64656 --- /dev/null +++ b/editor/composer/test/chrome.ini @@ -0,0 +1,5 @@ +[DEFAULT] +skip-if = os == 'android' + +[test_bug434998.xhtml] +[test_bug1266815.html] diff --git a/editor/composer/test/file_bug1453190.html b/editor/composer/test/file_bug1453190.html new file mode 100644 index 0000000000..74b13bb0ec --- /dev/null +++ b/editor/composer/test/file_bug1453190.html @@ -0,0 +1,12 @@ +<script> +window.onload = function () { + document.createElement("frameset").setAttribute("onunload", "go()") +} +function go() { + let a = document.getElementById("a"); + let b = document.getElementById("b"); + a.appendChild(b); +} +</script> +<div id="a"> +<li id="b" contenteditable="true"> diff --git a/editor/composer/test/mochitest.ini b/editor/composer/test/mochitest.ini new file mode 100644 index 0000000000..4e221a0320 --- /dev/null +++ b/editor/composer/test/mochitest.ini @@ -0,0 +1,11 @@ +[DEFAULT] +support-files = + file_bug1453190.html + +[test_bug348497.html] +[test_bug384147.html] +[test_bug389350.html] +[test_bug519928.html] +[test_bug738440.html] +[test_bug1453190.html] +skip-if = os == "android" diff --git a/editor/composer/test/test_bug1266815.html b/editor/composer/test/test_bug1266815.html new file mode 100644 index 0000000000..b63ee02874 --- /dev/null +++ b/editor/composer/test/test_bug1266815.html @@ -0,0 +1,95 @@ +<!DOCTYPE html> +<html> +<head> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> +</head> +<body> +<p id="display"></p> +<script type="text/javascript"> +// XXX(nika): Why are we using SpecialPowers here? If we're a chrome mochitest +// can't we avoid using the SpecialPowers wrappers? +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; +const Cu = SpecialPowers.Cu; + +const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm"); + +const HELPERAPP_DIALOG_CID = + SpecialPowers.wrap(SpecialPowers.Components) + .ID(Cc["@mozilla.org/helperapplauncherdialog;1"].number); +const HELPERAPP_DIALOG_CONTRACT_ID = "@mozilla.org/helperapplauncherdialog;1"; +const MOCK_HELPERAPP_DIALOG_CID = + SpecialPowers.wrap(SpecialPowers.Components) + .ID("{391832c8-5232-4676-b838-cc8ad373f3d8}"); + +var registrar = SpecialPowers.wrap(Components).manager + .QueryInterface(Ci.nsIComponentRegistrar); + +const HandlerService = Cc[ + "@mozilla.org/uriloader/handler-service;1" +].getService(Ci.nsIHandlerService); + +const MIMEService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService); + +var helperAppDlgPromise = new Promise(function(resolve) { + var mockHelperAppService; + + function HelperAppLauncherDialog() { + } + + HelperAppLauncherDialog.prototype = { + show(aLauncher, aWindowContext, aReason) { + ok(true, "Whether showing Dialog"); + resolve(); + registrar.unregisterFactory(MOCK_HELPERAPP_DIALOG_CID, + mockHelperAppService); + }, + QueryInterface: ChromeUtils.generateQI(["nsIHelperAppLauncherDialog"]), + }; + + mockHelperAppService = ComponentUtils.generateSingletonFactory(HelperAppLauncherDialog); + registrar.registerFactory(MOCK_HELPERAPP_DIALOG_CID, "", + HELPERAPP_DIALOG_CONTRACT_ID, + mockHelperAppService); +}); + +add_task(async function() { + // ensure the download triggers the external app dialog + const mimeInfo = MIMEService.getFromTypeAndExtension("application/octet-stream", ""); + mimeInfo.alwaysAskBeforeHandling = true; + HandlerService.store(mimeInfo); + + SimpleTest.registerCleanupFunction(() => { + HandlerService.remove(mimeInfo); + }); + + let promise = new Promise(function(resolve) { + let iframe = document.createElement("iframe"); + iframe.onload = function() { + is(iframe.contentDocument.getElementById("edit").innerText, "abc", + "load iframe source"); + resolve(); + }; + iframe.id = "testframe"; + iframe.src = "data:text/html,<div id=edit contenteditable=true>abc</div>"; + document.body.appendChild(iframe); + }); + + await promise; + + let iframe = document.getElementById("testframe"); + let docShell = SpecialPowers.wrap(iframe.contentWindow).docShell; + + ok(docShell.hasEditingSession, "Should have editing session"); + + document.getElementById("testframe").src = + "data:application/octet-stream,TESTCONTENT"; + + await helperAppDlgPromise; + + ok(docShell.hasEditingSession, "Should have editing session"); +}); +</script> +</body> +</html> diff --git a/editor/composer/test/test_bug1453190.html b/editor/composer/test/test_bug1453190.html new file mode 100644 index 0000000000..cf6b0d888a --- /dev/null +++ b/editor/composer/test/test_bug1453190.html @@ -0,0 +1,36 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1453190 +--> +<head> + <title>Test for Bug 1453190</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=1453190">Mozilla Bug 1453190</a> +<p id="display"></p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> +SimpleTest.waitForExplicitFinish(); + +let testWindow = window.open("file_bug1453190.html"); +testWindow.addEventListener("load", () => { + SimpleTest.executeSoon(() => { + runTest(testWindow); + }); +}, {once: true}); + +function runTest(win) { + ok(!win.closed, "test window is opened"); + win.close(); + ok(win.closed, "test window is closed"); + SimpleTest.finish(); +} +</script> +</pre> +</body> +</html> diff --git a/editor/composer/test/test_bug348497.html b/editor/composer/test/test_bug348497.html new file mode 100644 index 0000000000..898fb49ae1 --- /dev/null +++ b/editor/composer/test/test_bug348497.html @@ -0,0 +1,36 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=348497 +--> +<head> + <title>Test for Bug 348497</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=348497">Mozilla Bug 348497</a> +<p id="display"></p> +<div id="content"> + This page should not crash Mozilla<br> + <iframe id="testIframe"></iframe> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 348497 **/ +function doe() { + document.getElementById("testIframe").style.display = "block"; + document.getElementById("testIframe").contentDocument.designMode = "on"; +} + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(doe); +addLoadEvent(function() { ok(true, "enabling designmode on an iframe onload does not crash Mozilla"); }); +addLoadEvent(SimpleTest.finish); + +</script> +</pre> +</body> +</html> + diff --git a/editor/composer/test/test_bug384147.html b/editor/composer/test/test_bug384147.html new file mode 100644 index 0000000000..6feb8b4ad4 --- /dev/null +++ b/editor/composer/test/test_bug384147.html @@ -0,0 +1,203 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=384147 +--> +<head> + <title>Test for Bug 384147</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> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=384147">Mozilla Bug 384147</a> +<p id="display"></p> +<div id="content" style="display: block"> +<div contentEditable id="editor"></div> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 384147 **/ + +SimpleTest.waitForExplicitFinish(); + +var editor = document.getElementById("editor"); + +editor.innerHTML = "<ol><li>Item 1</li><li>Item 2</li><ol><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>"; +editor.focus(); + +// If executed directly, a race condition exists that will cause execCommand +// to fail occasionally (but often). Defer test execution to page load. +addLoadEvent(function() { + var sel = window.getSelection(); + + // Test the effect that the tab key has on list items. Each test is + // documented with the initial state of the list on the left, and the + // expected state of the list on the right. {\t} indicates the list item + // that will be indented. {\st} indicates that a shift-tab will be simulated + // on that list item, outdenting it. + // + // Note: any test failing will likely result in all following tests failing + // as well, since each test depends on the document being in a given state. + // Unfortunately, due to the problems getting document focus and key events + // to fire consistently, it's difficult to reset state between tests. + // If there are test failures here, only debug the first test failure. + + // *** test 1 *** + // 1. Item 1 1. Item 1 + // 2. {\t}Item 2 1. Item 2 + // 1. Item 3 2. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[1]); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 1"); + + // *** test 2 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. {\t}Item 3 1. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[2]); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><ol><li>Item 3</li></ol></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 2"); + + // *** test 3 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 1. {\st}Item 3 2. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + document.execCommand("outdent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 3"); + + // *** test 4 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. {\st}Item 3 2. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + document.execCommand("outdent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li></ol><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 4"); + + // *** test 5 *** + // 1. Item 1 1. Item 1 + // 1. {\st}Item 2 2. Item 2 + // 2. Item 3 3. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[1]); + document.execCommand("outdent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 5"); + + // *** test 6 *** + // 1. Item 1 1. Item 1 + // 2. {\t}Item 2 1. Item 2 + // 3. Item 3 2. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li></ol><li>Item 3</li></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 6"); + + // *** test 7 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. {\t}Item 3 2. Item 3 + // * Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[2]); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><li>Item 5</li></ul>", + "html output doesn't match expected value in test 7"); + + // That covers the basics of merging lists on indent and outdent. + // We also want to check that ul / ol lists won't be merged together, + // since they're different types of lists. + // *** test 8 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. Item 3 2. Item 3 + // * {\t}Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[3]); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><ul><li>Item 4</li></ul><li>Item 5</li></ul>", + "html output doesn't match expected value in test 8"); + + // Better test merging with <ul> rather than <ol> too. + // *** test 9 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. Item 3 2. Item 3 + // * Item 4 * Item 4 + // * {\t}Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[4]); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><ul><li>Item 4</li><li>Item 5</li></ul></ul>", + "html output doesn't match expected value in test 9"); + + // Same test as test 8, but with outdent rather than indent. + // *** test 10 *** + // 1. Item 1 1. Item 1 + // 1. Item 2 1. Item 2 + // 2. Item 3 2. Item 3 + // * {\st}Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + sel.selectAllChildren(editor.getElementsByTagName("li")[3]); + document.execCommand("outdent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><ul><li>Item 5</li></ul></ul>", + "html output doesn't match expected value in test 10"); + + // Test indenting multiple items at once. Hold down "shift" and select + // upwards to get all the <ol> items and the first <ul> item. + // *** test 11 *** + // 1. Item 1 1. Item 1 + // 1. {\t}Item 2 1. Item 2 + // 2. {\t}Item 3 2. Item 3 + // * {\t}Item 4 * Item 4 + // * Item 5 * Item 5 + sel.removeAllRanges(); + var range = document.createRange(); + range.setStart(editor.getElementsByTagName("li")[1], 0); + range.setEnd(editor.getElementsByTagName("li")[3], editor.getElementsByTagName("li")[3].childNodes.length); + sel.addRange(range); + document.execCommand("indent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><ol><li>Item 2</li><li>Item 3</li></ol></ol></ol><ul><ul><li>Item 4</li><li>Item 5</li></ul></ul>", + "html output doesn't match expected value in test 11"); + + // Test outdenting multiple items at once. Selection is already ready... + // *** test 12 *** + // 1. Item 1 1. Item 1 + // 1. {\st}Item 2 1. Item 2 + // 2. {\st}Item 3 2. Item 3 + // * {\st}Item 4 * Item 4 + // * Item 5 * Item 5 + document.execCommand("outdent", false, null); + ok(editor.innerHTML == "<ol><li>Item 1</li><ol><li>Item 2</li><li>Item 3</li></ol></ol><ul><li>Item 4</li><ul><li>Item 5</li></ul></ul>", + "html output doesn't match expected value in test 12"); + + SimpleTest.finish(); +}); + + + +</script> +</pre> +</body> +</html> + diff --git a/editor/composer/test/test_bug389350.html b/editor/composer/test/test_bug389350.html new file mode 100644 index 0000000000..9b9aecd1e7 --- /dev/null +++ b/editor/composer/test/test_bug389350.html @@ -0,0 +1,33 @@ +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=389350 +--> +<head> +<title>Test for Bug 389350</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" /> + +<script type="text/javascript"> + +function runTest() { + var e = document.getElementById("edit"); + e.contentDocument.designMode = "on"; + e.style.display = "block"; + e.focus(); + sendString("abc"); + var expected = "<head></head><body>abc</body>"; + var result = e.contentDocument.documentElement.innerHTML; + is(result, expected, "iframe with designmode on had incorrect content"); + SimpleTest.finish(); +} + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(runTest); +</script> + +</head> +<body id="body"> +<iframe id="edit" width="200" height="100" style="display: none;" src=""> +</body> +</html> diff --git a/editor/composer/test/test_bug434998.xhtml b/editor/composer/test/test_bug434998.xhtml new file mode 100644 index 0000000000..db2261e3a5 --- /dev/null +++ b/editor/composer/test/test_bug434998.xhtml @@ -0,0 +1,106 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" + type="text/css"?> +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" + type="text/css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=434998 +--> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + title="Mozilla Bug 434998" onload="runTest();"> + <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=434998" + target="_blank">Mozilla Bug 434998</a> + <p/> + <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + id="editor" + type="content" + primary="true" + editortype="html" + style="width: 400px; height: 100px; border: thin solid black"/> + <p/> + <pre id="test"> + </pre> + </body> + <script class="testbody" type="application/javascript"> + <![CDATA[ + + SimpleTest.waitForExplicitFinish(); + + function EditorContentListener(aEditor) + { + this.init(aEditor); + } + + EditorContentListener.prototype = { + init(aEditor) + { + this.mEditor = aEditor; + }, + + QueryInterface: ChromeUtils.generateQI(["nsIWebProgressListener", + "nsISupportsWeakReference"]), + + onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) + { + if (aStateFlags & Ci.nsIWebProgressListener.STATE_STOP) + { + var editor = this.mEditor.getEditor(this.mEditor.contentWindow); + if (editor) { + // Should not throw + var threw = false; + try { + this.mEditor.contentDocument.execCommand("bold", false, null); + } catch (e) { + threw = true; + } + ok(!threw, "The execCommand API should work on <xul:editor>"); + progress.removeProgressListener(progressListener, Ci.nsIWebProgress.NOTIFY_ALL); + SimpleTest.finish(); + } + } + }, + + + onProgressChange(aWebProgress, aRequest, + aCurSelfProgress, aMaxSelfProgress, + aCurTotalProgress, aMaxTotalProgress) + { + }, + + onLocationChange(aWebProgress, aRequest, aLocation, aFlags) + { + }, + + onStatusChange(aWebProgress, aRequest, aStatus, aMessage) + { + }, + + onSecurityChange(aWebProgress, aRequest, aState) + { + }, + + onContentBlockingEvent(aWebProgress, aRequest, aEvent) + { + }, + + mEditor: null + }; + + var progress, progressListener; + + function runTest() { + var newEditorElement = document.getElementById("editor"); + newEditorElement.makeEditable("html", true); + var docShell = newEditorElement.docShell; + progress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress); + progressListener = new EditorContentListener(newEditorElement); + progress.addProgressListener(progressListener, Ci.nsIWebProgress.NOTIFY_ALL); + newEditorElement.setAttribute("src", "data:text/html,"); + } +]]> +</script> +</window> diff --git a/editor/composer/test/test_bug519928.html b/editor/composer/test/test_bug519928.html new file mode 100644 index 0000000000..4ccb1aaba5 --- /dev/null +++ b/editor/composer/test/test_bug519928.html @@ -0,0 +1,119 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=519928 +--> +<head> + <title>Test for Bug 519928</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=519928">Mozilla Bug 519928</a> +<p id="display"></p> +<div id="content"> +<iframe id="load-frame"></iframe> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +var iframe = document.getElementById("load-frame"); + +function enableJS() { allowJS(true, iframe); } +function disableJS() { allowJS(false, iframe); } +function allowJS(allow, frame) { + SpecialPowers.wrap(frame.contentWindow).windowGlobalChild.windowContext.allowJavascript = allow; +} + +function expectJSAllowed(allowed, testCondition, callback) { + window.ICanRunMyJS = false; + var self_ = window; + testCondition(); + + var doc = iframe.contentDocument; + doc.body.innerHTML = "<iframe></iframe>"; + var innerFrame = doc.querySelector("iframe"); + innerFrame.addEventListener("load", function() { + var msg = "The inner iframe should" + (allowed ? "" : " not") + " be able to run Javascript"; + is(self_.ICanRunMyJS, allowed, msg); + callback(); + }, {once: true}); + // eslint-disable-next-line no-useless-concat + var iframeSrc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>"; + innerFrame.srcdoc = iframeSrc; +} + +SimpleTest.waitForExplicitFinish(); +/* eslint-disable max-nested-callbacks */ +addLoadEvent(function() { + var enterDesignMode = function() { document.designMode = "on"; }; + var leaveDesignMode = function() { document.designMode = "off"; }; + expectJSAllowed(false, disableJS, function() { + expectJSAllowed(true, enableJS, function() { + expectJSAllowed(true, enterDesignMode, function() { + expectJSAllowed(true, leaveDesignMode, function() { + expectJSAllowed(false, disableJS, function() { + expectJSAllowed(false, enterDesignMode, function() { + expectJSAllowed(false, leaveDesignMode, function() { + expectJSAllowed(true, enableJS, function() { + enterDesignMode = function() { iframe.contentDocument.designMode = "on"; }; + leaveDesignMode = function() { iframe.contentDocument.designMode = "off"; }; + expectJSAllowed(false, disableJS, function() { + expectJSAllowed(true, enableJS, function() { + expectJSAllowed(true, enterDesignMode, function() { + expectJSAllowed(true, leaveDesignMode, function() { + expectJSAllowed(false, disableJS, function() { + expectJSAllowed(false, enterDesignMode, function() { + expectJSAllowed(false, leaveDesignMode, function() { + expectJSAllowed(true, enableJS, function() { + testDocumentDisabledJS(); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); + }); +}); +/* eslint-enable max-nested-callbacks */ + +function testDocumentDisabledJS() { + window.ICanRunMyJS = false; + var self_ = window; + // Ensure design modes are disabled + document.designMode = "off"; + iframe.contentDocument.designMode = "off"; + + // Javascript enabled on the main iframe + enableJS(); + + var doc = iframe.contentDocument; + doc.body.innerHTML = "<iframe></iframe>"; + var innerFrame = doc.querySelector("iframe"); + + // Javascript disabled on the innerFrame. + allowJS(false, innerFrame); + + innerFrame.addEventListener("load", function() { + var msg = "The inner iframe should not be able to run Javascript"; + is(self_.ICanRunMyJS, false, msg); + SimpleTest.finish(); + }, {once: true}); + // eslint-disable-next-line no-useless-concat + var iframeSrc = "<script>parent.parent.ICanRunMyJS = true;</scr" + "ipt>"; + innerFrame.srcdoc = iframeSrc; +} + +</script> +</pre> +</body> +</html> diff --git a/editor/composer/test/test_bug738440.html b/editor/composer/test/test_bug738440.html new file mode 100644 index 0000000000..a021906cfc --- /dev/null +++ b/editor/composer/test/test_bug738440.html @@ -0,0 +1,37 @@ +<!doctype html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=738440 +--> +<title>Test for Bug 738440</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css" /> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=738440">Mozilla Bug 738440</a> +<div contenteditable></div> +<script> + +/** Test for Bug 738440 **/ +document.execCommand("stylewithcss", false, "true"); +is(document.queryCommandState("stylewithcss"), true, + "setting stylewithcss to true should cause its state to be true"); +is(document.queryCommandState("usecss"), false, + "usecss state should always be false"); + +document.execCommand("stylewithcss", false, "false"); +is(document.queryCommandState("stylewithcss"), false, + "setting stylewithcss to false should cause its state to be false"); +is(document.queryCommandState("usecss"), false, + "usecss state should always be false"); + +document.execCommand("usecss", false, "true"); +is(document.queryCommandState("stylewithcss"), false, + "setting usecss to true should cause stylewithcss state to be false"); +is(document.queryCommandState("usecss"), false, + "usecss state should always be false"); + +document.execCommand("usecss", false, "false"); +is(document.queryCommandState("stylewithcss"), true, + "setting usecss to false should cause stylewithcss state to be true"); +is(document.queryCommandState("usecss"), false, + "usecss state should always be false"); + +</script> |