8000 Webdriver GoBack and GoForward commands wait for navigation complete · servo/servo@19b8dd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 19b8dd9

Browse files
Webdriver GoBack and GoForward commands wait for navigation complete
Signed-off-by: batu_hoang <longvatrong111@gmail.com>
1 parent 3526b7e commit 19b8dd9

File tree

6 files changed

+96
-24
lines changed

6 files changed

+96
-24
lines changed

components/shared/embedder/webdriver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub enum WebDriverCommandMsg {
4343
/// Refresh the top-level browsing context with the given ID.
4444
Refresh(WebViewId, IpcSender<WebDriverLoadStatus>),
4545
/// Navigate the webview with the given ID to the previous page in the browsing context's history.
46-
GoBack(WebViewId),
46+
GoBack(WebViewId, IpcSender<WebDriverLoadStatus>),
4747
/// Navigate the webview with the given ID to the next page in the browsing context's history.
48-
GoForward(WebViewId),
48+
GoForward(WebViewId, IpcSender<WebDriverLoadStatus>),
4949
/// Pass a webdriver command to the script thread of the current pipeline
5050
/// of a browsing context.
5151
ScriptCommand(BrowsingContextId, WebDriverScriptCommand),

components/webdriver_server/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,11 @@ impl Handler {
928928
// return error with error code no such window.
929929
self.verify_top_level_browsing_context_is_open(webview_id)?;
930930

931-
self.send_message_to_embedder(WebDriverCommandMsg::GoBack(webview_id))?;
932-
Ok(WebDriverResponse::Void)
931+
self.send_message_to_embedder(WebDriverCommandMsg::GoBack(
932+
webview_id,
933+
self.load_status_sender.clone(),
934+
))?;
935+
self.wait_for_load()
933936
}
934937

935938
fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
@@ -938,8 +941,11 @@ impl Handler {
938941
// return error with error code no such window.
939942
self.verify_top_level_browsing_context_is_open(webview_id)?;
940943

941-
self.send_message_to_embedder(WebDriverCommandMsg::GoForward(webview_id))?;
942-
Ok(WebDriverResponse::Void)
944+
self.send_message_to_embedder(WebDriverCommandMsg::GoForward(
945+
webview_id,
946+
self.load_status_sender.clone(),
947+
))?;
948+
self.wait_for_load()
943949
}
944950

945951
fn handle_refresh(&self) -> WebDriverResult<WebDriverResponse> {

Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use servo::webrender_api::ScrollLocation;
2727
use servo::webrender_api::units::DeviceIntSize;
2828
use servo::{
2929
EventLoopWaker, InputEvent, KeyboardEvent, MouseButtonEvent, MouseMoveEvent,
30-
WebDriverCommandMsg, WheelDelta, WheelEvent, WheelMode,
30+
WebDriverCommandMsg, WebDriverLoadStatus, WheelDelta, WheelEvent, WheelMode,
3131
};
3232
use url::Url;
3333
use winit::application::ApplicationHandler;
@@ -454,23 +454,45 @@ impl App {
454454
},
455455
WebDriverCommandMsg::LoadUrl(webview_id, url, load_status_sender) => {
456456
if let Some(webview) = running_state.webview_by_id(webview_id) {
457-
webview.load(url.into_url());
458457
running_state.set_load_status_sender(webview_id, load_status_sender);
458+
webview.load(url.into_url());
459459
}
460460
},
461461
WebDriverCommandMsg::Refresh(webview_id, load_status_sender) => {
462462
if let Some(webview) = running_state.webview_by_id(webview_id) {
463-
webview.reload();
464463
running_state.set_load_status_sender(webview_id, load_status_sender);
464+
webview.reload();
465465
}
466466
},
467-
WebDriverCommandMsg::GoBack(webview_id) => {
467+
WebDriverCommandMsg::GoBack(webview_id, load_status_sender) => {
468+
let ignore = match running_state.url_history_for_webview(webview_id) {
469+
Some(url_history) => url_history.current_index == 0,
470+
None => true,
471+
};
472+
473+
if ignore {
474+
let _ = load_status_sender.send(WebDriverLoadStatus::Complete);
475+
}
476+
468477
if let Some(webview) = running_state.webview_by_id(webview_id) {
478+
running_state.set_load_status_sender(webview_id, load_status_sender);
469479
webview.go_back(1);
470480
}
471481
},
472-
WebDriverCommandMsg::GoForward(webview_id) => {
482+
WebDriverCommandMsg::GoForward(webview_id, load_status_sender) => {
483+
let ignore = match running_state.url_history_for_webview(webview_id) {
484+
Some(url_history) => {
485+
url_history.current_index == url_history.urls.len() - 1
486+
},
487+
None => true,
488+
};
489+
490+
if ignore {
491+
let _ = load_status_sender.send(WebDriverLoadStatus::Complete);
492+
}
493+
473494
if let Some(webview) = running_state.webview_by_id(webview_id) {
495+
running_state.set_load_status_sender(webview_id, load_status_sender);
474496
webview.go_forward(1);
475497
}
476498
},

Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ struct WebDriverSenders {
4444
pub load_status_senders: HashMap<WebViewId, IpcSender<WebDriverLoadStatus>>,
4545
}
4646

47+
#[derive(Clone, Default)]
48+
pub(crate) struct UrlHistory {
49+
pub urls: Vec<Url>,
50+
pub current_index: usize,
51+
}
52+
4753
pub(crate) struct RunningAppState {
4854
/// A handle to the Servo instance of the [`RunningAppState`]. This is not stored inside
4955
/// `inner` so that we can keep a reference to Servo in order to spin the event loop,
@@ -87,6 +93,8 @@ pub struct RunningAppStateInner {
8793
/// Whether or not Servo needs to repaint its display. Currently this is global
8894
/// because every `WebView` shares a `RenderingContext`.
8995
need_repaint: bool,
96+
97+
url_history: HashMap<WebViewId, UrlHistory>,
9098
}
9199

92100
impl Drop for RunningAppState {
@@ -117,6 +125,7 @@ impl RunningAppState {
117125
gamepad_support: GamepadSupport::maybe_new(),
118126
need_update: false,
119127
need_repaint: false,
128+
url_history: Default::default(),
120129
}),
121130
}
122131
}
@@ -406,6 +415,10 @@ impl RunningAppState {
406415
.load_status_senders
407416
.insert(webview_id, sender);
408417
}
418+
419+
pub(crate) fn url_history_for_webview(&self, webview_id: WebViewId) -> Option<UrlHistory> {
420+
self.inner().url_history.get(&webview_id).cloned()
421+
}
409422
}
410423

411424
struct ServoShellServoDelegate;
@@ -550,6 +563,26 @@ impl WebViewDelegate for RunningAppState {
550563
}
551564
}
552565

566+
fn notify_history_changed(&self, webview: servo::WebView, url: Vec<Url>, current_idx: usize) {
567+
if let Some(sender) = self
568+
.webdriver_senders
569+
.borrow_mut()
570+
.load_status_senders
571+
.remove(&webview.id())
572+
{
573+
let _ = sender.send(WebDriverLoadStatus::Complete);
574+
}
575+
576+
// Update the URL history for the webview.
577+
self.inner_mut().url_history.insert(
578+
webview.id(),
579+
UrlHistory {
580+
urls: url,
581+
current_index: current_idx,
582+
},
583+
);
584+
}
585+
553586
fn notify_fullscreen_state_changed(&self, _webview: servo::WebView, fullscreen_state: bool) {
554587
self.inner().window.set_fullscreen(fullscreen_state);
555588
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
[back.py]
2-
disabled: consistent panic
3-
[test_no_top_browsing_context]
4-
expected: FAIL
2+
[test_seen_nodes[http\]]
3+
expected: ERROR
4+
5+
[test_seen_nodes[https\]]
6+
expected: ERROR
7+
8+
[test_seen_nodes[https coop\]]
9+
expected: ERROR
510

611
[test_no_browsing_context]
712
expected: ERROR
813

9-
[test_seen_nodes[http\]]
10-
expected: FAIL
14+
[test_no_browsing_history]
15+
expected: ERROR
1116

12-
[test_seen_nodes[https\]]
13-
expected: FAIL
17+
[test_data_urls]
18+
expected: ERROR
1419

15-
[test_seen_nodes[https coop\]]
16-
expected: FAIL
20+
[test_fragments]
21+
expected: ERROR
1722

1823
[test_history_pushstate]
19-
expected: FAIL
24+
expected: ERROR
25+
26+
[test_removed_iframe]
27+
expected: ERROR
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
[forward.py]
2-
[test_basic]
3-
expected: FAIL
4-
52
[test_seen_nodes[http\]]
63
expected: FAIL
74

@@ -10,3 +7,9 @@
107

118
[test_seen_nodes[https coop\]]
129
expected: FAIL
10+
11+
[test_removed_iframe]
12+
expected: FAIL
13+
14+
[test_basic]
15+
expected: FAIL