OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "public/web/WebDocument.h" | 7 #include "public/web/WebDocument.h" |
8 | 8 |
9 #include "core/CSSPropertyNames.h" | 9 #include "core/CSSPropertyNames.h" |
10 #include "core/dom/NodeComputedStyle.h" | 10 #include "core/dom/NodeComputedStyle.h" |
11 #include "core/dom/StyleEngine.h" | 11 #include "core/dom/StyleEngine.h" |
12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
13 #include "core/html/HTMLElement.h" | 13 #include "core/html/HTMLElement.h" |
14 #include "core/style/ComputedStyle.h" | 14 #include "core/style/ComputedStyle.h" |
15 #include "core/page/Page.h" | 15 #include "core/page/Page.h" |
16 #include "platform/RuntimeEnabledFeatures.h" | |
17 #include "platform/graphics/Color.h" | 16 #include "platform/graphics/Color.h" |
18 #include "platform/testing/URLTestHelpers.h" | 17 #include "platform/testing/URLTestHelpers.h" |
19 #include "platform/weborigin/SecurityOrigin.h" | |
20 #include "web/tests/FrameTestHelpers.h" | 18 #include "web/tests/FrameTestHelpers.h" |
21 #include <gtest/gtest.h> | 19 #include <gtest/gtest.h> |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 using blink::FrameTestHelpers::WebViewHelper; | 23 using blink::FrameTestHelpers::WebViewHelper; |
26 using blink::URLTestHelpers::toKURL; | 24 using blink::URLTestHelpers::toKURL; |
27 using namespace blink; | 25 using namespace blink; |
28 | 26 |
29 TEST(WebDocumentTest, InsertStyleSheet) | 27 TEST(WebDocumentTest, InsertStyleSheet) |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 197 |
200 ASSERT_FALSE(coreDoc->isTransitionDocument()); | 198 ASSERT_FALSE(coreDoc->isTransitionDocument()); |
201 | 199 |
202 frame->document().setIsTransitionDocument(true); | 200 frame->document().setIsTransitionDocument(true); |
203 ASSERT_TRUE(coreDoc->isTransitionDocument()); | 201 ASSERT_TRUE(coreDoc->isTransitionDocument()); |
204 | 202 |
205 frame->document().setIsTransitionDocument(false); | 203 frame->document().setIsTransitionDocument(false); |
206 ASSERT_FALSE(coreDoc->isTransitionDocument()); | 204 ASSERT_FALSE(coreDoc->isTransitionDocument()); |
207 } | 205 } |
208 | 206 |
209 namespace { | |
210 const char* baseURLOriginA = "http://example.test:0/"; | |
211 const char* baseURLOriginB = "http://not-example.test:0/"; | |
212 const char* emptyFile = "first_party/empty.html"; | |
213 const char* nestedData = "first_party/nested-data.html"; | |
214 const char* nestedOriginA = "first_party/nested-originA.html"; | |
215 const char* nestedOriginAInOriginA = "first_party/nested-originA-in-originA.
html"; | |
216 const char* nestedOriginAInOriginB = "first_party/nested-originA-in-originB.
html"; | |
217 const char* nestedOriginB = "first_party/nested-originB.html"; | |
218 const char* nestedOriginBInOriginA = "first_party/nested-originB-in-originA.
html"; | |
219 const char* nestedOriginBInOriginB = "first_party/nested-originB-in-originB.
html"; | |
220 const char* nestedSrcDoc = "first_party/nested-srcdoc.html"; | |
221 | |
222 static KURL toOriginA(const char* file) | |
223 { | |
224 return toKURL(std::string(baseURLOriginA) + file); | |
225 } | |
226 | |
227 static KURL toOriginB(const char* file) | |
228 { | |
229 return toKURL(std::string(baseURLOriginB) + file); | |
230 } | |
231 } | 207 } |
232 | |
233 class WebDocumentFirstPartyTest : public ::testing::Test { | |
234 public: | |
235 static void SetUpTestCase(); | |
236 | |
237 protected: | |
238 void load(const char*); | |
239 Document* topDocument() const; | |
240 Document* nestedDocument() const; | |
241 Document* nestedNestedDocument() const; | |
242 | |
243 WebViewHelper m_webViewHelper; | |
244 }; | |
245 | |
246 void WebDocumentFirstPartyTest::SetUpTestCase() | |
247 { | |
248 URLTestHelpers::registerMockedURLLoad(toOriginA(emptyFile), WebString::fromU
TF8(emptyFile)); | |
249 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedData), WebString::from
UTF8(nestedData)); | |
250 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginA), WebString::f
romUTF8(nestedOriginA)); | |
251 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginAInOriginA), Web
String::fromUTF8(nestedOriginAInOriginA)); | |
252 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginAInOriginB), Web
String::fromUTF8(nestedOriginAInOriginB)); | |
253 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginB), WebString::f
romUTF8(nestedOriginB)); | |
254 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginBInOriginA), Web
String::fromUTF8(nestedOriginBInOriginA)); | |
255 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginBInOriginB), Web
String::fromUTF8(nestedOriginBInOriginB)); | |
256 URLTestHelpers::registerMockedURLLoad(toOriginA(nestedSrcDoc), WebString::fr
omUTF8(nestedSrcDoc)); | |
257 | |
258 URLTestHelpers::registerMockedURLLoad(toOriginB(emptyFile), WebString::fromU
TF8(emptyFile)); | |
259 URLTestHelpers::registerMockedURLLoad(toOriginB(nestedOriginA), WebString::f
romUTF8(nestedOriginA)); | |
260 URLTestHelpers::registerMockedURLLoad(toOriginB(nestedOriginB), WebString::f
romUTF8(nestedOriginB)); | |
261 } | |
262 | |
263 void WebDocumentFirstPartyTest::load(const char* file) | |
264 { | |
265 m_webViewHelper.initializeAndLoad(std::string(baseURLOriginA) + file); | |
266 } | |
267 | |
268 Document* WebDocumentFirstPartyTest::topDocument() const | |
269 { | |
270 return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame())->doc
ument(); | |
271 } | |
272 | |
273 Document* WebDocumentFirstPartyTest::nestedDocument() const | |
274 { | |
275 return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame()->tree
().firstChild())->document(); | |
276 } | |
277 | |
278 Document* WebDocumentFirstPartyTest::nestedNestedDocument() const | |
279 { | |
280 return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame()->tree
().firstChild()->tree().firstChild())->document(); | |
281 } | |
282 | |
283 TEST_F(WebDocumentFirstPartyTest, Empty) | |
284 { | |
285 load(emptyFile); | |
286 | |
287 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
288 ASSERT_EQ(toOriginA(emptyFile), topDocument()->firstPartyForCookies()); | |
289 | |
290 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
291 ASSERT_EQ(toOriginA(emptyFile), topDocument()->firstPartyForCookies()); | |
292 } | |
293 | |
294 TEST_F(WebDocumentFirstPartyTest, NestedOriginA) | |
295 { | |
296 load(nestedOriginA); | |
297 | |
298 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
299 ASSERT_EQ(toOriginA(nestedOriginA), topDocument()->firstPartyForCookies()); | |
300 ASSERT_EQ(toOriginA(nestedOriginA), nestedDocument()->firstPartyForCookies()
); | |
301 | |
302 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
303 ASSERT_EQ(toOriginA(nestedOriginA), topDocument()->firstPartyForCookies()); | |
304 ASSERT_EQ(toOriginA(nestedOriginA), nestedDocument()->firstPartyForCookies()
); | |
305 } | |
306 | |
307 TEST_F(WebDocumentFirstPartyTest, NestedOriginAInOriginA) | |
308 { | |
309 load(nestedOriginAInOriginA); | |
310 | |
311 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
312 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), topDocument()->firstPartyForCoo
kies()); | |
313 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedDocument()->firstPartyFor
Cookies()); | |
314 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedNestedDocument()->firstPa
rtyForCookies()); | |
315 | |
316 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
317 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), topDocument()->firstPartyForCoo
kies()); | |
318 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedDocument()->firstPartyFor
Cookies()); | |
319 ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedNestedDocument()->firstPa
rtyForCookies()); | |
320 } | |
321 | |
322 TEST_F(WebDocumentFirstPartyTest, NestedOriginAInOriginB) | |
323 { | |
324 load(nestedOriginAInOriginB); | |
325 | |
326 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
327 ASSERT_EQ(toOriginA(nestedOriginAInOriginB), topDocument()->firstPartyForCoo
kies()); | |
328 ASSERT_EQ(toOriginA(nestedOriginAInOriginB), nestedDocument()->firstPartyFor
Cookies()); | |
329 ASSERT_EQ(toOriginA(nestedOriginAInOriginB), nestedNestedDocument()->firstPa
rtyForCookies()); | |
330 | |
331 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
332 ASSERT_EQ(toOriginA(nestedOriginAInOriginB), topDocument()->firstPartyForCoo
kies()); | |
333 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->f
irstPartyForCookies()); | |
334 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocumen
t()->firstPartyForCookies()); | |
335 } | |
336 | |
337 TEST_F(WebDocumentFirstPartyTest, NestedOriginB) | |
338 { | |
339 load(nestedOriginB); | |
340 | |
341 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
342 ASSERT_EQ(toOriginA(nestedOriginB), topDocument()->firstPartyForCookies()); | |
343 ASSERT_EQ(toOriginA(nestedOriginB), nestedDocument()->firstPartyForCookies()
); | |
344 | |
345 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
346 ASSERT_EQ(toOriginA(nestedOriginB), topDocument()->firstPartyForCookies()); | |
347 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->f
irstPartyForCookies()); | |
348 } | |
349 | |
350 TEST_F(WebDocumentFirstPartyTest, NestedOriginBInOriginA) | |
351 { | |
352 load(nestedOriginBInOriginA); | |
353 | |
354 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
355 ASSERT_EQ(toOriginA(nestedOriginBInOriginA), topDocument()->firstPartyForCoo
kies()); | |
356 ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedDocument()->firstPartyFor
Cookies()); | |
357 ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedNestedDocument()->firstPa
rtyForCookies()); | |
358 | |
359 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
360 ASSERT_EQ(toOriginA(nestedOriginBInOriginA), topDocument()->firstPartyForCoo
kies()); | |
361 ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedDocument()->firstPartyFor
Cookies()); | |
362 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocumen
t()->firstPartyForCookies()); | |
363 } | |
364 | |
365 TEST_F(WebDocumentFirstPartyTest, NestedOriginBInOriginB) | |
366 { | |
367 load(nestedOriginBInOriginB); | |
368 | |
369 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
370 ASSERT_EQ(toOriginA(nestedOriginBInOriginB), topDocument()->firstPartyForCoo
kies()); | |
371 ASSERT_EQ(toOriginA(nestedOriginBInOriginB), nestedDocument()->firstPartyFor
Cookies()); | |
372 ASSERT_EQ(toOriginA(nestedOriginBInOriginB), nestedNestedDocument()->firstPa
rtyForCookies()); | |
373 | |
374 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
375 ASSERT_EQ(toOriginA(nestedOriginBInOriginB), topDocument()->firstPartyForCoo
kies()); | |
376 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->f
irstPartyForCookies()); | |
377 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocumen
t()->firstPartyForCookies()); | |
378 } | |
379 | |
380 TEST_F(WebDocumentFirstPartyTest, NestedSrcdoc) | |
381 { | |
382 load(nestedSrcDoc); | |
383 | |
384 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
385 ASSERT_EQ(toOriginA(nestedSrcDoc), topDocument()->firstPartyForCookies()); | |
386 ASSERT_EQ(toOriginA(nestedSrcDoc), nestedDocument()->firstPartyForCookies())
; | |
387 | |
388 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
389 ASSERT_EQ(toOriginA(nestedSrcDoc), topDocument()->firstPartyForCookies()); | |
390 ASSERT_EQ(toOriginA(nestedSrcDoc), nestedDocument()->firstPartyForCookies())
; | |
391 } | |
392 | |
393 TEST_F(WebDocumentFirstPartyTest, NestedData) | |
394 { | |
395 load(nestedData); | |
396 | |
397 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false); | |
398 ASSERT_EQ(toOriginA(nestedData), topDocument()->firstPartyForCookies()); | |
399 ASSERT_EQ(toOriginA(nestedData), nestedDocument()->firstPartyForCookies()); | |
400 | |
401 RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true); | |
402 ASSERT_EQ(toOriginA(nestedData), topDocument()->firstPartyForCookies()); | |
403 ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->f
irstPartyForCookies()); | |
404 } | |
405 } | |
OLD | NEW |