1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_autocomplete_delayOnPaste.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,128 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 + 1.8 +<window title="Autocomplete Widget Test 4" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + onload="runTest();"> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.14 + <script type="application/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.16 + <script type="application/javascript" 1.17 + src="chrome://global/content/globalOverlay.js"/> 1.18 + 1.19 +<textbox id="autocomplete" 1.20 + type="autocomplete" 1.21 + completedefaultindex="true" 1.22 + onsearchcomplete="searchComplete();" 1.23 + timeout="0" 1.24 + autocompletesearch="simple"/> 1.25 + 1.26 +<script class="testbody" type="application/javascript"> 1.27 +<![CDATA[ 1.28 + 1.29 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.30 + 1.31 +function autoCompleteSimpleResult(aString) { 1.32 + this.searchString = aString; 1.33 + this.searchResult = Components.interfaces.nsIAutoCompleteResult.RESULT_SUCCESS; 1.34 + this.matchCount = 1; 1.35 + this._param = "Result"; 1.36 +} 1.37 +autoCompleteSimpleResult.prototype = { 1.38 + _param: "", 1.39 + searchString: null, 1.40 + searchResult: Components.interfaces.nsIAutoCompleteResult.RESULT_FAILURE, 1.41 + defaultIndex: 0, 1.42 + errorDescription: null, 1.43 + matchCount: 0, 1.44 + getValueAt: function() { return this._param; }, 1.45 + getCommentAt: function() { return null; }, 1.46 + getStyleAt: function() { return null; }, 1.47 + getImageAt: function() { return null; }, 1.48 + getFinalCompleteValueAt: function() { return this.getValueAt(); }, 1.49 + getLabelAt: function() { return null; }, 1.50 + removeValueAt: function() {} 1.51 +}; 1.52 + 1.53 +// A basic autocomplete implementation that returns one result. 1.54 +let autoCompleteSimple = { 1.55 + classID: Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca"), 1.56 + contractID: "@mozilla.org/autocomplete/search;1?name=simple", 1.57 + QueryInterface: XPCOMUtils.generateQI([ 1.58 + Components.interfaces.nsIFactory, 1.59 + Components.interfaces.nsIAutoCompleteSearch 1.60 + ]), 1.61 + createInstance: function (outer, iid) { 1.62 + return this.QueryInterface(iid); 1.63 + }, 1.64 + 1.65 + registerFactory: function () { 1.66 + let registrar = 1.67 + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); 1.68 + registrar.registerFactory(this.classID, "Test Simple Autocomplete", 1.69 + this.contractID, this); 1.70 + }, 1.71 + unregisterFactory: function () { 1.72 + let registrar = 1.73 + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar); 1.74 + registrar.unregisterFactory(this.classID, this); 1.75 + }, 1.76 + 1.77 + startSearch: function (aString, aParam, aResult, aListener) { 1.78 + let result = new autoCompleteSimpleResult(aString); 1.79 + aListener.onSearchResult(this, result); 1.80 + }, 1.81 + stopSearch: function () {} 1.82 +}; 1.83 + 1.84 +SimpleTest.waitForExplicitFinish(); 1.85 + 1.86 +// XPFE AutoComplete needs to register early. 1.87 +autoCompleteSimple.registerFactory(); 1.88 + 1.89 +let gACTimer; 1.90 +let gAutoComplete; 1.91 + 1.92 +function searchComplete() { 1.93 + is(gAutoComplete.value, "result", "Value should be autocompleted now"); 1.94 + ok(Date.now() - gACTimer > 500, "There should be a delay before autocomplete"); 1.95 + 1.96 + // Unregister the factory so that we don't get in the way of other tests 1.97 + autoCompleteSimple.unregisterFactory(); 1.98 + SimpleTest.finish(); 1.99 +} 1.100 + 1.101 +function runTest() { 1.102 + gAutoComplete = $("autocomplete"); 1.103 + 1.104 + const SEARCH_STRING = "res"; 1.105 + 1.106 + function cbCallback() { 1.107 + gAutoComplete.focus(); 1.108 + synthesizeKey("v", { accelKey: true }); 1.109 + is(gAutoComplete.value, SEARCH_STRING, "Value should not be autocompleted immediately"); 1.110 + } 1.111 + 1.112 + SimpleTest.waitForClipboard(SEARCH_STRING, function () { 1.113 + gACTimer = Date.now(); 1.114 + Components.classes["@mozilla.org/widget/clipboardhelper;1"] 1.115 + .getService(Components.interfaces.nsIClipboardHelper) 1.116 + .copyStringToClipboard(SEARCH_STRING, Components.interfaces.nsIClipboard.kGlobalClipboard, document); 1.117 + }, cbCallback, cbCallback); 1.118 +} 1.119 +]]> 1.120 +</script> 1.121 + 1.122 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.123 +<p id="display"> 1.124 +</p> 1.125 +<div id="content" style="display: none"> 1.126 +</div> 1.127 +<pre id="test"> 1.128 +</pre> 1.129 +</body> 1.130 + 1.131 +</window>