OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 "platform/weborigin/OriginAccessEntry.h" | 32 #include "platform/weborigin/OriginAccessEntry.h" |
33 | 33 |
34 #include "platform/testing/TestingPlatformSupport.h" | |
35 #include "platform/weborigin/KURL.h" | 34 #include "platform/weborigin/KURL.h" |
36 #include "platform/weborigin/SecurityOrigin.h" | 35 #include "platform/weborigin/SecurityOrigin.h" |
37 #include "public/platform/Platform.h" | 36 #include "public/platform/Platform.h" |
38 #include "public/platform/WebPublicSuffixList.h" | 37 #include "public/platform/WebPublicSuffixList.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
40 | 39 |
41 namespace blink { | 40 namespace blink { |
42 | 41 |
43 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { | 42 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { |
44 public: | 43 public: |
45 size_t getPublicSuffixLength(const blink::WebString&) override | 44 size_t getPublicSuffixLength(const blink::WebString&) override |
46 { | 45 { |
47 return m_length; | 46 return m_length; |
48 } | 47 } |
49 | 48 |
50 void setPublicSuffix(const blink::WebString& suffix) | 49 void setPublicSuffix(const blink::WebString& suffix) |
51 { | 50 { |
52 m_length = suffix.length(); | 51 m_length = suffix.length(); |
53 } | 52 } |
54 | 53 |
55 private: | 54 private: |
56 size_t m_length; | 55 size_t m_length; |
57 }; | 56 }; |
58 | 57 |
59 class OriginAccessEntryTestPlatform : public TestingPlatformSupport { | 58 class OriginAccessEntryTestPlatform : public blink::Platform { |
60 public: | 59 public: |
| 60 OriginAccessEntryTestPlatform() |
| 61 : m_oldPlatform(Platform::current()) |
| 62 { |
| 63 Platform::initialize(this); |
| 64 } |
| 65 |
| 66 ~OriginAccessEntryTestPlatform() |
| 67 { |
| 68 Platform::initialize(m_oldPlatform); |
| 69 } |
| 70 |
61 blink::WebPublicSuffixList* publicSuffixList() override | 71 blink::WebPublicSuffixList* publicSuffixList() override |
62 { | 72 { |
63 return &m_suffixList; | 73 return &m_suffixList; |
64 } | 74 } |
65 | 75 |
| 76 // Stub for pure virtual method. |
| 77 void cryptographicallyRandomValues(unsigned char*, size_t) override |
| 78 { |
| 79 RELEASE_ASSERT_NOT_REACHED(); |
| 80 } |
| 81 |
| 82 const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) o
verride |
| 83 { |
| 84 static const unsigned char tracingIsDisabled = 0; |
| 85 return &tracingIsDisabled; |
| 86 } |
| 87 |
66 void setPublicSuffix(const blink::WebString& suffix) | 88 void setPublicSuffix(const blink::WebString& suffix) |
67 { | 89 { |
68 m_suffixList.setPublicSuffix(suffix); | 90 m_suffixList.setPublicSuffix(suffix); |
69 } | 91 } |
70 | 92 |
71 private: | 93 private: |
| 94 blink::Platform* m_oldPlatform; |
72 OriginAccessEntryTestSuffixList m_suffixList; | 95 OriginAccessEntryTestSuffixList m_suffixList; |
73 }; | 96 }; |
74 | 97 |
75 TEST(OriginAccessEntryTest, PublicSuffixListTest) | 98 TEST(OriginAccessEntryTest, PublicSuffixListTest) |
76 { | 99 { |
77 OriginAccessEntryTestPlatform platform; | 100 OriginAccessEntryTestPlatform platform; |
78 platform.setPublicSuffix("com"); | 101 platform.setPublicSuffix("com"); |
79 | 102 |
80 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www
.google.com"); | 103 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www
.google.com"); |
81 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo
mains); | 104 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo
mains); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); | 306 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t
est.origin); |
284 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); | 307 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al
lowSubdomains); |
285 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); | 308 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); |
286 | 309 |
287 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); | 310 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di
sallowSubdomains); |
288 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); | 311 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); |
289 } | 312 } |
290 } | 313 } |
291 | 314 |
292 } // namespace blink | 315 } // namespace blink |
| 316 |
OLD | NEW |