Skip to content

Commit

Permalink
[bidi] [js] Add storage module (#13684)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Mar 14, 2024
1 parent 83083c6 commit cce0385
Show file tree
Hide file tree
Showing 7 changed files with 711 additions and 9 deletions.
76 changes: 76 additions & 0 deletions javascript/node/selenium-webdriver/bidi/cookieFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

const { SameSite } = require('./networkTypes')

class CookieFilter {
#map = new Map()

name(name) {
this.#map.set('name', name)
return this
}

value(value) {
this.#map.set('value', Object.fromEntries(value.asMap()))
return this
}

domain(domain) {
this.#map.set('domain', domain)
return this
}

path(path) {
this.#map.set('path', path)
return this
}

size(size) {
this.#map.set('size', size)
return this
}

httpOnly(httpOnly) {
this.#map.set('httpOnly', httpOnly)
return this
}

secure(secure) {
this.#map.set('secure', secure)
return this
}

sameSite(sameSite) {
if (!(sameSite instanceof SameSite)) {
throw new Error(`Params must be a value in SameSite. Received:'${sameSite}'`)
}
this.#map.set('sameSite', sameSite)
return this
}

expiry(expiry) {
this.#map.set('expiry', expiry)
return this
}

asMap() {
return this.#map
}
}

module.exports = { CookieFilter }
53 changes: 44 additions & 9 deletions javascript/node/selenium-webdriver/bidi/networkTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@

const { NavigationInfo } = require('./browsingContextTypes')

const SameSite = {
STRICT: 'strict',
LAX: 'lax',
NONE: 'none',

findByName(name) {
return (
Object.values(this).find((type) => {
return typeof type === 'string' && name.toLowerCase() === type.toLowerCase()
}) || null
)
},
}

class BytesValue {
static Type = {
STRING: 'string',
BASE64: 'base64',
}

constructor(type, value) {
this._type = type
this._value = value
}

get type() {
return this._type
}

get value() {
return this._value
}

asMap() {
const map = new Map()
map.set('type', this._type)
map.set('value', this._value)
return map
}
}

class Header {
constructor(name, value, binaryValue) {
this._name = name
Expand All @@ -38,10 +79,9 @@ class Header {
}

class Cookie {
constructor(name, value, binaryValue, domain, path, expires, size, httpOnly, secure, sameSite) {
constructor(name, value, domain, path, size, httpOnly, secure, sameSite, expires) {
this._name = name
this._value = value
this._binaryValue = binaryValue
this._domain = domain
this._path = path
this._expires = expires
Expand All @@ -59,10 +99,6 @@ class Cookie {
return this._value
}

get binaryValue() {
return this._binaryValue
}

get domain() {
return this._domain
}
Expand Down Expand Up @@ -201,10 +237,9 @@ class RequestData {
let secure = cookie.secure
let sameSite = cookie.sameSite
let value = 'value' in cookie ? cookie.value : null
let binaryValue = 'binaryValue' in cookie ? cookie.binaryValue : null
let expires = 'expires' in cookie ? cookie.expires : null

this._cookies.push(new Cookie(name, value, binaryValue, domain, path, expires, size, httpOnly, secure, sameSite))
this._cookies.push(new Cookie(name, value, domain, path, size, httpOnly, secure, sameSite, expires))
})
this._headersSize = headersSize
this._bodySize = bodySize
Expand Down Expand Up @@ -453,4 +488,4 @@ class ResponseStarted extends BaseParameters {
}
}

module.exports = { BeforeRequestSent, ResponseStarted, FetchError }
module.exports = { BytesValue, Cookie, SameSite, BeforeRequestSent, ResponseStarted, FetchError }
62 changes: 62 additions & 0 deletions javascript/node/selenium-webdriver/bidi/partialCookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

class PartialCookie {
#map = new Map()

constructor(name, value, domain) {
this.#map.set('name', name)
this.#map.set('value', Object.fromEntries(value.asMap()))
this.#map.set('domain', domain)
}

path(path) {
this.#map.set('path', path)
return this
}

size(size) {
this.#map.set('size', size)
return this
}

httpOnly(httpOnly) {
this.#map.set('httpOnly', httpOnly)
return this
}

secure(secure) {
this.#map.set('secure', secure)
return this
}

sameSite(sameSite) {
this.#map.set('sameSite', sameSite)
return this
}

expiry(expiry) {
this.#map.set('expiry', expiry)
return this
}

asMap() {
return this.#map
}
}

module.exports = { PartialCookie }
69 changes: 69 additions & 0 deletions javascript/node/selenium-webdriver/bidi/partitionDescriptor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

Type = {
CONTEXT: 'context',
STORAGE_KEY: 'storageKey',
}

class PartitionDescriptor {
#type

constructor(type) {
this.#type = type
}
}

class BrowsingContextPartitionDescriptor extends PartitionDescriptor {
#context = null

constructor(context) {
super(Type.CONTEXT)
this.#context = context
}

asMap() {
const map = new Map()
map.set('type', Type.CONTEXT)
map.set('context', this.#context)
return map
}
}

class StorageKeyPartitionDescriptor extends PartitionDescriptor {
#map = new Map()

constructor() {
super(Type.STORAGE_KEY)
}

userContext(userContext) {
this.#map.set('userContext', userContext)
return this
}

sourceOrigin(sourceOrigin) {
this.#map.set('sourceOrigin', sourceOrigin)
return this
}

asMap() {
return this.#map
}
}

module.exports = { BrowsingContextPartitionDescriptor, StorageKeyPartitionDescriptor }
36 changes: 36 additions & 0 deletions javascript/node/selenium-webdriver/bidi/partitionKey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

class PartitionKey {
#userContext
#sourceOrigin

constructor(userContext, sourceOrigin) {
this.#userContext = userContext
this.#sourceOrigin = sourceOrigin
}

get userContext() {
return this.#userContext
}

get sourceOrigin() {
return this.#sourceOrigin
}
}

module.exports = { PartitionKey }
Loading

0 comments on commit cce0385

Please sign in to comment.