1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug528292.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +Cu.import("resource://testing-common/httpd.js"); 1.5 + 1.6 +const sentCookieVal = "foo=bar"; 1.7 +const responseBody = "response body"; 1.8 + 1.9 +XPCOMUtils.defineLazyGetter(this, "baseURL", function() { 1.10 + return "http://localhost:" + httpServer.identity.primaryPort; 1.11 +}); 1.12 + 1.13 +const preRedirectPath = "/528292/pre-redirect"; 1.14 + 1.15 +XPCOMUtils.defineLazyGetter(this, "preRedirectURL", function() { 1.16 + return baseURL + preRedirectPath; 1.17 +}); 1.18 + 1.19 +const postRedirectPath = "/528292/post-redirect"; 1.20 + 1.21 +XPCOMUtils.defineLazyGetter(this, "postRedirectURL", function() { 1.22 + return baseURL + postRedirectPath; 1.23 +}); 1.24 + 1.25 +var httpServer = null; 1.26 +var receivedCookieVal = null; 1.27 + 1.28 +function preRedirectHandler(metadata, response) 1.29 +{ 1.30 + response.setStatusLine(metadata.httpVersion, 302, "Found"); 1.31 + response.setHeader("Location", postRedirectURL, false); 1.32 + return; 1.33 +} 1.34 + 1.35 +function postRedirectHandler(metadata, response) 1.36 +{ 1.37 + receivedCookieVal = metadata.getHeader("Cookie"); 1.38 + response.setHeader("Content-Type", "text/plain"); 1.39 + response.bodyOutputStream.write(responseBody, responseBody.length); 1.40 +} 1.41 + 1.42 +function run_test() 1.43 +{ 1.44 + // Start the HTTP server. 1.45 + httpServer = new HttpServer(); 1.46 + httpServer.registerPathHandler(preRedirectPath, preRedirectHandler); 1.47 + httpServer.registerPathHandler(postRedirectPath, postRedirectHandler); 1.48 + httpServer.start(-1); 1.49 + 1.50 + // Disable third-party cookies in general. 1.51 + Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch). 1.52 + setIntPref("network.cookie.cookieBehavior", 1); 1.53 + 1.54 + var ioService = Cc["@mozilla.org/network/io-service;1"]. 1.55 + getService(Ci.nsIIOService); 1.56 + 1.57 + // Set up a channel with forceAllowThirdPartyCookie set to true. We'll use 1.58 + // the channel both to set a cookie (since nsICookieService::setCookieString 1.59 + // requires such a channel in order to successfully set a cookie) and then 1.60 + // to load the pre-redirect URI. 1.61 + var chan = ioService.newChannel(preRedirectURL, "", null). 1.62 + QueryInterface(Ci.nsIHttpChannel). 1.63 + QueryInterface(Ci.nsIHttpChannelInternal); 1.64 + chan.forceAllowThirdPartyCookie = true; 1.65 + 1.66 + // Set a cookie on one of the URIs. It doesn't matter which one, since 1.67 + // they're both from the same host, which is enough for the cookie service 1.68 + // to send the cookie with both requests. 1.69 + var postRedirectURI = ioService.newURI(postRedirectURL, "", null); 1.70 + Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService). 1.71 + setCookieString(postRedirectURI, null, sentCookieVal, chan); 1.72 + 1.73 + // Load the pre-redirect URI. 1.74 + chan.asyncOpen(new ChannelListener(finish_test, null), null); 1.75 + do_test_pending(); 1.76 +} 1.77 + 1.78 +function finish_test(event) 1.79 +{ 1.80 + do_check_eq(receivedCookieVal, sentCookieVal); 1.81 + httpServer.stop(do_test_finished); 1.82 +}