Files
plezy/test/services/device_performance_test.dart
edde746 834895486b style: apply dart format to six drifted sources
Formatting was clean through 53288116 and then drifted across three commits on
2026-07-30: 1bf7aac7 left one source unformatted, f13f5af6 a second, and
daab4f1e four more. CI's Verify formatting job checks the whole tree, so it has
had six files to report ever since. No pre-commit hook is installed in this
checkout, so the aggregate check never ran locally to catch them.

Formatted with the dart_style revision Dart 3.12.0 bundles, which is what the
pinned Flutter 3.44.0 CI toolchain runs, rather than with a newer local SDK; the
two disagree about some argument-list splits. The current stable formatter
accepts this result as well, so both report the tree clean.
2026-07-30 14:57:26 +02:00

95 lines
3.3 KiB
Dart

import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/services/device_performance.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(() {
DevicePerformance.debugReset();
addTearDown(DevicePerformance.debugReset);
});
test('concurrent callers wait for hardware detection', () async {
final detection = Completer<void>();
DevicePerformance.debugDetectionGate = detection.future;
final first = DevicePerformance.getInstance(override: VisualEffectsSetting.reduced);
var secondCompleted = false;
final second = DevicePerformance.getInstance();
unawaited(second.then((_) => secondCompleted = true));
await Future<void>.delayed(Duration.zero);
expect(secondCompleted, isFalse);
detection.complete();
final instances = await Future.wait([first, second]);
expect(identical(instances.first, instances.last), isTrue);
expect(DevicePerformance.isReduced, isTrue);
});
test('failed hardware detection can be retried', () async {
DevicePerformance.debugDetectionGate = Future<void>.error(StateError('detection failed'));
await expectLater(DevicePerformance.getInstance(), throwsStateError);
DevicePerformance.debugDetectionGate = null;
final recovered = await DevicePerformance.getInstance();
expect(recovered, isNotNull);
});
group('displayBudgetFactor', () {
void detectAt(double shortestSide) {
DevicePerformance.debugDisplayShortestSideOverride = shortestSide;
DevicePerformance.debugDetectDisplayBudget();
}
test('stays 1.0 until a latch runs', () {
DevicePerformance.debugReset(autoReduced: false, override: VisualEffectsSetting.auto);
expect(DevicePerformance.displayBudgetFactor(), 1.0);
});
test('scales with the display shortest side up to 2x', () {
DevicePerformance.debugReset(autoReduced: false, override: VisualEffectsSetting.auto);
detectAt(1080);
expect(DevicePerformance.displayBudgetFactor(), 1.0);
detectAt(1440);
expect(DevicePerformance.displayBudgetFactor(), closeTo(1440 / 1080, 0.001));
detectAt(2160);
expect(DevicePerformance.displayBudgetFactor(), 2.0);
// 8K stays at the 2x ceiling.
detectAt(4320);
expect(DevicePerformance.displayBudgetFactor(), 2.0);
});
test('sub-1080p displays never shrink the budget below 1.0', () {
DevicePerformance.debugReset(autoReduced: false, override: VisualEffectsSetting.auto);
detectAt(720);
expect(DevicePerformance.displayBudgetFactor(), 1.0);
});
test('mid-RAM hardware holds a 4K budget at 1.5x', () {
DevicePerformance.debugReset(autoReduced: false, override: VisualEffectsSetting.auto, totalMemBytes: 2400 << 20);
detectAt(2160);
expect(DevicePerformance.displayBudgetFactor(), 1.5);
});
test('high-RAM hardware keeps the full 4K budget', () {
DevicePerformance.debugReset(autoReduced: false, override: VisualEffectsSetting.auto, totalMemBytes: 2870 << 20);
detectAt(2160);
expect(DevicePerformance.displayBudgetFactor(), 2.0);
});
test('reduced tier pins the budget to 1.0 even after a 4K latch', () {
DevicePerformance.debugReset(autoReduced: true, override: VisualEffectsSetting.auto);
detectAt(2160);
expect(DevicePerformance.displayBudgetFactor(), 1.0);
});
});
}