Skip to content

Commit cbf00f4

Browse files
committed
test(platform-android): move the helper display-pair proof to the capture test (#3182)
parseAndroidSnapshotHelperOutput lives in snapshot-helper-capture.ts, so its viewport claim follows the source topology instead of the legacy aggregation; the capture fixture gains result lines rather than keeping a second output builder.
1 parent 5f950e1 commit cbf00f4

2 files changed

Lines changed: 33 additions & 44 deletions

File tree

‎packages/platform-android/src/__tests__/snapshot-helper-capture.test.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import assert from 'node:assert/strict';
22
import { beforeEach, test } from 'vitest';
3-
import { captureAndroidSnapshotWithHelper } from '../snapshot-helper-capture.ts';
3+
import {
4+
captureAndroidSnapshotWithHelper,
5+
parseAndroidSnapshotHelperOutput,
6+
} from '../snapshot-helper-capture.ts';
47
import { resetAndroidSnapshotHelperRetirements } from '../snapshot-helper-retirement.ts';
58
import type { AndroidAdbExecutor } from '../snapshot-helper-types.ts';
69
import {
@@ -130,7 +133,7 @@ test('canceled one-shot capture reports the cancellation and the next capture re
130133
]);
131134
});
132135

133-
function helperOutput(xml: string): string {
136+
function helperOutput(xml: string, resultLines: readonly string[] = []): string {
134137
return [
135138
'INSTRUMENTATION_STATUS: agentDeviceProtocol=android-snapshot-helper-v1',
136139
'INSTRUMENTATION_STATUS: helperApiVersion=1',
@@ -143,6 +146,34 @@ function helperOutput(xml: string): string {
143146
'INSTRUMENTATION_RESULT: helperApiVersion=1',
144147
'INSTRUMENTATION_RESULT: ok=true',
145148
'INSTRUMENTATION_RESULT: outputFormat=uiautomator-xml',
149+
...resultLines,
146150
'INSTRUMENTATION_CODE: 0',
147151
].join('\n');
148152
}
153+
154+
// The helper publishes the display's extent beside its density (#3182), and the transport reader
155+
// keeps an omitted pair absent rather than carrying a zero the host would have to second-guess.
156+
test('parseAndroidSnapshotHelperOutput carries the helper display extent beside its density (#3182)', () => {
157+
const parsed = parseAndroidSnapshotHelperOutput(
158+
helperOutput('<hierarchy><node text="row" /></hierarchy>', [
159+
'INSTRUMENTATION_RESULT: pixelDensity=2.625',
160+
'INSTRUMENTATION_RESULT: displayWidth=1080',
161+
'INSTRUMENTATION_RESULT: displayHeight=2400',
162+
]),
163+
);
164+
165+
assert.equal(parsed.metadata.pixelDensity, 2.625);
166+
assert.equal(parsed.metadata.displayWidth, 1080);
167+
assert.equal(parsed.metadata.displayHeight, 2400);
168+
});
169+
170+
test('parseAndroidSnapshotHelperOutput leaves the display extent absent when the helper omits it (#3182)', () => {
171+
const parsed = parseAndroidSnapshotHelperOutput(
172+
helperOutput('<hierarchy><node text="row" /></hierarchy>', [
173+
'INSTRUMENTATION_RESULT: pixelDensity=2.625',
174+
]),
175+
);
176+
177+
assert.equal(parsed.metadata.displayWidth, undefined);
178+
assert.equal(parsed.metadata.displayHeight, undefined);
179+
});

‎packages/platform-android/src/__tests__/snapshot-helper.test.ts‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -88,48 +88,6 @@ test('parseAndroidSnapshotHelperOutput reconstructs XML chunks and metadata', ()
8888
});
8989
});
9090

91-
// The helper publishes the display's extent beside its density (#3182). Both transports read the
92-
// same pair, and a helper that answered with nothing usable must leave the keys absent rather than
93-
// carry a zero the host would have to second-guess.
94-
test('readHelperMetadata carries the helper display extent beside its density (#3182)', () => {
95-
const xml = '<hierarchy><node text="row" /></hierarchy>';
96-
const output = helperOutput({
97-
chunks: [xml],
98-
result: {
99-
ok: 'true',
100-
helperApiVersion: '1',
101-
outputFormat: 'uiautomator-xml',
102-
pixelDensity: '2.625',
103-
displayWidth: '1080',
104-
displayHeight: '2400',
105-
},
106-
});
107-
108-
const parsed = parseAndroidSnapshotHelperOutput(output);
109-
110-
assert.equal(parsed.metadata.pixelDensity, 2.625);
111-
assert.equal(parsed.metadata.displayWidth, 1080);
112-
assert.equal(parsed.metadata.displayHeight, 2400);
113-
});
114-
115-
test('readHelperMetadata leaves the display extent absent when the helper omits it (#3182)', () => {
116-
const xml = '<hierarchy><node text="row" /></hierarchy>';
117-
const output = helperOutput({
118-
chunks: [xml],
119-
result: {
120-
ok: 'true',
121-
helperApiVersion: '1',
122-
outputFormat: 'uiautomator-xml',
123-
pixelDensity: '2.625',
124-
},
125-
});
126-
127-
const parsed = parseAndroidSnapshotHelperOutput(output);
128-
129-
assert.equal(parsed.metadata.displayWidth, undefined);
130-
assert.equal(parsed.metadata.displayHeight, undefined);
131-
});
132-
13391
test('parseAndroidSnapshotHelperOutput decodes UTF-8 across byte chunk boundaries', () => {
13492
const xml = '<hierarchy><node text="Save 👍" /></hierarchy>';
13593
const bytes = Buffer.from(xml, 'utf8');

0 commit comments

Comments
 (0)