mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Webdriver GoBack and GoForward commands wait for navigation complete (#37950)
After sending `GoBack` or `GoForward` command, webdriver wait for the navigation complete. It can be achieved by waiting for `WebViewDelegate::notify_history_changed` Testing: `tests/wpt/meta/webdriver/tests/classic/back/back.py` `tests/wpt/meta/webdriver/tests/classic/forward/forward.py` --------- Signed-off-by: batu_hoang <longvatrong111@gmail.com> Signed-off-by: Josh Matthews <josh@joshmatthews.net> Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
c817d7b9ce
commit
8e2d2bde6f
16 changed files with 114 additions and 40 deletions
|
@ -1378,8 +1378,17 @@ where
|
|||
self.embedder_proxy.send(EmbedderMsg::WebViewBlurred);
|
||||
},
|
||||
// Handle a forward or back request
|
||||
EmbedderToConstellationMessage::TraverseHistory(webview_id, direction) => {
|
||||
EmbedderToConstellationMessage::TraverseHistory(
|
||||
webview_id,
|
||||
direction,
|
||||
traversal_id,
|
||||
) => {
|
||||
self.handle_traverse_history_msg(webview_id, direction);
|
||||
self.embedder_proxy
|
||||
.send(EmbedderMsg::HistoryTraversalComplete(
|
||||
webview_id,
|
||||
traversal_id,
|
||||
));
|
||||
},
|
||||
EmbedderToConstellationMessage::ChangeViewportDetails(
|
||||
webview_id,
|
||||
|
|
|
@ -214,6 +214,7 @@ mod from_script {
|
|||
Self::SetCursor(..) => target_variant!("SetCursor"),
|
||||
Self::NewFavicon(..) => target_variant!("NewFavicon"),
|
||||
Self::HistoryChanged(..) => target_variant!("HistoryChanged"),
|
||||
Self::HistoryTraversalComplete(..) => target_variant!("HistoryTraversalComplete"),
|
||||
Self::GetWindowRect(..) => target_variant!("GetWindowRect"),
|
||||
Self::GetScreenMetrics(..) => target_variant!("GetScreenMetrics"),
|
||||
Self::NotifyFullscreenStateChanged(..) => {
|
||||
|
|
|
@ -801,6 +801,13 @@ impl Servo {
|
|||
webview.set_load_status(load_status);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::HistoryTraversalComplete(webview_id, traversal_id) => {
|
||||
if let Some(webview) = self.get_webview_handle(webview_id) {
|
||||
webview
|
||||
.delegate()
|
||||
.notify_traversal_complete(webview.clone(), traversal_id);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::HistoryChanged(webview_id, urls, current_index) => {
|
||||
if let Some(webview) = self.get_webview_handle(webview_id) {
|
||||
let urls: Vec<_> = urls.into_iter().map(ServoUrl::into_url).collect();
|
||||
|
|
|
@ -14,7 +14,7 @@ use constellation_traits::{EmbedderToConstellationMessage, TraversalDirection};
|
|||
use dpi::PhysicalSize;
|
||||
use embedder_traits::{
|
||||
Cursor, InputEvent, JSValue, JavaScriptEvaluationError, LoadStatus, MediaSessionActionType,
|
||||
ScreenGeometry, Theme, ViewportDetails,
|
||||
ScreenGeometry, Theme, TraversalId, ViewportDetails,
|
||||
};
|
||||
use euclid::{Point2D, Scale, Size2D};
|
||||
use servo_geometry::DeviceIndependentPixel;
|
||||
|
@ -416,22 +416,28 @@ impl WebView {
|
|||
.send(EmbedderToConstellationMessage::Reload(self.id()))
|
||||
}
|
||||
|
||||
pub fn go_back(&self, amount: usize) {
|
||||
pub fn go_back(&self, amount: usize) -> TraversalId {
|
||||
let traversal_id = TraversalId::new();
|
||||
self.inner()
|
||||
.constellation_proxy
|
||||
.send(EmbedderToConstellationMessage::TraverseHistory(
|
||||
self.id(),
|
||||
TraversalDirection::Back(amount),
|
||||
))
|
||||
traversal_id.clone(),
|
||||
));
|
||||
traversal_id
|
||||
}
|
||||
|
||||
pub fn go_forward(&self, amount: usize) {
|
||||
pub fn go_forward(&self, amount: usize) -> TraversalId {
|
||||
let traversal_id = TraversalId::new();
|
||||
self.inner()
|
||||
.constellation_proxy
|
||||
.send(EmbedderToConstellationMessage::TraverseHistory(
|
||||
self.id(),
|
||||
TraversalDirection::Forward(amount),
|
||||
))
|
||||
traversal_id.clone(),
|
||||
));
|
||||
traversal_id
|
||||
}
|
||||
|
||||
/// Ask the [`WebView`] to scroll web content. Note that positive scroll offsets reveal more
|
||||
|
|
|
@ -10,7 +10,7 @@ use embedder_traits::{
|
|||
AllowOrDeny, AuthenticationResponse, ContextMenuResult, Cursor, FilterPattern,
|
||||
GamepadHapticEffectType, InputMethodType, KeyboardEvent, LoadStatus, MediaSessionEvent,
|
||||
Notification, PermissionFeature, RgbColor, ScreenGeometry, SelectElementOptionOrOptgroup,
|
||||
SimpleDialog, WebResourceRequest, WebResourceResponse, WebResourceResponseMsg,
|
||||
SimpleDialog, TraversalId, WebResourceRequest, WebResourceResponse, WebResourceResponseMsg,
|
||||
};
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use serde::Serialize;
|
||||
|
@ -438,6 +438,8 @@ pub trait WebViewDelegate {
|
|||
/// The history state has changed.
|
||||
// changed pattern; maybe wasteful if embedder doesn’t care?
|
||||
fn notify_history_changed(&self, _webview: WebView, _: Vec<Url>, _: usize) {}
|
||||
/// A history traversal operation is complete.
|
||||
fn notify_traversal_complete(&self, _webview: WebView, _: TraversalId) {}
|
||||
/// Page content has closed this [`WebView`] via `window.close()`. It's the embedder's
|
||||
/// responsibility to remove the [`WebView`] from the interface when this notification
|
||||
/// occurs.
|
||||
|
|
|
@ -20,7 +20,7 @@ use base::cross_process_instant::CrossProcessInstant;
|
|||
use base::id::{MessagePortId, PipelineId, WebViewId};
|
||||
use embedder_traits::{
|
||||
CompositorHitTestResult, Cursor, InputEvent, JavaScriptEvaluationId, MediaSessionActionType,
|
||||
Theme, ViewportDetails, WebDriverCommandMsg, WebDriverCommandResponse,
|
||||
Theme, TraversalId, ViewportDetails, WebDriverCommandMsg, WebDriverCommandResponse,
|
||||
};
|
||||
pub use from_script_message::*;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
|
@ -48,7 +48,7 @@ pub enum EmbedderToConstellationMessage {
|
|||
/// Clear the network cache.
|
||||
ClearCache,
|
||||
/// Request to traverse the joint session history of the provided browsing context.
|
||||
TraverseHistory(WebViewId, TraversalDirection),
|
||||
TraverseHistory(WebViewId, TraversalDirection, TraversalId),
|
||||
/// Inform the Constellation that a `WebView`'s [`ViewportDetails`] have changed.
|
||||
ChangeViewportDetails(WebViewId, ViewportDetails, WindowSizeType),
|
||||
/// Inform the constellation of a theme change.
|
||||
|
|
|
@ -37,6 +37,7 @@ strum_macros = { workspace = true }
|
|||
stylo_traits = { workspace = true }
|
||||
stylo = { workspace = true }
|
||||
url = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
webdriver = { workspace = true }
|
||||
webrender_api = { workspace = true }
|
||||
servo_geometry = { path = "../../geometry" }
|
||||
|
|
|
@ -37,6 +37,7 @@ use strum_macros::IntoStaticStr;
|
|||
use style::queries::values::PrefersColorScheme;
|
||||
use style_traits::CSSPixel;
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixel};
|
||||
|
||||
pub use crate::input_events::*;
|
||||
|
@ -318,6 +319,17 @@ pub struct ScreenMetrics {
|
|||
pub available_size: DeviceIndependentIntSize,
|
||||
}
|
||||
|
||||
/// An opaque identifier for a single history traversal operation.
|
||||
#[derive(Clone, Deserialize, PartialEq, Serialize)]
|
||||
pub struct TraversalId(String);
|
||||
|
||||
impl TraversalId {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
Self(Uuid::new_v4().to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, IntoStaticStr, Serialize)]
|
||||
pub enum EmbedderMsg {
|
||||
/// A status message to be displayed by the browser chrome.
|
||||
|
@ -372,6 +384,8 @@ pub enum EmbedderMsg {
|
|||
NewFavicon(WebViewId, ServoUrl),
|
||||
/// The history state has changed.
|
||||
HistoryChanged(WebViewId, Vec<ServoUrl>, usize),
|
||||
/// A history traversal operation completed.
|
||||
HistoryTraversalComplete(WebViewId, TraversalId),
|
||||
/// Get the device independent window rectangle.
|
||||
GetWindowRect(WebViewId, IpcSender<DeviceIndependentIntRect>),
|
||||
/// Get the device independent screen size and available size.
|
||||
|
|
|
@ -49,9 +49,9 @@ pub enum WebDriverCommandMsg {
|
|||
/// Refresh the top-level browsing context with the given ID.
|
||||
Refresh(WebViewId, IpcSender<WebDriverLoadStatus>),
|
||||
/// Navigate the webview with the given ID to the previous page in the browsing context's history.
|
||||
GoBack(WebViewId),
|
||||
GoBack(WebViewId, IpcSender<WebDriverLoadStatus>),
|
||||
/// Navigate the webview with the given ID to the next page in the browsing context's history.
|
||||
GoForward(WebViewId),
|
||||
GoForward(WebViewId, IpcSender<WebDriverLoadStatus>),
|
||||
/// Pass a webdriver command to the script thread of the current pipeline
|
||||
/// of a browsing context.
|
||||
ScriptCommand(BrowsingContextId, WebDriverScriptCommand),
|
||||
|
|
|
@ -946,8 +946,11 @@ impl Handler {
|
|||
// return error with error code no such window.
|
||||
self.verify_top_level_browsing_context_is_open(webview_id)?;
|
||||
|
||||
self.send_message_to_embedder(WebDriverCommandMsg::GoBack(webview_id))?;
|
||||
Ok(WebDriverResponse::Void)
|
||||
self.send_message_to_embedder(WebDriverCommandMsg::GoBack(
|
||||
webview_id,
|
||||
self.load_status_sender.clone(),
|
||||
))?;
|
||||
self.wait_for_load()
|
||||
}
|
||||
|
||||
fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
|
||||
|
@ -956,8 +959,11 @@ impl Handler {
|
|||
// return error with error code no such window.
|
||||
self.verify_top_level_browsing_context_is_open(webview_id)?;
|
||||
|
||||
self.send_message_to_embedder(WebDriverCommandMsg::GoForward(webview_id))?;
|
||||
Ok(WebDriverResponse::Void)
|
||||
self.send_message_to_embedder(WebDriverCommandMsg::GoForward(
|
||||
webview_id,
|
||||
self.load_status_sender.clone(),
|
||||
))?;
|
||||
self.wait_for_load()
|
||||
}
|
||||
|
||||
fn handle_refresh(&self) -> WebDriverResult<WebDriverResponse> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue