OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/frame/History.h" |
| 6 |
| 7 #include "platform/weborigin/KURL.h" |
| 8 #include "platform/weborigin/SecurityOrigin.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class HistoryTest : public ::testing::Test { |
| 14 }; |
| 15 |
| 16 TEST_F(HistoryTest, CanChangeToURL) |
| 17 { |
| 18 struct TestCase { |
| 19 const char* url; |
| 20 const char* documentURL; |
| 21 bool expected; |
| 22 } cases[] = { |
| 23 {"http://example.com/", "http://example.com/", true}, |
| 24 {"http://example.com/#hash", "http://example.com/", true}, |
| 25 {"http://example.com/path", "http://example.com/", true}, |
| 26 {"http://example.com/path#hash", "http://example.com/", true}, |
| 27 {"http://example.com/path?query", "http://example.com/", true}, |
| 28 {"http://example.com/path?query#hash", "http://example.com/", true}, |
| 29 {"http://example.com:80/", "http://example.com/", true}, |
| 30 {"http://example.com:80/#hash", "http://example.com/", true}, |
| 31 {"http://example.com:80/path", "http://example.com/", true}, |
| 32 {"http://example.com:80/path#hash", "http://example.com/", true}, |
| 33 {"http://example.com:80/path?query", "http://example.com/", true}, |
| 34 {"http://example.com:80/path?query#hash", "http://example.com/", true}, |
| 35 {"http://not-example.com:80/", "http://example.com/", false}, |
| 36 {"http://not-example.com:80/#hash", "http://example.com/", false}, |
| 37 {"http://not-example.com:80/path", "http://example.com/", false}, |
| 38 {"http://not-example.com:80/path#hash", "http://example.com/", false}, |
| 39 {"http://not-example.com:80/path?query", "http://example.com/", false}, |
| 40 {"http://not-example.com:80/path?query#hash", "http://example.com/", fal
se}, |
| 41 {"http://example.com:81/", "http://example.com/", false}, |
| 42 {"http://example.com:81/#hash", "http://example.com/", false}, |
| 43 {"http://example.com:81/path", "http://example.com/", false}, |
| 44 {"http://example.com:81/path#hash", "http://example.com/", false}, |
| 45 {"http://example.com:81/path?query", "http://example.com/", false}, |
| 46 {"http://example.com:81/path?query#hash", "http://example.com/", false}, |
| 47 }; |
| 48 |
| 49 for (const auto& test : cases) { |
| 50 KURL url(ParsedURLString, test.url); |
| 51 KURL documentURL(ParsedURLString, test.documentURL); |
| 52 RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::create(documentU
RL); |
| 53 EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get
(), documentURL)); |
| 54 } |
| 55 } |
| 56 |
| 57 TEST_F(HistoryTest, CanChangeToURLInFileOrigin) |
| 58 { |
| 59 struct TestCase { |
| 60 const char* url; |
| 61 const char* documentURL; |
| 62 bool expected; |
| 63 } cases[] = { |
| 64 {"file:///path/to/file/", "file:///path/to/file/", true}, |
| 65 {"file:///path/to/file/#hash", "file:///path/to/file/", true}, |
| 66 {"file:///path/to/file/path", "file:///path/to/file/", false}, |
| 67 {"file:///path/to/file/path#hash", "file:///path/to/file/", false}, |
| 68 {"file:///path/to/file/path?query", "file:///path/to/file/", false}, |
| 69 {"file:///path/to/file/path?query#hash", "file:///path/to/file/", false}
, |
| 70 }; |
| 71 |
| 72 for (const auto& test : cases) { |
| 73 KURL url(ParsedURLString, test.url); |
| 74 KURL documentURL(ParsedURLString, test.documentURL); |
| 75 RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::create(documentU
RL); |
| 76 EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get
(), documentURL)); |
| 77 } |
| 78 } |
| 79 |
| 80 TEST_F(HistoryTest, CanChangeToURLInUniqueOrigin) |
| 81 { |
| 82 struct TestCase { |
| 83 const char* url; |
| 84 const char* documentURL; |
| 85 bool expected; |
| 86 } cases[] = { |
| 87 {"http://example.com/", "http://example.com/", true}, |
| 88 {"http://example.com/#hash", "http://example.com/", true}, |
| 89 {"http://example.com/path", "http://example.com/", false}, |
| 90 {"http://example.com/path#hash", "http://example.com/", false}, |
| 91 {"http://example.com/path?query", "http://example.com/", false}, |
| 92 {"http://example.com/path?query#hash", "http://example.com/", false}, |
| 93 {"http://example.com:80/", "http://example.com/", true}, |
| 94 {"http://example.com:80/#hash", "http://example.com/", true}, |
| 95 {"http://example.com:80/path", "http://example.com/", false}, |
| 96 {"http://example.com:80/path#hash", "http://example.com/", false}, |
| 97 {"http://example.com:80/path?query", "http://example.com/", false}, |
| 98 {"http://example.com:80/path?query#hash", "http://example.com/", false}, |
| 99 {"http://example.com:81/", "http://example.com/", false}, |
| 100 {"http://example.com:81/#hash", "http://example.com/", false}, |
| 101 {"http://example.com:81/path", "http://example.com/", false}, |
| 102 {"http://example.com:81/path#hash", "http://example.com/", false}, |
| 103 {"http://example.com:81/path?query", "http://example.com/", false}, |
| 104 {"http://example.com:81/path?query#hash", "http://example.com/", false}, |
| 105 }; |
| 106 |
| 107 for (const auto& test : cases) { |
| 108 KURL url(ParsedURLString, test.url); |
| 109 KURL documentURL(ParsedURLString, test.documentURL); |
| 110 RefPtr<SecurityOrigin> documentOrigin = SecurityOrigin::createUnique(); |
| 111 EXPECT_EQ(test.expected, History::canChangeToUrl(url, documentOrigin.get
(), documentURL)); |
| 112 } |
| 113 } |
| 114 |
| 115 } // namespace blink |
| 116 |
OLD | NEW |