Skip to content

Commit 388d70f

Browse files
Merge branch 'trunk' into not-null-response
2 parents 9a76e89 + 800abb1 commit 388d70f

File tree

18 files changed

+218
-31
lines changed

18 files changed

+218
-31
lines changed

dotnet/src/webdriver/DevTools/DevToolsDomains.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public abstract class DevToolsDomains
8282
/// Initializes the supplied DevTools session's domains for the specified browser version.
8383
/// </summary>
8484
/// <param name="protocolVersion">The version of the DevTools Protocol to use.</param>
85-
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
85+
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialize the domains.</param>
8686
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
8787
/// <exception cref="ArgumentException">If <paramref name="protocolVersion"/> is negative.</exception>
8888
/// <exception cref="WebDriverException">If the desired protocol version is not supported.</exception>
@@ -95,7 +95,7 @@ public static DevToolsDomains InitializeDomains(int protocolVersion, DevToolsSes
9595
/// Initializes the supplied DevTools session's domains for the specified browser version within the specified number of versions.
9696
/// </summary>
9797
/// <param name="protocolVersion">The version of the DevTools Protocol to use.</param>
98-
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialiize the domains.</param>
98+
/// <param name="session">The <see cref="DevToolsSession"/> for which to initialize the domains.</param>
9999
/// <param name="versionRange">The range of versions within which to match the provided version number. Defaults to 5 versions.</param>
100100
/// <returns>The <see cref="DevToolsDomains"/> object containing the version-specific domains.</returns>
101101
/// <exception cref="ArgumentException">If <paramref name="protocolVersion"/> is negative.</exception>

dotnet/src/webdriver/DevTools/v130/V130Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V130
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 130 of the DevTools Protocol.
2428
/// </summary>
2529
public class V130Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V130Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V130Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v131/V131Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V131
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 131 of the DevTools Protocol.
2428
/// </summary>
2529
public class V131Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V131Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V131Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v132/V132Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V132
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 132 of the DevTools Protocol.
2428
/// </summary>
2529
public class V132Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V132Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V132Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

dotnet/src/webdriver/DevTools/v85/V85Domains.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium.DevTools.V85
2125
{
2226
/// <summary>
2327
/// Class containing the domain implementation for version 86 of the DevTools Protocol.
2428
/// </summary>
2529
public class V85Domains : DevToolsDomains
2630
{
27-
private DevToolsSessionDomains domains;
31+
private readonly DevToolsSessionDomains domains;
2832

2933
/// <summary>
3034
/// Initializes a new instance of the V85Domains class.
3135
/// </summary>
3236
/// <param name="session">The DevToolsSession to use with this set of domains.</param>
37+
/// <exception cref="ArgumentNullException">If <paramref name="session"/> is <see langword="null"/>.</exception>
3338
public V85Domains(DevToolsSession session)
3439
{
35-
this.domains = new DevToolsSessionDomains(session);
40+
this.domains = new DevToolsSessionDomains(session ?? throw new ArgumentNullException(nameof(session)));
3641
}
3742

3843
/// <summary>

javascript/node/selenium-webdriver/bidi/network.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const NetworkEvent = {
2929
FETCH_ERROR: 'network.fetchError',
3030
}
3131

32+
const CacheBehavior = Object.freeze({
33+
DEFAULT: 'default',
34+
BYPASS: 'bypass',
35+
})
36+
3237
/**
3338
* Represents all commands and events of Network module.
3439
* Described in https://w3c.github.io/webdriver-bidi/#module-network.
@@ -355,6 +360,40 @@ class Network {
355360
await this.bidi.send(command)
356361
}
357362

363+
/**
364+
* Sets the cache behavior for network requests.
365+
*
366+
* @param {string} behavior - The cache behavior ("default" or "bypass")
367+
* @param {Array<string>} [contexts] - Optional array of browsing context IDs
368+
* @returns {Promise<void>} A promise that resolves when the cache behavior is set
369+
* @throws {Error} If behavior is invalid or context IDs are invalid
370+
*/
371+
async setCacheBehavior(behavior, contexts = null) {
372+
if (!Object.values(CacheBehavior).includes(behavior)) {
373+
throw new Error(`Cache behavior must be either "${CacheBehavior.DEFAULT}" or "${CacheBehavior.BYPASS}"`)
374+
}
375+
376+
const command = {
377+
method: 'network.setCacheBehavior',
378+
params: {
379+
cacheBehavior: behavior,
380+
},
381+
}
382+
383+
if (contexts !== null) {
384+
if (
385+
!Array.isArray(contexts) ||
386+
contexts.length === 0 ||
387+
contexts.some((c) => typeof c !== 'string' || c.trim() === '')
388+
) {
389+
throw new Error('Contexts must be an array of non-empty strings')
390+
}
391+
command.params.contexts = contexts
392+
}
393+
394+
await this.bidi.send(command)
395+
}
396+
358397
/**
359398
* Unsubscribes from network events for all browsing contexts.
360399
* @returns {Promise<void>} A promise that resolves when the network connection is closed.
@@ -389,4 +428,4 @@ async function getNetworkInstance(driver, browsingContextIds = null) {
389428
return instance
390429
}
391430

392-
module.exports = getNetworkInstance
431+
module.exports = { Network: getNetworkInstance, CacheBehavior }

javascript/node/selenium-webdriver/lib/network.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
const network = require('../bidi/network')
18+
const { Network: getNetwork } = require('../bidi/network')
1919
const { InterceptPhase } = require('../bidi/interceptPhase')
2020
const { AddInterceptParameters } = require('../bidi/addInterceptParameters')
2121

@@ -39,7 +39,7 @@ class Network {
3939
if (this.#network !== undefined) {
4040
return
4141
}
42-
this.#network = await network(this.#driver)
42+
this.#network = await getNetwork(this.#driver)
4343

4444
await this.#network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED))
4545

javascript/node/selenium-webdriver/test/bidi/add_intercept_parameters_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const assert = require('node:assert')
2121
const { Browser } = require('selenium-webdriver')
2222
const { suite } = require('../../lib/test')
23-
const Network = require('selenium-webdriver/bidi/network')
23+
const { Network } = require('selenium-webdriver/bidi/network')
2424
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
2525
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
2626
const { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')

javascript/node/selenium-webdriver/test/bidi/network_commands_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const assert = require('node:assert')
2121
const { Browser, By } = require('selenium-webdriver')
2222
const { Pages, suite } = require('../../lib/test')
23-
const Network = require('selenium-webdriver/bidi/network')
23+
const { Network } = require('selenium-webdriver/bidi/network')
2424
const { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')
2525
const { InterceptPhase } = require('selenium-webdriver/bidi/interceptPhase')
2626
const { until } = require('selenium-webdriver/index')

javascript/node/selenium-webdriver/test/bidi/network_test.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
const assert = require('node:assert')
2121
const { Browser } = require('selenium-webdriver')
2222
const { Pages, suite, ignore } = require('../../lib/test')
23-
const Network = require('selenium-webdriver/bidi/network')
23+
const { Network, CacheBehavior } = require('selenium-webdriver/bidi/network')
24+
const BrowsingContext = require('selenium-webdriver/bidi/browsingContext')
2425
const until = require('selenium-webdriver/lib/until')
2526

2627
suite(
@@ -212,6 +213,52 @@ suite(
212213
assert(onResponseCompleted[0].response.mimeType.includes('text/plain'))
213214
})
214215
})
216+
217+
describe('setCacheBehavior', function () {
218+
it('can set cache behavior to bypass for a context', async function () {
219+
await driver.get(Pages.emptyPage)
220+
const browsingContext = await BrowsingContext(driver, {
221+
type: 'tab',
222+
})
223+
const contextId = browsingContext.id
224+
await network.setCacheBehavior(CacheBehavior.BYPASS, [contextId])
225+
})
226+
227+
it('can set cache behavior to default for a context', async function () {
228+
await driver.get(Pages.emptyPage)
229+
const browsingContext = await BrowsingContext(driver, {
230+
type: 'tab',
231+
})
232+
const contextId = browsingContext.id
233+
await network.setCacheBehavior(CacheBehavior.DEFAULT, [contextId])
234+
})
235+
236+
it('can set cache behavior to default/bypass with no context id', async function () {
237+
await driver.get(Pages.emptyPage)
238+
await network.setCacheBehavior(CacheBehavior.DEFAULT)
239+
await network.setCacheBehavior(CacheBehavior.BYPASS)
240+
})
241+
242+
it('throws error for invalid cache behavior', async function () {
243+
await driver.get(Pages.emptyPage)
244+
await assert.rejects(
245+
async () => await network.setCacheBehavior('invalid'),
246+
/Cache behavior must be either "default" or "bypass"/,
247+
)
248+
})
249+
250+
it('throws error for invalid context id types', async function () {
251+
await driver.get(Pages.emptyPage)
252+
await assert.rejects(
253+
async () => await network.setCacheBehavior(CacheBehavior.BYPASS, ''),
254+
/Contexts must be an array of non-empty strings/,
255+
)
256+
await assert.rejects(
257+
async () => await network.setCacheBehavior(CacheBehavior.BYPASS, ['', ' ']),
258+
/Contexts must be an array of non-empty strings/,
259+
)
260+
})
261+
})
215262
},
216263
{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
217264
)

0 commit comments

Comments
 (0)