summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/changes/test/browser_changes_declaration_identical_rules.js
blob: 08ac6d173d0736225d25e95c525c2cd4b97e09b4 (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
61
62
63
64
65
66
67
68
69
70
71
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test tracking changes to CSS declarations in different stylesheets but in rules
// with identical selectors.

const TEST_URI = `
  <style type='text/css'>
    div {
      color: red;
    }
  </style>
  <style type='text/css'>
    div {
      font-size: 1em;
    }
  </style>
  <div></div>
`;

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, view: ruleView } = await openRuleView();
  const { document: doc, store } = selectChangesView(inspector);

  await selectNode("div", inspector);
  const prop1 = getTextProperty(ruleView, 1, { "font-size": "1em" });
  const prop2 = getTextProperty(ruleView, 2, { color: "red" });

  let onTrackChange;

  onTrackChange = waitForDispatch(store, "TRACK_CHANGE");
  info("Disable the declaration in the first rule");
  await togglePropStatus(ruleView, prop1);
  info("Wait for change to be tracked");
  await onTrackChange;

  onTrackChange = waitForDispatch(store, "TRACK_CHANGE");
  info("Disable the declaration in the second rule");
  await togglePropStatus(ruleView, prop2);
  info("Wait for change to be tracked");
  await onTrackChange;

  const removeDecl = getRemovedDeclarations(doc);
  is(removeDecl.length, 2, "Two declarations tracked as removed");
  // The last of the two matching rules shows up first in Rule view given that the
  // specificity is the same. This is correct. If the properties were the same, the latest
  // declaration would overwrite the first and thus show up on top.
  is(
    removeDecl[0].property,
    "font-size",
    "Correct property name for second declaration"
  );
  is(
    removeDecl[0].value,
    "1em",
    "Correct property value for second declaration"
  );
  is(
    removeDecl[1].property,
    "color",
    "Correct property name for first declaration"
  );
  is(
    removeDecl[1].value,
    "red",
    "Correct property value for first declaration"
  );
});