| // Copyright 2021 The Chromium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| import * as Common from '../core/common/common.js'; | |
| import type * as SDK from '../core/sdk/sdk.js'; | |
| import * as Logs from '../models/logs/logs.js'; | |
| interface MockNetworkRequest { | |
| requestId(): string; | |
| } | |
| export class MockNetworkLog extends Common.ObjectWrapper.ObjectWrapper<Logs.NetworkLog.EventTypes> { | |
| #mockRequests: MockNetworkRequest[]; | |
| constructor(mockRequests: MockNetworkRequest[]) { | |
| super(); | |
| this.#mockRequests = mockRequests; | |
| } | |
| requestsForId(requestId: string): MockNetworkRequest[] { | |
| return this.#mockRequests.filter(x => x.requestId() === requestId); | |
| } | |
| addRequest(mockRequest: MockNetworkRequest): void { | |
| this.#mockRequests.push(mockRequest); | |
| this.dispatchEventToListeners( | |
| Logs.NetworkLog.Events.RequestAdded, {request: mockRequest as SDK.NetworkRequest.NetworkRequest}); | |
| } | |
| } |