зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1683171 - JS/C++ FOG test APIs will now fail if there are errors r=janerik
Differential Revision: https://phabricator.services.mozilla.com/D117923
This commit is contained in:
Родитель
e98399a595
Коммит
cb30e92549
|
@ -7,12 +7,12 @@
|
|||
use nsstring::nsACString;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_boolean_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
pub extern "C" fn fog_boolean_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
with_metric!(BOOLEAN_MAP, id, metric, test_has!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_boolean_test_get_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
pub extern "C" fn fog_boolean_test_get_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
with_metric!(BOOLEAN_MAP, id, metric, test_get!(metric, ping_name))
|
||||
}
|
||||
|
||||
|
|
|
@ -20,3 +20,13 @@ pub unsafe extern "C" fn fog_counter_test_has_value(id: u32, ping_name: &nsACStr
|
|||
pub unsafe extern "C" fn fog_counter_test_get_value(id: u32, ping_name: &nsACString) -> i32 {
|
||||
with_metric!(COUNTER_MAP, id, metric, test_get!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_counter_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(COUNTER_MAP, id, metric, test_get_errors!(metric, ping_name));
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -64,3 +64,18 @@ pub extern "C" fn fog_custom_distribution_accumulate_samples_signed(
|
|||
metric.accumulate_samples_signed(samples)
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_custom_distribution_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
CUSTOM_DISTRIBUTION_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -59,3 +59,18 @@ pub extern "C" fn fog_datetime_set(id: u32, dt: &FogDatetime) {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_datetime_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
DATETIME_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -96,6 +96,21 @@ pub unsafe extern "C" fn fog_event_test_has_value(id: u32, ping_name: &nsACStrin
|
|||
metric_maps::event_test_get_value_wrapper(id, storage).is_some()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_event_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let storage = if ping_name.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(ping_name.to_utf8().into_owned())
|
||||
};
|
||||
let err = metric_maps::event_test_get_error(id, storage);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
||||
/// FFI-compatible representation of recorded event data.
|
||||
///
|
||||
/// This wraps Gecko strings, but ensures they are not dropped on the Rust side.
|
||||
|
|
|
@ -118,6 +118,58 @@ macro_rules! test_get {
|
|||
}};
|
||||
}
|
||||
|
||||
/// Check the provided metric in the provided storage for errors.
|
||||
/// On finding one, return an error string.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `$metric` - The metric to test.
|
||||
/// * `$storage` - the storage name to look into, an nsACString.
|
||||
macro_rules! test_get_errors {
|
||||
($metric:path, $storage:ident) => {{
|
||||
let storage = if $storage.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some($storage.to_utf8())
|
||||
};
|
||||
// Note: I'd really appreciate a trick that'd get the compiler to
|
||||
// double-check I haven't missed any error types here.
|
||||
|
||||
test_get_errors_string!($metric, storage)
|
||||
}};
|
||||
}
|
||||
|
||||
/// Check the provided metric in the provided storage for errors.
|
||||
/// On finding one, return an error string.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `$metric` - The metric to test.
|
||||
/// * `$storage` - the storage name to look into, an Option<String>
|
||||
macro_rules! test_get_errors_string {
|
||||
($metric:path, $storage:ident) => {{
|
||||
let error_types = [
|
||||
glean::ErrorType::InvalidValue,
|
||||
glean::ErrorType::InvalidLabel,
|
||||
glean::ErrorType::InvalidState,
|
||||
glean::ErrorType::InvalidOverflow,
|
||||
];
|
||||
let mut error_str = None;
|
||||
for &error_type in error_types.iter() {
|
||||
let num_errors = $metric.test_get_num_recorded_errors(error_type, $storage.as_deref());
|
||||
if num_errors > 0 {
|
||||
error_str = Some(format!(
|
||||
"Metric had {} error(s) of type {}!",
|
||||
num_errors,
|
||||
error_type.as_str()
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
error_str
|
||||
}};
|
||||
}
|
||||
|
||||
/// Get the submetric id for a given labeled metric and label.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -47,3 +47,18 @@ pub extern "C" fn fog_memory_distribution_accumulate(id: u32, sample: u64) {
|
|||
metric.accumulate(sample)
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_memory_distribution_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
MEMORY_DISTRIBUTION_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -12,11 +12,26 @@ pub extern "C" fn fog_quantity_set(id: u32, value: i64) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_quantity_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
pub extern "C" fn fog_quantity_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
with_metric!(QUANTITY_MAP, id, metric, test_has!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_quantity_test_get_value(id: u32, ping_name: &nsACString) -> i64 {
|
||||
pub extern "C" fn fog_quantity_test_get_value(id: u32, ping_name: &nsACString) -> i64 {
|
||||
with_metric!(QUANTITY_MAP, id, metric, test_get!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_quantity_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
QUANTITY_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -25,3 +25,13 @@ pub extern "C" fn fog_string_test_get_value(
|
|||
pub extern "C" fn fog_string_set(id: u32, value: &nsACString) {
|
||||
with_metric!(STRING_MAP, id, metric, metric.set(value.to_utf8()));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_string_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(STRING_MAP, id, metric, test_get_errors!(metric, ping_name));
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -34,3 +34,18 @@ pub extern "C" fn fog_string_list_set(id: u32, value: &ThinVec<nsCString>) {
|
|||
let value = value.iter().map(|s| s.to_utf8().into()).collect();
|
||||
with_metric!(STRING_LIST_MAP, id, metric, metric.set(value));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_string_list_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
STRING_LIST_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -7,22 +7,22 @@
|
|||
use nsstring::nsACString;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_start(id: u32) {
|
||||
pub extern "C" fn fog_timespan_start(id: u32) {
|
||||
with_metric!(TIMESPAN_MAP, id, metric, metric.start());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_stop(id: u32) {
|
||||
pub extern "C" fn fog_timespan_stop(id: u32) {
|
||||
with_metric!(TIMESPAN_MAP, id, metric, metric.stop());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_cancel(id: u32) {
|
||||
pub extern "C" fn fog_timespan_cancel(id: u32) {
|
||||
with_metric!(TIMESPAN_MAP, id, metric, metric.cancel());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_set_raw(id: u32, duration: u32) {
|
||||
pub extern "C" fn fog_timespan_set_raw(id: u32, duration: u32) {
|
||||
with_metric!(
|
||||
TIMESPAN_MAP,
|
||||
id,
|
||||
|
@ -32,11 +32,26 @@ pub unsafe extern "C" fn fog_timespan_set_raw(id: u32, duration: u32) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
pub extern "C" fn fog_timespan_test_has_value(id: u32, ping_name: &nsACString) -> bool {
|
||||
with_metric!(TIMESPAN_MAP, id, metric, test_has!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fog_timespan_test_get_value(id: u32, ping_name: &nsACString) -> u64 {
|
||||
pub extern "C" fn fog_timespan_test_get_value(id: u32, ping_name: &nsACString) -> u64 {
|
||||
with_metric!(TIMESPAN_MAP, id, metric, test_get!(metric, ping_name))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_timespan_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
TIMESPAN_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -62,3 +62,18 @@ pub extern "C" fn fog_timing_distribution_test_get_value(
|
|||
counts.push(count);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_timing_distribution_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(
|
||||
TIMING_DISTRIBUTION_MAP,
|
||||
id,
|
||||
metric,
|
||||
test_get_errors!(metric, ping_name)
|
||||
);
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -29,3 +29,13 @@ pub extern "C" fn fog_uuid_set(id: u32, value: &nsACString) {
|
|||
pub extern "C" fn fog_uuid_generate_and_set(id: u32) {
|
||||
with_metric!(UUID_MAP, id, metric, metric.generate_and_set());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn fog_uuid_test_get_error(
|
||||
id: u32,
|
||||
ping_name: &nsACString,
|
||||
error_str: &mut nsACString,
|
||||
) -> bool {
|
||||
let err = with_metric!(UUID_MAP, id, metric, test_get_errors!(metric, ping_name));
|
||||
err.map(|err_str| error_str.assign(&err_str)).is_some()
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ pub extern crate uuid;
|
|||
// Re-exporting for use in user tests.
|
||||
pub use private::{DistributionData, ErrorType, RecordedEvent};
|
||||
|
||||
// Must appear before `metrics` or its use of `ffi`'s macros will fail.
|
||||
#[macro_use]
|
||||
mod ffi;
|
||||
|
||||
pub mod metrics;
|
||||
pub mod pings;
|
||||
pub mod private;
|
||||
|
@ -20,4 +24,3 @@ pub mod ipc;
|
|||
|
||||
#[cfg(test)]
|
||||
mod common_test;
|
||||
mod ffi;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -32,13 +33,14 @@ void BooleanMetric::Set(bool aValue) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<bool> BooleanMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<bool>, nsCString> BooleanMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<bool>();
|
||||
#else
|
||||
if (!fog_boolean_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<bool>();
|
||||
}
|
||||
return Some(fog_boolean_test_get_value(mId, &aPingName));
|
||||
#endif
|
||||
|
@ -58,7 +60,9 @@ GleanBoolean::Set(bool aValue) {
|
|||
NS_IMETHODIMP
|
||||
GleanBoolean::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mBoolean.TestGetValue(aStorageName);
|
||||
// Unchecked unwrap is safe because BooleanMetric::TestGetValue() always
|
||||
// returns Ok. (`boolean` has no error return).
|
||||
auto result = mBoolean.TestGetValue(aStorageName).unwrap();
|
||||
if (result.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#ifndef mozilla_glean_GleanBoolean_h
|
||||
#define mozilla_glean_GleanBoolean_h
|
||||
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -43,7 +44,8 @@ class BooleanMetric {
|
|||
*
|
||||
* @return value of the stored metric.
|
||||
*/
|
||||
Maybe<bool> TestGetValue(const nsACString& aPingName = nsCString()) const;
|
||||
Result<Maybe<bool>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
const uint32_t mId;
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#ifndef mozilla_glean_Common_h
|
||||
#define mozilla_glean_Common_h
|
||||
|
||||
#include "nsIScriptError.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -33,13 +34,18 @@ void CounterMetric::Add(int32_t aAmount) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<int32_t> CounterMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<int32_t>, nsCString> CounterMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_counter_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_counter_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<int32_t>(); // can't use Nothing() or templates will fail.
|
||||
}
|
||||
return Some(fog_counter_test_get_value(mId, &aPingName));
|
||||
#endif
|
||||
|
@ -51,7 +57,7 @@ NS_IMPL_CLASSINFO(GleanCounter, nullptr, 0, {0})
|
|||
NS_IMPL_ISUPPORTS_CI(GleanCounter, nsIGleanCounter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
GleanCounter::Add(uint32_t aAmount) {
|
||||
GleanCounter::Add(int32_t aAmount) {
|
||||
mCounter.Add(aAmount);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -60,10 +66,17 @@ NS_IMETHODIMP
|
|||
GleanCounter::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mCounter.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::Int32Value(result.value()));
|
||||
aResult.set(JS::Int32Value(optresult.value()));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_glean_GleanCounter_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -43,7 +44,8 @@ class CounterMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<int32_t> TestGetValue(const nsACString& aPingName = nsCString()) const;
|
||||
Result<Maybe<int32_t>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
const uint32_t mId;
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include "mozilla/glean/bindings/CustomDistribution.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/HistogramGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -50,14 +52,18 @@ void CustomDistributionMetric::AccumulateSamplesSigned(
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<DistributionData> CustomDistributionMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
Result<Maybe<DistributionData>, nsCString>
|
||||
CustomDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_custom_distribution_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_custom_distribution_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
}
|
||||
nsTArray<uint64_t> buckets;
|
||||
nsTArray<uint64_t> counts;
|
||||
|
@ -84,7 +90,14 @@ GleanCustomDistribution::TestGetValue(const nsACString& aPingName,
|
|||
JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mCustomDist.TestGetValue(aPingName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1, ...}
|
||||
|
@ -92,7 +105,7 @@ GleanCustomDistribution::TestGetValue(const nsACString& aPingName,
|
|||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = result.ref().sum;
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -102,7 +115,7 @@ GleanCustomDistribution::TestGetValue(const nsACString& aPingName,
|
|||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
auto& data = result.ref().values;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "mozilla/glean/bindings/DistributionData.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -56,7 +57,7 @@ class CustomDistributionMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<DistributionData> TestGetValue(
|
||||
Result<Maybe<DistributionData>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "js/Date.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -58,14 +59,18 @@ void DatetimeMetric::Set(const PRExplodedTime* aValue) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<PRExplodedTime> DatetimeMetric::TestGetValue(
|
||||
Result<Maybe<PRExplodedTime>, nsCString> DatetimeMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<PRExplodedTime>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_datetime_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_datetime_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<PRExplodedTime>();
|
||||
}
|
||||
FogDatetime ret{0};
|
||||
fog_datetime_test_get_value(mId, &aPingName, &ret);
|
||||
|
@ -104,11 +109,18 @@ NS_IMETHODIMP
|
|||
GleanDatetime::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mDatetime.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
double millis =
|
||||
static_cast<double>(PR_ImplodeTime(result.ptr())) / PR_USEC_PER_MSEC;
|
||||
static_cast<double>(PR_ImplodeTime(optresult.ptr())) / PR_USEC_PER_MSEC;
|
||||
JS::RootedObject root(aCx, JS::NewDateObject(aCx, JS::TimeClip(millis)));
|
||||
aResult.setObject(*root);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_glean_GleanDatetime_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
#include "prtime.h"
|
||||
|
@ -44,7 +45,7 @@ class DatetimeMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<PRExplodedTime> TestGetValue(
|
||||
Result<Maybe<PRExplodedTime>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -101,7 +101,14 @@ GleanEvent::Record(JS::HandleValue aExtra, JSContext* aCx) {
|
|||
NS_IMETHODIMP
|
||||
GleanEvent::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto optEvents = mEvent.TestGetValue(aStorageName);
|
||||
auto resEvents = mEvent.TestGetValue(aStorageName);
|
||||
if (resEvents.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(resEvents.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optEvents = resEvents.unwrap();
|
||||
if (optEvents.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
return NS_OK;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "nsIGleanMetrics.h"
|
||||
#include "mozilla/glean/bindings/EventGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
|
@ -98,14 +99,19 @@ class EventMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<nsTArray<RecordedEvent>> TestGetValue(
|
||||
Result<Maybe<nsTArray<RecordedEvent>>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<nsTArray<RecordedEvent>>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_event_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
|
||||
if (!fog_event_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<nsTArray<RecordedEvent>>();
|
||||
}
|
||||
|
||||
nsTArray<FfiRecordedEvent> events;
|
||||
|
|
|
@ -28,14 +28,18 @@ void MemoryDistributionMetric::Accumulate(uint64_t aSample) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<DistributionData> MemoryDistributionMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
Result<Maybe<DistributionData>, nsCString>
|
||||
MemoryDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_memory_distribution_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_memory_distribution_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
}
|
||||
nsTArray<uint64_t> buckets;
|
||||
nsTArray<uint64_t> counts;
|
||||
|
@ -62,15 +66,21 @@ GleanMemoryDistribution::TestGetValue(const nsACString& aPingName,
|
|||
JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mMemoryDist.TestGetValue(aPingName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1, ...}
|
||||
// Build return value of the form:
|
||||
// { sum: #, values: {bucket1: count1, ...} }
|
||||
JS::RootedObject root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = result.ref().sum;
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -80,7 +90,7 @@ GleanMemoryDistribution::TestGetValue(const nsACString& aPingName,
|
|||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
auto& data = result.ref().values;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
|
|
|
@ -48,7 +48,7 @@ class MemoryDistributionMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<DistributionData> TestGetValue(
|
||||
Result<Maybe<DistributionData>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "mozilla/glean/bindings/Quantity.h"
|
||||
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -26,13 +27,18 @@ void QuantityMetric::Set(int64_t aValue) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<int64_t> QuantityMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<int64_t>, nsCString> QuantityMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<int64_t>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_quantity_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_quantity_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<int64_t>();
|
||||
}
|
||||
return Some(fog_quantity_test_get_value(mId, &aPingName));
|
||||
#endif
|
||||
|
@ -53,10 +59,17 @@ NS_IMETHODIMP
|
|||
GleanQuantity::TestGetValue(const nsACString& aPingName,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mQuantity.TestGetValue(aPingName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::DoubleValue(result.value()));
|
||||
aResult.set(JS::DoubleValue(static_cast<double>(optresult.value())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,8 @@ class QuantityMetric {
|
|||
*
|
||||
* @return value of the stored metric.
|
||||
*/
|
||||
Maybe<int64_t> TestGetValue(const nsACString& aPingName = nsCString()) const;
|
||||
Result<Maybe<int64_t>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
const uint32_t mId;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -26,13 +27,18 @@ void StringMetric::Set(const nsACString& aValue) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<nsCString> StringMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<nsCString>, nsCString> StringMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<nsCString>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_string_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_string_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<nsCString>();
|
||||
}
|
||||
nsCString ret;
|
||||
fog_string_test_get_value(mId, &aPingName, &ret);
|
||||
|
@ -55,10 +61,17 @@ NS_IMETHODIMP
|
|||
GleanString::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mString.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
const NS_ConvertUTF8toUTF16 str(result.value());
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.ref());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_glean_GleanString_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -46,7 +47,7 @@ class StringMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<nsCString> TestGetValue(
|
||||
Result<Maybe<nsCString>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "mozilla/glean/bindings/StringList.h"
|
||||
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
|
@ -39,14 +40,18 @@ void StringListMetric::Set(const nsTArray<nsCString>& aValue) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<nsTArray<nsCString>> StringListMetric::TestGetValue(
|
||||
Result<Maybe<nsTArray<nsCString>>, nsCString> StringListMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<nsTArray<nsCString>>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_string_list_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_string_list_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<nsTArray<nsCString>>();
|
||||
}
|
||||
nsTArray<nsCString> ret;
|
||||
fog_string_list_test_get_value(mId, &aPingName, &ret);
|
||||
|
@ -75,10 +80,17 @@ NS_IMETHODIMP
|
|||
GleanStringList::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mStringList.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
if (!dom::ToJSValue(aCx, result.ref(), aResult)) {
|
||||
if (!dom::ToJSValue(aCx, optresult.ref(), aResult)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ class StringListMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<nsTArray<nsCString>> TestGetValue(
|
||||
Result<Maybe<nsTArray<nsCString>>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "nsString.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -69,13 +70,14 @@ void TimespanMetric::SetRaw(uint32_t aDuration) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<int64_t> TimespanMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<uint64_t>, nsCString> TimespanMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<uint64_t>();
|
||||
#else
|
||||
if (!fog_timespan_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<uint64_t>();
|
||||
}
|
||||
return Some(fog_timespan_test_get_value(mId, &aPingName));
|
||||
#endif
|
||||
|
@ -114,10 +116,17 @@ NS_IMETHODIMP
|
|||
GleanTimespan::TestGetValue(const nsACString& aStorageName,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mTimespan.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
aResult.set(JS::DoubleValue(result.value()));
|
||||
aResult.set(JS::DoubleValue(static_cast<double>(optresult.value())));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_glean_GleanTimespan_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
|
||||
namespace mozilla::glean {
|
||||
|
@ -72,7 +73,8 @@ class TimespanMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<int64_t> TestGetValue(const nsACString& aPingName = nsCString()) const;
|
||||
Result<Maybe<uint64_t>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
const uint32_t mId;
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include "mozilla/glean/bindings/TimingDistribution.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/glean/bindings/HistogramGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
|
@ -64,14 +66,18 @@ void TimingDistributionMetric::Cancel(const TimerId&& aId) const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<DistributionData> TimingDistributionMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
Result<Maybe<DistributionData>, nsCString>
|
||||
TimingDistributionMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_timing_distribution_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_timing_distribution_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<DistributionData>();
|
||||
}
|
||||
nsTArray<uint64_t> buckets;
|
||||
nsTArray<uint64_t> counts;
|
||||
|
@ -112,15 +118,23 @@ GleanTimingDistribution::TestGetValue(const nsACString& aPingName,
|
|||
JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mTimingDist.TestGetValue(aPingName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1, ...}
|
||||
// Build return value of the form: { sum: #, values: {bucket1: count1,
|
||||
// ...}
|
||||
JS::RootedObject root(aCx, JS_NewPlainObject(aCx));
|
||||
if (!root) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
uint64_t sum = result.ref().sum;
|
||||
uint64_t sum = optresult.ref().sum;
|
||||
if (!JS_DefineProperty(aCx, root, "sum", static_cast<double>(sum),
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -130,7 +144,7 @@ GleanTimingDistribution::TestGetValue(const nsACString& aPingName,
|
|||
!JS_DefineProperty(aCx, root, "values", valuesObj, JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
auto& data = result.ref().values;
|
||||
auto& data = optresult.ref().values;
|
||||
for (const auto& entry : data) {
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
const uint64_t count = entry.GetData();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "mozilla/glean/bindings/DistributionData.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -65,7 +66,7 @@ class TimingDistributionMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<DistributionData> TestGetValue(
|
||||
Result<Maybe<DistributionData>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
|
||||
#include "mozilla/glean/bindings/Uuid.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/Components.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/glean/bindings/ScalarGIFFTMap.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "nsIClassInfoImpl.h"
|
||||
|
@ -36,13 +38,18 @@ void UuidMetric::GenerateAndSet() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
Maybe<nsCString> UuidMetric::TestGetValue(const nsACString& aPingName) const {
|
||||
Result<Maybe<nsCString>, nsCString> UuidMetric::TestGetValue(
|
||||
const nsACString& aPingName) const {
|
||||
#ifdef MOZ_GLEAN_ANDROID
|
||||
Unused << mId;
|
||||
return Nothing();
|
||||
return Maybe<nsCString>();
|
||||
#else
|
||||
nsCString err;
|
||||
if (fog_uuid_test_get_error(mId, &aPingName, &err)) {
|
||||
return Err(err);
|
||||
}
|
||||
if (!fog_uuid_test_has_value(mId, &aPingName)) {
|
||||
return Nothing();
|
||||
return Maybe<nsCString>();
|
||||
}
|
||||
nsCString ret;
|
||||
fog_uuid_test_get_value(mId, &aPingName, &ret);
|
||||
|
@ -71,10 +78,17 @@ NS_IMETHODIMP
|
|||
GleanUuid::TestGetValue(const nsACString& aStorageName, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult) {
|
||||
auto result = mUuid.TestGetValue(aStorageName);
|
||||
if (result.isNothing()) {
|
||||
if (result.isErr()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
LogToBrowserConsole(nsIScriptError::errorFlag,
|
||||
NS_ConvertUTF8toUTF16(result.unwrapErr()));
|
||||
return NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
|
||||
}
|
||||
auto optresult = result.unwrap();
|
||||
if (optresult.isNothing()) {
|
||||
aResult.set(JS::UndefinedValue());
|
||||
} else {
|
||||
const NS_ConvertUTF8toUTF16 str(result.value());
|
||||
const NS_ConvertUTF8toUTF16 str(optresult.value());
|
||||
aResult.set(
|
||||
JS::StringValue(JS_NewUCStringCopyN(aCx, str.Data(), str.Length())));
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_glean_GleanUuid_h
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "nsIGleanMetrics.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
@ -48,7 +49,7 @@ class UuidMetric {
|
|||
*
|
||||
* @return value of the stored metric, or Nothing() if there is no value.
|
||||
*/
|
||||
Maybe<nsCString> TestGetValue(
|
||||
Result<Maybe<nsCString>, nsCString> TestGetValue(
|
||||
const nsACString& aPingName = nsCString()) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -219,6 +219,37 @@ pub(crate) mod __glean_metric_maps {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check the provided event for errors.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `metric_id` - The metric's ID to look up
|
||||
/// * `ping_name` - (Optional) The ping name to look into.
|
||||
/// Defaults to the first value in `send_in_pings`.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns a string for the recorded error or `None`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if no event by the given metric ID could be found.
|
||||
#[allow(unused_variables)]
|
||||
pub(crate) fn event_test_get_error(metric_id: u32, ping_name: Option<String>) -> Option<String> {
|
||||
#[cfg(feature = "with_gecko")]
|
||||
match metric_id {
|
||||
{% for metric_id, event in events_by_id.items() %}
|
||||
{{metric_id}} => test_get_errors_string!(super::{{event}}, ping_name),
|
||||
{% endfor %}
|
||||
_ => panic!("No event for metric id {}", metric_id),
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "with_gecko"))]
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod submetric_maps {
|
||||
use std::sync::{
|
||||
atomic::AtomicU32,
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "mozilla/glean/GleanPings.h"
|
||||
#include "mozilla/glean/fog_ffi_generated.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/Result.h"
|
||||
#include "mozilla/ResultVariant.h"
|
||||
#include "mozilla/Tuple.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -58,11 +60,11 @@ TEST(FOG, TestCppCounterWorks)
|
|||
{
|
||||
mozilla::glean::test_only::bad_code.Add(42);
|
||||
|
||||
ASSERT_EQ(
|
||||
42,
|
||||
mozilla::glean::test_only::bad_code.TestGetValue("test-ping"_ns).value());
|
||||
ASSERT_EQ(42, mozilla::glean::test_only::bad_code.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value());
|
||||
// And test that the ping name's optional, while you're at it:
|
||||
ASSERT_EQ(42, test_only::bad_code.TestGetValue().value());
|
||||
ASSERT_EQ(42, test_only::bad_code.TestGetValue().unwrap().value());
|
||||
}
|
||||
|
||||
TEST(FOG, TestCppStringWorks)
|
||||
|
@ -72,6 +74,7 @@ TEST(FOG, TestCppStringWorks)
|
|||
|
||||
ASSERT_STREQ(kValue.get(), mozilla::glean::test_only::cheesy_string
|
||||
.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value()
|
||||
.get());
|
||||
}
|
||||
|
@ -84,6 +87,7 @@ TEST(FOG, TestCppTimespanWorks)
|
|||
|
||||
ASSERT_TRUE(
|
||||
mozilla::glean::test_only::can_we_time_it.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value() > 0);
|
||||
}
|
||||
|
||||
|
@ -91,16 +95,20 @@ TEST(FOG, TestCppUuidWorks)
|
|||
{
|
||||
nsCString kTestUuid("decafdec-afde-cafd-ecaf-decafdecafde");
|
||||
test_only::what_id_it.Set(kTestUuid);
|
||||
ASSERT_STREQ(
|
||||
kTestUuid.get(),
|
||||
test_only::what_id_it.TestGetValue("test-ping"_ns).value().get());
|
||||
ASSERT_STREQ(kTestUuid.get(),
|
||||
test_only::what_id_it.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value()
|
||||
.get());
|
||||
|
||||
test_only::what_id_it.GenerateAndSet();
|
||||
// Since we generate v4 UUIDs, and the first character of the third group
|
||||
// isn't 4, this won't ever collide with kTestUuid.
|
||||
ASSERT_STRNE(
|
||||
kTestUuid.get(),
|
||||
test_only::what_id_it.TestGetValue("test-ping"_ns).value().get());
|
||||
ASSERT_STRNE(kTestUuid.get(),
|
||||
test_only::what_id_it.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value()
|
||||
.get());
|
||||
}
|
||||
|
||||
TEST(FOG, TestCppBooleanWorks)
|
||||
|
@ -109,6 +117,7 @@ TEST(FOG, TestCppBooleanWorks)
|
|||
|
||||
ASSERT_EQ(false, mozilla::glean::test_only::can_we_flag_it
|
||||
.TestGetValue("test-ping"_ns)
|
||||
.unwrap()
|
||||
.value());
|
||||
}
|
||||
|
||||
|
@ -122,7 +131,7 @@ TEST(FOG, TestCppDatetimeWorks)
|
|||
PRExplodedTime date{0, 35, 10, 12, 6, 10, 2020, 0, 0, {5 * 60 * 60, 0}};
|
||||
test_only::what_a_date.Set(&date);
|
||||
|
||||
auto received = test_only::what_a_date.TestGetValue("test-ping"_ns);
|
||||
auto received = test_only::what_a_date.TestGetValue("test-ping"_ns).unwrap();
|
||||
ASSERT_THAT(received.value(), BitEq(date));
|
||||
}
|
||||
|
||||
|
@ -135,11 +144,13 @@ using mozilla::glean::test_only_ipc::EventWithExtraExtra;
|
|||
TEST(FOG, TestCppEventWorks)
|
||||
{
|
||||
test_only_ipc::no_extra_event.Record();
|
||||
ASSERT_TRUE(test_only_ipc::no_extra_event.TestGetValue("store1"_ns).isSome());
|
||||
ASSERT_TRUE(test_only_ipc::no_extra_event.TestGetValue("store1"_ns)
|
||||
.unwrap()
|
||||
.isSome());
|
||||
|
||||
AnEventExtra extra = {.extra1 = Some("can set extras"_ns)};
|
||||
test_only_ipc::an_event.Record(Some(extra));
|
||||
auto optEvents = test_only_ipc::an_event.TestGetValue("store1"_ns);
|
||||
auto optEvents = test_only_ipc::an_event.TestGetValue("store1"_ns).unwrap();
|
||||
ASSERT_TRUE(optEvents.isSome());
|
||||
|
||||
auto events = optEvents.extract();
|
||||
|
@ -157,7 +168,8 @@ TEST(FOG, TestCppEventsWithDifferentExtraTypes)
|
|||
.extra2 = Some(37),
|
||||
.extra3LongerName = Some(false)};
|
||||
test_only_ipc::event_with_extra.Record(Some(extra));
|
||||
auto optEvents = test_only_ipc::event_with_extra.TestGetValue("store1"_ns);
|
||||
auto optEvents =
|
||||
test_only_ipc::event_with_extra.TestGetValue("store1"_ns).unwrap();
|
||||
ASSERT_TRUE(optEvents.isSome());
|
||||
|
||||
auto events = optEvents.extract();
|
||||
|
@ -188,7 +200,7 @@ TEST(FOG, TestCppMemoryDistWorks)
|
|||
test_only::do_you_remember.Accumulate(17);
|
||||
|
||||
DistributionData data =
|
||||
test_only::do_you_remember.TestGetValue("test-ping"_ns).ref();
|
||||
test_only::do_you_remember.TestGetValue("test-ping"_ns).unwrap().ref();
|
||||
// Sum is in bytes, test_only::do_you_remember is in megabytes. So
|
||||
// multiplication ahoy!
|
||||
ASSERT_EQ(data.sum, 24UL * 1024 * 1024);
|
||||
|
@ -206,7 +218,7 @@ TEST(FOG, TestCppCustomDistWorks)
|
|||
test_only_ipc::a_custom_dist.AccumulateSamples({7, 268435458});
|
||||
|
||||
DistributionData data =
|
||||
test_only_ipc::a_custom_dist.TestGetValue("store1"_ns).ref();
|
||||
test_only_ipc::a_custom_dist.TestGetValue("store1"_ns).unwrap().ref();
|
||||
ASSERT_EQ(data.sum, 7UL + 268435458);
|
||||
for (const auto& entry : data.values) {
|
||||
const uint64_t bucket = entry.GetKey();
|
||||
|
@ -224,7 +236,8 @@ TEST(FOG, TestCppPings)
|
|||
bool submitted = false;
|
||||
ping.TestBeforeNextSubmit([&submitted](const nsACString& aReason) {
|
||||
submitted = true;
|
||||
ASSERT_EQ(false, test_only::one_ping_one_bool.TestGetValue().ref());
|
||||
ASSERT_EQ(false,
|
||||
test_only::one_ping_one_bool.TestGetValue().unwrap().ref());
|
||||
});
|
||||
ping.Submit();
|
||||
ASSERT_TRUE(submitted)
|
||||
|
@ -243,14 +256,14 @@ TEST(FOG, TestCppStringLists)
|
|||
|
||||
test_only::cheesy_string_list.Set(cheezList);
|
||||
|
||||
auto val = test_only::cheesy_string_list.TestGetValue().value();
|
||||
auto val = test_only::cheesy_string_list.TestGetValue().unwrap().value();
|
||||
// Note: This is fragile if the order is ever not preserved.
|
||||
ASSERT_STREQ(kValue.get(), val[0].get());
|
||||
ASSERT_STREQ(kValue2.get(), val[1].get());
|
||||
|
||||
test_only::cheesy_string_list.Add(kValue3);
|
||||
|
||||
val = test_only::cheesy_string_list.TestGetValue().value();
|
||||
val = test_only::cheesy_string_list.TestGetValue().unwrap().value();
|
||||
ASSERT_STREQ(kValue3.get(), val[2].get());
|
||||
}
|
||||
|
||||
|
@ -265,7 +278,8 @@ TEST(FOG, TestCppTimingDistWorks)
|
|||
test_only::what_time_is_it.StopAndAccumulate(std::move(id2));
|
||||
test_only::what_time_is_it.StopAndAccumulate(std::move(id3));
|
||||
|
||||
DistributionData data = test_only::what_time_is_it.TestGetValue().ref();
|
||||
DistributionData data =
|
||||
test_only::what_time_is_it.TestGetValue().unwrap().ref();
|
||||
const uint64_t NANOS_IN_MILLIS = 1e6;
|
||||
|
||||
// bug 1701847 - Sleeps don't necessarily round up as you'd expect.
|
||||
|
@ -287,46 +301,58 @@ TEST(FOG, TestCppTimingDistWorks)
|
|||
TEST(FOG, TestLabeledBooleanWorks)
|
||||
{
|
||||
ASSERT_EQ(mozilla::Nothing(),
|
||||
test_only::mabels_like_balloons.Get("hot_air"_ns).TestGetValue());
|
||||
test_only::mabels_like_balloons.Get("hot_air"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap());
|
||||
test_only::mabels_like_balloons.Get("hot_air"_ns).Set(true);
|
||||
test_only::mabels_like_balloons.Get("helium"_ns).Set(false);
|
||||
ASSERT_EQ(
|
||||
true,
|
||||
test_only::mabels_like_balloons.Get("hot_air"_ns).TestGetValue().ref());
|
||||
ASSERT_EQ(
|
||||
false,
|
||||
test_only::mabels_like_balloons.Get("helium"_ns).TestGetValue().ref());
|
||||
ASSERT_EQ(true, test_only::mabels_like_balloons.Get("hot_air"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref());
|
||||
ASSERT_EQ(false, test_only::mabels_like_balloons.Get("helium"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref());
|
||||
}
|
||||
|
||||
TEST(FOG, TestLabeledCounterWorks)
|
||||
{
|
||||
ASSERT_EQ(mozilla::Nothing(),
|
||||
test_only::mabels_kitchen_counters.Get("marble"_ns).TestGetValue());
|
||||
test_only::mabels_kitchen_counters.Get("marble"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap());
|
||||
test_only::mabels_kitchen_counters.Get("marble"_ns).Add(1);
|
||||
test_only::mabels_kitchen_counters.Get("laminate"_ns).Add(2);
|
||||
ASSERT_EQ(
|
||||
1,
|
||||
test_only::mabels_kitchen_counters.Get("marble"_ns).TestGetValue().ref());
|
||||
ASSERT_EQ(1, test_only::mabels_kitchen_counters.Get("marble"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref());
|
||||
ASSERT_EQ(2, test_only::mabels_kitchen_counters.Get("laminate"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref());
|
||||
}
|
||||
|
||||
TEST(FOG, TestLabeledStringWorks)
|
||||
{
|
||||
ASSERT_EQ(mozilla::Nothing(),
|
||||
test_only::mabels_balloon_strings.Get("twine"_ns).TestGetValue());
|
||||
test_only::mabels_balloon_strings.Get("twine"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap());
|
||||
test_only::mabels_balloon_strings.Get("twine"_ns).Set("seems acceptable"_ns);
|
||||
test_only::mabels_balloon_strings.Get("parachute_cord"_ns)
|
||||
.Set("preferred"_ns);
|
||||
ASSERT_STREQ("seems acceptable",
|
||||
test_only::mabels_balloon_strings.Get("twine"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref()
|
||||
.get());
|
||||
ASSERT_STREQ("preferred",
|
||||
test_only::mabels_balloon_strings.Get("parachute_cord"_ns)
|
||||
.TestGetValue()
|
||||
.unwrap()
|
||||
.ref()
|
||||
.get());
|
||||
}
|
||||
|
@ -337,6 +363,7 @@ TEST(FOG, TestCppQuantityWorks)
|
|||
const uint32_t kValue = 6 * 9;
|
||||
mozilla::glean::test_only::meaning_of_life.Set(kValue);
|
||||
|
||||
ASSERT_EQ(kValue,
|
||||
mozilla::glean::test_only::meaning_of_life.TestGetValue().value());
|
||||
ASSERT_EQ(kValue, mozilla::glean::test_only::meaning_of_life.TestGetValue()
|
||||
.unwrap()
|
||||
.value());
|
||||
}
|
||||
|
|
|
@ -578,6 +578,36 @@ pub(crate) mod __glean_metric_maps {
|
|||
}
|
||||
}
|
||||
|
||||
/// Check the provided event for errors.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `metric_id` - The metric's ID to look up
|
||||
/// * `ping_name` - (Optional) The ping name to look into.
|
||||
/// Defaults to the first value in `send_in_pings`.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns a string for the recorded error or `None`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if no event by the given metric ID could be found.
|
||||
#[allow(unused_variables)]
|
||||
pub(crate) fn event_test_get_error(metric_id: u32, ping_name: Option<String>) -> Option<String> {
|
||||
#[cfg(feature = "with_gecko")]
|
||||
match metric_id {
|
||||
17 => test_get_errors_string!(super::test_nested::event_metric, ping_name),
|
||||
18 => test_get_errors_string!(super::test_nested::event_metric_with_extra, ping_name),
|
||||
_ => panic!("No event for metric id {}", metric_id),
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "with_gecko"))]
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod submetric_maps {
|
||||
use std::sync::{
|
||||
atomic::AtomicU32,
|
||||
|
|
|
@ -182,6 +182,23 @@ test_only:
|
|||
send_in_pings:
|
||||
- test-ping
|
||||
|
||||
mabels_bathroom_counters:
|
||||
type: labeled_counter
|
||||
description: |
|
||||
Counts Mabels labeled by their bathroom counters.
|
||||
This is a test-only metric.
|
||||
bugs:
|
||||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1683171
|
||||
data_reviews:
|
||||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1683171#c1
|
||||
data_sensitivity:
|
||||
- technical
|
||||
expires: never
|
||||
notification_emails:
|
||||
- glean-team@mozilla.com
|
||||
send_in_pings:
|
||||
- test-ping
|
||||
|
||||
mabels_like_balloons:
|
||||
type: labeled_boolean
|
||||
description: |
|
||||
|
|
|
@ -75,7 +75,7 @@ interface nsIGleanCounter : nsISupports
|
|||
*
|
||||
* @param amount The amount to increase by. Should be positive.
|
||||
*/
|
||||
void add(in uint32_t amount);
|
||||
void add(in int32_t amount);
|
||||
|
||||
/**
|
||||
* **Test-only API**
|
||||
|
|
|
@ -237,7 +237,11 @@ add_task(function test_gifft_labeled_counter() {
|
|||
Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue()
|
||||
);
|
||||
Glean.testOnlyIpc.aLabeledCounter.InvalidLabel.add(3);
|
||||
Assert.equal(3, Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue());
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aLabeledCounter.__other__.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Can't get the value when you're error'd"
|
||||
);
|
||||
|
||||
let value = keyedScalarValue("telemetry.test.keyed_unsigned_int");
|
||||
Assert.deepEqual(
|
||||
|
|
|
@ -219,10 +219,6 @@ add_task(async function test_fog_memory_distribution_works() {
|
|||
add_task(async function test_fog_custom_distribution_works() {
|
||||
Glean.testOnlyIpc.aCustomDist.accumulateSamples([7, 268435458]);
|
||||
|
||||
// Negative values will not be recorded, instead an error is recorded.
|
||||
// We can't check the error yet.
|
||||
Glean.testOnlyIpc.aCustomDist.accumulateSamples([-7]);
|
||||
|
||||
let data = Glean.testOnlyIpc.aCustomDist.testGetValue("store1");
|
||||
Assert.equal(7 + 268435458, data.sum, "Sum's correct");
|
||||
for (let [bucket, count] of Object.entries(data.values)) {
|
||||
|
@ -231,6 +227,13 @@ add_task(async function test_fog_custom_distribution_works() {
|
|||
`Only two buckets have a sample ${bucket} ${count}`
|
||||
);
|
||||
}
|
||||
|
||||
// Negative values will not be recorded, instead an error is recorded.
|
||||
Glean.testOnlyIpc.aCustomDist.accumulateSamples([-7]);
|
||||
Assert.throws(
|
||||
() => Glean.testOnlyIpc.aCustomDist.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
});
|
||||
|
||||
add_task(function test_fog_custom_pings() {
|
||||
|
@ -330,11 +333,10 @@ add_task(async function test_fog_labeled_counter_works() {
|
|||
Glean.testOnly.mabelsKitchenCounters.__other__.testGetValue()
|
||||
);
|
||||
Glean.testOnly.mabelsKitchenCounters.InvalidLabel.add(1);
|
||||
Assert.equal(
|
||||
1,
|
||||
Glean.testOnly.mabelsKitchenCounters.__other__.testGetValue()
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsKitchenCounters.__other__.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
// TODO: Test that we have the right number and type of errors (bug 1683171)
|
||||
});
|
||||
|
||||
add_task(async function test_fog_labeled_string_works() {
|
||||
|
@ -359,11 +361,10 @@ add_task(async function test_fog_labeled_string_works() {
|
|||
Glean.testOnly.mabelsBalloonStrings.__other__.testGetValue()
|
||||
);
|
||||
Glean.testOnly.mabelsBalloonStrings.InvalidLabel.set("valid");
|
||||
Assert.equal(
|
||||
"valid",
|
||||
Glean.testOnly.mabelsBalloonStrings.__other__.testGetValue()
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsBalloonStrings.__other__.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/
|
||||
);
|
||||
// TODO: Test that we have the right number and type of errors (bug 1683171)
|
||||
});
|
||||
|
||||
add_task(function test_fog_quantity_works() {
|
||||
|
|
|
@ -126,7 +126,8 @@ add_task({ skip_if: () => runningInParent }, async function run_child_stuff() {
|
|||
Glean.testOnly.mabelsKitchenCounters.with_junk_on_them.add(
|
||||
COUNTERS_WITH_JUNK_ON_THEM
|
||||
);
|
||||
Glean.testOnly.mabelsKitchenCounters.InvalidLabel.add(INVALID_COUNTERS);
|
||||
|
||||
Glean.testOnly.mabelsBathroomCounters.InvalidLabel.add(INVALID_COUNTERS);
|
||||
});
|
||||
|
||||
add_task(
|
||||
|
@ -195,6 +196,11 @@ add_task(
|
|||
mabelsCounters.with_junk_on_them.testGetValue(),
|
||||
COUNTERS_WITH_JUNK_ON_THEM
|
||||
);
|
||||
Assert.equal(mabelsCounters.__other__.testGetValue(), INVALID_COUNTERS);
|
||||
|
||||
Assert.throws(
|
||||
() => Glean.testOnly.mabelsBathroomCounters.__other__.testGetValue(),
|
||||
/NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/,
|
||||
"Invalid labels record errors, which throw"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче