bug 1440673 - Permit snapshotting non-parent-process scalars r?Dexter
MozReview-Commit-ID: CBjLy7uDEeb
--- a/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.cpp
@@ -1,16 +1,17 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#include "TelemetryTestHelpers.h"
#include "gtest/gtest.h"
#include "mozilla/CycleCollectedJSContext.h"
+#include "TelemetryCommon.h"
#include "mozilla/Unused.h"
using namespace mozilla;
// Helper methods provided to simplify writing tests and meant to be used in C++ Gtests.
namespace TelemetryTestHelpers {
void
@@ -93,17 +94,18 @@ CheckNumberOfProperties(const char* aNam
ASSERT_TRUE(JS_Enumerate(aCx, keyedScalarObj, &ids))
<< "We must be able to get keyed scalar members.";
ASSERT_EQ(expectedNumProperties, ids.length())
<< "The scalar must report the expected number of properties.";
}
void
-GetScalarsSnapshot(bool aKeyed, JSContext* aCx, JS::MutableHandle<JS::Value> aResult)
+GetScalarsSnapshot(bool aKeyed, JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
+ ProcessID aProcessType)
{
nsCOMPtr<nsITelemetry> telemetry = do_GetService("@mozilla.org/base/telemetry;1");
// Get a snapshot of the scalars.
JS::RootedValue scalarsSnapshot(aCx);
nsresult rv;
if (aKeyed) {
@@ -113,24 +115,26 @@ GetScalarsSnapshot(bool aKeyed, JSContex
rv = telemetry->SnapshotScalars(nsITelemetry::DATASET_RELEASE_CHANNEL_OPTIN,
false, aCx, 0, &scalarsSnapshot);
}
// Validate the snapshot.
ASSERT_EQ(rv, NS_OK) << "Creating a snapshot of the data must not fail.";
ASSERT_TRUE(scalarsSnapshot.isObject()) << "The snapshot must be an object.";
- // We currently only support scalars from the parent process in the gtests.
- JS::RootedValue parentScalars(aCx);
+ JS::RootedValue processScalars(aCx);
JS::RootedObject scalarObj(aCx, &scalarsSnapshot.toObject());
- // Don't complain if no scalars for the parent process can be found. Just
+ // Don't complain if no scalars for the process can be found. Just
// return an empty object.
- Unused << JS_GetProperty(aCx, scalarObj, "parent", &parentScalars);
+ Unused << JS_GetProperty(aCx,
+ scalarObj,
+ Telemetry::Common::GetNameForProcessID(aProcessType),
+ &processScalars);
- aResult.set(parentScalars);
+ aResult.set(processScalars);
}
void
GetAndClearHistogram(JSContext* cx, nsCOMPtr<nsITelemetry> mTelemetry,
const nsACString &name, bool is_keyed)
{
JS::RootedValue testHistogram(cx);
nsresult rv = is_keyed ? mTelemetry->GetKeyedHistogramById(name, cx, &testHistogram)
--- a/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.h
+++ b/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.h
@@ -1,18 +1,21 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
#ifndef TelemetryTestHelpers_h_
#define TelemetryTestHelpers_h_
#include "js/TypeDecls.h"
+#include "mozilla/TelemetryProcessEnums.h"
#include "nsITelemetry.h"
+using mozilla::Telemetry::ProcessID;
+
namespace TelemetryTestHelpers {
void
CheckUintScalar(const char* aName, JSContext* aCx, JS::HandleValue aSnapshot, uint32_t expectedValue);
void
CheckBoolScalar(const char* aName, JSContext* aCx, JS::HandleValue aSnapshot, bool expectedValue);
@@ -27,17 +30,17 @@ void
CheckKeyedBoolScalar(const char* aName, const char* aKey, JSContext* aCx, JS::HandleValue aSnapshot,
bool expectedValue);
void
CheckNumberOfProperties(const char* aName, JSContext* aCx, JS::HandleValue aSnapshot,
uint32_t expectedNumProperties);
void
-GetScalarsSnapshot(bool aKeyed, JSContext* aCx, JS::MutableHandle<JS::Value> aResult);
+GetScalarsSnapshot(bool aKeyed, JSContext* aCx, JS::MutableHandle<JS::Value> aResult, ProcessID aProcessType=ProcessID::Parent);
void
GetAndClearHistogram(JSContext* cx, nsCOMPtr<nsITelemetry> mTelemetry,
const nsACString &name, bool is_keyed);
void
GetProperty(JSContext* cx, const char* name, JS::HandleValue valueIn,
JS::MutableHandleValue valueOut);