summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/sjs_imported_stylesheet_edit.sjs
blob: 5a68c5571c743866c26c78402427d2bbe7c7d6a3 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

"use strict";
const INITIAL_CONTENT = `
div {
  color: red
}
`;

const UPDATED_CONTENT = `
span {
  color: green;
}

a {
  color: blue;
}

div {
  color: gold;
}
`;

/**
 * This sjs file supports three endpoint:
 * - "sjs_imported_stylesheet_edit.sjs" -> will return a text/css content which
 *   will be either INITIAL_CONTENT or UPDATED_CONTENT. Initially will return
 *   INITIAL_CONTENT.
 * - "sjs_imported_stylesheet_edit.sjs?update-stylesheet" -> will update an
 *   internal flag. After calling this URL, the regular endpoint will return
 *   UPDATED_CONTENT instead of INITIAL_CONTENT
 * - "sjs_imported_stylesheet_edit.sjs?setup" -> set the internal flag to its
 *   default value. Should be called at the beginning of every test to avoid
 *   side effects.
 */
function handleRequest(request, response) {
  const { queryString } = request;
  if (queryString === "setup") {
    setState("serve-updated-content", "false");
    response.setHeader("Content-Type", "text/html");
    response.write("OK");
  } else if (queryString === "update-stylesheet") {
    setState("serve-updated-content", "true");
    response.setHeader("Content-Type", "text/html");
    response.write("OK");
  } else {
    response.setHeader("Content-Type", "text/css");
    const shouldServeUpdatedCSS = getState("serve-updated-content") == "true";
    response.write(shouldServeUpdatedCSS ? UPDATED_CONTENT : INITIAL_CONTENT);
  }
}