зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1498729 - Handle the cases where the name of viewport meta tag changes. r=smaug,botond
Differential Revision: https://phabricator.services.mozilla.com/D38925 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d333ece344
Коммит
69317a4a45
|
@ -742,6 +742,8 @@ skip-if = !e10s # Track Bug 1281415
|
|||
[test_meta_viewport_auto_size_by_invalid_width.html]
|
||||
[test_meta_viewport_auto_size_by_invalid_width_and_fixed_height.html]
|
||||
[test_meta_viewport_change_content_among_multiple.html]
|
||||
[test_meta_viewport_change_name.html]
|
||||
[test_meta_viewport_change_name_among_multiple.html]
|
||||
[test_meta_viewport_device_width.html]
|
||||
[test_meta_viewport_device_width_with_initial_scale_0_5.html]
|
||||
[test_meta_viewport_device_width_with_initial_scale_2.html]
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>name attribute changes</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta id="viewport" name="initial-name" content="width=device-width, initial-scale=1">
|
||||
<script src="viewport_helpers.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
|
||||
add_task(async function change_name_attribute() {
|
||||
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
|
||||
|
||||
let info = getViewportInfo(800, 480);
|
||||
// There is no valid <meta name="viewport"> so that viewport info values
|
||||
// are the same as values in test_meta_viewport0.html.
|
||||
is(info.defaultZoom, 0.25, "initial scale is clamped to the default mimumim scale");
|
||||
is(info.minZoom, 0.25, "minimum scale defaults to the absolute minimum");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 980, "width is the default width");
|
||||
is(info.height, 588, "height is proportional to displayHeight");
|
||||
is(info.autoSize, false, "autoSize is disabled by default");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
|
||||
// Now it's a valid viewport.
|
||||
viewport.setAttribute("name", "viewport");
|
||||
info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1, "initial zoom is 1");
|
||||
is(info.width, 800, "width should be 800");
|
||||
is(info.height, 480, "height should be 480");
|
||||
|
||||
// Now it's invalid again.
|
||||
viewport.setAttribute("name", "other");
|
||||
info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 0.25, "initial scale is clamped to the default mimumim scale");
|
||||
is(info.minZoom, 0.25, "minimum scale defaults to the absolute minimum");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 980, "width is the default width");
|
||||
is(info.height, 588, "height is proportional to displayHeight");
|
||||
is(info.autoSize, false, "autoSize is disabled by default");
|
||||
is(info.allowZoom, true, "zooming is enabled by default");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>name attribute changes among multiple meta viewport tags</title>
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
<meta name="viewport" content="width=980">
|
||||
<meta id="viewport" name="initial-name" content="width=device-width, initial-scale=1">
|
||||
<script src="viewport_helpers.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<script type="application/javascript">
|
||||
"use strict";
|
||||
|
||||
add_task(async function change_name_attribute() {
|
||||
await SpecialPowers.pushPrefEnv(scaleRatio(1.0));
|
||||
|
||||
let info = getViewportInfo(800, 480);
|
||||
// The "width=980" content is a valid one.
|
||||
fuzzeq(info.defaultZoom, 800/980, "initial scale is calculated based on width");
|
||||
is(info.minZoom, 0.25, "minimum scale defaults to the absolute minimum");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 980, "width is the default width");
|
||||
is(info.height, 588, "height is proportional to displayHeight");
|
||||
|
||||
// Now the second meta tag is a valid viewport.
|
||||
viewport.setAttribute("name", "viewport");
|
||||
info = getViewportInfo(800, 480);
|
||||
is(info.defaultZoom, 1, "initial zoom is 1");
|
||||
is(info.width, 800, "width should be 800");
|
||||
is(info.height, 480, "height should be 480");
|
||||
|
||||
// Now it's invalid again.
|
||||
viewport.setAttribute("name", "other");
|
||||
info = getViewportInfo(800, 480);
|
||||
fuzzeq(info.defaultZoom, 800/980, "initial scale is calculated based on width");
|
||||
is(info.minZoom, 0.25, "minimum scale defaults to the absolute minimum");
|
||||
is(info.maxZoom, 10, "maximum scale defaults to the absolute maximum");
|
||||
is(info.width, 980, "width is the default width");
|
||||
is(info.height, 588, "height is proportional to displayHeight");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -61,6 +61,14 @@ nsresult HTMLMetaElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
|
|||
ProcessViewportContent(document);
|
||||
}
|
||||
CreateAndDispatchEvent(document, NS_LITERAL_STRING("DOMMetaChanged"));
|
||||
} else if (document && aName == nsGkAtoms::name) {
|
||||
if (aValue && aValue->Equals(nsGkAtoms::viewport, eIgnoreCase)) {
|
||||
ProcessViewportContent(document);
|
||||
} else if (aOldValue &&
|
||||
aOldValue->Equals(nsGkAtoms::viewport, eIgnoreCase)) {
|
||||
DiscardViewportContent(document);
|
||||
}
|
||||
CreateAndDispatchEvent(document, NS_LITERAL_STRING("DOMMetaChanged"));
|
||||
}
|
||||
// Update referrer policy when it got changed from JS
|
||||
SetMetaReferrer(document);
|
||||
|
@ -136,7 +144,7 @@ void HTMLMetaElement::UnbindFromTree(bool aNullParent) {
|
|||
nsCOMPtr<Document> oldDoc = GetUncomposedDoc();
|
||||
if (oldDoc && AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
||||
nsGkAtoms::viewport, eIgnoreCase)) {
|
||||
oldDoc->RemoveMetaViewportElement(this);
|
||||
DiscardViewportContent(oldDoc);
|
||||
}
|
||||
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMMetaRemoved"));
|
||||
nsGenericHTMLElement::UnbindFromTree(aNullParent);
|
||||
|
@ -166,5 +174,9 @@ void HTMLMetaElement::ProcessViewportContent(Document* aDocument) {
|
|||
aDocument->AddMetaViewportElement(this, std::move(data));
|
||||
}
|
||||
|
||||
void HTMLMetaElement::DiscardViewportContent(Document* aDocument) {
|
||||
aDocument->RemoveMetaViewportElement(this);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -64,6 +64,7 @@ class HTMLMetaElement final : public nsGenericHTMLElement {
|
|||
private:
|
||||
void SetMetaReferrer(Document* aDocument);
|
||||
void ProcessViewportContent(Document* aDocument);
|
||||
void DiscardViewportContent(Document* aDocument);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
Загрузка…
Ссылка в новой задаче