Skip to content

Commit

Permalink
[web] remove references to IE11 and old Edge; treat Samsung browser a…
Browse files Browse the repository at this point in the history
…s Blink (flutter#35205)
  • Loading branch information
yjbanov authored Aug 31, 2022
1 parent 7e27b92 commit 4cb5be0
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 181 deletions.
46 changes: 7 additions & 39 deletions lib/web_ui/lib/src/engine/browser_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@ bool get _workAroundBug91333 => operatingSystem == OperatingSystem.iOs;
enum BrowserEngine {
/// The engine that powers Chrome, Samsung Internet Browser, UC Browser,
/// Microsoft Edge, Opera, and others.
///
/// Blink is assumed in case when a more precise browser engine wasn't
/// detected.
blink,

/// The engine that powers Safari.
webkit,

/// The engine that powers Firefox.
firefox,

/// The engine that powers Edge.
edge,

/// The engine that powers Internet Explorer 11.
ie11,

/// The engine that powers Samsung stock browser. It is based on blink.
samsung,

/// We were unable to detect the current browser engine.
unknown,
}

/// html webgl version qualifier constants.
Expand Down Expand Up @@ -70,51 +61,28 @@ BrowserEngine _detectBrowserEngine() {
return detectBrowserEngineByVendorAgent(vendor, agent);
}

/// Detects samsung blink variants.
///
/// Example patterns:
/// Note 2 : GT-N7100
/// Note 3 : SM-N900T
/// Tab 4 : SM-T330NU
/// Galaxy S4: SHV-E330S
/// Galaxy Note2: SHV-E250L
/// Note: SAMSUNG-SGH-I717
/// SPH/SCH are very old Palm models.
bool _isSamsungBrowser(String agent) {
final RegExp exp = RegExp(
r'SAMSUNG|SGH-[I|N|T]|GT-[I|N]|SM-[A|N|P|T|Z]|SHV-E|SCH-[I|J|R|S]|SPH-L');
return exp.hasMatch(agent.toUpperCase());
}

/// Detects browser engine for a given vendor and agent string.
///
/// Used for testing this library.
@visibleForTesting
BrowserEngine detectBrowserEngineByVendorAgent(String vendor, String agent) {
if (vendor == 'Google Inc.') {
// Samsung browser is based on blink, check for variant.
if (_isSamsungBrowser(agent)) {
return BrowserEngine.samsung;
}
return BrowserEngine.blink;
} else if (vendor == 'Apple Computer, Inc.') {
return BrowserEngine.webkit;
} else if (agent.contains('edge/')) {
return BrowserEngine.edge;
} else if (agent.contains('Edg/')) {
// Chromium based Microsoft Edge has `Edg` in the user-agent.
// https://docs.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-string
return BrowserEngine.blink;
} else if (agent.contains('trident/7.0')) {
return BrowserEngine.ie11;
} else if (vendor == '' && agent.contains('firefox')) {
// An empty string means firefox:
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vendor
return BrowserEngine.firefox;
}
// Assume unknown otherwise, but issue a warning.
print('WARNING: failed to detect current browser engine.');
return BrowserEngine.unknown;

// Assume Blink otherwise, but issue a warning.
print('WARNING: failed to detect current browser engine. Assuming this is a Chromium-compatible browser.');
return BrowserEngine.blink;
}

/// Operating system where the current browser runs.
Expand Down
4 changes: 1 addition & 3 deletions lib/web_ui/lib/src/engine/html_image_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ class HtmlCodec implements ui.Codec {
int naturalWidth = imgElement.naturalWidth;
int naturalHeight = imgElement.naturalHeight;
// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=700533.
if (naturalWidth == 0 && naturalHeight == 0 && (
browserEngine == BrowserEngine.firefox ||
browserEngine == BrowserEngine.ie11)) {
if (naturalWidth == 0 && naturalHeight == 0 && browserEngine == BrowserEngine.firefox) {
const int kDefaultImageSizeFallback = 300;
naturalWidth = kDefaultImageSizeFallback;
naturalHeight = kDefaultImageSizeFallback;
Expand Down
4 changes: 0 additions & 4 deletions lib/web_ui/lib/src/engine/semantics/text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,7 @@ class TextField extends RoleManager {

switch (browserEngine) {
case BrowserEngine.blink:
case BrowserEngine.samsung:
case BrowserEngine.edge:
case BrowserEngine.ie11:
case BrowserEngine.firefox:
case BrowserEngine.unknown:
_initializeForBlink();
break;
case BrowserEngine.webkit:
Expand Down
4 changes: 1 addition & 3 deletions lib/web_ui/lib/src/engine/text/font_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'dart:typed_data';
import 'package:ui/src/engine/fonts.dart';

import '../assets.dart';
import '../browser_detection.dart';
import '../dom.dart';
import '../safe_browser_api.dart';
import '../util.dart';
Expand Down Expand Up @@ -252,8 +251,7 @@ class _PolyfillFontManager extends FontManager {
paragraph.style.position = 'absolute';
paragraph.style.visibility = 'hidden';
paragraph.style.fontSize = '72px';
final String fallbackFontName =
browserEngine == BrowserEngine.ie11 ? 'Times New Roman' : 'sans-serif';
const String fallbackFontName = 'sans-serif';
paragraph.style.fontFamily = fallbackFontName;
if (descriptors['style'] != null) {
paragraph.style.fontStyle = descriptors['style']!;
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const int _kReturnKeyCode = 13;
/// is autofilled.
bool browserHasAutofillOverlay() =>
browserEngine == BrowserEngine.blink ||
browserEngine == BrowserEngine.samsung ||
browserEngine == BrowserEngine.webkit;

/// `transparentTextEditing` class is configured to make the autofill overlay
Expand Down
9 changes: 0 additions & 9 deletions lib/web_ui/test/browser_detect_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ void testMain() {
'(khtml, like gecko) version/14.0.3 safari/605.1.15');
expect(browserEngine, BrowserEngine.webkit);
});

test('Should detect Samsung browser', () {
// Samsung 13.2.1.70 on Galaxy Tab S6.
final BrowserEngine browserEngine = detectBrowserEngineByVendorAgent(
'Google Inc.',
'mozilla/5.0 (x11; linux x86_64) applewebkit/537.36 (khtml, like gecko)'
' samsungbrowser/13.2 chrome/83.0.4103.106 safari/537.36');
expect(browserEngine, BrowserEngine.samsung);
});
});

group('detectOperatingSystem', () {
Expand Down
4 changes: 1 addition & 3 deletions lib/web_ui/test/embedder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ void testMain() {
embedder.reset();
},
// TODO(ferhat): https://github.com/flutter/flutter/issues/46638
// TODO(ferhat): https://github.com/flutter/flutter/issues/50828
skip: browserEngine == BrowserEngine.firefox ||
browserEngine == BrowserEngine.edge);
skip: browserEngine == BrowserEngine.firefox);

test('accesibility placeholder is attached after creation', () {
final FlutterViewEmbedder embedder = FlutterViewEmbedder();
Expand Down
42 changes: 10 additions & 32 deletions lib/web_ui/test/engine/history_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ void testMain() {

// The flutter entry is the current entry.
expect(strategy.currentEntry, flutterEntry);
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('disposes of its listener without touching history', () async {
const String unwrappedOriginState = 'initial state';
Expand Down Expand Up @@ -216,9 +214,7 @@ void testMain() {
// The url of the current entry (flutter entry) should go back to /home.
expect(strategy.currentEntry.state, flutterState);
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('multiple browser back clicks', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand Down Expand Up @@ -284,10 +280,7 @@ void testMain() {
// 3. The active entry doesn't belong to our history anymore because we
// navigated past it.
expect(originalStrategy.currentEntryIndex, -1);
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge ||
browserEngine == BrowserEngine.webkit);
}, skip: browserEngine == BrowserEngine.webkit);

test('handle user-provided url', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand Down Expand Up @@ -328,9 +321,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 1);
expect(strategy.currentEntry.state, flutterState);
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('user types unknown url', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand All @@ -354,9 +345,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 1);
expect(strategy.currentEntry.state, flutterState);
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});
});

group('$MultiEntriesBrowserHistory', () {
Expand Down Expand Up @@ -384,9 +373,7 @@ void testMain() {
final TestHistoryEntry taggedOriginEntry = strategy.history[0];
expect(taggedOriginEntry.state, _tagStateWithSerialCount('initial state', 0));
expect(taggedOriginEntry.url, '/initial');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('disposes of its listener without touching history', () async {
const String untaggedState = 'initial state';
Expand Down Expand Up @@ -481,9 +468,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 0);
expect(strategy.currentEntry.state, _tagStateWithSerialCount('initial state', 0));
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('multiple browser back clicks', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand Down Expand Up @@ -532,10 +517,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 0);
expect(strategy.currentEntry.state, _tagStateWithSerialCount('initial state', 0));
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge ||
browserEngine == BrowserEngine.webkit);
}, skip: browserEngine == BrowserEngine.webkit);

test('handle user-provided url', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand Down Expand Up @@ -578,9 +560,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 0);
expect(strategy.currentEntry.state, _tagStateWithSerialCount('initial state', 0));
expect(strategy.currentEntry.url, '/home');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});

test('forward button works', () async {
final TestUrlStrategy strategy = TestUrlStrategy.fromEntry(
Expand Down Expand Up @@ -630,9 +610,7 @@ void testMain() {
expect(strategy.currentEntryIndex, 2);
expect(strategy.currentEntry.state, _tagStateWithSerialCount('page2 state', 2));
expect(strategy.currentEntry.url, '/page2');
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50836
skip: browserEngine == BrowserEngine.edge);
});
});

group('$HashUrlStrategy', () {
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/test/engine/image/html_image_codec_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Future<void> testMain() async {
expect(buffer.toString(), '0/100,100/100,');
});

/// Regression test for Firefox/ie11
/// Regression test for Firefox
/// https://github.com/flutter/flutter/issues/66412
test('Returns nonzero natural width/height', () async {
final HtmlCodec codec = HtmlCodec(
Expand Down
5 changes: 1 addition & 4 deletions lib/web_ui/test/engine/semantics/semantics_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:async';
import 'dart:typed_data';

import 'package:test/test.dart';
import 'package:ui/src/engine/browser_detection.dart';
import 'package:ui/src/engine/dom.dart';
import 'package:ui/src/engine/embedder.dart';
import 'package:ui/src/engine/host_node.dart';
Expand All @@ -28,9 +27,7 @@ HostNode get appHostNode => flutterViewEmbedder.glassPaneShadow!;
/// CSS style applied to the root of the semantics tree.
// TODO(yjbanov): this should be handled internally by [expectSemanticsTree].
// No need for every test to inject it.
final String rootSemanticStyle = browserEngine != BrowserEngine.edge
? 'filter: opacity(0%); color: rgba(0, 0, 0, 0)'
: 'color: rgba(0, 0, 0, 0); filter: opacity(0%)';
const String rootSemanticStyle = 'filter: opacity(0%); color: rgba(0, 0, 0, 0)';

/// A convenience wrapper of the semantics API for building and inspecting the
/// semantics tree in unit tests.
Expand Down
4 changes: 1 addition & 3 deletions lib/web_ui/test/engine/semantics/text_field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ void testMain() {

semantics().semanticsEnabled = false;
});
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50769
skip: browserEngine == BrowserEngine.edge);
});
}

SemanticsObject createTextFieldSemantics({
Expand Down
17 changes: 4 additions & 13 deletions lib/web_ui/test/keyboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'dart:typed_data';
import 'package:quiver/testing/async.dart';
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine/browser_detection.dart';
import 'package:ui/src/engine/dom.dart';
import 'package:ui/src/engine/keyboard.dart';
import 'package:ui/src/engine/services.dart';
Expand Down Expand Up @@ -68,9 +67,7 @@ void testMain() {
});

Keyboard.instance!.dispose();
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50815
skip: browserEngine == BrowserEngine.edge);
});

test('dispatches keydown to flutter/keyevent channel', () {
Keyboard.initialize();
Expand Down Expand Up @@ -101,9 +98,7 @@ void testMain() {
expect(event.defaultPrevented, isFalse);

Keyboard.instance!.dispose();
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50815
skip: browserEngine == BrowserEngine.edge);
});

test('dispatches correct meta state', () {
Keyboard.initialize();
Expand Down Expand Up @@ -155,9 +150,7 @@ void testMain() {
});

Keyboard.instance!.dispose();
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50815
skip: browserEngine == BrowserEngine.edge);
});

test('dispatches repeat events', () {
Keyboard.initialize();
Expand Down Expand Up @@ -210,9 +203,7 @@ void testMain() {
]);

Keyboard.instance!.dispose();
},
// TODO(mdebbar): https://github.com/flutter/flutter/issues/50815
skip: browserEngine == BrowserEngine.edge);
});

test('stops dispatching events after dispose', () {
Keyboard.initialize();
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/test/text/canvas_paragraph_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ String fontFamilyToAttribute(String fontFamily) {
if (browserEngine == BrowserEngine.firefox) {
return fontFamily.replaceAll('"', '&quot;');
} else if (browserEngine == BrowserEngine.blink ||
browserEngine == BrowserEngine.samsung ||
browserEngine == BrowserEngine.webkit) {
return fontFamily.replaceAll('"', '');
}
Expand Down
Loading

0 comments on commit 4cb5be0

Please sign in to comment.