Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / DocumentTest.cpp
index c5766a8..7e2d35e 100644 (file)
 #include "config.h"
 #include "core/dom/Document.h"
 
+#include "core/html/HTMLHeadElement.h"
+#include "core/html/HTMLLinkElement.h"
 #include "core/testing/DummyPageHolder.h"
+#include "platform/heap/Handle.h"
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
-using namespace WebCore;
+using namespace blink;
 
 namespace {
 
@@ -43,6 +46,13 @@ class DocumentTest : public ::testing::Test {
 protected:
     virtual void SetUp() OVERRIDE;
 
+#if ENABLE(OILPAN)
+    virtual void TearDown() OVERRIDE
+    {
+        Heap::collectAllGarbage();
+    }
+#endif
+
     Document& document() const { return m_dummyPageHolder->document(); }
     Page& page() const { return m_dummyPageHolder->page(); }
 
@@ -130,4 +140,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(blink::HTMLNames::relAttr, "manifest");
+    link->setAttribute(blink::HTMLNames::hrefAttr, "foo.json");
+    document().head()->appendChild(link);
+    EXPECT_EQ(link, document().linkManifest());
+
+    RefPtrWillBeRawPtr<HTMLLinkElement> link2 = HTMLLinkElement::create(document(), false);
+    link2->setAttribute(blink::HTMLNames::relAttr, "manifest");
+    link2->setAttribute(blink::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(blink::HTMLNames::hrefAttr, "http:foo.json");
+    EXPECT_EQ(link, document().linkManifest());
+
+    // Check that empty URLs are accepted.
+    link->setAttribute(blink::HTMLNames::hrefAttr, "");
+    EXPECT_EQ(link, document().linkManifest());
+
+    // Check that URLs from different origins are accepted.
+    link->setAttribute(blink::HTMLNames::hrefAttr, "http://example.org/manifest.json");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::hrefAttr, "http://foo.example.org/manifest.json");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::hrefAttr, "http://foo.bar/manifest.json");
+    EXPECT_EQ(link, document().linkManifest());
+
+    // More than one token in @rel is accepted.
+    link->setAttribute(blink::HTMLNames::relAttr, "foo bar manifest");
+    EXPECT_EQ(link, document().linkManifest());
+
+    // Such as spaces around the token.
+    link->setAttribute(blink::HTMLNames::relAttr, " manifest ");
+    EXPECT_EQ(link, document().linkManifest());
+
+    // Check that rel=manifest actually matters.
+    link->setAttribute(blink::HTMLNames::relAttr, "");
+    EXPECT_EQ(link2, document().linkManifest());
+    link->setAttribute(blink::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(blink::HTMLNames::crossoriginAttr, "use-credentials");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::hreflangAttr, "klingon");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::typeAttr, "image/gif");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::sizesAttr, "16x16");
+    EXPECT_EQ(link, document().linkManifest());
+    link->setAttribute(blink::HTMLNames::mediaAttr, "print");
+    EXPECT_EQ(link, document().linkManifest());
+}
+
 } // unnamed namespace