mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
> [!IMPORTANT] > Requires the following engine PR: > * https://github.com/flutter/engine/pull/52380 > ---- This PR refactors Flutter `foundation`'s library `platform` for the web with the same code we use to detect platforms in the engine. ## Issues * Fixes: https://github.com/flutter/flutter/issues/128943 ## Testing Demo app deployed here: * https://dit-browser-detect.web.app
34 lines
1.0 KiB
Dart
34 lines
1.0 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
@TestOn('chrome')
|
|
library;
|
|
|
|
import 'dart:ui_web' as ui_web;
|
|
|
|
import 'package:flutter/foundation.dart' show TargetPlatform, defaultTargetPlatform;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
tearDown(() {
|
|
// Remove the `debugOperatingSystemOverride`.
|
|
ui_web.browser.debugOperatingSystemOverride = null;
|
|
});
|
|
|
|
group('defaultTargetPlatform', () {
|
|
testWidgets('returns what ui_web says', (WidgetTester _) async {
|
|
// Set the OS reported by web_ui to anything that is not linux.
|
|
ui_web.browser.debugOperatingSystemOverride = ui_web.OperatingSystem.iOs;
|
|
|
|
expect(defaultTargetPlatform, TargetPlatform.iOS);
|
|
});
|
|
|
|
testWidgets('defaults `unknown` to android', (WidgetTester _) async {
|
|
ui_web.browser.debugOperatingSystemOverride = ui_web.OperatingSystem.unknown;
|
|
|
|
expect(defaultTargetPlatform, TargetPlatform.android);
|
|
});
|
|
});
|
|
}
|