Skip to content

Commit

Permalink
build(spec): update WebDriverBiDi types (#2647)
Browse files Browse the repository at this point in the history
Closes #2640
  • Loading branch information
Lightning00Blade authored Sep 25, 2024
1 parent abde94d commit 9be3749
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 34 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/update-bidi-types.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow will update the WebdriverBidi types.
# This workflow will update the WebdriverBiDi types.

name: Update WebdriverBidi types
name: Update WebdriverBiDi types

# Declare default permissions as read only.
permissions: read-all
Expand All @@ -24,7 +24,7 @@ on:

jobs:
build:
name: Build WebDriverBidi types
name: Build WebDriverBiDi types
runs-on: ubuntu-latest
steps:
- name: Check out the main spec repository
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
delete-branch: true
committer: Browser Automation Bot <browser-automation-bot@google.com>
author: Browser Automation Bot <browser-automation-bot@google.com>
commit-message: 'build(spec): update WebDriverBidi types'
title: 'build(spec): update WebDriverBidi types'
commit-message: 'build(spec): update WebDriverBiDi types'
title: 'build(spec): update WebDriverBiDi types'
body: Automatically generated by https://github.com/GoogleChromeLabs/chromium-bidi/blob/main/.github/workflows/update-bidi-types.yml
push-to-fork: browser-automation-bot/chromium-bidi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ npm install

<!-- TODO(jrandolf): Remove after binaries get published -->

We use [cddlconv](https://github.com/google/cddlconv) to generate our WebDriverBidi types before building.
We use [cddlconv](https://github.com/google/cddlconv) to generate our WebDriverBiDi types before building.

1. Install [Rust](https://rustup.rs/).
2. Run `cargo install --git https://github.com/google/cddlconv.git cddlconv`
Expand Down
8 changes: 8 additions & 0 deletions src/bidiMapper/CommandProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,20 @@ export class CommandProcessor extends EventEmitter<CommandProcessorEventsMap> {
return this.#browserProcessor.close();
case 'browser.createUserContext':
return await this.#browserProcessor.createUserContext(command.params);
case 'browser.getClientWindows':
throw new UnknownErrorException(
`Method ${command.method} is not implemented.`
);
case 'browser.getUserContexts':
return await this.#browserProcessor.getUserContexts();
case 'browser.removeUserContext':
return await this.#browserProcessor.removeUserContext(
this.#parser.parseRemoveUserContextParams(command.params)
);
case 'browser.setClientWindowState':
throw new UnknownErrorException(
`Method ${command.method} is not implemented.`
);
// keep-sorted end

// Browsing Context domain
Expand Down
2 changes: 2 additions & 0 deletions src/bidiMapper/modules/context/BrowsingContextImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ export class BrowsingContextImpl {
url: this.url,
userContext: this.userContext,
originalOpener: this.#originalOpener ?? null,
// TODO(#2646): Implement Client Window correctly
clientWindow: '',
children:
maxDepth > 0
? this.directChildren.map((c) =>
Expand Down
73 changes: 73 additions & 0 deletions src/protocol-parser/generated/webdriver-bidi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,11 @@ export const BrowserCommandSchema = z.lazy(() =>
z.union([
Browser.CloseSchema,
Browser.CreateUserContextSchema,
Browser.GetClientWindowsSchema,
Browser.GetUserContextsSchema,
Browser.RemoveUserContextSchema,
Browser.SetClientWindowStateSchema,
z.object({}),
])
);
export const BrowserResultSchema = z.lazy(() =>
Expand All @@ -361,6 +364,22 @@ export const BrowserResultSchema = z.lazy(() =>
Browser.GetUserContextsResultSchema,
])
);
export namespace Browser {
export const ClientWindowSchema = z.lazy(() => z.string());
}
export namespace Browser {
export const ClientWindowInfoSchema = z.lazy(() =>
z.object({
active: z.boolean(),
clientWindow: Browser.ClientWindowSchema,
height: JsUintSchema,
state: z.enum(['fullscreen', 'maximized', 'minimized', 'normal']),
width: JsUintSchema,
x: JsIntSchema,
y: JsIntSchema,
})
);
}
export namespace Browser {
export const UserContextSchema = z.lazy(() => z.string());
}
Expand Down Expand Up @@ -392,6 +411,21 @@ export namespace Browser {
() => Browser.UserContextInfoSchema
);
}
export namespace Browser {
export const GetClientWindowsSchema = z.lazy(() =>
z.object({
method: z.literal('browser.getClientWindows'),
params: EmptyParamsSchema,
})
);
}
export namespace Browser {
export const GetClientWindowsResultSchema = z.lazy(() =>
z.object({
clientWindows: z.array(Browser.ClientWindowInfoSchema),
})
);
}
export namespace Browser {
export const GetUserContextsSchema = z.lazy(() =>
z.object({
Expand Down Expand Up @@ -422,6 +456,44 @@ export namespace Browser {
})
);
}
export namespace Browser {
export const SetClientWindowStateSchema = z.lazy(() =>
z.object({
method: z.literal('browser.setClientWindowState'),
params: Browser.SetClientWindowStateParametersSchema,
})
);
}
export namespace Browser {
export const SetClientWindowStateParametersSchema = z.lazy(() =>
z.union([
z
.object({
clientWindow: Browser.ClientWindowSchema,
})
.and(Browser.ClientWindowNamedStateSchema),
Browser.ClientWindowRectStateSchema,
])
);
}
export namespace Browser {
export const ClientWindowNamedStateSchema = z.lazy(() =>
z.object({
state: z.enum(['fullscreen', 'maximized', 'minimized']),
})
);
}
export namespace Browser {
export const ClientWindowRectStateSchema = z.lazy(() =>
z.object({
state: z.literal('normal'),
width: JsUintSchema.optional(),
height: JsUintSchema.optional(),
x: JsIntSchema.optional(),
y: JsIntSchema.optional(),
})
);
}
export const BrowsingContextCommandSchema = z.lazy(() =>
z.union([
BrowsingContext.ActivateSchema,
Expand Down Expand Up @@ -476,6 +548,7 @@ export namespace BrowsingContext {
export const InfoSchema = z.lazy(() =>
z.object({
children: z.union([BrowsingContext.InfoListSchema, z.null()]),
clientWindow: Browser.ClientWindowSchema,
context: BrowsingContext.BrowsingContextSchema,
originalOpener: z.union([
BrowsingContext.BrowsingContextSchema,
Expand Down
58 changes: 57 additions & 1 deletion src/protocol/generated/webdriver-bidi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,28 @@ export namespace Session {
export type BrowserCommand =
| Browser.Close
| Browser.CreateUserContext
| Browser.GetClientWindows
| Browser.GetUserContexts
| Browser.RemoveUserContext;
| Browser.RemoveUserContext
| Browser.SetClientWindowState
| Record<string, never>;
export type BrowserResult =
| Browser.CreateUserContextResult
| Browser.GetUserContextsResult;
export namespace Browser {
export type ClientWindow = string;
}
export namespace Browser {
export type ClientWindowInfo = {
active: boolean;
clientWindow: Browser.ClientWindow;
height: JsUint;
state: 'fullscreen' | 'maximized' | 'minimized' | 'normal';
width: JsUint;
x: JsInt;
y: JsInt;
};
}
export namespace Browser {
export type UserContext = string;
}
Expand All @@ -288,6 +305,17 @@ export namespace Browser {
export namespace Browser {
export type CreateUserContextResult = Browser.UserContextInfo;
}
export namespace Browser {
export type GetClientWindows = {
method: 'browser.getClientWindows';
params: EmptyParams;
};
}
export namespace Browser {
export type GetClientWindowsResult = {
clientWindows: [...Browser.ClientWindowInfo[]];
};
}
export namespace Browser {
export type GetUserContexts = {
method: 'browser.getUserContexts';
Expand All @@ -310,6 +338,33 @@ export namespace Browser {
userContext: Browser.UserContext;
};
}
export namespace Browser {
export type SetClientWindowState = {
method: 'browser.setClientWindowState';
params: Browser.SetClientWindowStateParameters;
};
}
export namespace Browser {
export type SetClientWindowStateParameters =
| ({
clientWindow: Browser.ClientWindow;
} & Browser.ClientWindowNamedState)
| Browser.ClientWindowRectState;
}
export namespace Browser {
export type ClientWindowNamedState = {
state: 'fullscreen' | 'maximized' | 'minimized';
};
}
export namespace Browser {
export type ClientWindowRectState = {
state: 'normal';
width?: JsUint;
height?: JsUint;
x?: JsInt;
y?: JsInt;
};
}
export type BrowsingContextCommand =
| BrowsingContext.Activate
| BrowsingContext.CaptureScreenshot
Expand Down Expand Up @@ -352,6 +407,7 @@ export namespace BrowsingContext {
export namespace BrowsingContext {
export type Info = {
children: BrowsingContext.InfoList | null;
clientWindow: Browser.ClientWindow;
context: BrowsingContext.BrowsingContext;
originalOpener: BrowsingContext.BrowsingContext | null;
url: string;
Expand Down
1 change: 1 addition & 0 deletions tests/browsing_context/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ async def test_browsingContext_close_prompt(websocket, context_id, html,
'context': context_id,
'children': None,
'originalOpener': None,
'clientWindow': ANY_STR,
'parent': None,
# Url-encoded `url`.
'url': ANY_STR,
Expand Down
9 changes: 7 additions & 2 deletions tests/browsing_context/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async def test_browsingContext_create_eventContextCreatedEmitted(
"children": None,
"parent": None,
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}
} == context_created_event

Expand Down Expand Up @@ -134,20 +135,23 @@ async def test_browsingContext_createWithNestedSameOriginContexts_eventContextCr
"url": top_level_page,
"userContext": "default",
"originalOpener": None,
'clientWindow': ANY_STR,
"children": [
{
"context": ANY_STR,
# It's not guaranteed the nested page is already loaded.
"url": ANY_STR,
"userContext": "default",
"originalOpener": None,
'clientWindow': ANY_STR,
"children": [{
"context": ANY_STR,
# It's not guaranteed the nested page is already loaded.
"url": ANY_STR,
"userContext": "default",
"children": [],
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}]
},
]
Expand Down Expand Up @@ -237,6 +241,7 @@ async def test_browsingContext_create_withUserGesture_eventsEmitted(
'params': {
'context': ANY_STR,
'url': 'about:blank',
'clientWindow': ANY_STR,
'children': None,
'parent': None,
'userContext': 'default',
Expand Down
18 changes: 12 additions & 6 deletions tests/browsing_context/test_get_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ async def test_browsingContext_getTree_contextReturned(websocket, context_id):
"parent": None,
"url": "about:blank",
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}]
}

Expand Down Expand Up @@ -56,7 +57,8 @@ async def test_browsingContext_getTreeWithRoot_contextReturned(websocket):
"url": "about:blank",
"children": [],
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}]
}

Expand All @@ -78,12 +80,14 @@ async def test_browsingContext_afterNavigation_getTree_contextsReturned(
"url": url_all_origins,
"children": [],
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}],
"parent": None,
"url": page_with_nested_iframe,
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}]
} == result

Expand All @@ -99,11 +103,13 @@ async def test_browsingContext_afterNavigation_getTree_contextsReturned(
"url": url_all_origins,
"children": [],
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}],
"parent": None,
"url": another_page_with_nested_iframe,
"userContext": "default",
"originalOpener": None
"originalOpener": None,
'clientWindow': ANY_STR,
}]
} == result
Loading

0 comments on commit 9be3749

Please sign in to comment.