Path: blob/trunk/javascript/selenium-webdriver/bidi/partialCookie.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.1617const { BytesValue } = require('./networkTypes')1819/**20* Represents a partial cookie used to set cookies.21* Described in https://w3c.github.io/webdriver-bidi/#command-storage-setCookie.22* @class23*/24class PartialCookie {25#map = new Map()2627/**28* Represents a partial cookie.29* @class30* @param {string} name - The name of the cookie.31* @param {BytesValue} value - The value of the cookie as an instance of BytesValue.32* @param {string} domain - The domain of the cookie.33*/34constructor(name, value, domain) {35this.#map.set('name', name)36if (!(value instanceof BytesValue)) {37throw new Error(`Value must be an instance of BytesValue. Received:'${value}'`)38}39this.#map.set('value', Object.fromEntries(value.asMap()))40this.#map.set('domain', domain)41}4243/**44* Sets the path for the cookie.45*46* @param {string} path - The path for the cookie.47* @returns {PartialCookie} - The updated PartialCookie instance for chaining.48*/49path(path) {50this.#map.set('path', path)51return this52}5354/**55* Sets the size of the cookie.56*57* @param {number} size - The size of the cookie.58* @returns {PartialCookie} - The updated PartialCookie instance for chaining.59*/60size(size) {61this.#map.set('size', size)62return this63}6465/**66* Sets the `httpOnly` flag for the cookie.67*68* @param {boolean} httpOnly - The value to set for the `httpOnly` flag.69* @returns {PartialCookie} - The updated PartialCookie instance for chaining.70*/71httpOnly(httpOnly) {72this.#map.set('httpOnly', httpOnly)73return this74}7576/**77* Sets the secure flag for the cookie.78*79* @param {boolean} secure - Indicates whether the cookie should only be sent over secure connections.80* @returns {PartialCookie} - The updated PartialCookie instance for chaining.81*/82secure(secure) {83this.#map.set('secure', secure)84return this85}8687/**88* Sets the SameSite attribute for the cookie.89*90* @param {SameSite} sameSite - The SameSite attribute value for the cookie.91* @returns {PartialCookie} - The updated PartialCookie instance for chaining.92*/93sameSite(sameSite) {94this.#map.set('sameSite', sameSite)95return this96}9798/**99* Sets the expiry for the cookie.100*101* @param {number} expiry - The expiry time of the cookie.102* @returns {PartialCookie} - The updated PartialCookie instance for chaining.103*/104expiry(expiry) {105this.#map.set('expiry', expiry)106return this107}108109asMap() {110return this.#map111}112}113114module.exports = { PartialCookie }115116117