From 3e39030d2f85cd62a410374eb5ca5580812afcbd Mon Sep 17 00:00:00 2001 From: Thomas Wisniewski Date: Mon, 18 Mar 2019 23:44:51 +0000 Subject: [PATCH] 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 --- .../webcompat-reporter/background.js | 35 ++++++++- .../test/browser/browser.ini | 2 + .../test/browser/browser_report_site_issue.js | 71 ++++++++++++++----- .../test/browser/fastclick1.html | 6 ++ .../test/browser/fastclick2.html | 11 +++ .../webcompat-reporter/test/browser/head.js | 2 + .../report-site-issue/background.js | 35 ++++++++- 7 files changed, 144 insertions(+), 18 deletions(-) create mode 100644 browser/extensions/webcompat-reporter/test/browser/fastclick1.html create mode 100644 browser/extensions/webcompat-reporter/test/browser/fastclick2.html diff --git a/browser/extensions/webcompat-reporter/background.js b/browser/extensions/webcompat-reporter/background.js index d529b39fbe40..490602b50557 100644 --- a/browser/extensions/webcompat-reporter/background.js +++ b/browser/extensions/webcompat-reporter/background.js @@ -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"); } diff --git a/browser/extensions/webcompat-reporter/test/browser/browser.ini b/browser/extensions/webcompat-reporter/test/browser/browser.ini index ce4656810c74..add8494d5dae 100644 --- a/browser/extensions/webcompat-reporter/test/browser/browser.ini +++ b/browser/extensions/webcompat-reporter/test/browser/browser.ini @@ -1,5 +1,7 @@ [DEFAULT] support-files = + fastclick1.html + fastclick2.html head.js test.html webcompat.html diff --git a/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js b/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js index 96834ea6f57b..a1f0495d872a 100644 --- a/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js +++ b/browser/extensions/webcompat-reporter/test/browser/browser_report_site_issue.js @@ -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); +}); diff --git a/browser/extensions/webcompat-reporter/test/browser/fastclick1.html b/browser/extensions/webcompat-reporter/test/browser/fastclick1.html new file mode 100644 index 000000000000..76d7c6ae2ffa --- /dev/null +++ b/browser/extensions/webcompat-reporter/test/browser/fastclick1.html @@ -0,0 +1,6 @@ + + + diff --git a/browser/extensions/webcompat-reporter/test/browser/fastclick2.html b/browser/extensions/webcompat-reporter/test/browser/fastclick2.html new file mode 100644 index 000000000000..e13329dfd78d --- /dev/null +++ b/browser/extensions/webcompat-reporter/test/browser/fastclick2.html @@ -0,0 +1,11 @@ + + + diff --git a/browser/extensions/webcompat-reporter/test/browser/head.js b/browser/extensions/webcompat-reporter/test/browser/head.js index 3600c5ab9fb7..eb9acfec1a13 100644 --- a/browser/extensions/webcompat-reporter/test/browser/head.js +++ b/browser/extensions/webcompat-reporter/test/browser/head.js @@ -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"; diff --git a/mobile/android/extensions/report-site-issue/background.js b/mobile/android/extensions/report-site-issue/background.js index 91eae84e97f4..fc852722b61d 100644 --- a/mobile/android/extensions/report-site-issue/background.js +++ b/mobile/android/extensions/report-site-issue/background.js @@ -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"); }