mobile/android/base/tests/robocop_suggestions.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /**
     2  * Used with testSearchSuggestions.
     3  * Returns a set of pre-defined suggestions for given prefixes.
     4  */
     6 function handleRequest(request, response) {
     7   let query = request.queryString.match(/^query=(.*)$/)[1];
     8   query = decodeURIComponent(query).replace(/\+/g, " ");
    10   let suggestMap = {
    11     "f":       ["facebook", "fandango", "frys", "forever 21", "fafsa"],
    12     "fo":      ["forever 21", "food network", "fox news", "foothill college", "fox"],
    13     "foo":     ["food network", "foothill college", "foot locker", "footloose", "foo fighters"],
    14     "foo ":    ["foo fighters", "foo bar", "foo bat", "foo bay"],
    15     "foo b":   ["foo bar", "foo bat", "foo bay"],
    16     "foo ba":  ["foo bar", "foo bat", "foo bay"],
    17     "foo bar": ["foo bar"]
    18   };
    20   let suggestions = suggestMap[query];
    21   if (!suggestions)
    22     suggestions = [];
    23   suggestions = [query, suggestions];
    25   /*
    26    * Sample result:
    27    * ["foo",["food network","foothill college","foot locker",...]]
    28    */
    29   response.setHeader("Content-Type", "text/json", false);
    30   response.setHeader("Cache-Control", "no-cache", false);
    31   response.write(JSON.stringify(suggestions));
    32 }

mercurial