michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // This server-side script is used for browser_thumbnails_update. One of the michael@0: // main things it must do in all cases is ensure a Cache-Control: no-store michael@0: // header, so the foreground capture doesn't interfere with the testing. michael@0: michael@0: // If the querystring is "simple", then all it does it return some content - michael@0: // it doesn't really matter what that content is. michael@0: michael@0: // Otherwise, its main role is that it must return different *content* for the michael@0: // second request than it did for the first. michael@0: // Also, it should be able to return an error response when requested for the michael@0: // second response. michael@0: // So the basic tests will be to grab the thumbnail, then request it to be michael@0: // grabbed again: michael@0: // * If the second request succeeded, the new thumbnail should exist. michael@0: // * If the second request is an error, the new thumbnail should be ignored. michael@0: michael@0: function handleRequest(aRequest, aResponse) { michael@0: aResponse.setHeader("Content-Type", "text/html;charset=utf-8", false); michael@0: // we want to disable gBrowserThumbnails on-load capture for these responses, michael@0: // so set as a "no-store" response. michael@0: aResponse.setHeader("Cache-Control", "no-store"); michael@0: michael@0: // for the simple test - just return some content. michael@0: if (aRequest.queryString == "simple") { michael@0: aResponse.write(""); michael@0: aResponse.setStatusLine(aRequest.httpVersion, 200, "Its simply OK"); michael@0: return; michael@0: } michael@0: michael@0: // it's one of the more complex tests where the first request for the given michael@0: // URL must return different content than the second, and possibly an error michael@0: // response for the second michael@0: let doneError = getState(aRequest.queryString); michael@0: if (!doneError) { michael@0: // first request - return a response with a green body and 200 response. michael@0: aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's green"); michael@0: aResponse.write(""); michael@0: // set the state so the next request does the "second request" thing below. michael@0: setState(aRequest.queryString, "yep"); michael@0: } else { michael@0: // second request - this will be done by the b/g service. michael@0: // We always return a red background, but depending on the query string we michael@0: // return either a 200 or 401 response. michael@0: if (aRequest.queryString == "fail") michael@0: aResponse.setStatusLine(aRequest.httpVersion, 401, "Oh no you don't"); michael@0: else michael@0: aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's red"); michael@0: aResponse.write(""); michael@0: // reset the error state incase this ends up being reused for the michael@0: // same url and querystring. michael@0: setState(aRequest.queryString, ""); michael@0: } michael@0: }