toolkit/components/thumbnails/test/thumbnails_update.sjs

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/thumbnails/test/thumbnails_update.sjs	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// This server-side script is used for browser_thumbnails_update.  One of the
     1.8 +// main things it must do in all cases is ensure a Cache-Control: no-store
     1.9 +// header, so the foreground capture doesn't interfere with the testing.
    1.10 +
    1.11 +// If the querystring is "simple", then all it does it return some content -
    1.12 +// it doesn't really matter what that content is.
    1.13 +
    1.14 +// Otherwise, its main role is that it must return different *content* for the
    1.15 +// second request than it did for the first.
    1.16 +// Also, it should be able to return an error response when requested for the
    1.17 +// second response.
    1.18 +// So the basic tests will be to grab the thumbnail, then request it to be
    1.19 +// grabbed again:
    1.20 +// * If the second request succeeded, the new thumbnail should exist.
    1.21 +// * If the second request is an error, the new thumbnail should be ignored.
    1.22 +
    1.23 +function handleRequest(aRequest, aResponse) {
    1.24 +  aResponse.setHeader("Content-Type", "text/html;charset=utf-8", false);
    1.25 +  // we want to disable gBrowserThumbnails on-load capture for these responses,
    1.26 +  // so set as a "no-store" response.
    1.27 +  aResponse.setHeader("Cache-Control", "no-store");
    1.28 +
    1.29 +  // for the simple test - just return some content.
    1.30 +  if (aRequest.queryString == "simple") {
    1.31 +    aResponse.write("<html><body></body></html>");
    1.32 +    aResponse.setStatusLine(aRequest.httpVersion, 200, "Its simply OK");
    1.33 +    return;
    1.34 +  }
    1.35 +
    1.36 +  // it's one of the more complex tests where the first request for the given
    1.37 +  // URL must return different content than the second, and possibly an error
    1.38 +  // response for the second
    1.39 +  let doneError = getState(aRequest.queryString);
    1.40 +  if (!doneError) {
    1.41 +    // first request - return a response with a green body and 200 response.
    1.42 +    aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's green");
    1.43 +    aResponse.write("<html><body bgcolor=00ff00></body></html>");
    1.44 +    // set the  state so the next request does the "second request" thing below.
    1.45 +    setState(aRequest.queryString, "yep");
    1.46 +  } else {
    1.47 +    // second request - this will be done by the b/g service.
    1.48 +    // We always return a red background, but depending on the query string we
    1.49 +    // return either a 200 or 401 response.
    1.50 +    if (aRequest.queryString == "fail")
    1.51 +      aResponse.setStatusLine(aRequest.httpVersion, 401, "Oh no you don't");
    1.52 +    else
    1.53 +      aResponse.setStatusLine(aRequest.httpVersion, 200, "OK - It's red");
    1.54 +    aResponse.write("<html><body bgcolor=ff0000></body></html>");
    1.55 +    // reset the error state incase this ends up being reused for the
    1.56 +    // same url and querystring.
    1.57 +    setState(aRequest.queryString, "");
    1.58 +  }
    1.59 +}

mercurial