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