Bug 1492036 - Reporting API - part 5 - tests, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 14 Nov 2018 20:02:33 +0100
changeset 446484 3e311bf1af407110e07215872044d8451347ff8f
parent 446483 c200472121fd75104ec9deb50d03d57655f9e668
child 446485 ed3b5f933b97dc43e40fa153a03c4a55e830e7cf
push id35042
push useraiakab@mozilla.com
push dateThu, 15 Nov 2018 09:54:38 +0000
treeherdermozilla-central@dca9c72df68b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1492036
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1492036 - Reporting API - part 5 - tests, r=smaug
dom/base/DOMPrefsInternal.h
dom/base/nsDeprecatedOperationList.h
dom/locales/en-US/chrome/dom/dom.properties
dom/reporting/TestingDeprecatedInterface.cpp
dom/reporting/TestingDeprecatedInterface.h
dom/reporting/moz.build
dom/reporting/tests/mochitest.ini
dom/reporting/tests/test_deprecated.html
dom/webidl/Reporting.webidl
modules/libpref/init/StaticPrefList.h
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
--- a/dom/base/DOMPrefsInternal.h
+++ b/dom/base/DOMPrefsInternal.h
@@ -24,9 +24,10 @@ DOM_WEBIDL_PREF(dom_promise_rejection_ev
 DOM_WEBIDL_PREF(dom_push_enabled)
 DOM_WEBIDL_PREF(gfx_offscreencanvas_enabled)
 DOM_WEBIDL_PREF(dom_webkitBlink_dirPicker_enabled)
 DOM_WEBIDL_PREF(dom_netinfo_enabled)
 DOM_WEBIDL_PREF(dom_fetchObserver_enabled)
 DOM_WEBIDL_PREF(dom_enable_performance_observer)
 DOM_WEBIDL_PREF(dom_performance_enable_scheduler_timing)
 DOM_WEBIDL_PREF(dom_reporting_enabled)
+DOM_WEBIDL_PREF(dom_reporting_testing_enabled)
 DOM_WEBIDL_PREF(javascript_options_streams)
--- a/dom/base/nsDeprecatedOperationList.h
+++ b/dom/base/nsDeprecatedOperationList.h
@@ -39,12 +39,15 @@ DEPRECATED_OPERATION(MixedDisplayObjectS
 DEPRECATED_OPERATION(MotionEvent)
 DEPRECATED_OPERATION(OrientationEvent)
 DEPRECATED_OPERATION(ProximityEvent)
 DEPRECATED_OPERATION(AmbientLightEvent)
 DEPRECATED_OPERATION(IDBOpenDBOptions_StorageType)
 DEPRECATED_OPERATION(DOMAttrModifiedEvent)
 DEPRECATED_OPERATION(MozBoxOrInlineBoxDisplay)
 DEPRECATED_OPERATION(DOMQuadBoundsAttr)
+DEPRECATED_OPERATION(DeprecatedTestingInterface)
+DEPRECATED_OPERATION(DeprecatedTestingMethod)
+DEPRECATED_OPERATION(DeprecatedTestingAttribute)
 DEPRECATED_OPERATION(CreateImageBitmapCanvasRenderingContext2D)
 DEPRECATED_OPERATION(MozRequestFullScreenDeprecatedPrefix)
 DEPRECATED_OPERATION(MozfullscreenchangeDeprecatedPrefix)
 DEPRECATED_OPERATION(MozfullscreenerrorDeprecatedPrefix)
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -348,16 +348,23 @@ MixedDisplayObjectSubrequestWarning=Load
 MotionEventWarning=Use of the motion sensor is deprecated.
 OrientationEventWarning=Use of the orientation sensor is deprecated.
 ProximityEventWarning=Use of the proximity sensor is deprecated.
 AmbientLightEventWarning=Use of the ambient light sensor is deprecated.
 # LOCALIZATION NOTE: Do not translate "storage", "indexedDB.open" and "navigator.storage.persist()".
 IDBOpenDBOptions_StorageTypeWarning=The ‘storage’ attribute in options passed to indexedDB.open is deprecated and will soon be removed. To get persistent storage, please use navigator.storage.persist() instead.
 DOMQuadBoundsAttrWarning=DOMQuad.bounds is deprecated in favor of DOMQuad.getBounds()
 UnsupportedEntryTypesIgnored=Ignoring unsupported entryTypes: %S.
+
+#LOCALIZATION NOTE(DeprecatedTestingInterfaceWarning): Do not translate this message. It's just testing only.
+DeprecatedTestingInterfaceWarning=TestingDeprecatedInterface is a testing-only interface and this is its testing deprecation message.
+#LOCALIZATION NOTE(DeprecatedTestingMethodWarning): Do not translate this message. It's just testing only.
+DeprecatedTestingMethodWarning=TestingDeprecatedInterface.deprecatedMethod() is a testing-only method and this is its testing deprecation message.
+#LOCALIZATION NOTE(DeprecatedTestingAttributeWarning): Do not translate this message. It's just testing only.
+DeprecatedTestingAttributeWarning=TestingDeprecatedInterface.deprecatedAttribute is a testing-only attribute and this is its testing deprecation message.
 # LOCALIZATION NOTE (CreateImageBitmapCanvasRenderingContext2DWarning): Do not translate CanvasRenderingContext2D and createImageBitmap.
 CreateImageBitmapCanvasRenderingContext2DWarning=Use of CanvasRenderingContext2D in createImageBitmap is deprecated.
 # LOCALIZATION NOTE (MozRequestFullScreenDeprecatedPrefixWarning): Do not translate mozRequestFullScreen.
 MozRequestFullScreenDeprecatedPrefixWarning=mozRequestFullScreen() is deprecated.
 # LOCALIZATION NOTE (MozfullscreenchangeDeprecatedPrefixWarning): Do not translate onmozfullscreenchange.
 MozfullscreenchangeDeprecatedPrefixWarning=onmozfullscreenchange is deprecated.
 # LOCALIZATION NOTE (MozfullscreenerrorDeprecatedPrefixWarning): Do not translate onmozfullscreenerror.
 MozfullscreenerrorDeprecatedPrefixWarning=onmozfullscreenerror is deprecated.
new file mode 100644
--- /dev/null
+++ b/dom/reporting/TestingDeprecatedInterface.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "mozilla/dom/TestingDeprecatedInterface.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TestingDeprecatedInterface, mGlobal)
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(TestingDeprecatedInterface)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(TestingDeprecatedInterface)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TestingDeprecatedInterface)
+  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+/* static */ already_AddRefed<TestingDeprecatedInterface>
+TestingDeprecatedInterface::Constructor(const GlobalObject& aGlobal,
+                                        ErrorResult& aRv)
+{
+  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
+  MOZ_ASSERT(global);
+
+  RefPtr<TestingDeprecatedInterface> obj =
+    new TestingDeprecatedInterface(global);
+  return obj.forget();
+}
+
+TestingDeprecatedInterface::TestingDeprecatedInterface(nsIGlobalObject* aGlobal)
+  : mGlobal(aGlobal)
+{}
+
+
+TestingDeprecatedInterface::~TestingDeprecatedInterface() = default;
+
+JSObject*
+TestingDeprecatedInterface::WrapObject(JSContext* aCx,
+                                       JS::Handle<JSObject*> aGivenProto)
+{
+  return TestingDeprecatedInterface_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+void
+TestingDeprecatedInterface::DeprecatedMethod() const
+{}
+
+bool
+TestingDeprecatedInterface::DeprecatedAttribute() const
+{
+  return true;
+}
+
+} // dom namespace
+} // mozilla namespace
new file mode 100644
--- /dev/null
+++ b/dom/reporting/TestingDeprecatedInterface.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#ifndef mozilla_dom_TestingDeprecatedInterface_h
+#define mozilla_dom_TestingDeprecatedInterface_h
+
+#include "mozilla/Attributes.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsWrapperCache.h"
+
+namespace mozilla {
+namespace dom {
+
+class TestingDeprecatedInterface final : public nsISupports
+                                       , public nsWrapperCache
+{
+public:
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TestingDeprecatedInterface)
+
+  static already_AddRefed<TestingDeprecatedInterface>
+  Constructor(const GlobalObject& aGlobal,
+              ErrorResult& aRv);
+
+  JSObject*
+  WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+  nsIGlobalObject*
+  GetParentObject() const
+  {
+    return mGlobal;
+  }
+
+  void
+  DeprecatedMethod() const;
+
+  bool
+  DeprecatedAttribute() const;
+
+private:
+  explicit TestingDeprecatedInterface(nsIGlobalObject* aGlobal);
+  ~TestingDeprecatedInterface();
+
+  nsCOMPtr<nsIGlobalObject> mGlobal;
+};
+
+} // dom namespace
+} // mozilla namespace
+
+#endif // mozilla_dom_TestingDeprecatedInterface_h
+
--- a/dom/reporting/moz.build
+++ b/dom/reporting/moz.build
@@ -5,24 +5,28 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS.mozilla.dom = [
     'DeprecationReportBody.h',
     'Report.h',
     'ReportBody.h',
     'ReportingObserver.h',
     'ReportingUtils.h',
+    'TestingDeprecatedInterface.h',
 ]
 
 UNIFIED_SOURCES += [
     'DeprecationReportBody.cpp',
     'Report.cpp',
     'ReportBody.cpp',
     'ReportingObserver.cpp',
     'ReportingUtils.cpp',
+    'TestingDeprecatedInterface.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 with Files('**'):
     BUG_COMPONENT = ('DOM', 'Security')
 
 FINAL_LIBRARY = 'xul'
+
+MOCHITEST_MANIFESTS += ['tests/mochitest.ini']
new file mode 100644
--- /dev/null
+++ b/dom/reporting/tests/mochitest.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+prefs =
+  dom.reporting.enabled=true
+  dom.reporting.testing.enabled=true
+
+[test_deprecated.html]
new file mode 100644
--- /dev/null
+++ b/dom/reporting/tests/test_deprecated.html
@@ -0,0 +1,143 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test for Deprecated reports</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript">
+
+let testingInterface;
+
+(new Promise(resolve => {
+  info("Testing DeprecatedTestingInterface report");
+  let obs = new ReportingObserver((reports, o) => {
+    is(obs, o, "Same observer!");
+    ok(reports.length == 1, "We have 1 report");
+
+    let report = reports[0];
+    is(report.type, "deprecation", "Deprecation report received");
+    is(report.url, location.href, "URL is window.location");
+    ok(!!report.body, "The report has a body");
+    ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
+    is(report.body.id, "DeprecatedTestingInterface", "report.body.id matches DeprecatedTestingMethod");
+    ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
+    ok(report.body.message.includes("TestingDeprecatedInterface"), "We have a message");
+    is(report.body.sourceFile, location.href, "We have a sourceFile");
+    is(report.body.lineNumber, 40, "We have a lineNumber");
+    is(report.body.columnNumber, 21, "We have a columnNumber");
+
+    obs.disconnect();
+    resolve();
+  });
+  ok(!!obs, "ReportingObserver is a thing");
+
+  obs.observe();
+  ok(true, "ReportingObserver.observe() is callable");
+
+  testingInterface = new TestingDeprecatedInterface();
+  ok(true, "Created a deprecated interface");
+}))
+
+.then(() => {
+  info("Testing DeprecatedTestingMethod report");
+  return new Promise(resolve => {
+    let obs = new ReportingObserver((reports, o) => {
+      is(obs, o, "Same observer!");
+      ok(reports.length == 1, "We have 1 report");
+
+      let report = reports[0];
+      is(report.type, "deprecation", "Deprecation report received");
+      is(report.url, location.href, "URL is window.location");
+      ok(!!report.body, "The report has a body");
+      ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
+      is(report.body.id, "DeprecatedTestingMethod", "report.body.id matches DeprecatedTestingMethod");
+      ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
+      ok(report.body.message.includes("TestingDeprecatedInterface.deprecatedMethod"), "We have a message");
+      is(report.body.sourceFile, location.href, "We have a sourceFile");
+      is(report.body.lineNumber, 71, "We have a lineNumber");
+      is(report.body.columnNumber, 4, "We have a columnNumber");
+
+      obs.disconnect();
+      resolve();
+    });
+    ok(!!obs, "ReportingObserver is a thing");
+
+    obs.observe();
+    ok(true, "ReportingObserver.observe() is callable");
+
+    testingInterface.deprecatedMethod();
+    ok(true, "Run a deprecated method.");
+  });
+})
+
+.then(() => {
+  info("Testing DeprecatedTestingAttribute report");
+  return new Promise(resolve => {
+    let obs = new ReportingObserver((reports, o) => {
+      is(obs, o, "Same observer!");
+      ok(reports.length == 1, "We have 1 report");
+
+      let report = reports[0];
+      is(report.type, "deprecation", "Deprecation report received");
+      is(report.url, location.href, "URL is window.location");
+      ok(!!report.body, "The report has a body");
+      ok(report.body instanceof DeprecationReportBody, "Correct type for the body");
+      is(report.body.id, "DeprecatedTestingAttribute", "report.body.id matches DeprecatedTestingAttribute");
+      ok(!report.body.anticipatedRemoval, "We don't have a anticipatedRemoval");
+      ok(report.body.message.includes("TestingDeprecatedInterface.deprecatedAttribute"), "We have a message");
+      is(report.body.sourceFile, location.href, "We have a sourceFile");
+      is(report.body.lineNumber, 103, "We have a lineNumber");
+      is(report.body.columnNumber, 4, "We have a columnNumber");
+
+      obs.disconnect();
+      resolve();
+    });
+    ok(!!obs, "ReportingObserver is a thing");
+
+    obs.observe();
+    ok(true, "ReportingObserver.observe() is callable");
+
+    ok(testingInterface.deprecatedAttribute, "Attributed called");
+  });
+})
+
+.then(() => {
+  info("Testing ReportingObserver.takeRecords()");
+  let p = new Promise(resolve => {
+    let obs = new ReportingObserver((reports, o) => {
+      is(obs, o, "Same observer!");
+      resolve(obs);
+    });
+    ok(!!obs, "ReportingObserver is a thing");
+
+    obs.observe();
+    ok(true, "ReportingObserver.observe() is callable");
+
+    testingInterface.deprecatedMethod();
+    ok(true, "Run a deprecated method.");
+  });
+
+  return p.then(obs => {
+    let reports = obs.takeRecords();
+    is(reports.length, 0, "No reports after an callback");
+
+    testingInterface.deprecatedAttribute + 1;
+
+    reports = obs.takeRecords();
+    ok(reports.length >= 1, "We have at least 1 report");
+
+    reports = obs.takeRecords();
+    is(reports.length, 0, "No more reports");
+  });
+})
+
+.then(() => { SimpleTest.finish(); });
+
+SimpleTest.waitForExplicitFinish();
+
+</script>
+</body>
+</html>
--- a/dom/webidl/Reporting.webidl
+++ b/dom/webidl/Reporting.webidl
@@ -39,8 +39,19 @@ typedef sequence<Report> ReportList;
 interface DeprecationReportBody : ReportBody {
   readonly attribute DOMString id;
   readonly attribute Date? anticipatedRemoval;
   readonly attribute DOMString message;
   readonly attribute DOMString? sourceFile;
   readonly attribute unsigned long? lineNumber;
   readonly attribute unsigned long? columnNumber;
 };
+
+[Constructor(), Deprecated="DeprecatedTestingInterface",
+ Func="mozilla::dom::DOMPrefs::dom_reporting_testing_enabled",
+ Exposed=(Window,DedicatedWorker)]
+interface TestingDeprecatedInterface {
+  [Deprecated="DeprecatedTestingMethod"]
+  void deprecatedMethod();
+
+  [Deprecated="DeprecatedTestingAttribute"]
+  readonly attribute boolean deprecatedAttribute;
+};
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -1785,13 +1785,19 @@ VARCACHE_PREF(
 //---------------------------------------------------------------------------
 
 VARCACHE_PREF(
   "dom.reporting.enabled",
    dom_reporting_enabled,
   RelaxedAtomicBool, false
 )
 
+VARCACHE_PREF(
+  "dom.reporting.testing.enabled",
+   dom_reporting_testing_enabled,
+  RelaxedAtomicBool, false
+)
+
 //---------------------------------------------------------------------------
 // End of prefs
 //---------------------------------------------------------------------------
 
 // clang-format on
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -30,16 +30,17 @@ module.exports = {
     "ChromeWorker": false,
     "Ci": false,
     "Components": false,
     "Cr": false,
     "Cu": false,
     "DOMRequest": false,
     "Debugger": false,
     "DedicatedWorkerGlobalScope": false,
+    "DeprecationReportBody": false,
     "DominatorTree": false,
     "HeapSnapshot": false,
     "IDBFileRequest": false,
     "IDBLocaleAwareKeyRange": false,
     "IDBMutableFile": false,
     "ImageDocument": false,
     "InstallTrigger": false,
     // Specific to Firefox
@@ -52,24 +53,26 @@ module.exports = {
     "MatchPatternSet": false,
     "MenuBoxObject": false,
     // Specific to Firefox (Chrome code only).
     "PlacesBookmarkAddition": false,
     "PlacesEvent": false,
     "PlacesObservers": false,
     "PlacesWeakCallbackWrapper": false,
     "PrioEncoder": false,
+    "ReportingObserver": false,
     // Specific to Firefox (Chrome code only).
     "SharedArrayBuffer": false,
     "SimpleGestureEvent": false,
     // Note: StopIteration will likely be removed as part of removing legacy
     // generators, see bug 968038.
     "StopIteration": false,
     "StructuredCloneHolder": false,
     "TelemetryStopwatch": false,
+    "TestingDeprecatedInterface": false,
     "WebAssembly": false,
     "WebExtensionContentScript": false,
     "WebExtensionPolicy": false,
     "WebrtcGlobalInformation": false,
     // Non-standard, specific to Firefox.
     "XULElement": false,
     "console": true,
     "dump": true,