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

Unified Diff: Source/web/tests/WebDocumentTest.cpp

Issue 1075163002: Ancestors count towards first-partyness. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tests. Created 5 years, 8 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/platform/RuntimeEnabledFeatures.in ('k') | Source/web/tests/data/first_party/empty.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/tests/WebDocumentTest.cpp
diff --git a/Source/web/tests/WebDocumentTest.cpp b/Source/web/tests/WebDocumentTest.cpp
index c401ea99cf3244d936de0b010be9f33d02df91bf..f24d3fdea5a644c0dc9d80a7c5fb6ad74b6b9449 100644
--- a/Source/web/tests/WebDocumentTest.cpp
+++ b/Source/web/tests/WebDocumentTest.cpp
@@ -13,8 +13,10 @@
#include "core/html/HTMLElement.h"
#include "core/style/ComputedStyle.h"
#include "core/page/Page.h"
+#include "platform/RuntimeEnabledFeatures.h"
#include "platform/graphics/Color.h"
#include "platform/testing/URLTestHelpers.h"
+#include "platform/weborigin/SecurityOrigin.h"
#include "web/tests/FrameTestHelpers.h"
#include <gtest/gtest.h>
@@ -204,4 +206,200 @@ TEST(WebDocumentTest, SetIsTransitionDocument)
ASSERT_FALSE(coreDoc->isTransitionDocument());
}
+namespace {
+ const char* baseURLOriginA = "http://example.test:0/";
+ const char* baseURLOriginB = "http://not-example.test:0/";
+ const char* emptyFile = "first_party/empty.html";
+ const char* nestedData = "first_party/nested-data.html";
+ const char* nestedOriginA = "first_party/nested-originA.html";
+ const char* nestedOriginAInOriginA = "first_party/nested-originA-in-originA.html";
+ const char* nestedOriginAInOriginB = "first_party/nested-originA-in-originB.html";
+ const char* nestedOriginB = "first_party/nested-originB.html";
+ const char* nestedOriginBInOriginA = "first_party/nested-originB-in-originA.html";
+ const char* nestedOriginBInOriginB = "first_party/nested-originB-in-originB.html";
+ const char* nestedSrcDoc = "first_party/nested-srcdoc.html";
+
+ static KURL toOriginA(const char* file)
+ {
+ return toKURL(std::string(baseURLOriginA) + file);
+ }
+
+ static KURL toOriginB(const char* file)
+ {
+ return toKURL(std::string(baseURLOriginB) + file);
+ }
+}
+
+class WebDocumentFirstPartyTest : public ::testing::Test {
+public:
+ static void SetUpTestCase();
+
+protected:
+ void load(const char*);
+ Document* topDocument() const;
+ Document* nestedDocument() const;
+ Document* nestedNestedDocument() const;
+
+ WebViewHelper m_webViewHelper;
+};
+
+void WebDocumentFirstPartyTest::SetUpTestCase()
+{
+ URLTestHelpers::registerMockedURLLoad(toOriginA(emptyFile), WebString::fromUTF8(emptyFile));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedData), WebString::fromUTF8(nestedData));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginA), WebString::fromUTF8(nestedOriginA));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginAInOriginA), WebString::fromUTF8(nestedOriginAInOriginA));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginAInOriginB), WebString::fromUTF8(nestedOriginAInOriginB));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginB), WebString::fromUTF8(nestedOriginB));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginBInOriginA), WebString::fromUTF8(nestedOriginBInOriginA));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedOriginBInOriginB), WebString::fromUTF8(nestedOriginBInOriginB));
+ URLTestHelpers::registerMockedURLLoad(toOriginA(nestedSrcDoc), WebString::fromUTF8(nestedSrcDoc));
+
+ URLTestHelpers::registerMockedURLLoad(toOriginB(emptyFile), WebString::fromUTF8(emptyFile));
+ URLTestHelpers::registerMockedURLLoad(toOriginB(nestedOriginA), WebString::fromUTF8(nestedOriginA));
+ URLTestHelpers::registerMockedURLLoad(toOriginB(nestedOriginB), WebString::fromUTF8(nestedOriginB));
+}
+
+void WebDocumentFirstPartyTest::load(const char* file)
+{
+ m_webViewHelper.initializeAndLoad(std::string(baseURLOriginA) + file);
+}
+
+Document* WebDocumentFirstPartyTest::topDocument() const
+{
+ return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame())->document();
+}
+
+Document* WebDocumentFirstPartyTest::nestedDocument() const
+{
+ return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame()->tree().firstChild())->document();
+}
+
+Document* WebDocumentFirstPartyTest::nestedNestedDocument() const
+{
+ return toLocalFrame(m_webViewHelper.webViewImpl()->page()->mainFrame()->tree().firstChild()->tree().firstChild())->document();
+}
+
+TEST_F(WebDocumentFirstPartyTest, Empty)
+{
+ load(emptyFile);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(emptyFile), topDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(emptyFile), topDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginA)
+{
+ load(nestedOriginA);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginA), nestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginA), nestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginAInOriginA)
+{
+ load(nestedOriginAInOriginA);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedNestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginA), nestedNestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginAInOriginB)
+{
+ load(nestedOriginAInOriginB);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginB), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginB), nestedNestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginAInOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginB)
+{
+ load(nestedOriginB);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginB), nestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginBInOriginA)
+{
+ load(nestedOriginBInOriginA);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedNestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginA), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginA), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedOriginBInOriginB)
+{
+ load(nestedOriginBInOriginB);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginB), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginB), nestedNestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedOriginBInOriginB), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedNestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedSrcdoc)
+{
+ load(nestedSrcDoc);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedSrcDoc), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedSrcDoc), nestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedSrcDoc), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedSrcDoc), nestedDocument()->firstPartyForCookies());
+}
+
+TEST_F(WebDocumentFirstPartyTest, NestedData)
+{
+ load(nestedData);
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(false);
+ ASSERT_EQ(toOriginA(nestedData), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(toOriginA(nestedData), nestedDocument()->firstPartyForCookies());
+
+ RuntimeEnabledFeatures::setFirstPartyIncludesAncestorsEnabled(true);
+ ASSERT_EQ(toOriginA(nestedData), topDocument()->firstPartyForCookies());
+ ASSERT_EQ(SecurityOrigin::urlWithUniqueSecurityOrigin(), nestedDocument()->firstPartyForCookies());
+}
}
« no previous file with comments | « Source/platform/RuntimeEnabledFeatures.in ('k') | Source/web/tests/data/first_party/empty.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698