Bug 1535479 - Have Report Site Issue detect the FastClick JS library; r=aswan

Have Report Site Issue detect the FastClick JS library

Differential Revision: https://phabricator.services.mozilla.com/D23607

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Wisniewski 2019-03-18 23:44:51 +00:00
Родитель 16874aaaff
Коммит 3e39030d2f
7 изменённых файлов: 144 добавлений и 18 удалений

Просмотреть файл

@ -41,6 +41,32 @@ async function checkEndpointPref() {
}
}
function hasFastClickPageScript() {
const win = window.wrappedJSObject;
if (win.FastClick) {
return true;
}
for (const property in win) {
try {
const proto = win[property].prototype;
if (proto && proto.needsClick) {
return true;
}
} catch (_) {
}
}
return false;
}
function checkForFastClick(tabId) {
return browser.tabs.executeScript(tabId, {
code: `${hasFastClickPageScript};hasFastClickPageScript()`,
}).then(([hasFastClick]) => hasFastClick).catch(() => false);
}
function getWebCompatInfoForTab(tab) {
const {id, url} = tab;
return Promise.all([
@ -50,12 +76,13 @@ function getWebCompatInfoForTab(tab) {
browser.browserInfo.getUpdateChannel(),
browser.browserInfo.hasTouchScreen(),
browser.tabExtras.getWebcompatInfo(id),
checkForFastClick(id),
browser.tabs.captureTab(id, Config.screenshotFormat).catch(e => {
console.error("WebCompat Reporter: getting a screenshot failed", e);
return Promise.resolve(undefined);
}),
]).then(([blockList, buildID, graphicsPrefs, channel, hasTouchScreen,
frameInfo, screenshot]) => {
frameInfo, hasFastClick, screenshot]) => {
if (channel !== "linux") {
delete graphicsPrefs["layers.acceleration.force-enabled"];
}
@ -70,6 +97,7 @@ function getWebCompatInfoForTab(tab) {
buildID,
channel,
consoleLog,
hasFastClick,
hasTouchScreen,
"mixed active content blocked": frameInfo.hasMixedActiveContentBlocked,
"mixed passive content blocked": frameInfo.hasMixedDisplayContentBlocked,
@ -104,6 +132,11 @@ async function openWebCompatTab(compatInfo) {
details,
label: [],
};
if (details.hasFastClick) {
params.label.push("type-fastclick");
} else {
delete details.hasFastClick;
}
if (details["gfx.webrender.all"] || details["gfx.webrender.enabled"]) {
params.label.push("type-webrender-enabled");
}

Просмотреть файл

@ -1,5 +1,7 @@
[DEFAULT]
support-files =
fastclick1.html
fastclick2.html
head.js
test.html
webcompat.html

Просмотреть файл

@ -1,20 +1,6 @@
"use strict";
/* Test that clicking on the Report Site Issue button opens a new tab
and sends a postMessaged blob to it. */
add_task(async function test_opened_page() {
requestLongerTimeout(2);
const serverLanding = await startIssueServer();
// ./head.js sets the value for PREF_WC_REPORTER_ENDPOINT
await SpecialPowers.pushPrefEnv({set: [
[PREF_WC_REPORTER_ENABLED, true],
[PREF_WC_REPORTER_ENDPOINT, serverLanding],
]});
let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
async function clickToReportAndAwaitReportTabLoad() {
await openPageActions();
await isPanelItemEnabled();
@ -28,8 +14,28 @@ add_task(async function test_opened_page() {
}, {once: true});
});
document.getElementById(WC_PAGE_ACTION_PANEL_ID).click();
let tab2 = await newTabPromise;
const tab = await newTabPromise;
await screenshotPromise;
return tab;
}
add_task(async function start_issue_server() {
requestLongerTimeout(2);
const serverLanding = await startIssueServer();
// ./head.js sets the value for PREF_WC_REPORTER_ENDPOINT
await SpecialPowers.pushPrefEnv({set: [
[PREF_WC_REPORTER_ENABLED, true],
[PREF_WC_REPORTER_ENDPOINT, serverLanding],
]});
});
/* Test that clicking on the Report Site Issue button opens a new tab
and sends a postMessaged blob to it. */
add_task(async function test_opened_page() {
let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_PAGE);
let tab2 = await clickToReportAndAwaitReportTabLoad();
await ContentTask.spawn(tab2.linkedBrowser, {TEST_PAGE}, async function(args) {
async function isGreen(dataUrl) {
@ -67,6 +73,7 @@ add_task(async function test_opened_page() {
ok(typeof details.buildID == "string", "Details has a buildID string.");
ok(typeof details.channel == "string", "Details has a channel string.");
ok(typeof details.hasTouchScreen == "boolean", "Details has a hasTouchScreen flag.");
ok(typeof details.hasFastClick == "undefined", "Details does not have FastClick if not found.");
ok(typeof details["mixed active content blocked"] == "boolean", "Details has a mixed active content blocked flag.");
ok(typeof details["mixed passive content blocked"] == "boolean", "Details has a mixed passive content blocked flag.");
ok(typeof details["tracking content blocked"] == "string", "Details has a tracking content blocked string.");
@ -85,3 +92,35 @@ add_task(async function test_opened_page() {
BrowserTestUtils.removeTab(tab2);
BrowserTestUtils.removeTab(tab1);
});
add_task(async function test_fastclick_detection1() {
let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, FASTCLICK_TEST_PAGE1);
let tab2 = await clickToReportAndAwaitReportTabLoad();
await ContentTask.spawn(tab2.linkedBrowser, {}, async function(args) {
let doc = content.document;
let detailsParam = doc.getElementById("details").innerText;
const details = JSON.parse(detailsParam);
ok(typeof details == "object", "Details param is a stringified JSON object.");
is(details.hasFastClick, true, "FastClick was found.");
});
BrowserTestUtils.removeTab(tab2);
BrowserTestUtils.removeTab(tab1);
});
add_task(async function test_fastclick_detection2() {
let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, FASTCLICK_TEST_PAGE2);
let tab2 = await clickToReportAndAwaitReportTabLoad();
await ContentTask.spawn(tab2.linkedBrowser, {}, async function(args) {
let doc = content.document;
let detailsParam = doc.getElementById("details").innerText;
const details = JSON.parse(detailsParam);
ok(typeof details == "object", "Details param is a stringified JSON object.");
is(details.hasFastClick, true, "FastClick was found.");
});
BrowserTestUtils.removeTab(tab2);
BrowserTestUtils.removeTab(tab1);
});

Просмотреть файл

@ -0,0 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
"use strict";
function FastClick() {}
</script>

Просмотреть файл

@ -0,0 +1,11 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
"use strict";
function ObscuredFastClick() {
}
ObscuredFastClick.prototype = {
needsClick: () => {},
};
window.someRandomVar = new ObscuredFastClick();
</script>

Просмотреть файл

@ -10,6 +10,8 @@ const PREF_WC_REPORTER_ENDPOINT = "extensions.webcompat-reporter.newIssueEndpoin
const TEST_ROOT = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
const TEST_PAGE = TEST_ROOT + "test.html";
const FASTCLICK_TEST_PAGE1 = TEST_ROOT + "fastclick1.html";
const FASTCLICK_TEST_PAGE2 = TEST_ROOT + "fastclick2.html";
const NEW_ISSUE_PAGE = TEST_ROOT + "webcompat.html";
const WC_ADDON_ID = "webcompat-reporter@mozilla.org";

Просмотреть файл

@ -109,6 +109,32 @@ async function checkEndpointPref() {
}
}
function hasFastClickPageScript() {
const win = window.wrappedJSObject;
if (win.FastClick) {
return true;
}
for (const property in win) {
try {
const proto = win[property].prototype;
if (proto && proto.needsClick) {
return true;
}
} catch (_) {
}
}
return false;
}
function checkForFastClick(tabId) {
return browser.tabs.executeScript(tabId, {
code: `${hasFastClickPageScript};hasFastClickPageScript()`,
}).then(([hasFastClick]) => hasFastClick).catch(() => false);
}
function getWebCompatInfoForTab(tab) {
const {id, windiwId, url} = tab;
return Promise.all([
@ -118,12 +144,13 @@ function getWebCompatInfoForTab(tab) {
browser.browserInfo.getUpdateChannel(),
browser.browserInfo.hasTouchScreen(),
browser.tabExtras.getWebcompatInfo(id),
checkForFastClick(id),
browser.tabs.captureVisibleTab(windiwId, Config.screenshotFormat).catch(e => {
console.error("Report Site Issue: getting a screenshot failed", e);
return Promise.resolve(undefined);
}),
]).then(([blockList, buildID, graphicsPrefs, channel, hasTouchScreen,
frameInfo, screenshot]) => {
frameInfo, hasFastClick, screenshot]) => {
if (channel !== "linux") {
delete graphicsPrefs["layers.acceleration.force-enabled"];
}
@ -138,6 +165,7 @@ function getWebCompatInfoForTab(tab) {
buildID,
channel,
consoleLog,
hasFastClick,
hasTouchScreen,
"mixed active content blocked": frameInfo.hasMixedActiveContentBlocked,
"mixed passive content blocked": frameInfo.hasMixedDisplayContentBlocked,
@ -166,6 +194,11 @@ async function openWebCompatTab(compatInfo, usePrivateTab) {
details,
label: [],
};
if (details.hasFastClick) {
params.label.push("type-fastclick");
} else {
delete details.hasFastClick;
}
if (details["gfx.webrender.all"] || details["gfx.webrender.enabled"]) {
params.label.push("type-webrender-enabled");
}