sjs_imported_stylesheet_edit.sjs (1623B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 "use strict"; 6 const INITIAL_CONTENT = ` 7 div { 8 color: red 9 } 10 `; 11 12 const UPDATED_CONTENT = ` 13 span { 14 color: green; 15 } 16 17 a { 18 color: blue; 19 } 20 21 div { 22 color: gold; 23 } 24 `; 25 26 /** 27 * This sjs file supports three endpoint: 28 * - "sjs_imported_stylesheet_edit.sjs" -> will return a text/css content which 29 * will be either INITIAL_CONTENT or UPDATED_CONTENT. Initially will return 30 * INITIAL_CONTENT. 31 * - "sjs_imported_stylesheet_edit.sjs?update-stylesheet" -> will update an 32 * internal flag. After calling this URL, the regular endpoint will return 33 * UPDATED_CONTENT instead of INITIAL_CONTENT 34 * - "sjs_imported_stylesheet_edit.sjs?setup" -> set the internal flag to its 35 * default value. Should be called at the beginning of every test to avoid 36 * side effects. 37 */ 38 function handleRequest(request, response) { 39 const { queryString } = request; 40 if (queryString === "setup") { 41 setState("serve-updated-content", "false"); 42 response.setHeader("Content-Type", "text/html"); 43 response.write("OK"); 44 } else if (queryString === "update-stylesheet") { 45 setState("serve-updated-content", "true"); 46 response.setHeader("Content-Type", "text/html"); 47 response.write("OK"); 48 } else { 49 response.setHeader("Content-Type", "text/css"); 50 const shouldServeUpdatedCSS = getState("serve-updated-content") == "true"; 51 response.write(shouldServeUpdatedCSS ? UPDATED_CONTENT : INITIAL_CONTENT); 52 } 53 }