diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /editor/libeditor/tests/test_set_document_title_transaction.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'editor/libeditor/tests/test_set_document_title_transaction.html')
-rw-r--r-- | editor/libeditor/tests/test_set_document_title_transaction.html | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/editor/libeditor/tests/test_set_document_title_transaction.html b/editor/libeditor/tests/test_set_document_title_transaction.html new file mode 100644 index 000000000..d745d4f13 --- /dev/null +++ b/editor/libeditor/tests/test_set_document_title_transaction.html @@ -0,0 +1,79 @@ +<!DOCTYPE html> +<html> +<head> + <title>Test for SetDocumentTitleTransaction</title> + <script type="text/javascript" + 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 onload="runTests()"> +<div id="display"> + <iframe src="data:text/html,<!DOCTYPE html><html><head><title>first title</title></head><body></body></html>"></iframe> +</div> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> + +<script class="testbody" type="application/javascript"> +function runTests() { + var iframe = document.getElementsByTagName("iframe")[0]; + function isDocumentTitleEquals(aDescription, aExpectedTitle) { + is(iframe.contentDocument.title, aExpectedTitle, aDescription + ": document.title should be " + aExpectedTitle); + is(iframe.contentDocument.getElementsByTagName("title")[0].textContent, aExpectedTitle, aDescription + ": The text in the title element should be " + aExpectedTitle); + } + + isDocumentTitleEquals("Checking isDocumentTitleEquals()", "first title"); + + const kTests = [ + { description: "designMode=\"on\"", + init: function () { + iframe.contentDocument.designMode = "on"; + }, + cleanUp: function () { + iframe.contentDocument.designMode = "off"; + } + }, + { description: "html element has contenteditable attribute", + init: function () { + iframe.contentDocument.documentElement.setAttribute("contenteditable", "true"); + }, + cleanUp: function () { + iframe.contentDocument.documentElement.removeAttribute("contenteditable"); + } + }, + ]; + + for (var i = 0; i < kTests.length; i++) { + const kTest = kTests[i]; + kTest.init(); + + var editor = SpecialPowers.wrap(iframe.contentWindow). + QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor). + getInterface(SpecialPowers.Ci.nsIWebNavigation). + QueryInterface(SpecialPowers.Ci.nsIDocShell).editor; + ok(editor, kTest.description + ": The docshell should have editor"); + var htmlEditor = editor.QueryInterface(SpecialPowers.Ci.nsIHTMLEditor); + ok(htmlEditor, kTest.description + ": The editor should have nsIHTMLEditor interface"); + + // Replace existing title. + htmlEditor.setDocumentTitle("Modified title"); + isDocumentTitleEquals(kTest.description, "Modified title"); + + // When the document doesn't have <title> element, title element should be created automatically. + iframe.contentDocument.head.removeChild(iframe.contentDocument.getElementsByTagName("title")[0]); + is(iframe.contentDocument.getElementsByTagName("title").length, 0, kTest.description + ": There should be no title element"); + htmlEditor.setDocumentTitle("new title"); + is(iframe.contentDocument.getElementsByTagName("title").length, 1, kTest.description + ": There should be a title element"); + isDocumentTitleEquals(kTest.description, "new title"); + + kTest.cleanUp(); + } + + SimpleTest.finish(); +} +</script> +</body> + +</html> |