browser_browser_resources_console_messages.js (2606B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the ResourceCommand API around CONSOLE_MESSAGE for the whole browser 7 8 const TEST_URL = URL_ROOT_SSL + "early_console_document.html"; 9 10 add_task(async function () { 11 // Enable Multiprocess Browser Toolbox. 12 await pushPref("devtools.browsertoolbox.scope", "everything"); 13 14 const { client, resourceCommand, targetCommand } = 15 await initMultiProcessResourceCommand(); 16 17 const d = Date.now(); 18 const CACHED_MESSAGE_TEXT = `cached-${d}`; 19 const LIVE_MESSAGE_TEXT = `live-${d}`; 20 21 info( 22 "Log some messages *before* calling ResourceCommand.watchResources in order to " + 23 "assert the behavior of already existing messages." 24 ); 25 console.log(CACHED_MESSAGE_TEXT); 26 27 info("Wait for existing browser mochitest log"); 28 const { onResource } = await resourceCommand.waitForNextResource( 29 resourceCommand.TYPES.CONSOLE_MESSAGE, 30 { 31 ignoreExistingResources: false, 32 predicate(message) { 33 return message.arguments[0] === CACHED_MESSAGE_TEXT; 34 }, 35 } 36 ); 37 const existingMsg = await onResource; 38 ok(existingMsg, "The existing log was retrieved"); 39 is( 40 existingMsg.isAlreadyExistingResource, 41 true, 42 "isAlreadyExistingResource is true for the existing message" 43 ); 44 45 const { onResource: onMochitestRuntimeLog } = 46 await resourceCommand.waitForNextResource( 47 resourceCommand.TYPES.CONSOLE_MESSAGE, 48 { 49 ignoreExistingResources: false, 50 predicate(message) { 51 return message.arguments[0] === LIVE_MESSAGE_TEXT; 52 }, 53 } 54 ); 55 console.log(LIVE_MESSAGE_TEXT); 56 57 info("Wait for runtime browser mochitest log"); 58 const runtimeLogResource = await onMochitestRuntimeLog; 59 ok(runtimeLogResource, "The runtime log was retrieved"); 60 is( 61 runtimeLogResource.isAlreadyExistingResource, 62 false, 63 "isAlreadyExistingResource is false for the runtime message" 64 ); 65 66 const { onResource: onEarlyLog } = await resourceCommand.waitForNextResource( 67 resourceCommand.TYPES.CONSOLE_MESSAGE, 68 { 69 ignoreExistingResources: true, 70 predicate(message) { 71 return message.arguments[0] === "early-page-log"; 72 }, 73 } 74 ); 75 await addTab(TEST_URL); 76 info("Wait for early page log"); 77 const earlyResource = await onEarlyLog; 78 ok(earlyResource, "The early page log was retrieved"); 79 is( 80 earlyResource.isAlreadyExistingResource, 81 false, 82 "isAlreadyExistingResource is false for the early message" 83 ); 84 85 targetCommand.destroy(); 86 await client.close(); 87 });