summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_window_reload_target_force.js
blob: d563fb7d3741e9e37c53c62bf74d66bd1c8e3a3e (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Simple test page which writes the value of the cache-control header.
const TEST_URL = URL_ROOT + "sjs_cache_controle_header.sjs";

const L10N = new LocalizationHelper(
  "devtools/client/locales/toolbox.properties"
);

// Test that "forceReload" shorcuts send requests with the correct cache-control
// header value: no-cache.
add_task(async function () {
  await addTab(TEST_URL);
  const tab = gBrowser.selectedTab;

  info("Open the toolbox with the inspector selected");
  const toolbox = await gDevTools.showToolboxForTab(tab, {
    toolId: "inspector",
  });

  // The VALIDATE_ALWAYS flag isn’t going to be applied when we only revalidate
  // the top level document, thus the expectedHeader is empty.
  const expectedHeader = Services.prefs.getBoolPref(
    "browser.soft_reload.only_force_validate_top_level_document",
    false
  )
    ? ""
    : "max-age=0";
  await testReload("toolbox.reload.key", toolbox, expectedHeader);
  await testReload("toolbox.reload2.key", toolbox, expectedHeader);
  await testReload("toolbox.forceReload.key", toolbox, "no-cache");
  await testReload("toolbox.forceReload2.key", toolbox, "no-cache");
});

async function testReload(shortcut, toolbox, expectedHeader) {
  info(`Reload with ${shortcut}`);
  await sendToolboxReloadShortcut(L10N.getStr(shortcut), toolbox);

  info("Retrieve the text content of the test page");
  const textContent = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [],
    function () {
      return content.document.body.textContent;
    }
  );

  // See sjs_cache_controle_header.sjs
  is(
    textContent,
    "cache-control:" + expectedHeader,
    "cache-control header for the page request had the expected value"
  );
}