1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/robocop_suggestions.sjs Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +/** 1.5 + * Used with testSearchSuggestions. 1.6 + * Returns a set of pre-defined suggestions for given prefixes. 1.7 + */ 1.8 + 1.9 +function handleRequest(request, response) { 1.10 + let query = request.queryString.match(/^query=(.*)$/)[1]; 1.11 + query = decodeURIComponent(query).replace(/\+/g, " "); 1.12 + 1.13 + let suggestMap = { 1.14 + "f": ["facebook", "fandango", "frys", "forever 21", "fafsa"], 1.15 + "fo": ["forever 21", "food network", "fox news", "foothill college", "fox"], 1.16 + "foo": ["food network", "foothill college", "foot locker", "footloose", "foo fighters"], 1.17 + "foo ": ["foo fighters", "foo bar", "foo bat", "foo bay"], 1.18 + "foo b": ["foo bar", "foo bat", "foo bay"], 1.19 + "foo ba": ["foo bar", "foo bat", "foo bay"], 1.20 + "foo bar": ["foo bar"] 1.21 + }; 1.22 + 1.23 + let suggestions = suggestMap[query]; 1.24 + if (!suggestions) 1.25 + suggestions = []; 1.26 + suggestions = [query, suggestions]; 1.27 + 1.28 + /* 1.29 + * Sample result: 1.30 + * ["foo",["food network","foothill college","foot locker",...]] 1.31 + */ 1.32 + response.setHeader("Content-Type", "text/json", false); 1.33 + response.setHeader("Cache-Control", "no-cache", false); 1.34 + response.write(JSON.stringify(suggestions)); 1.35 +}