summaryrefslogtreecommitdiffstats
path: root/browser/components/originattributes/test/browser/file_saveAs.sjs
blob: 6be46daa6a79c05aa2ddc8749b08fa15aec1795d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const HTTP_ORIGIN = "http://example.com";
const SECOND_ORIGIN = "http://example.org";
const URI_PATH = "/browser/browser/components/originattributes/test/browser/";
const LINK_PATH = `${URI_PATH}file_saveAs.sjs`;
// Reusing existing ogv file for testing.
const VIDEO_PATH = `${URI_PATH}file_thirdPartyChild.video.ogv`;
// Reusing existing png file for testing.
const IMAGE_PATH = `${URI_PATH}file_favicon.png`;
const FRAME_PATH = `${SECOND_ORIGIN}${URI_PATH}file_saveAs.sjs?image=1`;

Cu.importGlobalProperties(["URLSearchParams"]);

function handleRequest(aRequest, aResponse) {
  var params = new URLSearchParams(aRequest.queryString);
  aResponse.setStatusLine(aRequest.httpVersion, 200);
  aResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
  let contentBody = "";

  if (params.has("link")) {
    contentBody = `<a href="${LINK_PATH}" id="link1">this is a link</a>`;
  } else if (params.has("video")) {
    contentBody = `<video src="${VIDEO_PATH}" id="video1"> </video>`;
  } else if (params.has("image")) {
    contentBody = `<img src="${IMAGE_PATH}" id="image1">`;
  } else if (params.has("page")) {
    // We need at least one resource, like a img, a link or a script, to trigger
    // downloading resources in "Save Page As". Otherwise, it will output the
    // document directly without any network request.
    contentBody = `<img src="${IMAGE_PATH}">`;
  } else if (params.has("frame")) {
    // Like "Save Page As", we need to put at least one resource in the frame.
    // Here we also use a image.
    contentBody = `<iframe src="${FRAME_PATH}" id="frame1"></iframe>`;
  } else if (params.has("pageinfo")) {
    contentBody = `<img src="${IMAGE_PATH}" id="image1">
                   <video src="${VIDEO_PATH}" id="video1"> </video>`;
  }

  aResponse.write(`<html><body>${contentBody}</body></html>`);
}