|
| 1 | +// Copyright 2026 The Chromium Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import type * as Protocol from '../../generated/protocol.js'; |
| 6 | +import {createTarget} from '../../testing/EnvironmentHelpers.js'; |
| 7 | +import {describeWithMockConnection, setMockConnectionResponseHandler} from '../../testing/MockConnection.js'; |
| 8 | + |
| 9 | +import * as SDK from './sdk.js'; |
| 10 | + |
| 11 | +describeWithMockConnection('CrashReportContextModel', () => { |
| 12 | + let model: SDK.CrashReportContextModel.CrashReportContextModel; |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + const target = createTarget(); |
| 16 | + model = target.model(SDK.CrashReportContextModel.CrashReportContextModel)!; |
| 17 | + assert.exists(model); |
| 18 | + }); |
| 19 | + |
| 20 | + it('can retrieve entries', async () => { |
| 21 | + const frameId = 'frame-1' as Protocol.Page.FrameId; |
| 22 | + setMockConnectionResponseHandler('CrashReportContext.getEntries', () => { |
| 23 | + return { |
| 24 | + entries: [ |
| 25 | + {key: 'key1', value: 'value1', frameId}, |
| 26 | + {key: 'key2', value: 'value2', frameId}, |
| 27 | + ], |
| 28 | + }; |
| 29 | + }); |
| 30 | + |
| 31 | + const entries = await model.getEntries(); |
| 32 | + assert.exists(entries); |
| 33 | + assert.lengthOf(entries, 2); |
| 34 | + assert.strictEqual(entries[0].key, 'key1'); |
| 35 | + assert.strictEqual(entries[0].value, 'value1'); |
| 36 | + assert.strictEqual(entries[0].frameId, 'frame-1'); |
| 37 | + assert.strictEqual(entries[1].key, 'key2'); |
| 38 | + assert.strictEqual(entries[1].value, 'value2'); |
| 39 | + assert.strictEqual(entries[1].frameId, 'frame-1'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('handles empty entries', async () => { |
| 43 | + setMockConnectionResponseHandler('CrashReportContext.getEntries', () => { |
| 44 | + return { |
| 45 | + entries: [], |
| 46 | + }; |
| 47 | + }); |
| 48 | + |
| 49 | + const entries = await model.getEntries(); |
| 50 | + assert.exists(entries); |
| 51 | + assert.lengthOf(entries, 0); |
| 52 | + }); |
| 53 | + |
| 54 | + it('returns null on protocol error', async () => { |
| 55 | + setMockConnectionResponseHandler('CrashReportContext.getEntries', () => { |
| 56 | + return { |
| 57 | + getError: () => 'Feature disabled', |
| 58 | + }; |
| 59 | + }); |
| 60 | + |
| 61 | + const entries = await model.getEntries(); |
| 62 | + assert.isNull(entries); |
| 63 | + }); |
| 64 | +}); |
0 commit comments