From 550a3cb3f453d8d43927295dd5674ae620de6f1c Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Wed, 27 May 2020 13:08:14 +0000 Subject: [PATCH] Bug 1641151 - Rename ResourceWatcher TYPES to their singular counterpart. r=jdescottes. Differential Revision: https://phabricator.services.mozilla.com/D77030 --- .../src/connector/firefox-connector.js | 6 ++--- .../browser_webconsole_stubs_console_api.js | 4 +-- .../browser_webconsole_stubs_css_message.js | 4 +-- .../browser_webconsole_stubs_page_error.js | 2 +- devtools/client/webconsole/webconsole-ui.js | 14 +++++----- devtools/shared/resources/resource-watcher.js | 20 +++++++------- .../browser_resources_console_messages.js | 10 +++---- .../browser_resources_document_events.js | 26 +++++++------------ .../tests/browser_resources_error_messages.js | 8 +++--- .../browser_resources_platform_messages.js | 8 +++--- .../browser_resources_several_resources.js | 20 +++++++------- 11 files changed, 58 insertions(+), 64 deletions(-) diff --git a/devtools/client/netmonitor/src/connector/firefox-connector.js b/devtools/client/netmonitor/src/connector/firefox-connector.js index dcf6176c6b17..e84d6c561666 100644 --- a/devtools/client/netmonitor/src/connector/firefox-connector.js +++ b/devtools/client/netmonitor/src/connector/firefox-connector.js @@ -74,7 +74,7 @@ class FirefoxConnector { ); await this.toolbox.resourceWatcher.watchResources( - [this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENTS], + [this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT], { onAvailable: this.onResourceAvailable } ); } @@ -93,7 +93,7 @@ class FirefoxConnector { ); this.toolbox.resourceWatcher.unwatchResources( - [this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENTS], + [this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT], { onAvailable: this.onResourceAvailable } ); @@ -154,7 +154,7 @@ class FirefoxConnector { } async onResourceAvailable({ resourceType, targetFront, resource }) { - if (resourceType === this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENTS) { + if (resourceType === this.toolbox.resourceWatcher.TYPES.DOCUMENT_EVENT) { this.onDocEvent(resource); } } diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_console_api.js b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_console_api.js index d10ba8dea541..858ce2ead02e 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_console_api.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_console_api.js @@ -77,7 +77,7 @@ async function generateConsoleApiStubs() { handleConsoleMessage(resource); }; await resourceWatcher.watchResources( - [resourceWatcher.TYPES.CONSOLE_MESSAGES], + [resourceWatcher.TYPES.CONSOLE_MESSAGE], { onAvailable: onConsoleMessage, } @@ -112,7 +112,7 @@ async function generateConsoleApiStubs() { await received; } - resourceWatcher.unwatchResources([resourceWatcher.TYPES.CONSOLE_MESSAGES], { + resourceWatcher.unwatchResources([resourceWatcher.TYPES.CONSOLE_MESSAGE], { onAvailable: onConsoleMessage, }); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_css_message.js b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_css_message.js index 4bfe7c8c1cee..b134465c2395 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_css_message.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_css_message.js @@ -76,7 +76,7 @@ async function generateCssMessageStubs() { }; /* CSS errors are considered as pageError on the server */ - await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGES], { + await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGE], { onAvailable: onErrorMessageAvailable, }); @@ -101,7 +101,7 @@ async function generateCssMessageStubs() { await received; } - resourceWatcher.unwatchResources([resourceWatcher.TYPES.ERROR_MESSAGES], { + resourceWatcher.unwatchResources([resourceWatcher.TYPES.ERROR_MESSAGE], { onAvailable: onErrorMessageAvailable, }); diff --git a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_page_error.js b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_page_error.js index 9577825568b8..4c26d51c5fd4 100644 --- a/devtools/client/webconsole/test/browser/browser_webconsole_stubs_page_error.js +++ b/devtools/client/webconsole/test/browser/browser_webconsole_stubs_page_error.js @@ -77,7 +77,7 @@ async function generatePageErrorStubs() { const onErrorMessageAvailable = ({ resource }) => { handleErrorMessage(resource); }; - await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGES], { + await resourceWatcher.watchResources([resourceWatcher.TYPES.ERROR_MESSAGE], { onAvailable: onErrorMessageAvailable, }); diff --git a/devtools/client/webconsole/webconsole-ui.js b/devtools/client/webconsole/webconsole-ui.js index 5d2135bc742d..bce9bc982c6e 100644 --- a/devtools/client/webconsole/webconsole-ui.js +++ b/devtools/client/webconsole/webconsole-ui.js @@ -198,7 +198,7 @@ class WebConsoleUI { // TODO: Re-enable as part of Bug 1627167. // const resourceWatcher = this.hud.resourceWatcher; // resourceWatcher.unwatchResources( - // [resourceWatcher.TYPES.CONSOLE_MESSAGES], + // [resourceWatcher.TYPES.CONSOLE_MESSAGE], // this._onResourceAvailable // ); @@ -334,9 +334,9 @@ class WebConsoleUI { const resourceWatcher = this.hud.resourceWatcher; await resourceWatcher.watchResources( [ - resourceWatcher.TYPES.CONSOLE_MESSAGES, - resourceWatcher.TYPES.ERROR_MESSAGES, - resourceWatcher.TYPES.PLATFORM_MESSAGES, + resourceWatcher.TYPES.CONSOLE_MESSAGE, + resourceWatcher.TYPES.ERROR_MESSAGE, + resourceWatcher.TYPES.PLATFORM_MESSAGE, ], { onAvailable: this._onResourceAvailable } ); @@ -344,7 +344,7 @@ class WebConsoleUI { _onResourceAvailable({ resourceType, targetFront, resource }) { const resourceWatcher = this.hud.resourceWatcher; - if (resourceType == resourceWatcher.TYPES.CONSOLE_MESSAGES) { + if (resourceType == resourceWatcher.TYPES.CONSOLE_MESSAGE) { // resource is the packet sent from `ConsoleActor.getCachedMessages().messages` // or via ConsoleActor's `consoleAPICall` event. resource.type = "consoleAPICall"; @@ -352,7 +352,7 @@ class WebConsoleUI { return; } - if (resourceType == resourceWatcher.TYPES.ERROR_MESSAGES) { + if (resourceType == resourceWatcher.TYPES.ERROR_MESSAGE) { // resource is the packet sent from `ConsoleActor.getCachedMessages().messages` // or via ConsoleActor's `pageError` event. resource.type = "pageError"; @@ -360,7 +360,7 @@ class WebConsoleUI { return; } - if (resourceType == resourceWatcher.TYPES.PLATFORM_MESSAGES) { + if (resourceType == resourceWatcher.TYPES.PLATFORM_MESSAGE) { // resource is the packet sent from `ConsoleActor.getCachedMessages().messages` // or via ConsoleActor's `logMessage` event. resource.type = "logMessage"; diff --git a/devtools/shared/resources/resource-watcher.js b/devtools/shared/resources/resource-watcher.js index dc957f342d8c..b22877a8d4d0 100644 --- a/devtools/shared/resources/resource-watcher.js +++ b/devtools/shared/resources/resource-watcher.js @@ -245,7 +245,7 @@ class ResourceWatcher { */ async _startListening(resourceType) { const isDocumentEvent = - resourceType === ResourceWatcher.TYPES.DOCUMENT_EVENTS; + resourceType === ResourceWatcher.TYPES.DOCUMENT_EVENT; let listeners = this._listenerCount.get(resourceType) || 0; listeners++; @@ -253,7 +253,7 @@ class ResourceWatcher { // If there are several calls to watch, only the first caller receives // "existing" resources. Throw to avoid inconsistent behaviors if (isDocumentEvent) { - // For DOCUMENT_EVENTS, return without throwing because this is already + // For DOCUMENT_EVENT, return without throwing because this is already // used by several callsites in the netmonitor. // This should be reviewed in Bug 1625909. this._listenerCount.set(resourceType, listeners); @@ -356,10 +356,10 @@ class ResourceWatcher { } ResourceWatcher.TYPES = ResourceWatcher.prototype.TYPES = { - CONSOLE_MESSAGES: "console-messages", - ERROR_MESSAGES: "error-messages", - PLATFORM_MESSAGES: "platform-messages", - DOCUMENT_EVENTS: "document-events", + CONSOLE_MESSAGE: "console-message", + ERROR_MESSAGE: "error-message", + PLATFORM_MESSAGE: "platform-message", + DOCUMENT_EVENT: "document-event", ROOT_NODE: "root-node", }; module.exports = { ResourceWatcher }; @@ -369,12 +369,12 @@ module.exports = { ResourceWatcher }; // code is implement in Firefox, in its release channel. const LegacyListeners = { [ResourceWatcher.TYPES - .CONSOLE_MESSAGES]: require("devtools/shared/resources/legacy-listeners/console-messages"), + .CONSOLE_MESSAGE]: require("devtools/shared/resources/legacy-listeners/console-messages"), [ResourceWatcher.TYPES - .ERROR_MESSAGES]: require("devtools/shared/resources/legacy-listeners/error-messages"), + .ERROR_MESSAGE]: require("devtools/shared/resources/legacy-listeners/error-messages"), [ResourceWatcher.TYPES - .PLATFORM_MESSAGES]: require("devtools/shared/resources/legacy-listeners/platform-messages"), - async [ResourceWatcher.TYPES.DOCUMENT_EVENTS]({ + .PLATFORM_MESSAGE]: require("devtools/shared/resources/legacy-listeners/platform-messages"), + async [ResourceWatcher.TYPES.DOCUMENT_EVENT]({ targetList, targetFront, onAvailable, diff --git a/devtools/shared/resources/tests/browser_resources_console_messages.js b/devtools/shared/resources/tests/browser_resources_console_messages.js index 3b260cdce763..ac47d06c061b 100644 --- a/devtools/shared/resources/tests/browser_resources_console_messages.js +++ b/devtools/shared/resources/tests/browser_resources_console_messages.js @@ -3,7 +3,7 @@ "use strict"; -// Test the ResourceWatcher API around CONSOLE_MESSAGES +// Test the ResourceWatcher API around CONSOLE_MESSAGE // // Reproduces assertions from: devtools/shared/webconsole/test/chrome/test_cached_messages.html @@ -29,7 +29,7 @@ add_task(async function() { }); add_task(async function() { - info("Test ignoreExistingResources option for CONSOLE_MESSAGES"); + info("Test ignoreExistingResources option for CONSOLE_MESSAGE"); const tab = await addTab("data:text/html,Console Messages"); @@ -46,7 +46,7 @@ add_task(async function() { const availableResources = []; await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.CONSOLE_MESSAGES], + [ResourceWatcher.TYPES.CONSOLE_MESSAGE], { onAvailable: ({ resource }) => availableResources.push(resource), ignoreExistingResources: true, @@ -94,7 +94,7 @@ async function testMessages(browser, resourceWatcher) { const onAvailable = ({ resourceType, targetFront, resource }) => { is( resourceType, - ResourceWatcher.TYPES.CONSOLE_MESSAGES, + ResourceWatcher.TYPES.CONSOLE_MESSAGE, "Received a message" ); ok(resource.message, "message is wrapped into a message attribute"); @@ -109,7 +109,7 @@ async function testMessages(browser, resourceWatcher) { }; await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.CONSOLE_MESSAGES], + [ResourceWatcher.TYPES.CONSOLE_MESSAGE], { onAvailable, } diff --git a/devtools/shared/resources/tests/browser_resources_document_events.js b/devtools/shared/resources/tests/browser_resources_document_events.js index 6541ef5bf8fb..bd31e982fa4b 100644 --- a/devtools/shared/resources/tests/browser_resources_document_events.js +++ b/devtools/shared/resources/tests/browser_resources_document_events.js @@ -3,7 +3,7 @@ "use strict"; -// Test the ResourceWatcher API around DOCUMENT_EVENTS +// Test the ResourceWatcher API around DOCUMENT_EVENT const { TargetList } = require("devtools/shared/resources/target-list"); const { @@ -11,7 +11,7 @@ const { } = require("devtools/shared/resources/resource-watcher"); add_task(async function() { - info("Test ResourceWatcher for DOCUMENT_EVENTS"); + info("Test ResourceWatcher for DOCUMENT_EVENT"); // Open a test tab const tab = await addTab("data:text/html,Document Events"); @@ -33,12 +33,9 @@ add_task(async function() { const onLoadingAtInit = listener.once("dom-loading"); const onInteractiveAtInit = listener.once("dom-interactive"); const onCompleteAtInit = listener.once("dom-complete"); - await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.DOCUMENT_EVENTS], - { - onAvailable: parameters => listener.dispatch(parameters), - } - ); + await resourceWatcher.watchResources([ResourceWatcher.TYPES.DOCUMENT_EVENT], { + onAvailable: parameters => listener.dispatch(parameters), + }); await assertPromises(onLoadingAtInit, onInteractiveAtInit, onCompleteAtInit); ok( true, @@ -62,7 +59,7 @@ add_task(async function() { }); add_task(async function() { - info("Test ignoreExistingResources option for DOCUMENT_EVENTS"); + info("Test ignoreExistingResources option for DOCUMENT_EVENT"); const tab = await addTab("data:text/html,Document Events"); @@ -74,13 +71,10 @@ add_task(async function() { info("Check whether the existing document events will not be fired"); const documentEvents = []; - await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.DOCUMENT_EVENTS], - { - onAvailable: ({ resource }) => documentEvents.push(resource), - ignoreExistingResources: true, - } - ); + await resourceWatcher.watchResources([ResourceWatcher.TYPES.DOCUMENT_EVENT], { + 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"); diff --git a/devtools/shared/resources/tests/browser_resources_error_messages.js b/devtools/shared/resources/tests/browser_resources_error_messages.js index b19da79ce9a4..29763a0bde1a 100644 --- a/devtools/shared/resources/tests/browser_resources_error_messages.js +++ b/devtools/shared/resources/tests/browser_resources_error_messages.js @@ -3,7 +3,7 @@ "use strict"; -// Test the ResourceWatcher API around ERROR_MESSAGES +// Test the ResourceWatcher API around ERROR_MESSAGE // Reproduces assertions from devtools/shared/webconsole/test/chrome/test_page_errors.html const { @@ -74,7 +74,7 @@ add_task(async function() { } }; - await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGES], { + await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], { onAvailable, }); @@ -97,7 +97,7 @@ add_task(async function() { }); add_task(async function() { - info("Test ignoreExistingResources option for ERROR_MESSAGES"); + info("Test ignoreExistingResources option for ERROR_MESSAGE"); // Disable the preloaded process as it creates processes intermittently // which forces the emission of RDP requests we aren't correctly waiting for. @@ -117,7 +117,7 @@ add_task(async function() { await triggerErrors(tab); const availableResources = []; - await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGES], { + await resourceWatcher.watchResources([ResourceWatcher.TYPES.ERROR_MESSAGE], { onAvailable: ({ resource }) => availableResources.push(resource), ignoreExistingResources: true, }); diff --git a/devtools/shared/resources/tests/browser_resources_platform_messages.js b/devtools/shared/resources/tests/browser_resources_platform_messages.js index 701ec68c701a..e47665831093 100644 --- a/devtools/shared/resources/tests/browser_resources_platform_messages.js +++ b/devtools/shared/resources/tests/browser_resources_platform_messages.js @@ -3,7 +3,7 @@ "use strict"; -// Test the ResourceWatcher API around PLATFORM_MESSAGES +// Test the ResourceWatcher API around PLATFORM_MESSAGE // Reproduces assertions from: devtools/shared/webconsole/test/chrome/test_nsiconsolemessage.html const { @@ -66,7 +66,7 @@ add_task(async function() { }; await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.PLATFORM_MESSAGES], + [ResourceWatcher.TYPES.PLATFORM_MESSAGE], { onAvailable, } @@ -88,7 +88,7 @@ add_task(async function() { }); add_task(async function() { - info("Test ignoreExistingResources option for PLATFORM_MESSAGES"); + info("Test ignoreExistingResources option for PLATFORM_MESSAGE"); // Disable the preloaded process as it creates processes intermittently // which forces the emission of RDP requests we aren't correctly waiting for. @@ -109,7 +109,7 @@ add_task(async function() { const availableResources = []; await resourceWatcher.watchResources( - [ResourceWatcher.TYPES.PLATFORM_MESSAGES], + [ResourceWatcher.TYPES.PLATFORM_MESSAGE], { onAvailable: ({ resource }) => { if (!expectedMessages.includes(resource.message)) { diff --git a/devtools/shared/resources/tests/browser_resources_several_resources.js b/devtools/shared/resources/tests/browser_resources_several_resources.js index 1fd5feea26d3..e275021bcf66 100644 --- a/devtools/shared/resources/tests/browser_resources_several_resources.js +++ b/devtools/shared/resources/tests/browser_resources_several_resources.js @@ -28,25 +28,25 @@ add_task(async function() { targetList, } = await initResourceWatcherAndTarget(); - const { CONSOLE_MESSAGES, ROOT_NODE } = ResourceWatcher.TYPES; + const { CONSOLE_MESSAGE, ROOT_NODE } = ResourceWatcher.TYPES; // We are only interested in console messages as a resource, the ROOT_NODE one // is here to test the ResourceWatcher::unwatchResources API with several resources. let receivedMessages = 0; const onAvailable = ({ resourceType }) => { - if (resourceType === CONSOLE_MESSAGES) { + if (resourceType === CONSOLE_MESSAGE) { receivedMessages++; } }; - info("Call watchResources([CONSOLE_MESSAGES, ROOT_NODE], ...)"); - await resourceWatcher.watchResources([CONSOLE_MESSAGES, ROOT_NODE], { + info("Call watchResources([CONSOLE_MESSAGE, ROOT_NODE], ...)"); + await resourceWatcher.watchResources([CONSOLE_MESSAGE, ROOT_NODE], { onAvailable, }); info("Use console.log in the content page"); logInTab(tab, "test"); - info("Wait until onAvailable received 1 resource of type CONSOLE_MESSAGES"); + info("Wait until onAvailable received 1 resource of type CONSOLE_MESSAGE"); await waitUntil(() => receivedMessages === 1); // Check that the resource watcher captures resources from new targets. @@ -56,7 +56,7 @@ add_task(async function() { ); info("Use console.log in the example.com page"); logInTab(comTab, "test-from-example-com"); - info("Wait until onAvailable received 2 resources of type CONSOLE_MESSAGES"); + info("Wait until onAvailable received 2 resources of type CONSOLE_MESSAGE"); await waitUntil(() => receivedMessages === 2); info("Stop watching ROOT_NODE resources"); @@ -70,11 +70,11 @@ add_task(async function() { ); info("Use console.log in the example.net page"); logInTab(netTab, "test-from-example-net"); - info("Wait until onAvailable received 3 resources of type CONSOLE_MESSAGES"); + info("Wait until onAvailable received 3 resources of type CONSOLE_MESSAGE"); await waitUntil(() => receivedMessages === 3); - info("Stop watching CONSOLE_MESSAGES resources"); - await resourceWatcher.unwatchResources([CONSOLE_MESSAGES], { onAvailable }); + info("Stop watching CONSOLE_MESSAGE resources"); + await resourceWatcher.unwatchResources([CONSOLE_MESSAGE], { onAvailable }); await logInTab(tab, "test-again"); // We don't have a specific event to wait for here, so allow some time for @@ -84,7 +84,7 @@ add_task(async function() { is( receivedMessages, 3, - "The resource watcher should not watch CONSOLE_MESSAGES anymore" + "The resource watcher should not watch CONSOLE_MESSAGE anymore" ); // Cleanup