Bug 600809: Make HTMLBaseElement.href work properly. r=smaug a=blocker

This commit is contained in:
Jonas Sicking 2010-10-07 09:39:01 -07:00
Родитель 2d5feee33e
Коммит c094c26ef4
2 изменённых файлов: 37 добавлений и 1 удалений

Просмотреть файл

@ -69,6 +69,14 @@ verifyBase("base/", "from markup");
// Modify existing <base>
basehref.href = "base2/";
verifyBase("base2/", "modify existing");
is(basehref.href, pre + "base2/", "HTMLBaseElement.href resolves correctly");
// Modify existing <base> to absolute url
basehref.href = "http://www.example.com/foo/bar.html";
is(document.baseURI, "http://www.example.com/foo/bar.html", "document base when setting absolute url");
is(a.href, "http://www.example.com/foo/dest.html", "link href when setting absolute url");
is(basehref.href, "http://www.example.com/foo/bar.html",
"HTMLBaseElement.href resolves correctly when setting absolute url");
// Remove href on existing element
basehref.removeAttribute("href");

Просмотреть файл

@ -265,8 +265,36 @@ nsHTMLSharedElement::SetProfile(const nsAString& aValue)
NS_IMPL_STRING_ATTR(nsHTMLSharedElement, Version, version)
// nsIDOMHTMLBaseElement
NS_IMPL_URI_ATTR(nsHTMLSharedElement, Href, href)
NS_IMPL_STRING_ATTR(nsHTMLSharedElement, Target, target)
NS_IMETHODIMP
nsHTMLSharedElement::GetHref(nsAString& aValue)
{
nsAutoString href;
GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
nsCOMPtr<nsIURI> uri;
nsIDocument* doc = GetOwnerDoc();
if (doc) {
nsContentUtils::NewURIWithDocumentCharset(
getter_AddRefs(uri), href, doc, doc->GetDocumentURI());
}
if (!uri) {
aValue = href;
return NS_OK;
}
nsCAutoString spec;
uri->GetSpec(spec);
CopyUTF8toUTF16(spec, aValue);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLSharedElement::SetHref(const nsAString& aValue)
{
return SetAttrHelper(nsGkAtoms::href, aValue);
}
PRBool
nsHTMLSharedElement::ParseAttribute(PRInt32 aNamespaceID,