Skip to content

Commit

Permalink
Ensure that a navigation to the same URL is aborted. Fixes servo#10952.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm authored and emilio committed May 21, 2016
1 parent eeea481 commit fc219f8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 14 deletions.
29 changes: 15 additions & 14 deletions components/script/script_thread.rs
Expand Up @@ -1833,24 +1833,25 @@ impl ScriptThread {
/// The entry point for content to notify that a new load has been requested
/// for the given pipeline (specifically the "navigate" algorithm).
fn handle_navigate(&self, pipeline_id: PipelineId, subpage_id: Option<SubpageId>, load_data: LoadData) {
// Step 8.
// Step 6.
{
let nurl = &load_data.url;
if let Some(fragment) = nurl.fragment() {
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = document.r();
let url = document.url();
if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] &&
load_data.method == Method::Get {
match document.find_fragment_node(fragment) {
Some(ref node) => {
self.scroll_fragment_point(pipeline_id, node.r());
}
None => {}
let context = get_browsing_context(&self.root_browsing_context(), pipeline_id);
let document = context.active_document();
let document = document.r();
let url = document.url();
if &url[..Position::AfterQuery] == &nurl[..Position::AfterQuery] &&
load_data.method == Method::Get {
if let Some(fragment) = nurl.fragment() {
if let Some(ref node) = document.find_fragment_node(fragment) {
self.scroll_fragment_point(pipeline_id, node.r());
}
return;
}
// TODO: Revisit this return statement when a decission is taken
// in https://github.com/whatwg/html/issues/1177.
//
// See #10954 for discussion and background.
return;
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/wpt/metadata/MANIFEST.json
Expand Up @@ -35938,6 +35938,12 @@
"deleted_reftests": {},
"items": {
"testharness": {
"html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html": [
{
"path": "html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html",
"url": "/html/browsers/browsing-the-web/navigating-across-documents/empty_fragment.html"
}
],
"html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_attribute-getter-setter.html": [
{
"path": "html/semantics/links/links-created-by-a-and-area-elements/htmlanchorelement_attribute-getter-setter.html",
Expand Down
@@ -0,0 +1,20 @@
<!doctype html>
<meta charset="utf-8">
<title>Navigating to the same URL with an empty fragment aborts the navigation</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe src="empty_fragment_iframe.html"></iframe>
<script>
// If the navigation were not aborted, we would expect multiple load events
// as the page continually reloads itself.
async_test(function(t) {
var count = 0;
var iframe = document.querySelector('iframe');
iframe.onload = t.step_func(function() {
count++;
});
window.child_succeeded = t.step_func_done(function() {
assert_equals(count, 1);
});
});
</script>
@@ -0,0 +1,11 @@
<script>
var timeout;
onload = function() {
location.hash = "";
timeout = setTimeout(function() { parent.child_succeeded() }, 2000);
};

onbeforeunload = function() {
clearTimeout(timeout);
}
</script>

0 comments on commit fc219f8

Please sign in to comment.