xpfe/components/autocomplete/test/autocomplete_test.xul
author Jason Evans <jasone@canonware.com>
Fri, 20 Jun 2008 10:29:43 -0700
changeset 15456 38972d94e6312cca26dc09bb1d8ac4a9bec84b1c
parent 1 9b2a99adc05e53cd4010de512f50118594756650
permissions -rw-r--r--
Bug 431743: Upstream jemalloc fixes, r=benjamin Incorporate upstream jemalloc fixes from FreeBSD: * Detect overflow for huge allocations via sbrk(2). * Fix deadlock for base (internal) allocations in OOM case. * Fix bitmap vector initialization for small allocation runs.

<?xml-stylesheet href="chrome://messenger/skin/messenger.css" type="text/css"?> 

<?xul-overlay href="chrome://global/content/globalOverlay.xul"?>
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>

                   
<window id="actest"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        xmlns:nc="http://home.netscape.com/NC-rdf#"
    		orient="vertical"
        width="750"
        height="500"
        onload="Initialize();"
        >
        
<script type="application/x-javascript">

var AutoCompleteSession = {
    onStartLookup: function(value, prevResult, listener)
    {
        dump("Search Session: onStartLookup\n");

        var results = Components.classes["@mozilla.org/autocomplete/results;1"].createInstance();
        results = results.QueryInterface(Components.interfaces.nsIAutoCompleteResults);
        results.searchString = value;
        results.defaultItemIndex = 0;
        results.param = null;

        var item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
        item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
        item.value = "Jean-Francois Ducarroz";
        item.comment = "[put your comment here]";
        item.className = "";
        item.param = null;
        
        results.items.AppendElement(item);
        listener.onAutoComplete(results, Components.interfaces.nsIAutoCompleteStatus.matchFound);
    },

    onStopLookup: function()
    {
        dump("Search Session: onStopLookup\n");
    },

    onAutoComplete: function(value, prevResult, listener)
    {
        dump("Search Session: onAutoComplete, value =" + value + "\n");
        
        var results = Components.classes["@mozilla.org/autocomplete/results;1"].createInstance();
        results = results.QueryInterface(Components.interfaces.nsIAutoCompleteResults);
        results.searchString = value;
        results.defaultItemIndex = 0;
        results.param = null;
        
        var item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
        item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
        item.value = value + "@mozilla.org";
        item.comment = "[put your comment here]";
        item.className = "";
        item.param = null;
        
        results.items.AppendElement(item);

        item = Components.classes["@mozilla.org/autocomplete/item;1"].createInstance();
        item = item.QueryInterface(Components.interfaces.nsIAutoCompleteItem);
        item.value = value + "@netscape.com";
        item.comment = "[put your comment here]";
        item.className = "";
        item.param = null;

        results.items.AppendElement(item);

        listener.onAutoComplete(results, Components.interfaces.nsIAutoCompleteStatus.matchFound);
    }
};

function function1()
{
    var myAutoComplete = document.getElementById("test");
    value = myAutoComplete.value;
    match = "Jean-Francois Ducarroz";
    
    lmatch = match.toLowerCase();
    lvalue = value.toLowerCase();

    dump("value = " + lvalue + ", match = " + lmatch + "\n");
    
    if (lvalue == lmatch)
        dump("exact match\n");
    else
    {
        dump("substring = " + lmatch.substring(0, lvalue.length) + "\n");
        if (lmatch.substring(0, lvalue.length) == lvalue)
        {
            dump("Ok, we can merge\n");
            myAutoComplete.value = value + match.substring(value.length, match.length);
//            myAutoComplete.anonymousContent[0].firstChild.anonymousContent[0].firstChild.setSelectionRange(value.length, match.length);
        }
        else
       {
            dump("oops, no match!\n");
            myAutoComplete.value = value + " " + match;
       }
    }
    
}

function Initialize()
{
    dump("Initialize!!\n");

    var myAutoComplete = document.getElementById("test");
    dump("myAutoComplete = " + myAutoComplete + ", session = " + myAutoComplete.mSessions + "\n");
    myAutoComplete.autoCompleteSession = AutoCompleteSession;

    var secondAutoComplete = document.getElementById("test2");
    abSession = secondAutoComplete.mSessions['addrbook'].QueryInterface(Components.interfaces.nsIAbAutoCompleteSession);
    abSession.defaultDomain = "mozilla.org";

    var thirdAutoComplete = document.getElementById("test3");
    var abSession3 = thirdAutoComplete.mSessions['ldap'].QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
    dump("\nthirdAutoComplete = " + thirdAutoComplete + "\n");
    dump("thirdAutoComplete.mSessions['ldap'] = " +
         thirdAutoComplete.mSessions['ldap'] + "\n");
    dump("abSession3 = " + abSession3 + "\n");

    var serverURL = Components.classes["@mozilla.org/network/ldap-url;1"].
                    createInstance().QueryInterface(                                               Components.interfaces.nsILDAPURL);

    //serverURL.spec = "ldap://ldap.bigfoot.com:389/??one?";
    serverURL.spec = "ldap://nsdirectory.netscape.com/ou=People," +
                     "dc=netscape,dc=com??one";

    abSession3.serverURL = serverURL;
    abSession3.filterTemplate = "sn=";
    abSession3.outputFormat = "cn &lt;mail&gt;";
    abSession3.sizeLimit = 10;

    var fourthAutoComplete = document.getElementById("test3");
    var abSession4 = fourthAutoComplete.mSessions['ldap'].QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
    dump("\nfourthAutoComplete = " + fourthAutoComplete + "\n");
    dump("fourthAutoComplete.mSessions['ldap'] = " +
         fourthAutoComplete.mSessions['ldap'] + "\n");
    dump("abSession4 = " + abSession4 + "\n");

    var serverURL4 = Components.classes["@mozilla.org/network/ldap-url;1"].
                    createInstance().QueryInterface(                                               Components.interfaces.nsILDAPURL);

    //serverURL4.spec = "ldap://ldap.bigfoot.com:389/??one?";
    serverURL4.spec = "ldap://nsdirectory.netscape.com/ou=People," +
                      "dc=netscape,dc=com??one";

    abSession3.serverURL = serverURL4;
    abSession3.filterTemplate = "sn=";
    abSession3.outputFormat = "cn &lt;mail&gt;";
    abSession3.sizeLimit = 10;

}

</script>

<html>Inline JS:</html>
<textbox id="test" timeout="300" type="autocomplete" />

<html>addrbook:</html>
<textbox id="test2" 
    type="autocomplete"
    searchSessions="addrbook"
    timeout="300"
    onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
/>

<html>ldap:</html>
<textbox id="test3"
    type="autocomplete"
    searchSessions="ldap"
    timeout="300"
    onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
/>

<html>composite (addrbook, ldap):</html>
<textbox id="test3"
    type="autocomplete"
    searchSessions="addrbook ldap"
    timeout="300"
    onkeypress="if (event.keyCode == 13) dump('Done, value=' + this.value + '\n');"
/>

</window>