This commit is contained in:
Pavel Feldman 2019-11-20 15:16:57 -08:00 коммит произвёл Andrey Lushnikov
Родитель 1fe1e150f3
Коммит f9a89eb313
22 изменённых файлов: 173 добавлений и 130 удалений

Просмотреть файл

@ -2,7 +2,7 @@
<!-- GEN:test-stats -->
|Firefox|Chromium|WebKit|all|
|---|---|---|---|
|508/634|685/692|325/637|309/634|
|508/632|683/690|325/635|309/632|
<!-- GEN:stop -->
# Contributing

Просмотреть файл

@ -70,7 +70,6 @@
* [event: 'console'](#event-console)
* [event: 'dialog'](#event-dialog)
* [event: 'domcontentloaded'](#event-domcontentloaded)
* [event: 'error'](#event-error)
* [event: 'frameattached'](#event-frameattached)
* [event: 'framedetached'](#event-framedetached)
* [event: 'framenavigated'](#event-framenavigated)
@ -995,13 +994,6 @@ Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` o
Emitted when the JavaScript [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.
#### event: 'error'
- <[Error]>
Emitted when the page crashes.
> **NOTE** `error` event has a special meaning in Node, see [error events](https://nodejs.org/api/events.html#events_error_events) for details.
#### event: 'frameattached'
- <[Frame]>

Просмотреть файл

@ -1,91 +1,10 @@
/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications copyright (c) Microsoft Corporation.
*
* Licensed 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.
*/
export = {
Chromium: {
Accessibility: require('./chromium/features/accessibility').Accessibility,
Browser: require('./chromium/Browser').Browser,
BrowserContext: require('./chromium/BrowserContext').BrowserContext,
BrowserFetcher: require('./chromium/BrowserFetcher').BrowserFetcher,
CDPSession: require('./chromium/Connection').CDPSession,
ConsoleMessage: require('./chromium/Page').ConsoleMessage,
Coverage: require('./chromium/features/coverage').Coverage,
Dialog: require('./chromium/Dialog').Dialog,
ElementHandle: require('./chromium/JSHandle').ElementHandle,
ExecutionContext: require('./chromium/ExecutionContext').ExecutionContext,
FileChooser: require('./chromium/Page').FileChooser,
Frame: require('./chromium/Frame').Frame,
Geolocation: require('./chromium/features/geolocation').Geolocation,
JSHandle: require('./chromium/JSHandle').JSHandle,
Keyboard: require('./chromium/Input').Keyboard,
Mouse: require('./chromium/Input').Mouse,
PDF: require('./chromium/features/pdf').PDF,
Page: require('./chromium/Page').Page,
Permissions: require('./chromium/features/permissions').Permissions,
Playwright: require('./chromium/Playwright').Playwright,
Request: require('./chromium/NetworkManager').Request,
Response: require('./chromium/NetworkManager').Response,
Target: require('./chromium/Target').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./chromium/Input').Touchscreen,
Tracing: require('./chromium/features/tracing').Tracing,
Worker: require('./chromium/features/workers').Worker,
Workers: require('./chromium/features/workers').Workers,
},
Firefox: {
Accessibility: require('./firefox/features/accessibility').Accessibility,
Browser: require('./firefox/Browser').Browser,
BrowserContext: require('./firefox/Browser').BrowserContext,
BrowserFetcher: require('./firefox/BrowserFetcher').BrowserFetcher,
CDPSession: require('./firefox/Connection').CDPSession,
ConsoleMessage: require('./firefox/Page').ConsoleMessage,
Dialog: require('./firefox/Dialog').Dialog,
ElementHandle: require('./firefox/JSHandle').ElementHandle,
ExecutionContext: require('./firefox/ExecutionContext').ExecutionContext,
FileChooser: require('./firefox/Page').FileChooser,
Frame: require('./firefox/FrameManager').Frame,
JSHandle: require('./firefox/JSHandle').JSHandle,
Keyboard: require('./firefox/Input').Keyboard,
Mouse: require('./firefox/Input').Mouse,
Page: require('./firefox/Page').Page,
Permissions: require('./firefox/features/permissions').Permissions,
Playwright: require('./firefox/Playwright').Playwright,
Request: require('./firefox/NetworkManager').Request,
Response: require('./firefox/NetworkManager').Response,
Target: require('./firefox/Browser').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./firefox/Input').Touchscreen,
},
WebKit: {
Browser: require('./webkit/Browser').Browser,
BrowserContext: require('./webkit/Browser').BrowserContext,
BrowserFetcher: require('./webkit/BrowserFetcher'),
ConsoleMessage: require('./webkit/Page').ConsoleMessage,
ElementHandle: require('./webkit/JSHandle').ElementHandle,
ExecutionContext: require('./webkit/ExecutionContext').ExecutionContext,
Frame: require('./webkit/FrameManager').Frame,
JSHandle: require('./webkit/JSHandle').JSHandle,
Keyboard: require('./webkit/Input').Keyboard,
Mouse: require('./webkit/Input').Mouse,
Page: require('./webkit/Page').Page,
Playwright: require('./webkit/Playwright').Playwright,
Request: require('./webkit/NetworkManager').Request,
Response: require('./webkit/NetworkManager').Response,
Target: require('./webkit/Browser').Target,
TimeoutError: require('./Errors').TimeoutError,
Touchscreen: require('./webkit/Input').Touchscreen,
}
};
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import * as chromium from './chromium/api';
import * as firefox from './firefox/api';
import * as webkit from './webkit/api';
export const Chromium = chromium;
export const Firefox = firefox;
export const WebKit = webkit;

Просмотреть файл

@ -17,7 +17,7 @@
import * as childProcess from 'child_process';
import { EventEmitter } from 'events';
import { Events } from '../Events';
import { Events } from './events';
import { assert, helper } from '../helper';
import { BrowserContext } from './BrowserContext';
import { Connection, ConnectionEvents } from './Connection';

Просмотреть файл

@ -15,11 +15,10 @@
* limitations under the License.
*/
import {assert} from '../helper';
import {Events} from '../Events';
import * as debug from 'debug';
import { EventEmitter } from 'events';
import { ConnectionTransport } from '../ConnectionTransport';
import { assert } from '../helper';
import { Protocol } from './protocol';
const debugProtocol = debug('playwright:protocol');

Просмотреть файл

@ -19,7 +19,7 @@ import { EventEmitter } from 'events';
import * as fs from 'fs';
import * as mime from 'mime';
import * as path from 'path';
import { Events } from '../Events';
import { Events } from './events';
import { assert, debugError, helper } from '../helper';
import { TimeoutSettings } from '../TimeoutSettings';
import { Accessibility } from './features/accessibility';

Просмотреть файл

@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Events } from '../Events';
import { Events } from './events';
import { Browser } from './Browser';
import { BrowserContext } from './BrowserContext';
import { CDPSession } from './Connection';

24
src/chromium/api.ts Normal file
Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { TimeoutError } from '../Errors';
export { Browser } from './Browser';
export { BrowserContext } from './BrowserContext';
export { BrowserFetcher } from './BrowserFetcher';
export { CDPSession } from './Connection';
export { Dialog } from './Dialog';
export { ExecutionContext } from './ExecutionContext';
export { Accessibility } from './features/accessibility';
export { Coverage } from './features/coverage';
export { Geolocation } from './features/geolocation';
export { PDF } from './features/pdf';
export { Permissions } from './features/permissions';
export { Tracing } from './features/tracing';
export { Worker, Workers } from './features/workers';
export { Frame } from './Frame';
export { Keyboard, Mouse, Touchscreen } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, FileChooser, Page } from './Page';
export { Playwright } from './Playwright';
export { Target } from './Target';

Просмотреть файл

@ -21,7 +21,6 @@ export const Events = {
Console: 'console',
Dialog: 'dialog',
DOMContentLoaded: 'domcontentloaded',
Error: 'error',
// Can't use just 'error' due to node.js special treatment of error events.
// @see https://nodejs.org/api/events.html#events_error_events
PageError: 'pageerror',

Просмотреть файл

@ -20,7 +20,7 @@ import { ExecutionContext } from '../ExecutionContext';
import { debugError } from '../../helper';
import { JSHandle } from '../JSHandle';
import { Protocol } from '../protocol';
import { Events } from '../../Events';
import { Events } from '../events';
type AddToConsoleCallback = (type: string, args: JSHandle[], stackTrace: Protocol.Runtime.StackTrace | undefined) => void;
type HandleExceptionCallback = (exceptionDetails: Protocol.Runtime.ExceptionDetails) => void;

Просмотреть файл

@ -16,7 +16,7 @@
*/
import { EventEmitter } from 'events';
import { Events } from '../Events';
import { Events } from './events';
import { assert, helper, RegisteredListener } from '../helper';
import { Connection, ConnectionEvents } from './Connection';
import { Permissions } from './features/permissions';

Просмотреть файл

@ -15,7 +15,7 @@ import {TimeoutSettings} from '../TimeoutSettings';
import {NavigationWatchdog} from './NavigationWatchdog';
import {Accessibility} from './features/accessibility';
import { Target, BrowserContext } from './Browser';
import { Events } from '../Events';
import { Events } from './events';
const writeFileAsync = helper.promisify(fs.writeFile);

16
src/firefox/api.ts Normal file
Просмотреть файл

@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { TimeoutError } from '../Errors';
export { Browser, BrowserContext, Target } from './Browser';
export { BrowserFetcher } from './BrowserFetcher';
export { Dialog } from './Dialog';
export { ExecutionContext } from './ExecutionContext';
export { Accessibility } from './features/accessibility';
export { Permissions } from './features/permissions';
export { Frame } from './FrameManager';
export { Keyboard, Mouse, Touchscreen } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, Page } from './Page';
export { Playwright } from './Playwright';

50
src/firefox/events.ts Normal file
Просмотреть файл

@ -0,0 +1,50 @@
/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications copyright (c) Microsoft Corporation.
*
* Licensed 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.
*/
export const Events = {
Page: {
Close: 'close',
Console: 'console',
Dialog: 'dialog',
DOMContentLoaded: 'domcontentloaded',
// Can't use just 'error' due to node.js special treatment of error events.
// @see https://nodejs.org/api/events.html#events_error_events
PageError: 'pageerror',
Request: 'request',
Response: 'response',
RequestFailed: 'requestfailed',
RequestFinished: 'requestfinished',
FrameAttached: 'frameattached',
FrameDetached: 'framedetached',
FrameNavigated: 'framenavigated',
Load: 'load',
Popup: 'popup',
},
Browser: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
Disconnected: 'disconnected'
},
BrowserContext: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
}
};

Просмотреть файл

@ -18,7 +18,7 @@
import * as childProcess from 'child_process';
import { EventEmitter } from 'events';
import { Connection } from './Connection';
import { Events } from '../Events';
import { Events } from './events';
import { RegisteredListener, assert, helper } from '../helper';
import { Page, Viewport } from './Page';
import { Target } from './Target';
@ -157,13 +157,6 @@ export class Browser extends EventEmitter {
context = this._defaultContext;
const target = new Target(targetInfo, context);
this._targets.set(targetInfo.targetId, target);
if (target.opener() && target.opener()._pagePromise) {
const openerPage = await target.opener()._pagePromise;
if (openerPage.listenerCount(Events.Page.Popup)) {
const popupPage = await target.page();
openerPage.emit(Events.Page.Popup, popupPage);
}
}
this.emit(Events.Browser.TargetCreated, target);
context.emit(Events.BrowserContext.TargetCreated, target);
}

Просмотреть файл

@ -17,7 +17,7 @@
import * as EventEmitter from 'events';
import * as fs from 'fs';
import { TimeoutError } from '../Errors';
import { Events } from '../Events';
import { Events } from './events';
import { assert, debugError, helper, RegisteredListener } from '../helper';
import { TimeoutSettings } from '../TimeoutSettings';
import { TargetSession } from './Connection';

Просмотреть файл

@ -19,7 +19,7 @@ import { EventEmitter } from 'events';
import * as fs from 'fs';
import * as mime from 'mime';
import { TargetSession, TargetSessionEvents } from './Connection';
import { Events } from '../Events';
import { Events } from './events';
import { Frame, FrameManager, FrameManagerEvents } from './FrameManager';
import { assert, debugError, helper, RegisteredListener } from '../helper';
import { valueFromRemoteObject } from './protocolHelper';

Просмотреть файл

@ -25,7 +25,6 @@ export class Target {
_targetId: string;
private _type: 'page' | 'service-worker' | 'worker';
_pagePromise: Promise<Page> | null = null;
private _openerId?: string;
private _url: string;
_initializedPromise: Promise<boolean>;
_initializedCallback: (value?: unknown) => void;
@ -34,7 +33,7 @@ export class Target {
_isInitialized: boolean;
_eventListeners: RegisteredListener[];
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext, openerId?: string) {
constructor(targetInfo: Protocol.Target.TargetInfo, browserContext: BrowserContext) {
const {targetId, url, type} = targetInfo;
this._browserContext = browserContext;
this._targetId = targetId;
@ -42,7 +41,6 @@ export class Target {
/** @type {?Promise<!Page>} */
this._pagePromise = null;
this._url = url;
this._openerId = openerId;
this._isClosedPromise = new Promise(fulfill => this._closedCallback = fulfill);
if (type === 'page') {
const session = this._browserContext.browser()._connection.session(this._targetId);
@ -88,8 +86,4 @@ export class Target {
browserContext(): BrowserContext {
return this._browserContext;
}
opener(): Target | null {
return this._openerId ? this.browser()._targets.get(this._openerId) : null;
}
}

13
src/webkit/api.ts Normal file
Просмотреть файл

@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export { TimeoutError } from '../Errors';
export { Browser, BrowserContext } from './Browser';
export { BrowserFetcher } from './BrowserFetcher';
export { ExecutionContext } from './ExecutionContext';
export { Frame } from './FrameManager';
export { Keyboard, Mouse } from './Input';
export { ElementHandle, JSHandle } from './JSHandle';
export { Request, Response } from './NetworkManager';
export { ConsoleMessage, Page } from './Page';
export { Playwright } from './Playwright';

44
src/webkit/events.ts Normal file
Просмотреть файл

@ -0,0 +1,44 @@
/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications copyright (c) Microsoft Corporation.
*
* Licensed 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.
*/
export const Events = {
Page: {
Close: 'close',
Console: 'console',
DOMContentLoaded: 'domcontentloaded',
Request: 'request',
Response: 'response',
RequestFailed: 'requestfailed',
RequestFinished: 'requestfinished',
FrameAttached: 'frameattached',
FrameDetached: 'framedetached',
FrameNavigated: 'framenavigated',
Load: 'load',
},
Browser: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
},
BrowserContext: {
TargetCreated: 'targetcreated',
TargetDestroyed: 'targetdestroyed',
TargetChanged: 'targetchanged',
},
};

Просмотреть файл

@ -100,7 +100,7 @@ if (process.env.BROWSER === 'firefox') {
testRunner,
});
if (process.env.COVERAGE)
utils.recordAPICoverage(testRunner, require('../lib/api').Chromium, require('../lib/Events').Events, CHROMIUM_NO_COVERAGE);
utils.recordAPICoverage(testRunner, require('../lib/api').Chromium, require('../lib/chromium/events').Events, CHROMIUM_NO_COVERAGE);
});
}

Просмотреть файл

@ -27,9 +27,9 @@ module.exports = checkSources;
function checkSources(sources) {
// special treatment for Events.js
const classEvents = new Map();
const eventsSource = sources.find(source => source.name().startsWith('Events.'));
const eventsSource = sources.find(source => source.name().startsWith('events.'));
if (eventsSource) {
const {Events} = eventsSource.filePath().endsWith('.js') ? require(eventsSource.filePath()) : require(path.join(eventsSource.filePath(), '..', '..', 'lib', 'Events.js'));
const {Events} = eventsSource.filePath().endsWith('.js') ? require(eventsSource.filePath()) : require(path.join(eventsSource.filePath(), '..', '..', '..', 'lib', 'chromium', 'events.js'));
for (const [className, events] of Object.entries(Events))
classEvents.set(className, Array.from(Object.values(events)).filter(e => typeof e === 'string').map(e => Documentation.Member.createEvent(e)));
}