Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
3c93ad4c
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
3c93ad4c
编写于
5月 11, 2021
作者:
D
David Iglesias
提交者:
GitHub
5月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[web] Resolve OS as iOs for iDevice Safari requesting desktop version of app. (#25957)
上级
af0a96bf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
161 addition
and
33 deletion
+161
-33
lib/web_ui/lib/src/engine/browser_detection.dart
lib/web_ui/lib/src/engine/browser_detection.dart
+16
-4
lib/web_ui/test/browser_detect_test.dart
lib/web_ui/test/browser_detect_test.dart
+145
-29
未找到文件。
lib/web_ui/lib/src/engine/browser_detection.dart
浏览文件 @
3c93ad4c
...
...
@@ -131,7 +131,7 @@ enum OperatingSystem {
}
/// Lazily initialized current operating system.
late
final
OperatingSystem
_operatingSystem
=
_
detectOperatingSystem
();
late
final
OperatingSystem
_operatingSystem
=
detectOperatingSystem
();
/// Returns the [OperatingSystem] the current browsers works on.
///
...
...
@@ -149,11 +149,23 @@ OperatingSystem get operatingSystem {
/// This is intended to be used for testing and debugging only.
OperatingSystem
?
debugOperatingSystemOverride
;
OperatingSystem
_detectOperatingSystem
(
)
{
final
String
platform
=
html
.
window
.
navigator
.
platform
!;
final
String
userAgent
=
html
.
window
.
navigator
.
userAgent
;
@visibleForTesting
OperatingSystem
detectOperatingSystem
(
{
String
?
overridePlatform
,
String
?
overrideUserAgent
,
int
?
overrideMaxTouchPoints
,
})
{
final
String
platform
=
overridePlatform
??
html
.
window
.
navigator
.
platform
!;
final
String
userAgent
=
overrideUserAgent
??
html
.
window
.
navigator
.
userAgent
;
if
(
platform
.
startsWith
(
'Mac'
))
{
// iDevices requesting a "desktop site" spoof their UA so it looks like a Mac.
// This checks if we're in a touch device, or on a real mac.
final
int
maxTouchPoints
=
overrideMaxTouchPoints
??
html
.
window
.
navigator
.
maxTouchPoints
??
0
;
if
(
maxTouchPoints
>
2
)
{
return
OperatingSystem
.
iOs
;
}
return
OperatingSystem
.
macOs
;
}
else
if
(
platform
.
toLowerCase
().
contains
(
'iphone'
)
||
platform
.
toLowerCase
().
contains
(
'ipad'
)
||
...
...
lib/web_ui/test/browser_detect_test.dart
浏览文件 @
3c93ad4c
...
...
@@ -11,38 +11,154 @@ void main() {
}
void
testMain
(
)
{
test
(
'Should detect Blink'
,
()
{
// Chrome Version 89.0.4389.90 (Official Build) (x86_64) / MacOS
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
'Google Inc.'
,
'mozilla/5.0 (macintosh; intel mac os x 11_2_3) applewebkit/537.36 '
'(khtml, like gecko) chrome/89.0.4389.90 safari/537.36'
);
expect
(
browserEngine
,
BrowserEngine
.
blink
);
});
group
(
'detectBrowserEngineByVendorAgent'
,
()
{
test
(
'Should detect Blink'
,
()
{
// Chrome Version 89.0.4389.90 (Official Build) (x86_64) / MacOS
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
'Google Inc.'
,
'mozilla/5.0 (macintosh; intel mac os x 11_2_3) applewebkit/537.36 '
'(khtml, like gecko) chrome/89.0.4389.90 safari/537.36'
);
expect
(
browserEngine
,
BrowserEngine
.
blink
);
});
test
(
'Should detect Firefox'
,
()
{
// 85.0.2 (64-bit) / MacOS
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
''
,
'mozilla/5.0 (macintosh; intel mac os x 10.16; rv:85.0) '
'gecko/20100101 firefox/85.0'
);
expect
(
browserEngine
,
BrowserEngine
.
firefox
);
});
test
(
'Should detect Firefox'
,
()
{
// 85.0.2 (64-bit) / MacOS
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
''
,
'mozilla/5.0 (macintosh; intel mac os x 10.16; rv:85.0) '
'gecko/20100101 firefox/85.0'
);
expect
(
browserEngine
,
BrowserEngine
.
firefox
);
});
test
(
'Should detect Safari'
,
()
{
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
'Apple Computer, Inc.'
,
'mozilla/5.0 (macintosh; intel mac os x 10_15_6) applewebkit/605.1.15 '
'(khtml, like gecko) version/14.0.3 safari/605.1.15'
);
expect
(
browserEngine
,
BrowserEngine
.
webkit
);
});
test
(
'Should detect Safari'
,
()
{
BrowserEngine
browserEngine
=
detectBrowserEngineByVendorAgent
(
'Apple Computer, Inc.'
,
'mozilla/5.0 (macintosh; intel mac os x 10_15_6) applewebkit/605.1.15 '
'(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.
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
);
});
});
test
(
'Should detect Samsung browser'
,
()
{
// Samsung 13.2.1.70 on Galaxy Tab S6.
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'
,
()
{
void
expectOs
(
OperatingSystem
expectedOs
,
{
String
platform
=
'any'
,
String
ua
=
'any'
,
int
touchPoints
=
0
,
})
{
expect
(
detectOperatingSystem
(
overridePlatform:
platform
,
overrideUserAgent:
ua
,
overrideMaxTouchPoints:
touchPoints
,
),
expectedOs
);
}
test
(
'Determine unknown for weird values of platform/ua'
,
()
{
expectOs
(
OperatingSystem
.
unknown
);
});
test
(
'Determine MacOS if platform starts by Mac'
,
()
{
expectOs
(
OperatingSystem
.
macOs
,
platform:
'MacIntel'
,
);
expectOs
(
OperatingSystem
.
macOs
,
platform:
'MacAnythingElse'
,
);
});
test
(
'Determine iOS if platform contains iPhone/iPad/iPod'
,
()
{
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPhone'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPhone Simulator'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPad'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPad Simulator'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPod'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'iPod Simulator'
,
);
});
// See https://github.com/flutter/flutter/issues/81918
test
(
'Tell apart MacOS from iOS requesting a desktop site.'
,
()
{
expectOs
(
OperatingSystem
.
macOs
,
platform:
'MacARM'
,
);
expectOs
(
OperatingSystem
.
iOs
,
platform:
'MacARM'
,
touchPoints:
5
,
);
});
test
(
'Determine Android if user agent contains Android'
,
()
{
expectOs
(
OperatingSystem
.
android
,
ua:
'Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
,
);
});
test
(
'Determine Linux if the platform begins with Linux'
,
()
{
expectOs
(
OperatingSystem
.
linux
,
platform:
'Linux'
,
);
expectOs
(
OperatingSystem
.
linux
,
platform:
'Linux armv8l'
,
);
expectOs
(
OperatingSystem
.
linux
,
platform:
'Linux x86_64'
,
);
});
test
(
'Determine Windows if the platform begins with Win'
,
()
{
expectOs
(
OperatingSystem
.
windows
,
platform:
'Windows'
,
);
expectOs
(
OperatingSystem
.
windows
,
platform:
'Win32'
,
);
expectOs
(
OperatingSystem
.
windows
,
platform:
'Win16'
,
);
expectOs
(
OperatingSystem
.
windows
,
platform:
'WinCE'
,
);
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录