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

"use strict";

/**
 * Check that the ruleview is still correctly displayed after reloading the page.
 * See Bug 1487284.
 */

// To trigger the initial issue, the stylesheet needs to be fetched from the network
// monitor, so we can not use a data:uri with inline styles here.
const TEST_URI = `${URL_ROOT}doc_toolbox_rule_view.html`;

addRDMTaskWithPreAndPost(
  TEST_URI,
  async function pre_task() {
    info("Open the rule-view and select the test node before opening RDM");
    const ruleViewValues = await openRuleView();
    const { inspector, view } = ruleViewValues;
    await selectNode("div", inspector);

    is(numberOfRules(view), 2, "Rule view has two rules.");

    return ruleViewValues;
  },
  async function task({ preTaskValue }) {
    const { inspector, view } = preTaskValue;

    info("Reload the current page");
    const onNewRoot = inspector.once("new-root");
    const onRuleViewRefreshed = inspector.once("rule-view-refreshed");
    await reloadBrowser();
    await onNewRoot;
    await inspector.markup._waitForChildren();
    await onRuleViewRefreshed;

    // Await two reflows of the Rule View window.
    await new Promise(resolve => {
      view.styleWindow.requestAnimationFrame(() => {
        view.styleWindow.requestAnimationFrame(resolve);
      });
    });

    is(
      numberOfRules(view),
      2,
      "Rule view still has two rules and is not empty."
    );
  },
  null
);

function numberOfRules(ruleView) {
  return ruleView.element.querySelectorAll(".ruleview-code").length;
}