summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_options_disable_cache-03.js
blob: f3a53f64226ea0a560b5f79cebfb56b9c69675b4 (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
54
55
56
57
58
59
60
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that even when the cache is disabled, the inspector/styleeditor don't fetch again
// stylesheets from the server to display them in devtools, but use the cached version.

const TEST_CSS = URL_ROOT + "browser_toolbox_options_disable_cache.css.sjs";
const TEST_PAGE = `<html>
  <head>
    <meta charset="utf-8"/>
    <link href="${TEST_CSS}" rel="stylesheet" type="text/css"/>
  </head>
  <body></body>
</html>`;

add_task(async function () {
  info("Setup preferences for testing");
  // Disable rcwn to make cache behavior deterministic.
  await pushPref("network.http.rcwn.enabled", false);
  // Disable the cache.
  await pushPref("devtools.cache.disabled", true);

  info("Open inspector");
  const toolbox = await openNewTabAndToolbox(
    `data:text/html;charset=UTF-8,${encodeURIComponent(TEST_PAGE)}`,
    "inspector"
  );
  const inspector = toolbox.getPanel("inspector");

  info(
    "Check that the CSS content loaded in the page " +
      "and the one shown in the inspector are the same"
  );
  const webContent = await getWebContent();
  const inspectorContent = await getInspectorContent(inspector);
  is(
    webContent,
    inspectorContent,
    "The contents of both web and DevTools are same"
  );

  await closeTabAndToolbox();
});

async function getInspectorContent(inspector) {
  const ruleView = inspector.getPanel("ruleview").view;
  const valueEl = await waitFor(() =>
    ruleView.styleDocument.querySelector(".ruleview-propertyvalue")
  );
  return valueEl.textContent;
}

async function getWebContent() {
  return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
    const doc = content.document;
    return doc.ownerGlobal.getComputedStyle(doc.body, "::before").content;
  });
}