summaryrefslogtreecommitdiffstats
path: root/browser/components/reportbrokensite/test/browser/send_more_info.js
blob: 6803403f63360dd5e14a086d6d75d0032ab8b92f (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* Helper methods for testing the "send more info" link
 * of the Report Broken Site feature.
 */

/* import-globals-from head.js */
/* import-globals-from send.js */

"use strict";

Services.scriptloader.loadSubScript(
  getRootDirectory(gTestPath) + "send.js",
  this
);

async function reformatExpectedWebCompatInfo(tab, overrides) {
  const gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
  const snapshot = await Troubleshoot.snapshot();
  const expected = await getExpectedWebCompatInfo(tab, snapshot, true);
  const { browserInfo, tabInfo } = expected;
  const { app, graphics, prefs, security } = browserInfo;
  const {
    applicationName,
    defaultUseragentString,
    fissionEnabled,
    osArchitecture,
    osName,
    osVersion,
    updateChannel,
    version,
  } = app;
  const { devicePixelRatio, hasTouchScreen } = graphics;
  const { antitracking, languages, useragentString } = tabInfo;

  const atOverrides = overrides.antitracking;
  const blockList = atOverrides?.blockList ?? antitracking.blockList;
  const hasMixedActiveContentBlocked =
    atOverrides?.hasMixedActiveContentBlocked ??
    antitracking.hasMixedActiveContentBlocked;
  const hasMixedDisplayContentBlocked =
    atOverrides?.hasMixedDisplayContentBlocked ??
    antitracking.hasMixedDisplayContentBlocked;
  const hasTrackingContentBlocked =
    atOverrides?.hasTrackingContentBlocked ??
    antitracking.hasTrackingContentBlocked;
  const isPrivateBrowsing =
    atOverrides?.isPrivateBrowsing ?? antitracking.isPrivateBrowsing;

  const extra_labels = [];
  const frameworks = overrides.frameworks ?? {
    fastclick: false,
    mobify: false,
    marfeel: false,
  };

  // ignore the console log unless explicily testing for it.
  const consoleLog = overrides.consoleLog ?? (() => true);

  const finalPrefs = {};
  for (const [key, pref] of Object.entries({
    cookieBehavior: "network.cookie.cookieBehavior",
    forcedAcceleratedLayers: "layers.acceleration.force-enabled",
    globalPrivacyControlEnabled: "privacy.globalprivacycontrol.enabled",
    installtriggerEnabled: "extensions.InstallTrigger.enabled",
    opaqueResponseBlocking: "browser.opaqueResponseBlocking",
    resistFingerprintingEnabled: "privacy.resistFingerprinting",
    softwareWebrender: "gfx.webrender.software",
  })) {
    if (key in prefs) {
      finalPrefs[pref] = prefs[key];
    }
  }

  const reformatted = {
    blockList,
    details: {
      additionalData: {
        applicationName,
        blockList,
        devicePixelRatio: parseInt(devicePixelRatio),
        finalUserAgent: useragentString,
        fissionEnabled,
        gfxData: {
          devices(actual) {
            const devices = getExpectedGraphicsDevices(snapshot);
            return compareGraphicsDevices(devices, actual);
          },
          drivers(actual) {
            const drvs = getExpectedGraphicsDrivers(snapshot);
            return compareGraphicsDrivers(drvs, actual);
          },
          features(actual) {
            const features = getExpectedGraphicsFeatures(snapshot);
            return areObjectsEqual(actual, features);
          },
          hasTouchScreen,
          monitors(actual) {
            // We don't care about monitor data on Android right now.
            if (AppConstants.platform === "android") {
              return actual == undefined;
            }
            return areObjectsEqual(actual, gfxInfo.getMonitors());
          },
        },
        hasMixedActiveContentBlocked,
        hasMixedDisplayContentBlocked,
        hasTrackingContentBlocked,
        isPB: isPrivateBrowsing,
        languages,
        osArchitecture,
        osName,
        osVersion,
        prefs: finalPrefs,
        updateChannel,
        userAgent: defaultUseragentString,
        version,
      },
      blockList,
      consoleLog,
      frameworks,
      hasTouchScreen,
      "gfx.webrender.software": prefs.softwareWebrender,
      "mixed active content blocked": hasMixedActiveContentBlocked,
      "mixed passive content blocked": hasMixedDisplayContentBlocked,
      "tracking content blocked": hasTrackingContentBlocked
        ? `true (${blockList})`
        : "false",
    },
    extra_labels,
    src: "desktop-reporter",
    utm_campaign: "report-broken-site",
    utm_source: "desktop-reporter",
  };

  // We only care about this pref on Linux right now on webcompat.com.
  if (AppConstants.platform != "linux") {
    delete finalPrefs["layers.acceleration.force-enabled"];
  } else {
    reformatted.details["layers.acceleration.force-enabled"] =
      finalPrefs["layers.acceleration.force-enabled"];
  }

  // Only bother adding the security key if it has any data
  if (Object.values(security).filter(e => e).length) {
    reformatted.details.additionalData.sec = security;
  }

  const expectedCodecs = snapshot.media.codecSupportInfo
    .replaceAll(" NONE", "")
    .split("\n")
    .sort()
    .join("\n");
  if (expectedCodecs) {
    reformatted.details.additionalData.gfxData.codecSupport = rawActual => {
      const actual = Object.entries(rawActual)
        .map(([name, { hardware, software }]) =>
          `${name} ${software ? "SW" : ""} ${hardware ? "HW" : ""}`.trim()
        )
        .sort()
        .join("\n");
      return areObjectsEqual(actual, expectedCodecs);
    };
  }

  if (blockList != "basic") {
    extra_labels.push(`type-tracking-protection-${blockList}`);
  }

  if (overrides.expectNoTabDetails) {
    delete reformatted.details.frameworks;
    delete reformatted.details.consoleLog;
    delete reformatted.details["mixed active content blocked"];
    delete reformatted.details["mixed passive content blocked"];
    delete reformatted.details["tracking content blocked"];
  } else {
    const { fastclick, mobify, marfeel } = frameworks;
    if (fastclick) {
      extra_labels.push("type-fastclick");
      reformatted.details.fastclick = true;
    }
    if (mobify) {
      extra_labels.push("type-mobify");
      reformatted.details.mobify = true;
    }
    if (marfeel) {
      extra_labels.push("type-marfeel");
      reformatted.details.marfeel = true;
    }
  }

  return reformatted;
}

async function testSendMoreInfo(tab, menu, expectedOverrides = {}) {
  const url = expectedOverrides.url ?? menu.win.gBrowser.currentURI.spec;
  const description = expectedOverrides.description ?? "";

  let rbs = await menu.openAndPrefillReportBrokenSite(url, description);

  const receivedData = await rbs.clickSendMoreInfo();
  const { message } = receivedData;

  const expected = await reformatExpectedWebCompatInfo(tab, expectedOverrides);
  expected.url = url;
  expected.description = description;

  ok(areObjectsEqual(message, expected), "ping matches expectations");

  // re-opening the panel, the url and description should be reset
  rbs = await menu.openReportBrokenSite();
  rbs.isMainViewResetToCurrentTab();
  rbs.close();
}