Bug 1637562: Add test for ignoreExistingResources flag for console messages. r=ochameau,nchevobbe
authorDaisuke Akatsuka <daisuke@birchill.co.jp>
Wed, 20 May 2020 08:16:04 +0000
changeset 530970 6761e905feaf3c47c282a7337af802d2c98879aa
parent 530969 c5b2ed837172140d6a2b0237250da2dcbfdfaa73
child 530971 44167342f7f064dfb2966c259401775221df3086
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, nchevobbe
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 console messages. r=ochameau,nchevobbe Depends on D75748 Differential Revision: https://phabricator.services.mozilla.com/D75749
devtools/shared/resources/tests/browser_resources_console_messages.js
--- a/devtools/shared/resources/tests/browser_resources_console_messages.js
+++ b/devtools/shared/resources/tests/browser_resources_console_messages.js
@@ -23,60 +23,106 @@ add_task(async function() {
   } = await initResourceWatcherAndTarget(tab);
 
   await testMessages(tab.linkedBrowser, resourceWatcher);
 
   targetList.stopListening();
   await client.close();
 });
 
+add_task(async function() {
+  info("Test ignoreExistingResources option for CONSOLE_MESSAGES");
+
+  const tab = await addTab("data:text/html,Console Messages");
+
+  const {
+    client,
+    resourceWatcher,
+    targetList,
+  } = await initResourceWatcherAndTarget(tab);
+
+  info(
+    "Check whether onAvailable will not be called with existing console messages"
+  );
+  await logExistingMessages(tab.linkedBrowser);
+
+  const availableResources = [];
+  await resourceWatcher.watch([ResourceWatcher.TYPES.CONSOLE_MESSAGES], {
+    onAvailable: ({ resource }) => availableResources.push(resource),
+    ignoreExistingResources: true,
+  });
+  is(
+    availableResources.length,
+    0,
+    "onAvailable wasn't called for existing console messages"
+  );
+
+  info(
+    "Check whether onAvailable will be called with the future console messages"
+  );
+  await logRuntimeMessages(tab.linkedBrowser);
+  await waitUntil(
+    () => availableResources.length === expectedRuntimeConsoleCalls.length
+  );
+  for (let i = 0; i < expectedRuntimeConsoleCalls.length; i++) {
+    const { message } = availableResources[i];
+    const expected = expectedRuntimeConsoleCalls[i];
+    checkConsoleAPICall(message, expected);
+  }
+
+  await targetList.stopListening();
+  await client.close();
+});
+
 async function testMessages(browser, resourceWatcher) {
   info(
     "Log some messages *before* calling ResourceWatcher.watch in order to assert the behavior of already existing messages."
   );
   await logExistingMessages(browser);
 
   let runtimeDoneResolve;
+  const expectedExistingCalls = [...expectedExistingConsoleCalls];
+  const expectedRuntimeCalls = [...expectedRuntimeConsoleCalls];
   const onRuntimeDone = new Promise(resolve => (runtimeDoneResolve = resolve));
   const onAvailable = ({ resourceType, targetFront, resource }) => {
     is(
       resourceType,
       ResourceWatcher.TYPES.CONSOLE_MESSAGES,
       "Received a message"
     );
     ok(resource.message, "message is wrapped into a message attribute");
-    const expected = (expectedExistingConsoleCalls.length > 0
-      ? expectedExistingConsoleCalls
-      : expectedRuntimeConsoleCalls
+    const expected = (expectedExistingCalls.length > 0
+      ? expectedExistingCalls
+      : expectedRuntimeCalls
     ).shift();
     checkConsoleAPICall(resource.message, expected);
-    if (expectedRuntimeConsoleCalls.length == 0) {
+    if (expectedRuntimeCalls.length == 0) {
       runtimeDoneResolve();
     }
   };
 
   await resourceWatcher.watch([ResourceWatcher.TYPES.CONSOLE_MESSAGES], {
     onAvailable,
   });
   is(
-    expectedExistingConsoleCalls.length,
+    expectedExistingCalls.length,
     0,
     "Got the expected number of existing messages"
   );
 
   info(
     "Now log messages *after* the call to ResourceWatcher.watch and after having received all existing messages"
   );
   await logRuntimeMessages(browser);
 
   info("Waiting for all runtime messages");
   await onRuntimeDone;
 
   is(
-    expectedRuntimeConsoleCalls.length,
+    expectedRuntimeCalls.length,
     0,
     "Got the expected number of runtime messages"
   );
 }
 
 // For both existing and runtime messages, we execute console API
 // from a frame script evaluated via ContentTask.
 // Records here the filename used by ContentTask and the function