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 /toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul | |
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 'toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul')
-rw-r--r-- | toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul b/toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul new file mode 100644 index 000000000..19f54ac21 --- /dev/null +++ b/toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul @@ -0,0 +1,128 @@ +<?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"?> + +<window title="Autocomplete Widget Test 4" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="runTest();"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + <script type="application/javascript" + src="chrome://global/content/globalOverlay.js"/> + +<textbox id="autocomplete" + type="autocomplete" + completedefaultindex="true" + onsearchcomplete="searchComplete();" + timeout="0" + autocompletesearch="simple"/> + +<script class="testbody" type="application/javascript"> +<![CDATA[ + +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +function autoCompleteSimpleResult(aString) { + this.searchString = aString; + this.searchResult = Components.interfaces.nsIAutoCompleteResult.RESULT_SUCCESS; + this.matchCount = 1; + this._param = "Result"; +} +autoCompleteSimpleResult.prototype = { + _param: "", + searchString: null, + searchResult: Components.interfaces.nsIAutoCompleteResult.RESULT_FAILURE, + defaultIndex: 0, + errorDescription: null, + matchCount: 0, + getValueAt: function() { return this._param; }, + getCommentAt: function() { return null; }, + getStyleAt: function() { return null; }, + getImageAt: function() { return null; }, + getFinalCompleteValueAt: function() { return this.getValueAt(); }, + getLabelAt: function() { return null; }, + removeValueAt: function() {} +}; + +// A basic autocomplete implementation that returns one result. +let autoCompleteSimple = { + classID: Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"), + contractID: "@mozilla.org/autocomplete/search;1?name=simple", + QueryInterface: XPCOMUtils.generateQI([ + Components.interfaces.nsIFactory, + Components.interfaces.nsIAutoCompleteSearch + ]), + createInstance: function (outer, iid) { + return this.QueryInterface(iid); + }, + + registerFactory: function () { + let registrar = + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); + registrar.registerFactory(this.classID, "Test Simple Autocomplete", + this.contractID, this); + }, + unregisterFactory: function () { + let registrar = + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); + registrar.unregisterFactory(this.classID, this); + }, + + startSearch: function (aString, aParam, aResult, aListener) { + let result = new autoCompleteSimpleResult(aString); + aListener.onSearchResult(this, result); + }, + stopSearch: function () {} +}; + +SimpleTest.waitForExplicitFinish(); + +// XPFE AutoComplete needs to register early. +autoCompleteSimple.registerFactory(); + +let gACTimer; +let gAutoComplete; + +function searchComplete() { + is(gAutoComplete.value, "result", "Value should be autocompleted now"); + ok(Date.now() - gACTimer > 500, "There should be a delay before autocomplete"); + + // Unregister the factory so that we don't get in the way of other tests + autoCompleteSimple.unregisterFactory(); + SimpleTest.finish(); +} + +function runTest() { + gAutoComplete = $("autocomplete"); + + const SEARCH_STRING = "res"; + + function cbCallback() { + gAutoComplete.focus(); + synthesizeKey("v", { accelKey: true }); + is(gAutoComplete.value, SEARCH_STRING, "Value should not be autocompleted immediately"); + } + + SimpleTest.waitForClipboard(SEARCH_STRING, function () { + gACTimer = Date.now(); + Components.classes["@mozilla.org/widget/clipboardhelper;1"] + .getService(Components.interfaces.nsIClipboardHelper) + .copyStringToClipboard(SEARCH_STRING, Components.interfaces.nsIClipboard.kGlobalClipboard); + }, cbCallback, cbCallback); +} +]]> +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +</window> |