From 68e6266159178e1db4c082ba68399f524b4d0a0a Mon Sep 17 00:00:00 2001 From: Liang-Heng Chen Date: Thu, 27 Feb 2020 21:40:04 +0000 Subject: [PATCH] Bug 1614777 - Part 4: Test cases; r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D64379 --HG-- extra : moz-landing-system : lando --- .../test/browser/browser_searchTelemetry.js | 28 +++++++++++++++++++ .../tests/xpcshell/test_searchSuggest.js | 20 +++++++++++++ 2 files changed, 48 insertions(+) diff --git a/browser/components/search/test/browser/browser_searchTelemetry.js b/browser/components/search/test/browser/browser_searchTelemetry.js index 040ac69ca7a2..8e36fa398d58 100644 --- a/browser/components/search/test/browser/browser_searchTelemetry.js +++ b/browser/components/search/test/browser/browser_searchTelemetry.js @@ -144,6 +144,34 @@ add_task(async function test_simple_search_page_visit() { ); }); +add_task(async function test_simple_search_page_visit_telemetry() { + searchCounts.clear(); + Services.telemetry.clearScalars(); + + await BrowserTestUtils.withNewTab( + { + gBrowser, + /* URL must not be in the cache */ + url: getSERPUrl(getPageUrl(false, true)), + }, + async () => { + let scalars = {}; + const key = "browser.search.data_transferred"; + + await TestUtils.waitForCondition(() => { + scalars = + Services.telemetry.getSnapshotForKeyedScalars("main", false).parent || + {}; + return key in scalars; + }, "should have the expected keyed scalars"); + + const scalar = scalars[key]; + Assert.ok("example" in scalar, "correct telemetry category"); + Assert.notEqual(scalars[key].example, 0, "bandwidth logged"); + } + ); +}); + add_task(async function test_follow_on_visit() { await BrowserTestUtils.withNewTab( { diff --git a/toolkit/components/search/tests/xpcshell/test_searchSuggest.js b/toolkit/components/search/tests/xpcshell/test_searchSuggest.js index bcff660b6794..409a8b87824b 100644 --- a/toolkit/components/search/tests/xpcshell/test_searchSuggest.js +++ b/toolkit/components/search/tests/xpcshell/test_searchSuggest.js @@ -147,6 +147,26 @@ add_task(async function simple_remote_no_local_result() { Assert.equal(result.remote[2], "mom"); }); +add_task(async function simple_remote_no_local_result_telemetry() { + Services.telemetry.clearScalars(); + + let controller = new SearchSuggestionController(); + await controller.fetch("mo", false, getEngine); + + let scalars = {}; + const key = "browser.search.data_transferred"; + + await TestUtils.waitForCondition(() => { + scalars = + Services.telemetry.getSnapshotForKeyedScalars("main", false).parent || {}; + return key in scalars; + }, "should have the expected keyed scalars"); + + const scalar = scalars[key]; + Assert.ok("sggt-other" in scalar, "correct telemetry category"); + Assert.notEqual(scalar["sggt-other"], 0, "bandwidth logged"); +}); + add_task(async function simple_remote_no_local_result_alternative_type() { let controller = new SearchSuggestionController(); let result = await controller.fetch("mo", false, alternateJSONEngine);