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.

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

mercurial