browser_target_command_invalid_api_usage.js (2534B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test watch/unwatchTargets throw when provided with invalid types. 7 8 const TEST_URL = "data:text/html;charset=utf-8,invalid api usage test"; 9 10 add_task(async function () { 11 info("Setup the test page with workers of all types"); 12 const tab = await addTab(TEST_URL); 13 14 info("Create a target list for a tab target"); 15 const commands = await CommandsFactory.forTab(tab); 16 const targetCommand = commands.targetCommand; 17 18 const onAvailable = function () {}; 19 20 await Assert.rejects( 21 targetCommand.watchTargets({ types: [null], onAvailable }), 22 /TargetCommand.watchTargets invoked with an unknown type/, 23 "watchTargets should throw for null type" 24 ); 25 26 await Assert.rejects( 27 targetCommand.watchTargets({ types: [undefined], onAvailable }), 28 /TargetCommand.watchTargets invoked with an unknown type/, 29 "watchTargets should throw for undefined type" 30 ); 31 32 await Assert.rejects( 33 targetCommand.watchTargets({ types: ["NOT_A_TARGET"], onAvailable }), 34 /TargetCommand.watchTargets invoked with an unknown type/, 35 "watchTargets should throw for unknown type" 36 ); 37 38 await Assert.rejects( 39 targetCommand.watchTargets({ 40 types: [targetCommand.TYPES.FRAME, "NOT_A_TARGET"], 41 onAvailable, 42 }), 43 /TargetCommand.watchTargets invoked with an unknown type/, 44 "watchTargets should throw for unknown type mixed with a correct type" 45 ); 46 47 Assert.throws( 48 () => targetCommand.unwatchTargets({ types: [null], onAvailable }), 49 /TargetCommand.unwatchTargets invoked with an unknown type/, 50 "unwatchTargets should throw for null type" 51 ); 52 53 Assert.throws( 54 () => targetCommand.unwatchTargets({ types: [undefined], onAvailable }), 55 /TargetCommand.unwatchTargets invoked with an unknown type/, 56 "unwatchTargets should throw for undefined type" 57 ); 58 59 Assert.throws( 60 () => 61 targetCommand.unwatchTargets({ types: ["NOT_A_TARGET"], onAvailable }), 62 /TargetCommand.unwatchTargets invoked with an unknown type/, 63 "unwatchTargets should throw for unknown type" 64 ); 65 66 Assert.throws( 67 () => 68 targetCommand.unwatchTargets({ 69 types: [targetCommand.TYPES.CONSOLE_MESSAGE, "NOT_A_TARGET"], 70 onAvailable, 71 }), 72 /TargetCommand.unwatchTargets invoked with an unknown type/, 73 "unwatchTargets should throw for unknown type mixed with a correct type" 74 ); 75 76 BrowserTestUtils.removeTab(tab); 77 await commands.destroy(); 78 });