Bug 1461965 - Enable xpcshell test coverage for GeckoView Telemetry. r?chutten,janerik,froydnj
This patch introduces the nsITelemetryGeckoViewTesting IDL interface which
allows to control the Telemetry GeckoView persistence feature. This is
useful to enable xpcshell test coverage for GeckoView code on all platforms.
MozReview-Commit-ID: Hh0oq4qdqrX
--- a/toolkit/components/build/moz.build
+++ b/toolkit/components/build/moz.build
@@ -23,16 +23,17 @@ LOCAL_INCLUDES += [
'../downloads',
'../feeds',
'../find',
'../perfmonitoring',
'../protobuf',
'../reputationservice',
'../startup',
'../statusfilter',
+ '../telemetry',
'../typeaheadfind',
'../url-classifier',
]
if not CONFIG['MOZ_DISABLE_PARENTAL_CONTROLS']:
LOCAL_INCLUDES += [
'../parentalcontrols',
]
--- a/toolkit/components/build/nsToolkitCompsCID.h
+++ b/toolkit/components/build/nsToolkitCompsCID.h
@@ -78,16 +78,21 @@
#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
#define NS_UPDATEPROCESSOR_CONTRACTID \
"@mozilla.org/updates/update-processor;1"
#endif
#define NS_ADDONCONTENTPOLICY_CONTRACTID \
"@mozilla.org/addons/content-policy;1"
+#if defined(ENABLE_TESTS)
+#define NS_TELEMETRYGECKOVIEWTESTING_CONTRACTID \
+ "@mozilla.org/telemetry/geckoview-testing;1"
+#endif
+
/////////////////////////////////////////////////////////////////////////////
#define ALERT_NOTIFICATION_CID \
{ 0x9a7b7a41, 0x0b47, 0x47f7, { 0xb6, 0x1b, 0x15, 0xa2, 0x10, 0xd6, 0xf0, 0x20 } }
// {A0CCAAF8-09DA-44D8-B250-9AC3E93C8117}
#define NS_ALERTSSERVICE_CID \
{ 0xa0ccaaf8, 0x9da, 0x44d8, { 0xb2, 0x50, 0x9a, 0xc3, 0xe9, 0x3c, 0x81, 0x17 } }
@@ -178,8 +183,13 @@
#define NS_ADDONCONTENTPOLICY_CID \
{ 0xc26a8241, 0xecf4, 0x4aed, { 0x9f, 0x3c, 0xf1, 0xf5, 0xc7, 0x13, 0xb9, 0xa5 } }
#define NS_ADDON_POLICY_SERVICE_CID \
{ 0x562de129, 0x8338, 0x482c, { 0xbb, 0x96, 0xa1, 0xff, 0x09, 0xee, 0x53, 0xcc } }
#define NS_ADDON_POLICY_SERVICE_CONTRACTID \
"@mozilla.org/addons/policy-service;1"
+
+#if defined(ENABLE_TESTS)
+#define NS_TELEMETRYGECKOVIEWTESTING_CID \
+ { 0xaaa3f7f2, 0x8ef0, 0x41ec, { 0x8d, 0x3, 0xae, 0xd6, 0x67, 0xcf, 0x7f, 0xa2 } };
+#endif
--- a/toolkit/components/build/nsToolkitCompsModule.cpp
+++ b/toolkit/components/build/nsToolkitCompsModule.cpp
@@ -54,16 +54,20 @@
#endif
#define MOZ_HAS_PERFSTATS
#if defined(MOZ_HAS_PERFSTATS)
#include "nsPerformanceStats.h"
#endif // defined (MOZ_HAS_PERFSTATS)
+#if defined(ENABLE_TESTS)
+#include "geckoview/TelemetryGeckoViewTesting.h"
+#endif
+
using namespace mozilla;
/////////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppStartup, Init)
#if defined(MOZ_HAS_PERFSTATS)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPerformanceStatsService, Init)
@@ -123,16 +127,20 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(NativeOSF
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NativeFileWatcherService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(AddonContentPolicy)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AddonManagerStartup, AddonManagerStartup::GetInstance)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ExtensionPolicyService, ExtensionPolicyService::GetInstance)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSessionStoreUtils)
+#if defined(ENABLE_TESTS)
+NS_GENERIC_FACTORY_CONSTRUCTOR(TelemetryGeckoViewTestingImpl)
+#endif
+
NS_DEFINE_NAMED_CID(NS_TOOLKIT_APPSTARTUP_CID);
#if defined(MOZ_HAS_PERFSTATS)
NS_DEFINE_NAMED_CID(NS_TOOLKIT_PERFORMANCESTATSSERVICE_CID);
#endif // defined (MOZ_HAS_PERFSTATS)
#if defined(MOZ_HAS_TERMINATOR)
NS_DEFINE_NAMED_CID(NS_TOOLKIT_TERMINATOR_CID);
#endif
@@ -157,16 +165,19 @@ NS_DEFINE_NAMED_CID(NS_UPDATEPROCESSOR_C
#endif
NS_DEFINE_NAMED_CID(FINALIZATIONWITNESSSERVICE_CID);
NS_DEFINE_NAMED_CID(NATIVE_OSFILE_INTERNALS_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_ADDONCONTENTPOLICY_CID);
NS_DEFINE_NAMED_CID(NS_ADDON_MANAGER_STARTUP_CID);
NS_DEFINE_NAMED_CID(NS_ADDON_POLICY_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_SESSIONSTOREUTILS_CID);
NS_DEFINE_NAMED_CID(NATIVE_FILEWATCHER_SERVICE_CID);
+#if defined(ENABLE_TESTS)
+NS_DEFINE_NAMED_CID(NS_TELEMETRYGECKOVIEWTESTING_CID);
+#endif
static const Module::CIDEntry kToolkitCIDs[] = {
{ &kNS_TOOLKIT_APPSTARTUP_CID, false, nullptr, nsAppStartupConstructor },
#if defined(MOZ_HAS_TERMINATOR)
{ &kNS_TOOLKIT_TERMINATOR_CID, false, nullptr, nsTerminatorConstructor },
#endif
#if defined(MOZ_HAS_PERFSTATS)
{ &kNS_TOOLKIT_PERFORMANCESTATSSERVICE_CID, false, nullptr, nsPerformanceStatsServiceConstructor },
@@ -192,16 +203,19 @@ static const Module::CIDEntry kToolkitCI
#endif
{ &kFINALIZATIONWITNESSSERVICE_CID, false, nullptr, FinalizationWitnessServiceConstructor },
{ &kNATIVE_OSFILE_INTERNALS_SERVICE_CID, false, nullptr, NativeOSFileInternalsServiceConstructor },
{ &kNS_ADDONCONTENTPOLICY_CID, false, nullptr, AddonContentPolicyConstructor },
{ &kNS_ADDON_MANAGER_STARTUP_CID, false, nullptr, AddonManagerStartupConstructor },
{ &kNS_ADDON_POLICY_SERVICE_CID, false, nullptr, ExtensionPolicyServiceConstructor },
{ &kNS_SESSIONSTOREUTILS_CID, false, nullptr, nsSessionStoreUtilsConstructor },
{ &kNATIVE_FILEWATCHER_SERVICE_CID, false, nullptr, NativeFileWatcherServiceConstructor },
+#if defined(ENABLE_TESTS)
+ { &kNS_TELEMETRYGECKOVIEWTESTING_CID, false, nullptr, TelemetryGeckoViewTestingImplConstructor },
+#endif
{ nullptr }
};
static const Module::ContractIDEntry kToolkitContracts[] = {
{ NS_APPSTARTUP_CONTRACTID, &kNS_TOOLKIT_APPSTARTUP_CID },
#if defined(MOZ_HAS_TERMINATOR)
{ NS_TOOLKIT_TERMINATOR_CONTRACTID, &kNS_TOOLKIT_TERMINATOR_CID },
#endif
@@ -230,16 +244,19 @@ static const Module::ContractIDEntry kTo
#endif
{ FINALIZATIONWITNESSSERVICE_CONTRACTID, &kFINALIZATIONWITNESSSERVICE_CID },
{ NATIVE_OSFILE_INTERNALS_SERVICE_CONTRACTID, &kNATIVE_OSFILE_INTERNALS_SERVICE_CID },
{ NS_ADDONCONTENTPOLICY_CONTRACTID, &kNS_ADDONCONTENTPOLICY_CID },
{ NS_ADDONMANAGERSTARTUP_CONTRACTID, &kNS_ADDON_MANAGER_STARTUP_CID },
{ NS_ADDON_POLICY_SERVICE_CONTRACTID, &kNS_ADDON_POLICY_SERVICE_CID },
{ NS_SESSIONSTOREUTILS_CONTRACTID, &kNS_SESSIONSTOREUTILS_CID },
{ NATIVE_FILEWATCHER_SERVICE_CONTRACTID, &kNATIVE_FILEWATCHER_SERVICE_CID },
+#if defined(ENABLE_TESTS)
+ { NS_TELEMETRYGECKOVIEWTESTING_CONTRACTID, &kNS_TELEMETRYGECKOVIEWTESTING_CID },
+#endif
{ nullptr }
};
static const mozilla::Module::CategoryEntry kToolkitCategories[] = {
{ "content-policy", NS_ADDONCONTENTPOLICY_CONTRACTID, NS_ADDONCONTENTPOLICY_CONTRACTID },
{ nullptr }
};
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/geckoview/TelemetryGeckoViewTesting.cpp
@@ -0,0 +1,43 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "TelemetryGeckoViewTesting.h"
+#include "TelemetryGeckoViewPersistence.h"
+
+namespace TelemetryGeckoViewTesting {
+ // This is defined in TelemetryGeckoViewPersistence.cpp
+ void TestDispatchPersist();
+} // TelemetryGeckoViewTesting
+
+NS_IMPL_ISUPPORTS(TelemetryGeckoViewTestingImpl, nsITelemetryGeckoViewTesting)
+
+// We don't need |aCx|. It's there to make these test functions harder
+// to call from C++.
+NS_IMETHODIMP
+TelemetryGeckoViewTestingImpl::InitPersistence(JSContext*)
+{
+ TelemetryGeckoViewPersistence::InitPersistence();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+TelemetryGeckoViewTestingImpl::DeInitPersistence(JSContext*)
+{
+ TelemetryGeckoViewPersistence::DeInitPersistence();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+TelemetryGeckoViewTestingImpl::ClearPersistenceData(JSContext*)
+{
+ TelemetryGeckoViewPersistence::ClearPersistenceData();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+TelemetryGeckoViewTestingImpl::ForcePersist(JSContext*)
+{
+ TelemetryGeckoViewTesting::TestDispatchPersist();
+ return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/geckoview/TelemetryGeckoViewTesting.h
@@ -0,0 +1,14 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsITelemetryGeckoViewTesting.h"
+
+class TelemetryGeckoViewTestingImpl final : public nsITelemetryGeckoViewTesting
+{
+ ~TelemetryGeckoViewTestingImpl() = default;
+
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSITELEMETRYGECKOVIEWTESTING
+};
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/geckoview/nsITelemetryGeckoViewTesting.idl
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsISupports.idl"
+
+/**
+ * This is an internal interface used only for testing purposes.
+ *
+ * THIS IS NOT AN API TO BE USED BY EXTENSIONS! ONLY USED BY MOZILLA TESTS.
+ */
+[scriptable, builtinclass, uuid(019feb07-e5dd-48e6-aa59-fc98bcb65e7f)]
+interface nsITelemetryGeckoViewTesting : nsISupports
+{
+ /**
+ * The following methods map to the functions with the
+ * same name from TelemetryGeckoViewPersistence.cpp.
+ * Even though [implicit_jscontext] it's not needed on the methods,
+ * it's there to make it harder to call them from C++: this IDL is only
+ * meant to be used in xpcshell tests (JS).
+ */
+ [implicit_jscontext]
+ void initPersistence();
+ [implicit_jscontext]
+ void deInitPersistence();
+ [implicit_jscontext]
+ void clearPersistenceData();
+
+ /**
+ * Enqueues a persist action into the Telemetry persistence thread:
+ * measurements might be written to the disk after it returns.
+ */
+ [implicit_jscontext]
+ void forcePersist();
+};
--- a/toolkit/components/telemetry/moz.build
+++ b/toolkit/components/telemetry/moz.build
@@ -209,10 +209,21 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
# on platforms other than Android, since gtests on Android are not supported
# yet (see bug 1318091).
DEFINES['MOZ_TELEMETRY_GECKOVIEW'] = True
EXTRA_JS_MODULES += [
'geckoview/GeckoViewTelemetryController.jsm',
]
+# Include the GeckoView testing IDL if we're building tests
+# as well. This will be used in xpcshell tests.
+if CONFIG['ENABLE_TESTS']:
+ XPIDL_SOURCES += [
+ 'geckoview/nsITelemetryGeckoViewTesting.idl'
+ ]
+
+ SOURCES += [
+ 'geckoview/TelemetryGeckoViewTesting.cpp'
+ ]
+
with Files('**'):
BUG_COMPONENT = ('Toolkit', 'Telemetry')