OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
33 | 33 |
| 34 #include "core/html/HTMLHeadElement.h" |
| 35 #include "core/html/HTMLLinkElement.h" |
34 #include "core/testing/DummyPageHolder.h" | 36 #include "core/testing/DummyPageHolder.h" |
35 #include <gmock/gmock.h> | 37 #include <gmock/gmock.h> |
36 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> |
37 | 39 |
38 using namespace WebCore; | 40 using namespace WebCore; |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 class DocumentTest : public ::testing::Test { | 44 class DocumentTest : public ::testing::Test { |
43 protected: | 45 protected: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 ::testing::Mock::VerifyAndClearExpectations(observer1.get()); | 125 ::testing::Mock::VerifyAndClearExpectations(observer1.get()); |
124 ::testing::Mock::VerifyAndClearExpectations(observer2.get()); | 126 ::testing::Mock::VerifyAndClearExpectations(observer2.get()); |
125 } | 127 } |
126 | 128 |
127 // observer2 destroyed | 129 // observer2 destroyed |
128 EXPECT_CALL(*observer1, didChangeVisibilityState(PageVisibilityStateHidden))
.Times(0); | 130 EXPECT_CALL(*observer1, didChangeVisibilityState(PageVisibilityStateHidden))
.Times(0); |
129 EXPECT_CALL(*observer1, didChangeVisibilityState(PageVisibilityStateVisible)
).Times(1); | 131 EXPECT_CALL(*observer1, didChangeVisibilityState(PageVisibilityStateVisible)
).Times(1); |
130 page().setVisibilityState(PageVisibilityStateVisible, false); | 132 page().setVisibilityState(PageVisibilityStateVisible, false); |
131 } | 133 } |
132 | 134 |
| 135 // This test checks that Documunt::linkManifest() returns a value conform to the
specification. |
| 136 TEST_F(DocumentTest, LinkManifest) |
| 137 { |
| 138 // Test the default result. |
| 139 EXPECT_EQ(0, document().linkManifest()); |
| 140 |
| 141 // Check that we use the first manifest with <link rel=manifest> |
| 142 RefPtrWillBeRawPtr<HTMLLinkElement> link = HTMLLinkElement::create(document(
), false); |
| 143 link->setAttribute(WebCore::HTMLNames::relAttr, "manifest"); |
| 144 link->setAttribute(WebCore::HTMLNames::hrefAttr, "foo.json"); |
| 145 document().head()->appendChild(link); |
| 146 EXPECT_EQ(link, document().linkManifest()); |
| 147 |
| 148 RefPtrWillBeRawPtr<HTMLLinkElement> link2 = HTMLLinkElement::create(document
(), false); |
| 149 link2->setAttribute(WebCore::HTMLNames::relAttr, "manifest"); |
| 150 link2->setAttribute(WebCore::HTMLNames::hrefAttr, "bar.json"); |
| 151 document().head()->insertBefore(link2, link.get()); |
| 152 EXPECT_EQ(link2, document().linkManifest()); |
| 153 document().head()->appendChild(link2); |
| 154 EXPECT_EQ(link, document().linkManifest()); |
| 155 |
| 156 // Check that crazy URLs are accepted. |
| 157 link->setAttribute(WebCore::HTMLNames::hrefAttr, "http:foo.json"); |
| 158 EXPECT_EQ(link, document().linkManifest()); |
| 159 |
| 160 // Check that empty URLs are accepted. |
| 161 link->setAttribute(WebCore::HTMLNames::hrefAttr, ""); |
| 162 EXPECT_EQ(link, document().linkManifest()); |
| 163 |
| 164 // Check that URLs from different origins are accepted. |
| 165 link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://example.org/manifes
t.json"); |
| 166 EXPECT_EQ(link, document().linkManifest()); |
| 167 link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://foo.example.org/man
ifest.json"); |
| 168 EXPECT_EQ(link, document().linkManifest()); |
| 169 link->setAttribute(WebCore::HTMLNames::hrefAttr, "http://foo.bar/manifest.js
on"); |
| 170 EXPECT_EQ(link, document().linkManifest()); |
| 171 |
| 172 // More than one token in @rel is accepted. |
| 173 link->setAttribute(WebCore::HTMLNames::relAttr, "foo bar manifest"); |
| 174 EXPECT_EQ(link, document().linkManifest()); |
| 175 |
| 176 // Such as spaces around the token. |
| 177 link->setAttribute(WebCore::HTMLNames::relAttr, " manifest "); |
| 178 EXPECT_EQ(link, document().linkManifest()); |
| 179 |
| 180 // Check that rel=manifest actually matters. |
| 181 link->setAttribute(WebCore::HTMLNames::relAttr, ""); |
| 182 EXPECT_EQ(link2, document().linkManifest()); |
| 183 link->setAttribute(WebCore::HTMLNames::relAttr, "manifest"); |
| 184 |
| 185 // Check that link outside of the <head> are ignored. |
| 186 document().head()->removeChild(link.get(), ASSERT_NO_EXCEPTION); |
| 187 document().head()->removeChild(link2.get(), ASSERT_NO_EXCEPTION); |
| 188 EXPECT_EQ(0, document().linkManifest()); |
| 189 document().body()->appendChild(link); |
| 190 EXPECT_EQ(0, document().linkManifest()); |
| 191 document().head()->appendChild(link); |
| 192 document().head()->appendChild(link2); |
| 193 |
| 194 // Check that some attribute values do not have an effect. |
| 195 link->setAttribute(WebCore::HTMLNames::crossoriginAttr, "use-credentials"); |
| 196 EXPECT_EQ(link, document().linkManifest()); |
| 197 link->setAttribute(WebCore::HTMLNames::hreflangAttr, "klingon"); |
| 198 EXPECT_EQ(link, document().linkManifest()); |
| 199 link->setAttribute(WebCore::HTMLNames::typeAttr, "image/gif"); |
| 200 EXPECT_EQ(link, document().linkManifest()); |
| 201 link->setAttribute(WebCore::HTMLNames::sizesAttr, "16x16"); |
| 202 EXPECT_EQ(link, document().linkManifest()); |
| 203 link->setAttribute(WebCore::HTMLNames::mediaAttr, "print"); |
| 204 EXPECT_EQ(link, document().linkManifest()); |
| 205 } |
| 206 |
133 } // unnamed namespace | 207 } // unnamed namespace |
OLD | NEW |