test: unskip style tag tests (#10572)

This commit is contained in:
Alex Rudenko 2023-07-18 18:27:41 +02:00 committed by GitHub
parent 1f08c54d83
commit a419abf509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 152 deletions

View File

@ -1,25 +0,0 @@
---
sidebar_label: Page.addStyleTag_2
---
# Page.addStyleTag() method
#### Signature:
```typescript
class Page {
addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>>;
}
```
## Parameters
| Parameter | Type | Description |
| --------- | ----------------------------------------------------------------- | ----------- |
| options | [FrameAddStyleTagOptions](./puppeteer.frameaddstyletagoptions.md) | |
**Returns:**
Promise&lt;[ElementHandle](./puppeteer.elementhandle.md)&lt;HTMLStyleElement \| HTMLLinkElement&gt;&gt;

View File

@ -84,7 +84,6 @@ page.off('request', logRequest);
| [addScriptTag(options)](./puppeteer.page.addscripttag.md) | | Adds a <code>&lt;script&gt;</code> tag into the page with the desired URL or content. |
| [addStyleTag(options)](./puppeteer.page.addstyletag.md) | | <p>Adds a <code>&lt;link rel=&quot;stylesheet&quot;&gt;</code> tag into the page with the desired URL or a <code>&lt;style type=&quot;text/css&quot;&gt;</code> tag with the content.</p><p>Shortcut for [page.mainFrame().addStyleTag(options)](./puppeteer.frame.addstyletag_1.md).</p> |
| [addStyleTag(options)](./puppeteer.page.addstyletag_1.md) | | |
| [addStyleTag(options)](./puppeteer.page.addstyletag_2.md) | | |
| [authenticate(credentials)](./puppeteer.page.authenticate.md) | | Provide credentials for <code>HTTP authentication</code>. |
| [bringToFront()](./puppeteer.page.bringtofront.md) | | Brings page to front (activates tab). |
| [browser()](./puppeteer.page.browser.md) | | Get the browser the page belongs to. |

View File

@ -25,6 +25,7 @@ import {
IsolatedWorldChart,
WaitForSelectorOptions,
} from '../common/IsolatedWorld.js';
import {LazyArg} from '../common/LazyArg.js';
import {PuppeteerLifeCycleEvent} from '../common/LifecycleWatcher.js';
import {
EvaluateFunc,
@ -33,6 +34,7 @@ import {
InnerLazyParams,
NodeFor,
} from '../common/types.js';
import {importFSPromises} from '../common/util.js';
import {TaskManager} from '../common/WaitTask.js';
import {KeyboardTypeOptions} from './Input.js';
@ -780,10 +782,67 @@ export class Frame {
async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLLinkElement>>;
async addStyleTag(): Promise<
ElementHandle<HTMLStyleElement | HTMLLinkElement>
> {
throw new Error('Not implemented');
async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>> {
let {content = ''} = options;
const {path} = options;
if (+!!options.url + +!!path + +!!content !== 1) {
throw new Error(
'Exactly one of `url`, `path`, or `content` must be specified.'
);
}
if (path) {
const fs = await importFSPromises();
content = await fs.readFile(path, 'utf8');
content += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
options.content = content;
}
return this.mainRealm().transferHandle(
await this.isolatedRealm().evaluateHandle(
async ({Deferred}, {url, content}) => {
const deferred = Deferred.create<void>();
let element: HTMLStyleElement | HTMLLinkElement;
if (!url) {
element = document.createElement('style');
element.appendChild(document.createTextNode(content!));
} else {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
element = link;
}
element.addEventListener(
'load',
() => {
deferred.resolve();
},
{once: true}
);
element.addEventListener(
'error',
event => {
deferred.reject(
new Error(
(event as ErrorEvent).message ?? 'Could not load style'
)
);
},
{once: true}
);
document.head.appendChild(element);
await deferred.valueOrThrow();
return element;
},
LazyArg.create(context => {
return context.puppeteerUtil;
}),
options
)
);
}
/**

View File

@ -1206,11 +1206,8 @@ export class Page extends EventEmitter {
): Promise<ElementHandle<HTMLLinkElement>>;
async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>>;
async addStyleTag(): Promise<
ElementHandle<HTMLStyleElement | HTMLLinkElement>
> {
throw new Error('Not implemented');
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>> {
return this.mainFrame().addStyleTag(options);
}
/**

View File

@ -17,11 +17,7 @@
import {Protocol} from 'devtools-protocol';
import {ElementHandle} from '../api/ElementHandle.js';
import {
Frame as BaseFrame,
FrameAddScriptTagOptions,
FrameAddStyleTagOptions,
} from '../api/Frame.js';
import {Frame as BaseFrame, FrameAddScriptTagOptions} from '../api/Frame.js';
import {HTTPResponse} from '../api/HTTPResponse.js';
import {Page, WaitTimeoutOptions} from '../api/Page.js';
import {assert} from '../util/assert.js';
@ -401,75 +397,6 @@ export class Frame extends BaseFrame {
);
}
override async addStyleTag(
options: Omit<FrameAddStyleTagOptions, 'url'>
): Promise<ElementHandle<HTMLStyleElement>>;
override async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLLinkElement>>;
override async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>> {
let {content = ''} = options;
const {path} = options;
if (+!!options.url + +!!path + +!!content !== 1) {
throw new Error(
'Exactly one of `url`, `path`, or `content` must be specified.'
);
}
if (path) {
const fs = await importFSPromises();
content = await fs.readFile(path, 'utf8');
content += '/*# sourceURL=' + path.replace(/\n/g, '') + '*/';
options.content = content;
}
return this.mainRealm().transferHandle(
await this.isolatedRealm().evaluateHandle(
async ({Deferred}, {url, content}) => {
const deferred = Deferred.create<void>();
let element: HTMLStyleElement | HTMLLinkElement;
if (!url) {
element = document.createElement('style');
element.appendChild(document.createTextNode(content!));
} else {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
element = link;
}
element.addEventListener(
'load',
() => {
deferred.resolve();
},
{once: true}
);
element.addEventListener(
'error',
event => {
deferred.reject(
new Error(
(event as ErrorEvent).message ?? 'Could not load style'
)
);
},
{once: true}
);
document.head.appendChild(element);
await deferred.valueOrThrow();
return element;
},
LazyArg.create(context => {
return context.puppeteerUtil;
}),
options
)
);
}
override async title(): Promise<string> {
return this.isolatedRealm().title();
}

View File

@ -21,11 +21,7 @@ import {Protocol} from 'devtools-protocol';
import type {Browser} from '../api/Browser.js';
import type {BrowserContext} from '../api/BrowserContext.js';
import {ElementHandle} from '../api/ElementHandle.js';
import {
Frame,
FrameAddScriptTagOptions,
FrameAddStyleTagOptions,
} from '../api/Frame.js';
import {Frame, FrameAddScriptTagOptions} from '../api/Frame.js';
import {HTTPRequest} from '../api/HTTPRequest.js';
import {HTTPResponse} from '../api/HTTPResponse.js';
import {JSHandle} from '../api/JSHandle.js';
@ -589,18 +585,6 @@ export class CDPPage extends Page {
return this.mainFrame().addScriptTag(options);
}
override async addStyleTag(
options: Omit<FrameAddStyleTagOptions, 'url'>
): Promise<ElementHandle<HTMLStyleElement>>;
override async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLLinkElement>>;
override async addStyleTag(
options: FrameAddStyleTagOptions
): Promise<ElementHandle<HTMLStyleElement | HTMLLinkElement>> {
return this.mainFrame().addStyleTag(options);
}
override async exposeFunction(
name: string,
pptrFunction: Function | {default: Function}

View File

@ -173,6 +173,12 @@
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL", "TIMEOUT"]
},
{
"testIdPattern": "[page.spec] Page Page.addStyleTag *",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.browser *",
"platforms": ["darwin", "linux", "win32"],
@ -1124,14 +1130,8 @@
{
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with content to the CSP page",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with URL to the CSP page",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["PASS"]
"parameters": ["firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[page.spec] Page Page.close should *not* run beforeunload by default",
@ -1763,12 +1763,6 @@
"parameters": ["cdp", "firefox"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[coverage.spec] Coverage specs CSSCoverage should ignore injected stylesheets",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL"]
},
{
"testIdPattern": "[coverage.spec] Coverage specs CSSCoverage should work with complicated usecases",
"platforms": ["darwin", "linux", "win32"],
@ -3077,18 +3071,6 @@
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw an error if loading from url fail",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"],
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.addStyleTag should throw when added with content to the CSP page",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["cdp", "firefox"],
"expectations": ["SKIP"]
},
{
"testIdPattern": "[page.spec] Page Page.close should not be visible in browser.pages",
"platforms": ["darwin", "linux", "win32"],