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

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/OriginAccessEntryTest.cpp

Issue 1456873003: More regular Platform implementations in unit tests (reland.) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: have GN disable c4267 also Created 5 years 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 unified diff | Download patch
OLDNEW
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
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"
34 #include "platform/weborigin/KURL.h" 35 #include "platform/weborigin/KURL.h"
35 #include "platform/weborigin/SecurityOrigin.h" 36 #include "platform/weborigin/SecurityOrigin.h"
36 #include "public/platform/Platform.h" 37 #include "public/platform/Platform.h"
37 #include "public/platform/WebPublicSuffixList.h" 38 #include "public/platform/WebPublicSuffixList.h"
38 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList { 43 class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList {
43 public: 44 public:
44 size_t getPublicSuffixLength(const blink::WebString&) override 45 size_t getPublicSuffixLength(const blink::WebString&) override
45 { 46 {
46 return m_length; 47 return m_length;
47 } 48 }
48 49
49 void setPublicSuffix(const blink::WebString& suffix) 50 void setPublicSuffix(const blink::WebString& suffix)
50 { 51 {
51 m_length = suffix.length(); 52 m_length = suffix.length();
52 } 53 }
53 54
54 private: 55 private:
55 size_t m_length; 56 size_t m_length;
56 }; 57 };
57 58
58 class OriginAccessEntryTestPlatform : public blink::Platform { 59 class OriginAccessEntryTestPlatform : public TestingPlatformSupport {
59 public: 60 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
71 blink::WebPublicSuffixList* publicSuffixList() override 61 blink::WebPublicSuffixList* publicSuffixList() override
72 { 62 {
73 return &m_suffixList; 63 return &m_suffixList;
74 } 64 }
75 65
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
88 void setPublicSuffix(const blink::WebString& suffix) 66 void setPublicSuffix(const blink::WebString& suffix)
89 { 67 {
90 m_suffixList.setPublicSuffix(suffix); 68 m_suffixList.setPublicSuffix(suffix);
91 } 69 }
92 70
93 private: 71 private:
94 blink::Platform* m_oldPlatform;
95 OriginAccessEntryTestSuffixList m_suffixList; 72 OriginAccessEntryTestSuffixList m_suffixList;
96 }; 73 };
97 74
98 TEST(OriginAccessEntryTest, PublicSuffixListTest) 75 TEST(OriginAccessEntryTest, PublicSuffixListTest)
99 { 76 {
100 OriginAccessEntryTestPlatform platform; 77 OriginAccessEntryTestPlatform platform;
101 platform.setPublicSuffix("com"); 78 platform.setPublicSuffix("com");
102 79
103 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www .google.com"); 80 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www .google.com");
104 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo mains); 81 OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdo mains);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); 283 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin);
307 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains); 284 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains);
308 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); 285 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest));
309 286
310 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains); 287 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains);
311 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); 288 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest));
312 } 289 }
313 } 290 }
314 291
315 } // namespace blink 292 } // namespace blink
316
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/text/LocaleMacTest.cpp ('k') | third_party/WebKit/Source/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698