toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_autocomplete_with_composition_on_textbox.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     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"
     1.7 +                 type="text/css"?>
     1.8 +<window title="Testing autocomplete with composition"
     1.9 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.10 +
    1.11 +  <script type="application/javascript"
    1.12 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.13 +  <script type="application/javascript"
    1.14 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" />
    1.15 +  <script type="text/javascript"
    1.16 +          src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js" />
    1.17 +  <script type="text/javascript"
    1.18 +          src="file_autocomplete_with_composition.js" />
    1.19 +
    1.20 +  <textbox id="textbox" type="autocomplete"
    1.21 +           autocompletesearch="simpleForComposition"/>
    1.22 +
    1.23 +<body  xmlns="http://www.w3.org/1999/xhtml">
    1.24 +<div id="content" style="display: none">
    1.25 +</div>
    1.26 +<pre id="test">
    1.27 +</pre>
    1.28 +</body>
    1.29 +
    1.30 +<script class="testbody" type="application/javascript">
    1.31 +<![CDATA[
    1.32 +
    1.33 +SimpleTest.waitForExplicitFinish();
    1.34 +
    1.35 +const nsIAutoCompleteResult = Components.interfaces.nsIAutoCompleteResult;
    1.36 +
    1.37 +// This result can't be constructed in-line, because otherwise we leak memory.
    1.38 +function nsAutoCompleteSimpleResult(aString)
    1.39 +{
    1.40 +  this.searchString = aString;
    1.41 +  if (aString == "" || aString == "Mozilla".substr(0, aString.length)) {
    1.42 +    this.searchResult = nsIAutoCompleteResult.RESULT_SUCCESS;
    1.43 +    this.matchCount = 1;
    1.44 +    this._value = "Mozilla";
    1.45 +  } else {
    1.46 +    this.searchResult = nsIAutoCompleteResult.RESULT_NOMATCH;
    1.47 +    this.matchCount = 0;
    1.48 +    this._value = "";
    1.49 +  }
    1.50 +}
    1.51 +
    1.52 +nsAutoCompleteSimpleResult.prototype = {
    1.53 + _value: "",
    1.54 + searchString: null,
    1.55 + searchResult: nsIAutoCompleteResult.RESULT_FAILURE,
    1.56 + defaultIndex: 0,
    1.57 + errorDescription: null,
    1.58 + matchCount: 0,
    1.59 + getValueAt: function(aIndex) { return aIndex == 0 ? this._value : null; },
    1.60 + getCommentAt: function() { return null; },
    1.61 + getStyleAt: function() { return null; },
    1.62 + getImageAt: function() { return null; },
    1.63 + getFinalCompleteValueAt: function(aIndex) { return this.getValueAt(aIndex); },
    1.64 + getLabelAt: function() { return null; },
    1.65 + removeValueAt: function() {}
    1.66 +};
    1.67 +
    1.68 +// A basic autocomplete implementation that either returns one result or none
    1.69 +var autoCompleteSimpleID =
    1.70 +  Components.ID("0a2afbdb-f30e-47d1-9cb1-0cd160240aca");
    1.71 +var autoCompleteSimpleName =
    1.72 +  "@mozilla.org/autocomplete/search;1?name=simpleForComposition"
    1.73 +var autoCompleteSimple = {
    1.74 +  QueryInterface: function(iid) {
    1.75 +    if (iid.equals(Components.interfaces.nsISupports) ||
    1.76 +        iid.equals(Components.interfaces.nsIFactory) ||
    1.77 +        iid.equals(Components.interfaces.nsIAutoCompleteSearch))
    1.78 +      return this;
    1.79 +
    1.80 +    throw Components.results.NS_ERROR_NO_INTERFACE;
    1.81 +  },
    1.82 +
    1.83 +  createInstance: function(outer, iid) {
    1.84 +    return this.QueryInterface(iid);
    1.85 +  },
    1.86 +
    1.87 +  startSearch: function(aString, aParam, aResult, aListener) {
    1.88 +    var result = new nsAutoCompleteSimpleResult(aString);
    1.89 +    aListener.onSearchResult(this, result);
    1.90 +  },
    1.91 +
    1.92 +  stopSearch: function() {}
    1.93 +};
    1.94 +
    1.95 +var componentManager =
    1.96 +  Components.manager
    1.97 +            .QueryInterface(Components.interfaces.nsIComponentRegistrar);
    1.98 +componentManager.registerFactory(autoCompleteSimpleID,
    1.99 +                                 "Test Simple Autocomplete for composition",
   1.100 +                                 autoCompleteSimpleName, autoCompleteSimple);
   1.101 +
   1.102 +function runTests()
   1.103 +{
   1.104 +  var target = document.getElementById("textbox");
   1.105 +  target.setAttribute("timeout", 1);
   1.106 +  var test1 = new nsDoTestsForAutoCompleteWithComposition(
   1.107 +    "Testing on XUL textbox (asynchronously search)",
   1.108 +    window, target, target.controller, is,
   1.109 +    function () { return target.value; },
   1.110 +    function () {
   1.111 +      target.setAttribute("timeout", 0);
   1.112 +      var test2 = new nsDoTestsForAutoCompleteWithComposition(
   1.113 +        "Testing on XUL textbox (synchronously search)",
   1.114 +        window, target, target.controller, is,
   1.115 +        function () { return target.value; },
   1.116 +        function () {
   1.117 +          // Unregister the factory so that we don't get in the way of other
   1.118 +          // tests
   1.119 +          componentManager.unregisterFactory(autoCompleteSimpleID,
   1.120 +                                             autoCompleteSimple);
   1.121 +          SimpleTest.finish();
   1.122 +        });
   1.123 +    });
   1.124 +}
   1.125 +
   1.126 +SimpleTest.waitForFocus(runTests);
   1.127 +]]>
   1.128 +</script>
   1.129 +</window>

mercurial