Bug 1566366 - Test Streaming Telemetry r=janerik

This test _can_ run on non-Android if we reconfigure GetCurrentProduct in
TelemetryCommon to not have an #ifdef for Android.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2019-08-01 14:20:35 +00:00
parent 51b6c6553e
commit 28f0161887
3 changed files with 73 additions and 0 deletions

View File

@ -8934,6 +8934,18 @@
"description": "a testing histogram; not meant to be touched",
"record_into_store": ["main", "sync"]
},
"TELEMETRY_TEST_STREAMING": {
"record_in_processes": ["main"],
"products": ["geckoview_streaming"],
"alert_emails": ["telemetry-client-dev@mozilla.com"],
"expires_in_version": "never",
"kind": "linear",
"low": 1,
"high": 2147483646,
"n_buckets": 10,
"bug_numbers": [1566366],
"description": "a testing histogram; not meant to be touched"
},
"STARTUP_CRASH_DETECTED": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec", "geckoview"],

View File

@ -0,0 +1,55 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "TelemetryFixture.h"
#include "streaming/GeckoViewStreamingTelemetry.h"
using namespace mozilla;
using namespace mozilla::Telemetry;
using namespace TelemetryTestHelpers;
using GeckoViewStreamingTelemetry::StreamingTelemetryDelegate;
using ::testing::_;
using ::testing::Eq;
namespace {
const char* kGeckoViewStreamingPref = "toolkit.telemetry.geckoview.streaming";
const char* kBatchTimeoutPref = "toolkit.telemetry.geckoview.batchDurationMS";
class MockDelegate final : public StreamingTelemetryDelegate {
public:
MOCK_METHOD2(ReceiveHistogramSamples,
void(const nsCString& aHistogramName,
const nsTArray<uint32_t>& aSamples));
}; // class MockDelegate
TEST_F(TelemetryTestFixture, StreamingTelemetryStreamsHistogramSamples) {
NS_NAMED_LITERAL_CSTRING(kTestHgramName, "TELEMETRY_TEST_STREAMING");
const uint32_t kSampleOne = 401;
const uint32_t kSampleTwo = 2019;
nsTArray<uint32_t> samplesArray;
samplesArray.AppendElement(kSampleOne);
samplesArray.AppendElement(kSampleTwo);
auto md = MakeRefPtr<MockDelegate>();
EXPECT_CALL(*md, ReceiveHistogramSamples(Eq(kTestHgramName),
Eq(std::move(samplesArray))));
GeckoViewStreamingTelemetry::RegisterDelegate(md);
Preferences::SetBool(kGeckoViewStreamingPref, true);
Preferences::SetInt(kBatchTimeoutPref, 5000);
Telemetry::Accumulate(Telemetry::TELEMETRY_TEST_STREAMING, kSampleOne);
Preferences::SetInt(kBatchTimeoutPref, 0);
Telemetry::Accumulate(Telemetry::TELEMETRY_TEST_STREAMING, kSampleTwo);
// Clear the delegate so when the batch is done being sent it can be deleted.
GeckoViewStreamingTelemetry::RegisterDelegate(nullptr);
}
} // namespace

View File

@ -20,6 +20,12 @@ UNIFIED_SOURCES = [
'TestGeckoView.cpp',
]
# GeckoView Streaming Telemetry is only available on Android.
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
UNIFIED_SOURCES += [
'TestGeckoViewStreaming.cpp',
]
# We need the following line otherwise including
# "TelemetryHistogram.h" in tests will fail due to
# missing headers.