mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
45fe6d3ae2
This patch does the following: * It adds nsITransferable::Init(nsILoadContext*). The load context might be null, which means that the transferable is non-private, but if it's non-null, we extract the boolean value for the privacy mode and store it in the transferable. * It adds checks in debug builds to make sure that Init is always called, in form of fatal assertions. * It adds nsIDOMDocument* agruments to nsIClipboardHelper methods which represent the document that the string is coming from. nsIClipboardHelper implementation internally gets the nsILoadContext from that and passes it on to the transferable upon creation. The reason that I did this was that nsIClipboardHelper is supposed to be a high-level helper, and in most of its call sites, we have easy access to a document object. * It modifies all of the call sites of the above interfaces according to this change. * It adds a GetLoadContext helper to nsIDocument to help with changing the call sites.
152 lines
4.5 KiB
HTML
152 lines
4.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=596333
|
|
-->
|
|
<head>
|
|
<title>Test for Bug 596333</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
|
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=596333">Mozilla Bug 596333</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
|
|
/** Test for Bug 596333 **/
|
|
const Ci = Components.interfaces;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
addLoadEvent(function() SimpleTest.executeSoon(runTest));
|
|
|
|
var gMisspeltWords;
|
|
|
|
function getEditor() {
|
|
return document.getElementById("edit")
|
|
.QueryInterface(Ci.nsIDOMNSEditableElement)
|
|
.editor;
|
|
}
|
|
|
|
function getSpellCheckSelection() {
|
|
var editor = getEditor();
|
|
var selcon = editor.selectionController;
|
|
return selcon.getSelection(selcon.SELECTION_SPELLCHECK);
|
|
}
|
|
|
|
function append(str) {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var edit = document.getElementById("edit");
|
|
edit.focus();
|
|
edit.selectionStart = edit.selectionEnd = edit.value.length;
|
|
var editor = getEditor();
|
|
|
|
for (var i = 0; i < str.length; ++i) {
|
|
synthesizeKey(str[i], {});
|
|
}
|
|
}
|
|
|
|
function getLoadContext() {
|
|
return window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
.QueryInterface(Ci.nsILoadContext);
|
|
}
|
|
|
|
function paste(str) {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var edit = document.getElementById("edit");
|
|
var Cc = Components.classes, Ci = Components.interfaces;
|
|
var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
|
|
trans.init(getLoadContext());
|
|
var s = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
|
s.data = str;
|
|
trans.setTransferData("text/unicode", s, str.length * 2);
|
|
|
|
getEditor().pasteTransferable(trans);
|
|
}
|
|
|
|
function runOnFocus() {
|
|
var edit = document.getElementById("edit");
|
|
edit.removeEventListener("focus", runOnFocus, false);
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
gMisspeltWords = ["haz", "cheezburger"];
|
|
is(isSpellingCheckOk(), true, "All misspellings before editing are accounted for.");
|
|
append(" becaz I'm a lolcat!");
|
|
SimpleTest.executeSoon(function() {
|
|
gMisspeltWords.push("becaz");
|
|
gMisspeltWords.push("lolcat");
|
|
is(isSpellingCheckOk(), true, "All misspellings after typing are accounted for.");
|
|
|
|
// Now, type an invalid word, and instead of hitting "space" at the end, just blur
|
|
// the textarea and see if the spell check after the blur event catches it.
|
|
append(" workd");
|
|
edit.blur();
|
|
SimpleTest.executeSoon(function() {
|
|
gMisspeltWords.push("workd");
|
|
is(isSpellingCheckOk(), true, "All misspellings after blur are accounted for.");
|
|
|
|
// Also, test the case when we're entering the first word in a textarea
|
|
gMisspeltWords = ["workd"];
|
|
edit.value = "";
|
|
append("workd ");
|
|
SimpleTest.executeSoon(function() {
|
|
is(isSpellingCheckOk(), true, "Misspelling in the first entered word is accounted for.");
|
|
|
|
// Make sure that pasting would also trigger spell checking for the previous word
|
|
gMisspeltWords = ["workd"];
|
|
edit.value = "";
|
|
append("workd");
|
|
paste(" x");
|
|
SimpleTest.executeSoon(function() {
|
|
is(isSpellingCheckOk(), true, "Misspelling is accounted for after pasting.");
|
|
|
|
SimpleTest.finish();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function runTest()
|
|
{
|
|
var edit = document.getElementById("edit");
|
|
edit.addEventListener("focus", runOnFocus, false);
|
|
edit.focus();
|
|
}
|
|
|
|
function isSpellingCheckOk() {
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var sel = getSpellCheckSelection();
|
|
var numWords = sel.rangeCount;
|
|
|
|
is(numWords, gMisspeltWords.length, "Correct number of misspellings and words.");
|
|
|
|
if (numWords != gMisspeltWords.length)
|
|
return false;
|
|
|
|
for (var i=0; i<numWords; i++) {
|
|
var word = sel.getRangeAt(i);
|
|
is (word, gMisspeltWords[i], "Misspelling is what we think it is.");
|
|
if (word != gMisspeltWords[i])
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
|
|
<textarea id="edit">I can haz cheezburger</textarea>
|
|
|
|
</body>
|
|
</html>
|