Skip to content

Commit 7fe0f60

Browse files
committed
Bug 1783261 - Add telemetry events when opening the text recognition modal; r=nordzilla
This patch is just the event for opening the modal, plus the tests. Other telemetry will be in a following commit. Differential Revision: https://phabricator.services.mozilla.com/D154701
1 parent 466b1d2 commit 7fe0f60

File tree

5 files changed

+89
-10
lines changed

5 files changed

+89
-10
lines changed

browser/components/textrecognition/tests/browser/browser_textrecognition.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ add_task(async function() {
1010
set: [["dom.text-recognition.enabled", true]],
1111
});
1212

13+
clearTelemetry();
14+
1315
await BrowserTestUtils.withNewTab(URL_IMG, async function(browser) {
1416
setClipboardText("");
1517
is(getTextFromClipboard(), "", "The copied text is empty.");
18+
ok(
19+
!getTelemetryScalars()["browser.ui.interaction.content_context"],
20+
"No telemetry has been recorded yet."
21+
);
1622

1723
info("Right click image to show context menu.");
1824
let popupShownPromise = BrowserTestUtils.waitForEvent(
@@ -43,6 +49,17 @@ add_task(async function() {
4349
document.querySelector(".textRecognitionDialogFrame")
4450
);
4551

52+
{
53+
info("Check the scalar telemetry.");
54+
const scalars = await BrowserTestUtils.waitForCondition(() =>
55+
getTelemetryScalars()
56+
);
57+
const contentContext = scalars["browser.ui.interaction.content_context"];
58+
ok(contentContext, "Opening the context menu was recorded.");
59+
60+
is(contentContext["context-imagetext"], 1, "Telemetry has been recorded");
61+
}
62+
4663
info("Waiting for text results.");
4764
const resultsHeader = contentDocument.querySelector(
4865
"#text-recognition-header-results"
@@ -51,14 +68,16 @@ add_task(async function() {
5168
return resultsHeader.style.display !== "none";
5269
});
5370

54-
info("Checking the text results.");
55-
const text = contentDocument.querySelector(".textRecognitionText");
56-
is(text.children.length, 2, "Two piece of text were found");
57-
const [p1, p2] = text.children;
58-
is(p1.tagName, "P", "The children are paragraph tags.");
59-
is(p2.tagName, "P", "The children are paragraph tags.");
60-
is(p1.innerText, "Mozilla\n", "The first piece of text matches.");
61-
is(p2.innerText, "Firefox\n", "The second piece of text matches.");
71+
{
72+
info("Check the text results.");
73+
const text = contentDocument.querySelector(".textRecognitionText");
74+
is(text.children.length, 2, "Two piece of text were found");
75+
const [p1, p2] = text.children;
76+
is(p1.tagName, "P", "The children are paragraph tags.");
77+
is(p2.tagName, "P", "The children are paragraph tags.");
78+
is(p1.innerText, "Mozilla\n", "The first piece of text matches.");
79+
is(p2.innerText, "Firefox\n", "The second piece of text matches.");
80+
}
6281

6382
info("Close the dialog box.");
6483
const close = contentDocument.querySelector("#text-recognition-close");
@@ -75,5 +94,6 @@ add_task(async function() {
7594
() => !document.querySelector(".textRecognitionDialogFrame")
7695
);
7796
setClipboardText("");
97+
clearTelemetry();
7898
});
7999
});

browser/components/textrecognition/tests/browser/browser_textrecognition_no_result.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ add_task(async function() {
1010
set: [["dom.text-recognition.enabled", true]],
1111
});
1212

13+
clearTelemetry();
14+
1315
await BrowserTestUtils.withNewTab(url, async function(browser) {
1416
setClipboardText("");
1517
is(getTextFromClipboard(), "", "The copied text is empty.");
@@ -51,6 +53,17 @@ add_task(async function() {
5153
return noResultsHeader.style.display !== "none";
5254
});
5355

56+
{
57+
info("Check the scalar telemetry.");
58+
const scalars = await BrowserTestUtils.waitForCondition(() =>
59+
getTelemetryScalars()
60+
);
61+
const contentContext = scalars["browser.ui.interaction.content_context"];
62+
ok(contentContext, "Opening the context menu was recorded.");
63+
64+
is(contentContext["context-imagetext"], 1, "Telemetry has been recorded");
65+
}
66+
5467
const text = contentDocument.querySelector(".textRecognitionText");
5568
is(text.children.length, 0, "No results are listed.");
5669

@@ -65,4 +78,6 @@ add_task(async function() {
6578

6679
is(getTextFromClipboard(), "", "The copied text is still empty.");
6780
});
81+
82+
clearTelemetry();
6883
});

browser/components/textrecognition/tests/browser/head.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,23 @@ function getTextFromClipboard() {
2626
transferable.getTransferData("text/unicode", results);
2727
return results.value.QueryInterface(Ci.nsISupportsString)?.data ?? "";
2828
}
29+
30+
/**
31+
* Returns events specifically for text recognition.
32+
*/
33+
function getTelemetryScalars() {
34+
const snapshot = Services.telemetry.getSnapshotForKeyedScalars(
35+
"main",
36+
true /* clear events */
37+
);
38+
39+
if (!snapshot.parent) {
40+
return {};
41+
}
42+
43+
return snapshot.parent;
44+
}
45+
46+
function clearTelemetry() {
47+
Services.telemetry.clearScalars();
48+
}

browser/components/textrecognition/textrecognition.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ class TextRecognitionModal {
5656
},
5757
error => {
5858
// There was an error in the text recognition call. Treat this as the same
59-
// as if there were no results, but report the error to the console.
60-
console.error(error);
59+
// as if there were no results, but report the error to the console and telemetry.
6160
this.showHeaderByID("text-recognition-header-no-results");
61+
62+
console.error(
63+
"There was an error recognizing the text from an image.",
64+
error
65+
);
66+
Services.telemetry.scalarAdd(
67+
"browser.ui.interaction.textrecognition_error",
68+
1
69+
);
6270
}
6371
);
6472
}

toolkit/components/telemetry/Scalars.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,22 @@ browser.ui.interaction:
11531153
record_in_processes:
11541154
- 'main'
11551155

1156+
textrecognition_error:
1157+
bug_numbers:
1158+
- 1783261
1159+
description: >
1160+
Recorded when text recognition in images fails for some unknown reason.
1161+
notification_emails:
1162+
- gtatum@mozilla.com
1163+
- nordzilla@mozilla.com
1164+
expires: never
1165+
kind: uint
1166+
release_channel_collection: opt-out
1167+
products:
1168+
- 'firefox'
1169+
record_in_processes:
1170+
- 'main'
1171+
11561172
gecko:
11571173
version:
11581174
bug_numbers:

0 commit comments

Comments
 (0)