summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/browser/browser_compatibility_cssIssues.js
blob: 7da37bc502dc5708ff9e099ffbcfe914049e26b2 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check the output of getNodeCssIssues

const { COMPATIBILITY_ISSUE_TYPE } = require("devtools/shared/constants");
const URL = MAIN_DOMAIN + "doc_compatibility.html";

const CHROME_81 = {
  id: "chrome",
  version: "81",
};

const CHROME_ANDROID = {
  id: "chrome_android",
  version: "81",
};

const EDGE_81 = {
  id: "edge",
  version: "81",
};

const FIREFOX_1 = {
  id: "firefox",
  version: "1",
};

const FIREFOX_60 = {
  id: "firefox",
  version: "60",
};

const FIREFOX_69 = {
  id: "firefox",
  version: "69",
};

const FIREFOX_MOBILE = {
  id: "firefox_android",
  version: "68",
};

const SAFARI_13 = {
  id: "safari",
  version: "13",
};

const SAFARI_MOBILE = {
  id: "safari_ios",
  version: "13.4",
};

const TARGET_BROWSERS = [
  FIREFOX_1,
  FIREFOX_60,
  FIREFOX_69,
  FIREFOX_MOBILE,
  CHROME_81,
  CHROME_ANDROID,
  SAFARI_13,
  SAFARI_MOBILE,
  EDGE_81,
];

const ISSUE_USER_SELECT = {
  type: COMPATIBILITY_ISSUE_TYPE.CSS_PROPERTY_ALIASES,
  property: "user-select",
  aliases: ["-moz-user-select"],
  url: "https://developer.mozilla.org/docs/Web/CSS/user-select",
  deprecated: false,
  experimental: false,
  prefixNeeded: true,
  unsupportedBrowsers: [
    CHROME_81,
    CHROME_ANDROID,
    SAFARI_13,
    SAFARI_MOBILE,
    EDGE_81,
  ],
};

const ISSUE_CLIP = {
  type: COMPATIBILITY_ISSUE_TYPE.CSS_PROPERTY,
  property: "clip",
  url: "https://developer.mozilla.org/docs/Web/CSS/clip",
  deprecated: true,
  experimental: false,
  unsupportedBrowsers: [],
};

async function testNodeCssIssues(selector, walker, compatibility, expected) {
  const node = await walker.querySelector(walker.rootNode, selector);
  const cssCompatibilityIssues = await compatibility.getNodeCssIssues(
    node,
    TARGET_BROWSERS
  );
  info("Ensure result is correct");
  Assert.deepEqual(
    cssCompatibilityIssues,
    expected,
    "Expected CSS browser compat data is correct."
  );
}

add_task(async function() {
  const { inspector, walker, target } = await initInspectorFront(URL);
  const compatibility = await inspector.getCompatibilityFront();

  info('Test CSS properties linked with the "div" tag');
  await testNodeCssIssues("div", walker, compatibility, []);

  info('Test CSS properties linked with class "class-user-select"');
  await testNodeCssIssues(".class-user-select", walker, compatibility, [
    ISSUE_USER_SELECT,
  ]);

  info("Test CSS properties linked with multiple classes and id");
  await testNodeCssIssues(
    "div#id-clip.class-clip.class-user-select",
    walker,
    compatibility,
    [ISSUE_CLIP, ISSUE_USER_SELECT]
  );

  info("Repeated incompatible CSS rule should be only reported once");
  await testNodeCssIssues(".duplicate", walker, compatibility, [ISSUE_CLIP]);

  await target.destroy();
  gBrowser.removeCurrentTab();
});