Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/bidi/partitionDescriptor.js
2884 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
/**
19
* Represents the types of partition descriptors.
20
* @enum {string}
21
* Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies.
22
*/
23
const Type = {
24
CONTEXT: 'context',
25
STORAGE_KEY: 'storageKey',
26
}
27
28
/**
29
* Represents a partition descriptor.
30
* Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies.
31
*/
32
class PartitionDescriptor {
33
/*eslint no-unused-private-class-members: "off"*/
34
#type
35
36
/**
37
* Constructs a new PartitionDescriptor instance.
38
* @param {Type} type - The type of the partition.
39
*/
40
constructor(type) {
41
this.#type = type
42
}
43
}
44
45
/**
46
* Represents a partition descriptor for a browsing context.
47
* @extends PartitionDescriptor
48
*/
49
class BrowsingContextPartitionDescriptor extends PartitionDescriptor {
50
#context = null
51
52
constructor(context) {
53
super(Type.CONTEXT)
54
this.#context = context
55
}
56
57
asMap() {
58
const map = new Map()
59
map.set('type', Type.CONTEXT)
60
map.set('context', this.#context)
61
return map
62
}
63
}
64
65
/**
66
* Represents a partition descriptor for storage key.
67
* @extends PartitionDescriptor
68
*/
69
class StorageKeyPartitionDescriptor extends PartitionDescriptor {
70
#map = new Map()
71
72
constructor() {
73
super(Type.STORAGE_KEY)
74
this.#map.set('type', Type.STORAGE_KEY)
75
}
76
77
/**
78
* Sets the user context for the partition descriptor.
79
* @param {any} userContext - The user context to set.
80
* @returns {PartitionDescriptor} - The updated partition descriptor instance for chaining.
81
*/
82
userContext(userContext) {
83
this.#map.set('userContext', userContext)
84
return this
85
}
86
87
/**
88
* Sets the source origin for the partition descriptor.
89
*
90
* @param {string} sourceOrigin - The source origin to set.
91
* @returns {PartitionDescriptor} - The updated PartitionDescriptor instance for chaining.
92
*/
93
sourceOrigin(sourceOrigin) {
94
this.#map.set('sourceOrigin', sourceOrigin)
95
return this
96
}
97
98
asMap() {
99
return this.#map
100
}
101
}
102
103
module.exports = { BrowsingContextPartitionDescriptor, StorageKeyPartitionDescriptor }
104
105