diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/about/browser_aboutHome_search_telemetry.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/about/browser_aboutHome_search_telemetry.js | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/browser/base/content/test/about/browser_aboutHome_search_telemetry.js b/browser/base/content/test/about/browser_aboutHome_search_telemetry.js new file mode 100644 index 0000000000..e23d07aa38 --- /dev/null +++ b/browser/base/content/test/about/browser_aboutHome_search_telemetry.js @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +ignoreAllUncaughtExceptions(); + +add_task(async function () { + info( + "Check that performing a search fires a search event and records to Telemetry." + ); + + await SpecialPowers.pushPrefEnv({ + set: [ + [ + "browser.newtabpage.activity-stream.improvesearch.handoffToAwesomebar", + false, + ], + ], + }); + + await BrowserTestUtils.withNewTab( + { gBrowser, url: "about:home" }, + async function (browser) { + let engine; + await promiseContentSearchChange(browser, async () => { + engine = await SearchTestUtils.promiseNewSearchEngine({ + url: getRootDirectory(gTestPath) + "searchSuggestionEngine.xml", + setAsDefault: true, + }); + return engine.name; + }); + + await SpecialPowers.spawn( + browser, + [{ expectedName: engine.name }], + async function (args) { + let engineName = + content.wrappedJSObject.gContentSearchController.defaultEngine.name; + is( + engineName, + args.expectedName, + "Engine name in DOM should match engine we just added" + ); + } + ); + + let numSearchesBefore = 0; + // Get the current number of recorded searches. + let histogramKey = `other-${engine.name}.abouthome`; + try { + let hs = Services.telemetry + .getKeyedHistogramById("SEARCH_COUNTS") + .snapshot(); + if (histogramKey in hs) { + numSearchesBefore = hs[histogramKey].sum; + } + } catch (ex) { + // No searches performed yet, not a problem, |numSearchesBefore| is 0. + } + + let searchStr = "a search"; + + let expectedURL = (await Services.search.getDefault()).getSubmission( + searchStr, + null, + "homepage" + ).uri.spec; + let promise = BrowserTestUtils.waitForDocLoadAndStopIt( + expectedURL, + browser + ); + + // Perform a search to increase the SEARCH_COUNT histogram. + await SpecialPowers.spawn( + browser, + [{ searchStr }], + async function (args) { + let doc = content.document; + info("Perform a search."); + let el = doc.querySelector(["#searchText", "#newtab-search-text"]); + el.value = args.searchStr; + doc.getElementById("searchSubmit").click(); + } + ); + + await promise; + + // Make sure the SEARCH_COUNTS histogram has the right key and count. + let hs = Services.telemetry + .getKeyedHistogramById("SEARCH_COUNTS") + .snapshot(); + Assert.ok(histogramKey in hs, "histogram with key should be recorded"); + Assert.equal( + hs[histogramKey].sum, + numSearchesBefore + 1, + "histogram sum should be incremented" + ); + } + ); + await SpecialPowers.popPrefEnv(); +}); |