browser_WebDriverBiDi.js (3687B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { RemoteAgent: RemoteAgentModule } = ChromeUtils.importESModule( 8 "chrome://remote/content/components/RemoteAgent.sys.mjs" 9 ); 10 const { WebDriverBiDi } = ChromeUtils.importESModule( 11 "chrome://remote/content/webdriver-bidi/WebDriverBiDi.sys.mjs" 12 ); 13 14 async function runBiDiTest(test, options = {}) { 15 const { capabilities = {}, connection, isBidi = false } = options; 16 17 const flags = new Set(); 18 if (isBidi) { 19 flags.add("bidi"); 20 } else { 21 flags.add("http"); 22 } 23 24 const wdBiDi = new WebDriverBiDi(RemoteAgentModule); 25 await wdBiDi.createSession(capabilities, flags, connection); 26 27 await test(wdBiDi); 28 29 wdBiDi.deleteSession(); 30 } 31 32 add_task(async function test_createSession() { 33 // Missing WebDriver session flags 34 const bidi = new WebDriverBiDi(RemoteAgent); 35 await Assert.rejects(bidi.createSession({}), /TypeError/); 36 37 // Session needs to be either HTTP or BiDi 38 for (const flags of [[], ["bidi", "http"]]) { 39 await Assert.rejects( 40 bidi.createSession({}, new Set(flags)), 41 /SessionNotCreatedError:/ 42 ); 43 } 44 45 // Session id and path 46 await runBiDiTest(wdBiDi => { 47 is(typeof wdBiDi.session.id, "string"); 48 is(wdBiDi.session.path, `/session/${wdBiDi.session.id}`); 49 }); 50 51 // Sets HTTP and BiDi flags correctly. 52 await runBiDiTest( 53 wdBiDi => { 54 is(wdBiDi.session.bidi, false); 55 is(wdBiDi.session.http, true); 56 }, 57 { isBidi: false } 58 ); 59 await runBiDiTest( 60 wdBiDi => { 61 is(wdBiDi.session.bidi, true); 62 is(wdBiDi.session.http, false); 63 }, 64 { isBidi: true } 65 ); 66 67 // Sets capabilities based on session configuration flag. 68 const capabilities = { 69 acceptInsecureCerts: true, 70 unhandledPromptBehavior: "ignore", 71 72 // HTTP only 73 pageLoadStrategy: "eager", 74 strictFileInteractability: true, 75 timeouts: { script: 1000 }, 76 // Bug 1731730: Requires matching for session.new command. 77 // webSocketUrl: false, 78 }; 79 80 // HTTP session (no webSocketUrl) 81 await runBiDiTest( 82 wdBiDi => { 83 is(wdBiDi.session.bidi, false); 84 is(wdBiDi.session.acceptInsecureCerts, true); 85 is(wdBiDi.session.pageLoadStrategy, "eager"); 86 is(wdBiDi.session.strictFileInteractability, true); 87 is(wdBiDi.session.timeouts.script, 1000); 88 is(wdBiDi.session.userPromptHandler.toJSON(), "ignore"); 89 is(wdBiDi.session.webSocketUrl, undefined); 90 }, 91 { capabilities, isBidi: false } 92 ); 93 94 // HTTP session (with webSocketUrl) 95 capabilities.webSocketUrl = true; 96 await runBiDiTest( 97 wdBiDi => { 98 is(wdBiDi.session.bidi, true); 99 is(wdBiDi.session.acceptInsecureCerts, true); 100 is(wdBiDi.session.pageLoadStrategy, "eager"); 101 is(wdBiDi.session.strictFileInteractability, true); 102 is(wdBiDi.session.timeouts.script, 1000); 103 is(wdBiDi.session.userPromptHandler.toJSON(), "ignore"); 104 is( 105 wdBiDi.session.webSocketUrl, 106 `ws://127.0.0.1:9222/session/${wdBiDi.session.id}` 107 ); 108 }, 109 { capabilities, isBidi: false } 110 ); 111 112 // BiDi session 113 await runBiDiTest( 114 wdBiDi => { 115 is(wdBiDi.session.bidi, true); 116 is(wdBiDi.session.acceptInsecureCerts, true); 117 is(wdBiDi.session.userPromptHandler.toJSON(), "ignore"); 118 119 is(wdBiDi.session.pageLoadStrategy, undefined); 120 is(wdBiDi.session.strictFileInteractability, undefined); 121 is(wdBiDi.session.timeouts, undefined); 122 is(wdBiDi.session.webSocketUrl, undefined); 123 }, 124 { capabilities, isBidi: true } 125 ); 126 });