Bug 1637562: Add test for ignoreExistingResources flag for document events. r=ochameau,jdescottes
authorDaisuke Akatsuka <daisuke@birchill.co.jp>
Wed, 20 May 2020 08:15:55 +0000
changeset 530969 c5b2ed837172140d6a2b0237250da2dcbfdfaa73
parent 530968 3d2af0d65f39995d6ebc017ffcc6e6797d1461dd
child 530970 6761e905feaf3c47c282a7337af802d2c98879aa
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, jdescottes
bugs1637562
milestone78.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 1637562: Add test for ignoreExistingResources flag for document events. r=ochameau,jdescottes Depends on D75747 Differential Revision: https://phabricator.services.mozilla.com/D75748
devtools/shared/resources/tests/browser_resources_document_events.js
--- a/devtools/shared/resources/tests/browser_resources_document_events.js
+++ b/devtools/shared/resources/tests/browser_resources_document_events.js
@@ -6,16 +6,18 @@
 // Test the ResourceWatcher API around DOCUMENT_EVENTS
 
 const { TargetList } = require("devtools/shared/resources/target-list");
 const {
   ResourceWatcher,
 } = require("devtools/shared/resources/resource-watcher");
 
 add_task(async function() {
+  info("Test ResourceWatcher for DOCUMENT_EVENTS");
+
   // Open a test tab
   const tab = await addTab("data:text/html,Document Events");
 
   // Create a TargetList for the test tab
   const client = await createLocalClient();
   const descriptor = await client.mainRoot.getTab({ tab });
   const target = await descriptor.getTarget();
   const targetList = new TargetList(client.mainRoot, target);
@@ -29,42 +31,75 @@ add_task(async function() {
     "Check whether the document events are fired correctly even when the document was already loaded"
   );
   const onLoadingAtInit = listener.once("dom-loading");
   const onInteractiveAtInit = listener.once("dom-interactive");
   const onCompleteAtInit = listener.once("dom-complete");
   await resourceWatcher.watch([ResourceWatcher.TYPES.DOCUMENT_EVENTS], {
     onAvailable: parameters => listener.dispatch(parameters),
   });
-  await assertEvents(onLoadingAtInit, onInteractiveAtInit, onCompleteAtInit);
+  await assertPromises(onLoadingAtInit, onInteractiveAtInit, onCompleteAtInit);
   ok(
     true,
     "Document events are fired even when the document was already loaded"
   );
 
   info("Check whether the document events are fired correctly when reloading");
   const onLoadingAtReloaded = listener.once("dom-loading");
   const onInteractiveAtReloaded = listener.once("dom-interactive");
   const onCompleteAtReloaded = listener.once("dom-complete");
   gBrowser.reloadTab(tab);
-  await assertEvents(
+  await assertPromises(
     onLoadingAtReloaded,
     onInteractiveAtReloaded,
     onCompleteAtReloaded
   );
   ok(true, "Document events are fired after reloading");
 
   await targetList.stopListening();
   await client.close();
 });
 
-async function assertEvents(onLoading, onInteractive, onComplete) {
+add_task(async function() {
+  info("Test ignoreExistingResources option for DOCUMENT_EVENTS");
+
+  const tab = await addTab("data:text/html,Document Events");
+
+  const {
+    client,
+    resourceWatcher,
+    targetList,
+  } = await initResourceWatcherAndTarget(tab);
+
+  info("Check whether the existing document events will not be fired");
+  const documentEvents = [];
+  await resourceWatcher.watch([ResourceWatcher.TYPES.DOCUMENT_EVENTS], {
+    onAvailable: ({ resource }) => documentEvents.push(resource),
+    ignoreExistingResources: true,
+  });
+  is(documentEvents.length, 0, "Existing document events are not fired");
+
+  info("Check whether the future document events are fired");
+  gBrowser.reloadTab(tab);
+  info("Wait for dom-loading, dom-interactive and dom-complete events");
+  await waitUntil(() => documentEvents.length === 3);
+  assertEvents(...documentEvents);
+
+  await targetList.stopListening();
+  await client.close();
+});
+
+async function assertPromises(onLoading, onInteractive, onComplete) {
   const loadingEvent = await onLoading;
   const interactiveEvent = await onInteractive;
   const completeEvent = await onComplete;
+  assertEvents(loadingEvent, interactiveEvent, completeEvent);
+}
+
+function assertEvents(loadingEvent, interactiveEvent, completeEvent) {
   is(
     typeof loadingEvent.time,
     "number",
     "Type of time attribute for loading event is correct"
   );
   is(
     typeof interactiveEvent.time,
     "number",