diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-08-09 12:10:08 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-08-09 12:10:08 -0600 |
commit | a74f3d1d9c09b40a81fa4410797e8c4920225c78 (patch) | |
tree | 89ebe6389cf7804a89e42fcf65d3b10ffd2b7b32 | |
parent | 6a8bc8528498c0cbb2e50567d765a989cde2d115 (diff) | |
parent | 97c79bbb995b0d2dc1f4af8b972bb6dcea54cddf (diff) | |
download | servo-a74f3d1d9c09b40a81fa4410797e8c4920225c78.tar.gz servo-a74f3d1d9c09b40a81fa4410797e8c4920225c78.zip |
Auto merge of #7114 - Ms2ger:follow-hyperlink, r=jdm
Introduce a follow_hyperlink function to implement the "follow a hyperlink" algorithm.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7114)
<!-- Reviewable:end -->
-rw-r--r-- | components/script/dom/htmlanchorelement.rs | 54 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/MANIFEST.json | 6 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/mozilla/follow-hyperlink.html | 17 |
3 files changed, 59 insertions, 18 deletions
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index 2774b74a60a..b47d799c8ae 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -24,13 +24,14 @@ use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_n use dom::virtualmethods::VirtualMethods; use dom::window::WindowHelpers; -use num::ToPrimitive; -use std::default::Default; -use string_cache::Atom; use util::str::DOMString; +use num::ToPrimitive; +use string_cache::Atom; use url::UrlParser; +use std::default::Default; + #[dom_struct] pub struct HTMLAnchorElement { htmlelement: HTMLElement, @@ -149,24 +150,41 @@ impl<'a> Activatable for &'a HTMLAnchorElement { } } - //TODO: Step 4. Download the link is `download` attribute is set. - - let href = element.get_attribute(&ns!(""), &atom!("href")).unwrap(); - let mut value = href.r().Value(); - if let Some(suffix) = ismap_suffix { - value.push_str(&suffix); - } - debug!("clicked on link to {}", value); - - let window = doc.window(); - let base_url = window.get_url(); - let url = UrlParser::new().base_url(&base_url).parse(&value); - // FIXME: handle URL parse errors more gracefully. - let url = url.unwrap(); - window.load_url(url); + // Step 4. + //TODO: Download the link is `download` attribute is set. + follow_hyperlink(element, ismap_suffix); } //TODO:https://html.spec.whatwg.org/multipage/#the-a-element fn implicit_submission(&self, _ctrlKey: bool, _shiftKey: bool, _altKey: bool, _metaKey: bool) { } } + +/// https://html.spec.whatwg.org/multipage/#following-hyperlinks-2 +fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<DOMString>) { + // Step 1: replace. + // Step 2: source browsing context. + // Step 3: target browsing context. + + // Step 4. + let attribute = subject.get_attribute(&ns!(""), &atom!("href")).unwrap(); + let mut href = attribute.Value(); + + // Step 6. + // https://www.w3.org/Bugs/Public/show_bug.cgi?id=28925 + if let Some(suffix) = hyperlink_suffix { + href.push_str(&suffix); + } + + // Step 4-5. + let document = document_from_node(subject); + let url = match UrlParser::new().base_url(&document.url()).parse(&href) { + Ok(url) => url, + Err(_) => return, + }; + + // Step 7. + debug!("following hyperlink to {}", url.serialize()); + let window = document.window(); + window.load_url(url); +} diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index c723119186e..d0b6512b141 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -539,6 +539,12 @@ "url": "/_mozilla/mozilla/focus_blur.html" } ], + "mozilla/follow-hyperlink.html": [ + { + "path": "mozilla/follow-hyperlink.html", + "url": "/_mozilla/mozilla/follow-hyperlink.html" + } + ], "mozilla/getBoundingClientRect.html": [ { "path": "mozilla/getBoundingClientRect.html", diff --git a/tests/wpt/mozilla/tests/mozilla/follow-hyperlink.html b/tests/wpt/mozilla/tests/mozilla/follow-hyperlink.html new file mode 100644 index 00000000000..6ac9eaeb581 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/follow-hyperlink.html @@ -0,0 +1,17 @@ +<!doctype html> +<meta charset=utf-8> +<title>Following hyperlinks</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<div id=log></div> +<p><a id=link href="http://:">test</a></p> +<script> +async_test(function(t) { + var a = document.getElementById("link"); + a.click(); + setTimeout(function() { + // Don't crash. + t.done(); + }, 0); +}); +</script> |