Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: Source/core/dom/DocumentTest.cpp

Issue 270283007: Implement the logic to find the correct <link> for Manifest in Document. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@link_manifest
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/core/loader/DocumentLoader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/DocumentTest.cpp
diff --git a/Source/core/dom/DocumentTest.cpp b/Source/core/dom/DocumentTest.cpp
index c5766a8fa5e964dee7d93c6e39930fcfc2444657..5867805f548aa60f514151be1b750fe710279c97 100644
--- a/Source/core/dom/DocumentTest.cpp
+++ b/Source/core/dom/DocumentTest.cpp
@@ -31,6 +31,8 @@
#include "config.h"
#include "core/dom/Document.h"
+#include "core/html/HTMLHeadElement.h"
+#include "core/html/HTMLLinkElement.h"
#include "core/testing/DummyPageHolder.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -130,4 +132,76 @@ TEST_F(DocumentTest, VisibilityOberver)
page().setVisibilityState(PageVisibilityStateVisible, false);
}
+// This test checks that Documunt::linkManifest() returns a value conform to the specification.
+TEST_F(DocumentTest, LinkManifest)
+{
+ // Test the default result.
+ EXPECT_EQ(0, document().linkManifest());
+
+ // Check that we use the first manifest with <link rel=manifest>
+ RefPtrWillBeRawPtr<HTMLLinkElement> link = HTMLLinkElement::create(document(), false);
+ link->setAttribute(WebCore::HTMLNames::relAttr, "manifest");
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "foo.json");
+ document().head()->appendChild(link);
+ EXPECT_EQ(link, document().linkManifest());
+
+ RefPtrWillBeRawPtr<HTMLLinkElement> link2 = HTMLLinkElement::create(document(), false);
+ link2->setAttribute(WebCore::HTMLNames::relAttr, "manifest");
+ link2->setAttribute(WebCore::HTMLNames::hrefAttr, "bar.json");
+ document().head()->insertBefore(link2, link.get());
+ EXPECT_EQ(link2, document().linkManifest());
+ document().head()->appendChild(link2);
+ EXPECT_EQ(link, document().linkManifest());
+
+ // Check that crazy URLs are accepted.
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "http:foo.json");
+ EXPECT_EQ(link, document().linkManifest());
+
+ // Check that empty URLs are accepted.
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "");
+ EXPECT_EQ(link, document().linkManifest());
+
+ // Check that URLs from different origins are accepted.
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://example.org/manifest.json");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://foo.example.org/manifest.json");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://foo.bar/manifest.json");
+ EXPECT_EQ(link, document().linkManifest());
+
+ // More than one token in @rel is accepted.
+ link->setAttribute(WebCore::HTMLNames::relAttr, "foo bar manifest");
+ EXPECT_EQ(link, document().linkManifest());
+
+ // Such as spaces around the token.
+ link->setAttribute(WebCore::HTMLNames::relAttr, " manifest ");
+ EXPECT_EQ(link, document().linkManifest());
+
+ // Check that rel=manifest actually matters.
+ link->setAttribute(WebCore::HTMLNames::relAttr, "");
+ EXPECT_EQ(link2, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::relAttr, "manifest");
+
+ // Check that link outside of the <head> are ignored.
+ document().head()->removeChild(link.get(), ASSERT_NO_EXCEPTION);
+ document().head()->removeChild(link2.get(), ASSERT_NO_EXCEPTION);
+ EXPECT_EQ(0, document().linkManifest());
+ document().body()->appendChild(link);
+ EXPECT_EQ(0, document().linkManifest());
+ document().head()->appendChild(link);
+ document().head()->appendChild(link2);
+
+ // Check that some attribute values do not have an effect.
+ link->setAttribute(WebCore::HTMLNames::crossoriginAttr, "use-credentials");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::hreflangAttr, "klingon");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::typeAttr, "image/gif");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::sizesAttr, "16x16");
+ EXPECT_EQ(link, document().linkManifest());
+ link->setAttribute(WebCore::HTMLNames::mediaAttr, "print");
+ EXPECT_EQ(link, document().linkManifest());
+}
+
} // unnamed namespace
« no previous file with comments | « Source/core/dom/Document.cpp ('k') | Source/core/loader/DocumentLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698