forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1627977 - Use the ResourceWatcher API to fetch ConsoleService Log…
…Messages. r=ochameau. Differential Revision: https://phabricator.services.mozilla.com/D71348
- Loading branch information
Showing
9 changed files
with
188 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
DevToolsModules( | ||
'console-messages.js', | ||
'platform-messages.js', | ||
) |
51 changes: 51 additions & 0 deletions
51
devtools/shared/resources/legacy-listeners/platform-messages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* 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/. */ | ||
|
||
"use strict"; | ||
|
||
module.exports = async function({ | ||
targetList, | ||
targetType, | ||
targetFront, | ||
isTopLevel, | ||
onAvailable, | ||
}) { | ||
// Only allow the top level target and processes. | ||
// Frames can be ignored as logMessage are never sent to them anyway. | ||
// Also ignore workers as they are not supported yet. (see bug 1592584) | ||
const isAllowed = isTopLevel || targetType === targetList.TYPES.PROCESS; | ||
if (!isAllowed) { | ||
return; | ||
} | ||
|
||
const webConsoleFront = await targetFront.getFront("console"); | ||
|
||
// Request notifying about new messages. Here the "PageError" type start listening for | ||
// both actual PageErrors (emitted as "pageError" events) as well as LogMessages ( | ||
// emitted as "logMessage" events). This function only set up the listener on the | ||
// webConsoleFront for "logMessage". | ||
await webConsoleFront.startListeners(["PageError"]); | ||
|
||
// Fetch already existing messages | ||
// /!\ The actor implementation requires to call startListeners("PageError") first /!\ | ||
// On older server (< v77), cached messages have to be retrieved at the same time as | ||
// PageError messages. | ||
const { messages } = await webConsoleFront.getCachedMessages([ | ||
webConsoleFront.traits.newCacheStructure ? "LogMessage" : "PageError", | ||
]); | ||
|
||
for (const message of messages) { | ||
// On older server (< v77), we're also getting pageError cached messages, so we need | ||
// to ignore those. | ||
if ( | ||
!webConsoleFront.traits.newCacheStructure && | ||
message._type !== "LogMessage" | ||
) { | ||
continue; | ||
} | ||
onAvailable(message); | ||
} | ||
|
||
webConsoleFront.on("logMessage", onAvailable); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
devtools/shared/resources/tests/browser_resources_platform_messages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
"use strict"; | ||
|
||
// Test the ResourceWatcher API around PLATFORM_MESSAGES | ||
// Reproduces assertions from: devtools/shared/webconsole/test/chrome/test_nsiconsolemessage.html | ||
|
||
const { | ||
ResourceWatcher, | ||
} = require("devtools/shared/resources/resource-watcher"); | ||
|
||
add_task(async function() { | ||
// Disable the preloaded process as it creates processes intermittently | ||
// which forces the emission of RDP requests we aren't correctly waiting for. | ||
await pushPref("dom.ipc.processPrelaunch.enabled", false); | ||
|
||
const { | ||
client, | ||
resourceWatcher, | ||
targetList, | ||
} = await initResourceWatcherAndTarget(); | ||
|
||
const expectedMessages = [ | ||
"This is a cached message", | ||
"This is another cached message", | ||
"This is a live message", | ||
"This is another live message", | ||
]; | ||
const receivedMessages = []; | ||
|
||
info( | ||
"Log some messages *before* calling ResourceWatcher.watch in order to assert the behavior of already existing messages." | ||
); | ||
Services.console.logStringMessage(expectedMessages[0]); | ||
Services.console.logStringMessage(expectedMessages[1]); | ||
|
||
let done; | ||
const onAllMessagesReceived = new Promise(resolve => (done = resolve)); | ||
|
||
await resourceWatcher.watch( | ||
[ResourceWatcher.TYPES.PLATFORM_MESSAGES], | ||
({ resourceType, targetFront, resource }) => { | ||
if (!expectedMessages.includes(resource.message)) { | ||
return; | ||
} | ||
|
||
receivedMessages.push(resource.message); | ||
is( | ||
resource.message, | ||
expectedMessages[receivedMessages.length - 1], | ||
`Received the expected «${resource.message}» message, in the expected order` | ||
); | ||
|
||
ok( | ||
resource.timeStamp.toString().match(/^\d+$/), | ||
"The resource has a timeStamp property" | ||
); | ||
|
||
if (receivedMessages.length == expectedMessages.length) { | ||
done(); | ||
} | ||
} | ||
); | ||
|
||
info( | ||
"Now log messages *after* the call to ResourceWatcher.watch and after having received all existing messages" | ||
); | ||
Services.console.logStringMessage(expectedMessages[2]); | ||
Services.console.logStringMessage(expectedMessages[3]); | ||
|
||
info("Waiting for all expected messages to be received"); | ||
await onAllMessagesReceived; | ||
ok(true, "All the expected messages were received"); | ||
|
||
Services.console.reset(); | ||
targetList.stopListening(); | ||
await client.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters