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

Unified Diff: third_party/WebKit/Source/core/frame/HistoryTest.cpp

Issue 1632513002: Add a fragment change exception to history API's unique origin restrictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test. Created 4 years, 11 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 | « third_party/WebKit/Source/core/frame/History.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/HistoryTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/HistoryTest.cpp b/third_party/WebKit/Source/core/frame/HistoryTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bb5e573c1294e49448ca900d9849fa44cf8496d0
--- /dev/null
+++ b/third_party/WebKit/Source/core/frame/HistoryTest.cpp
@@ -0,0 +1,116 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/frame/History.h"
+
+#include "platform/weborigin/KURL.h"
+#include "platform/weborigin/SecurityOrigin.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class HistoryTest : public ::testing::Test {
+};
+
+TEST_F(HistoryTest, CanChangeToURL)
+{
+ struct TestCase {
+ const char* url;
+ const char* documentURL;
+ bool expected;
+ } cases[] = {
+ {"http://example.com/", "http://example.com/", true},
+ {"http://example.com/#hash", "http://example.com/", true},
+ {"http://example.com/path", "http://example.com/", true},
+ {"http://example.com/path#hash", "http://example.com/", true},
+ {"http://example.com/path?query", "http://example.com/", true},
+ {"http://example.com/path?query#hash", "http://example.com/", true},
+ {"http://example.com:80/", "http://example.com/", true},
+ {"http://example.com:80/#hash", "http://example.com/", true},
+ {"http://example.com:80/path", "http://example.com/", true},
+ {"http://example.com:80/path#hash", "http://example.com/", true},
+ {"http://example.com:80/path?query", "http://example.com/", true},
+ {"http://example.com:80/path?query#hash", "http://example.com/", true},
+ {"http://not-example.com:80/", "http://example.com/", false},
+ {"http://not-example.com:80/#hash", "http://example.com/", false},
+ {"http://not-example.com:80/path", "http://example.com/", false},
+ {"http://not-example.com:80/path#hash", "http://example.com/", false},
+ {"http://not-example.com:80/path?query", "http://example.com/", false},
+ {"http://not-example.com:80/path?query#hash", "http://example.com/", false},
+ {"http://example.com:81/", "http://example.com/", false},
+ {"http://example.com:81/#hash", "http://example.com/", false},
+ {"http://example.com:81/path", "http://example.com/", false},
+ {"http://example.com:81/path#hash", "http://example.com/", false},
+ {"http://example.com:81/path?query", "http://example.com/", false},
+ {"http://example.com:81/path?query#hash", "http://example.com/", false},
+ };
+
+ for (const auto& test : cases) {
+ KURL url(ParsedURLString, test.url);
+ KURL documentURL(ParsedURLString, test.documentURL);
+ RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::create(documentURL);
+ EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get(), documentURL));
+ }
+}
+
+TEST_F(HistoryTest, CanChangeToURLInFileOrigin)
+{
+ struct TestCase {
+ const char* url;
+ const char* documentURL;
+ bool expected;
+ } cases[] = {
+ {"file:///path/to/file/", "file:///path/to/file/", true},
+ {"file:///path/to/file/#hash", "file:///path/to/file/", true},
+ {"file:///path/to/file/path", "file:///path/to/file/", false},
+ {"file:///path/to/file/path#hash", "file:///path/to/file/", false},
+ {"file:///path/to/file/path?query", "file:///path/to/file/", false},
+ {"file:///path/to/file/path?query#hash", "file:///path/to/file/", false},
+ };
+
+ for (const auto& test : cases) {
+ KURL url(ParsedURLString, test.url);
+ KURL documentURL(ParsedURLString, test.documentURL);
+ RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::create(documentURL);
+ EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get(), documentURL));
+ }
+}
+
+TEST_F(HistoryTest, CanChangeToURLInUniqueOrigin)
+{
+ struct TestCase {
+ const char* url;
+ const char* documentURL;
+ bool expected;
+ } cases[] = {
+ {"http://example.com/", "http://example.com/", true},
+ {"http://example.com/#hash", "http://example.com/", true},
+ {"http://example.com/path", "http://example.com/", false},
+ {"http://example.com/path#hash", "http://example.com/", false},
+ {"http://example.com/path?query", "http://example.com/", false},
+ {"http://example.com/path?query#hash", "http://example.com/", false},
+ {"http://example.com:80/", "http://example.com/", true},
+ {"http://example.com:80/#hash", "http://example.com/", true},
+ {"http://example.com:80/path", "http://example.com/", false},
+ {"http://example.com:80/path#hash", "http://example.com/", false},
+ {"http://example.com:80/path?query", "http://example.com/", false},
+ {"http://example.com:80/path?query#hash", "http://example.com/", false},
+ {"http://example.com:81/", "http://example.com/", false},
+ {"http://example.com:81/#hash", "http://example.com/", false},
+ {"http://example.com:81/path", "http://example.com/", false},
+ {"http://example.com:81/path#hash", "http://example.com/", false},
+ {"http://example.com:81/path?query", "http://example.com/", false},
+ {"http://example.com:81/path?query#hash", "http://example.com/", false},
+ };
+
+ for (const auto& test : cases) {
+ KURL url(ParsedURLString, test.url);
+ KURL documentURL(ParsedURLString, test.documentURL);
+ RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::createUnique();
+ EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get(), documentURL));
+ }
+}
+
+} // namespace blink
+
« no previous file with comments | « third_party/WebKit/Source/core/frame/History.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698