toolkit/components/thumbnails/test/thumbnails_update.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 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // This server-side script is used for browser_thumbnails_update. One of the
michael@0 5 // main things it must do in all cases is ensure a Cache-Control: no-store
michael@0 6 // header, so the foreground capture doesn't interfere with the testing.
michael@0 7
michael@0 8 // If the querystring is "simple", then all it does it return some content -
michael@0 9 // it doesn't really matter what that content is.
michael@0 10
michael@0 11 // Otherwise, its main role is that it must return different *content* for the
michael@0 12 // second request than it did for the first.
michael@0 13 // Also, it should be able to return an error response when requested for the
michael@0 14 // second response.
michael@0 15 // So the basic tests will be to grab the thumbnail, then request it to be
michael@0 16 // grabbed again:
michael@0 17 // * If the second request succeeded, the new thumbnail should exist.
michael@0 18 // * If the second request is an error, the new thumbnail should be ignored.
michael@0 19
michael@0 20 function handleRequest(aRequest, aResponse) {
michael@0 21 aResponse.setHeader("Content-Type", "text/html;charset=utf-8", false);
michael@0 22 // we want to disable gBrowserThumbnails on-load capture for these responses,
michael@0 23 // so set as a "no-store" response.
michael@0 24 aResponse.setHeader("Cache-Control", "no-store");
michael@0 25
michael@0 26 // for the simple test - just return some content.
michael@0 27 if (aRequest.queryString == "simple") {
michael@0 28 aResponse.write("<html><body></body></html>");
michael@0 29 aResponse.setStatusLine(aRequest.httpVersion, 200, "Its simply OK");
michael@0 30 return;
michael@0 31 }
michael@0 32
michael@0 33 // it's one of the more complex tests where the first request for the given
michael@0 34 // URL must return different content than the second, and possibly an error
michael@0 35 // response for the second
michael@0 36 let doneError = getState(aRequest.queryString);
michael@0 37 if (!doneError) {
michael@0 38 // first request - return a response with a green body and 200 response.
michael@0 39 aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's green");
michael@0 40 aResponse.write("<html><body bgcolor=00ff00></body></html>");
michael@0 41 // set the state so the next request does the "second request" thing below.
michael@0 42 setState(aRequest.queryString, "yep");
michael@0 43 } else {
michael@0 44 // second request - this will be done by the b/g service.
michael@0 45 // We always return a red background, but depending on the query string we
michael@0 46 // return either a 200 or 401 response.
michael@0 47 if (aRequest.queryString == "fail")
michael@0 48 aResponse.setStatusLine(aRequest.httpVersion, 401, "Oh no you don't");
michael@0 49 else
michael@0 50 aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's red");
michael@0 51 aResponse.write("<html><body bgcolor=ff0000></body></html>");
michael@0 52 // reset the error state incase this ends up being reused for the
michael@0 53 // same url and querystring.
michael@0 54 setState(aRequest.queryString, "");
michael@0 55 }
michael@0 56 }

mercurial