Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
2739bbfc
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
2739bbfc
编写于
6月 10, 2020
作者:
M
Mouad Debbar
提交者:
GitHub
6月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[web] Provide a hook to disable location strategy (#18969)
上级
74291b73
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
9 deletion
+63
-9
lib/web_ui/lib/src/engine/history.dart
lib/web_ui/lib/src/engine/history.dart
+4
-0
lib/web_ui/lib/src/engine/window.dart
lib/web_ui/lib/src/engine/window.dart
+10
-0
lib/web_ui/test/window_test.dart
lib/web_ui/test/window_test.dart
+49
-9
未找到文件。
lib/web_ui/lib/src/engine/history.dart
浏览文件 @
2739bbfc
...
...
@@ -53,6 +53,10 @@ class BrowserHistory {
}
}
/// Returns the currently active location strategy.
@visibleForTesting
LocationStrategy
get
locationStrategy
=>
_locationStrategy
;
/// The path of the current location of the user's browser.
String
get
currentPath
=>
_locationStrategy
?.
path
??
'/'
;
...
...
lib/web_ui/lib/src/engine/window.dart
浏览文件 @
2739bbfc
...
...
@@ -17,6 +17,12 @@ ui.VoidCallback scheduleFrameCallback;
class
EngineWindow
extends
ui
.
Window
{
EngineWindow
()
{
_addBrightnessMediaQueryListener
();
js
.
context
[
'_flutter_web_set_location_strategy'
]
=
(
LocationStrategy
strategy
)
{
locationStrategy
=
strategy
;
};
registerHotRestartListener
(()
{
js
.
context
[
'_flutter_web_set_location_strategy'
]
=
null
;
});
}
@override
...
...
@@ -178,6 +184,10 @@ class EngineWindow extends ui.Window {
_browserHistory
.
locationStrategy
=
strategy
;
}
/// Returns the currently active location strategy.
@visibleForTesting
LocationStrategy
get
locationStrategy
=>
_browserHistory
.
locationStrategy
;
@override
ui
.
VoidCallback
get
onTextScaleFactorChanged
=>
_onTextScaleFactorChanged
;
ui
.
VoidCallback
_onTextScaleFactorChanged
;
...
...
lib/web_ui/test/window_test.dart
浏览文件 @
2739bbfc
...
...
@@ -3,6 +3,9 @@
// found in the LICENSE file.
// @dart = 2.6
import
'dart:async'
;
import
'dart:html'
as
html
;
import
'dart:js_util'
as
js_util
;
import
'dart:typed_data'
;
import
'package:test/test.dart'
;
...
...
@@ -12,24 +15,18 @@ const MethodCodec codec = JSONMethodCodec();
void
emptyCallback
(
ByteData
date
)
{}
TestLocationStrategy
_strategy
;
TestLocationStrategy
get
strategy
=>
_strategy
;
set
strategy
(
TestLocationStrategy
newStrategy
)
{
window
.
locationStrategy
=
_strategy
=
newStrategy
;
}
void
main
(
)
{
test
(
'window.defaultRouteName should not change'
,
()
{
s
trategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
window
.
locationS
trategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
expect
(
window
.
defaultRouteName
,
'/initial'
);
// Changing the URL in the address bar later shouldn't affect [window.defaultRouteName].
s
trategy
.
replaceState
(
null
,
null
,
'/newpath'
);
window
.
locationS
trategy
.
replaceState
(
null
,
null
,
'/newpath'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
});
test
(
'window.defaultRouteName should reset after navigation platform message'
,
()
{
s
trategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
window
.
locationS
trategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
'initial state'
,
null
,
'/initial'
));
// Reading it multiple times should return the same value.
expect
(
window
.
defaultRouteName
,
'/initial'
);
expect
(
window
.
defaultRouteName
,
'/initial'
);
...
...
@@ -46,4 +43,47 @@ void main() {
// reset to "/".
expect
(
window
.
defaultRouteName
,
'/'
);
});
test
(
'can disable location strategy'
,
()
async
{
final
testStrategy
=
TestLocationStrategy
.
fromEntry
(
TestHistoryEntry
(
null
,
null
,
'/'
),
);
window
.
locationStrategy
=
testStrategy
;
expect
(
window
.
locationStrategy
,
testStrategy
);
// A single listener should've been setup.
expect
(
testStrategy
.
listeners
,
hasLength
(
1
));
// The initial entry should be there, plus another "flutter" entry.
expect
(
testStrategy
.
history
,
hasLength
(
2
));
expect
(
testStrategy
.
history
[
0
].
state
,
<
String
,
bool
>{
'origin'
:
true
});
expect
(
testStrategy
.
history
[
1
].
state
,
<
String
,
bool
>{
'flutter'
:
true
});
expect
(
testStrategy
.
currentEntry
,
testStrategy
.
history
[
1
]);
// Now, let's disable location strategy and make sure things get cleaned up.
expect
(()
=>
jsSetLocationStrategy
(
null
),
returnsNormally
);
expect
(
window
.
locationStrategy
,
isNull
);
// The listener is removed asynchronously.
await
Future
<
void
>.
delayed
(
const
Duration
(
milliseconds:
10
));
// No more listeners.
expect
(
testStrategy
.
listeners
,
isEmpty
);
// History should've moved back to the initial entry.
expect
(
testStrategy
.
history
[
0
].
state
,
<
String
,
bool
>{
'origin'
:
true
});
expect
(
testStrategy
.
currentEntry
,
testStrategy
.
history
[
0
]);
});
test
(
'js interop throws on wrong type'
,
()
{
expect
(()
=>
jsSetLocationStrategy
(
123
),
throwsA
(
anything
));
expect
(()
=>
jsSetLocationStrategy
(
'foo'
),
throwsA
(
anything
));
expect
(()
=>
jsSetLocationStrategy
(
false
),
throwsA
(
anything
));
});
}
void
jsSetLocationStrategy
(
dynamic
strategy
)
{
js_util
.
callMethod
(
html
.
window
,
'_flutter_web_set_location_strategy'
,
<
dynamic
>[
strategy
],
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录