Path: blob/trunk/javascript/selenium-webdriver/bidi/partitionDescriptor.js
2884 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617/**18* Represents the types of partition descriptors.19* @enum {string}20* Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies.21*/22const Type = {23CONTEXT: 'context',24STORAGE_KEY: 'storageKey',25}2627/**28* Represents a partition descriptor.29* Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies.30*/31class PartitionDescriptor {32/*eslint no-unused-private-class-members: "off"*/33#type3435/**36* Constructs a new PartitionDescriptor instance.37* @param {Type} type - The type of the partition.38*/39constructor(type) {40this.#type = type41}42}4344/**45* Represents a partition descriptor for a browsing context.46* @extends PartitionDescriptor47*/48class BrowsingContextPartitionDescriptor extends PartitionDescriptor {49#context = null5051constructor(context) {52super(Type.CONTEXT)53this.#context = context54}5556asMap() {57const map = new Map()58map.set('type', Type.CONTEXT)59map.set('context', this.#context)60return map61}62}6364/**65* Represents a partition descriptor for storage key.66* @extends PartitionDescriptor67*/68class StorageKeyPartitionDescriptor extends PartitionDescriptor {69#map = new Map()7071constructor() {72super(Type.STORAGE_KEY)73this.#map.set('type', Type.STORAGE_KEY)74}7576/**77* Sets the user context for the partition descriptor.78* @param {any} userContext - The user context to set.79* @returns {PartitionDescriptor} - The updated partition descriptor instance for chaining.80*/81userContext(userContext) {82this.#map.set('userContext', userContext)83return this84}8586/**87* Sets the source origin for the partition descriptor.88*89* @param {string} sourceOrigin - The source origin to set.90* @returns {PartitionDescriptor} - The updated PartitionDescriptor instance for chaining.91*/92sourceOrigin(sourceOrigin) {93this.#map.set('sourceOrigin', sourceOrigin)94return this95}9697asMap() {98return this.#map99}100}101102module.exports = { BrowsingContextPartitionDescriptor, StorageKeyPartitionDescriptor }103104105