addon-sdk/source/test/test-httpd.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const port = 8099;
michael@0 6 const file = require("sdk/io/file");
michael@0 7 const { pathFor } = require("sdk/system");
michael@0 8 const { Loader } = require("sdk/test/loader");
michael@0 9 const options = require("@test/options");
michael@0 10
michael@0 11 const loader = Loader(module);
michael@0 12 const httpd = loader.require("sdk/test/httpd");
michael@0 13 if (options.parseable || options.verbose)
michael@0 14 loader.sandbox("sdk/test/httpd").DEBUG = true;
michael@0 15
michael@0 16 exports.testBasicHTTPServer = function(assert, done) {
michael@0 17 // Use the profile directory for the temporary file as that will be deleted
michael@0 18 // when tests are complete
michael@0 19 let basePath = pathFor("ProfD");
michael@0 20 let filePath = file.join(basePath, 'test-httpd.txt');
michael@0 21 let content = "This is the HTTPD test file.\n";
michael@0 22 let fileStream = file.open(filePath, 'w');
michael@0 23 fileStream.write(content);
michael@0 24 fileStream.close();
michael@0 25
michael@0 26 let srv = httpd.startServerAsync(port, basePath);
michael@0 27
michael@0 28 // Request this very file.
michael@0 29 let Request = require('sdk/request').Request;
michael@0 30 Request({
michael@0 31 url: "http://localhost:" + port + "/test-httpd.txt",
michael@0 32 onComplete: function (response) {
michael@0 33 assert.equal(response.text, content);
michael@0 34 srv.stop(done);
michael@0 35 }
michael@0 36 }).get();
michael@0 37 };
michael@0 38
michael@0 39 exports.testDynamicServer = function (assert, done) {
michael@0 40 let content = "This is the HTTPD test file.\n";
michael@0 41
michael@0 42 let srv = httpd.startServerAsync(port);
michael@0 43
michael@0 44 // See documentation here:
michael@0 45 //http://doxygen.db48x.net/mozilla/html/interfacensIHttpServer.html#a81fc7e7e29d82aac5ce7d56d0bedfb3a
michael@0 46 //http://doxygen.db48x.net/mozilla/html/interfacensIHttpRequestHandler.html
michael@0 47 srv.registerPathHandler("/test-httpd.txt", function handle(request, response) {
michael@0 48 // Add text content type, only to avoid error in `Request` API
michael@0 49 response.setHeader("Content-Type", "text/plain", false);
michael@0 50 response.write(content);
michael@0 51 });
michael@0 52
michael@0 53 // Request this very file.
michael@0 54 let Request = require('sdk/request').Request;
michael@0 55 Request({
michael@0 56 url: "http://localhost:" + port + "/test-httpd.txt",
michael@0 57 onComplete: function (response) {
michael@0 58 assert.equal(response.text, content);
michael@0 59 srv.stop(done);
michael@0 60 }
michael@0 61 }).get();
michael@0 62 };
michael@0 63
michael@0 64 exports.testAutomaticPortSelection = function (assert, done) {
michael@0 65 const srv = httpd.startServerAsync(-1);
michael@0 66
michael@0 67 const port = srv.identity.primaryPort;
michael@0 68 assert.ok(0 <= port && port <= 65535);
michael@0 69
michael@0 70 srv.stop(done);
michael@0 71 };
michael@0 72
michael@0 73 require('sdk/test').run(exports);

mercurial