Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | var gBasePath = "tests/dom/datastore/tests/"; |
michael@0 | 2 | |
michael@0 | 3 | function handleRequest(request, response) { |
michael@0 | 4 | var query = getQuery(request); |
michael@0 | 5 | |
michael@0 | 6 | var testToken = ''; |
michael@0 | 7 | if ('testToken' in query) { |
michael@0 | 8 | testToken = query.testToken; |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | var template = 'file_app.template.webapp'; |
michael@0 | 12 | if ('template' in query) { |
michael@0 | 13 | template = query.template; |
michael@0 | 14 | } |
michael@0 | 15 | var template = gBasePath + template; |
michael@0 | 16 | response.setHeader("Content-Type", "application/x-web-app-manifest+json", false); |
michael@0 | 17 | response.write(readTemplate(template).replace(/TESTTOKEN/g, testToken)); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | // Copy-pasted incantations. There ought to be a better way to synchronously read |
michael@0 | 21 | // a file into a string, but I guess we're trying to discourage that. |
michael@0 | 22 | function readTemplate(path) { |
michael@0 | 23 | var file = Components.classes["@mozilla.org/file/directory_service;1"]. |
michael@0 | 24 | getService(Components.interfaces.nsIProperties). |
michael@0 | 25 | get("CurWorkD", Components.interfaces.nsILocalFile); |
michael@0 | 26 | var fis = Components.classes['@mozilla.org/network/file-input-stream;1']. |
michael@0 | 27 | createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 28 | var cis = Components.classes["@mozilla.org/intl/converter-input-stream;1"]. |
michael@0 | 29 | createInstance(Components.interfaces.nsIConverterInputStream); |
michael@0 | 30 | var split = path.split("/"); |
michael@0 | 31 | for(var i = 0; i < split.length; ++i) { |
michael@0 | 32 | file.append(split[i]); |
michael@0 | 33 | } |
michael@0 | 34 | fis.init(file, -1, -1, false); |
michael@0 | 35 | cis.init(fis, "UTF-8", 0, 0); |
michael@0 | 36 | |
michael@0 | 37 | var data = ""; |
michael@0 | 38 | let (str = {}) { |
michael@0 | 39 | let read = 0; |
michael@0 | 40 | do { |
michael@0 | 41 | read = cis.readString(0xffffffff, str); // read as much as we can and put it in str.value |
michael@0 | 42 | data += str.value; |
michael@0 | 43 | } while (read != 0); |
michael@0 | 44 | } |
michael@0 | 45 | cis.close(); |
michael@0 | 46 | return data; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function getQuery(request) { |
michael@0 | 50 | var query = {}; |
michael@0 | 51 | request.queryString.split('&').forEach(function (val) { |
michael@0 | 52 | var [name, value] = val.split('='); |
michael@0 | 53 | query[name] = unescape(value); |
michael@0 | 54 | }); |
michael@0 | 55 | return query; |
michael@0 | 56 | } |