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

Side by Side Diff: third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.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) 2014, Google Inc. All rights reserved. 2 * Copyright (c) 2014, 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 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "core/fetch/FetchContext.h" 33 #include "core/fetch/FetchContext.h"
34 #include "core/fetch/ImageResource.h" 34 #include "core/fetch/ImageResource.h"
35 #include "core/fetch/MemoryCache.h" 35 #include "core/fetch/MemoryCache.h"
36 #include "core/fetch/RawResource.h" 36 #include "core/fetch/RawResource.h"
37 #include "core/fetch/Resource.h" 37 #include "core/fetch/Resource.h"
38 #include "core/fetch/ResourceFetcher.h" 38 #include "core/fetch/ResourceFetcher.h"
39 #include "core/fetch/ResourcePtr.h" 39 #include "core/fetch/ResourcePtr.h"
40 #include "platform/network/ResourceRequest.h" 40 #include "platform/network/ResourceRequest.h"
41 #include "platform/testing/TestingPlatformSupport.h"
41 #include "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
42 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
43 #include "wtf/OwnPtr.h" 44 #include "wtf/OwnPtr.h"
44 #include "wtf/RefPtr.h" 45 #include "wtf/RefPtr.h"
45 46
46 namespace blink { 47 namespace blink {
47 48
48 // An URL for the original request. 49 // An URL for the original request.
49 const char kResourceURL[] = "http://resource.com/"; 50 const char kResourceURL[] = "http://resource.com/";
50 51
51 // The origin time of our first request. 52 // The origin time of our first request.
52 const char kOriginalRequestDateAsString[] = "Thu, 25 May 1977 18:30:00 GMT"; 53 const char kOriginalRequestDateAsString[] = "Thu, 25 May 1977 18:30:00 GMT";
53 const double kOriginalRequestDateAsDouble = 233433000.; 54 const double kOriginalRequestDateAsDouble = 233433000.;
54 55
55 const char kOneDayBeforeOriginalRequest[] = "Wed, 24 May 1977 18:30:00 GMT"; 56 const char kOneDayBeforeOriginalRequest[] = "Wed, 24 May 1977 18:30:00 GMT";
56 const char kOneDayAfterOriginalRequest[] = "Fri, 26 May 1977 18:30:00 GMT"; 57 const char kOneDayAfterOriginalRequest[] = "Fri, 26 May 1977 18:30:00 GMT";
57 58
58 const unsigned char kAConstUnsignedCharZero = 0;
59
60 class MockFetchContext : public FetchContext { 59 class MockFetchContext : public FetchContext {
61 public: 60 public:
62 static MockFetchContext* create() 61 static MockFetchContext* create()
63 { 62 {
64 return new MockFetchContext; 63 return new MockFetchContext;
65 } 64 }
66 65
67 ~MockFetchContext() { } 66 ~MockFetchContext() { }
68 67
69 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; } 68 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ResourcePtr<Resource> fetchImage() 112 ResourcePtr<Resource> fetchImage()
114 { 113 {
115 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo()); 114 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc eURL)), FetchInitiatorInfo());
116 return ImageResource::fetch(fetchRequest, fetcher()); 115 return ImageResource::fetch(fetchRequest, fetcher());
117 } 116 }
118 117
119 ResourceFetcher* fetcher() const { return m_fetcher.get(); } 118 ResourceFetcher* fetcher() const { return m_fetcher.get(); }
120 119
121 private: 120 private:
122 // A simple platform that mocks out the clock, for cache freshness testing. 121 // A simple platform that mocks out the clock, for cache freshness testing.
123 class ProxyPlatform : public blink::Platform { 122 class ProxyPlatform : public TestingPlatformSupport {
124 public: 123 public:
125 ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSecon ds(0.) { } 124 ProxyPlatform() : m_elapsedSeconds(0.) { }
126
127 ~ProxyPlatform()
128 {
129 blink::Platform::initialize(m_platform);
130 }
131 125
132 void advanceClock(double seconds) 126 void advanceClock(double seconds)
133 { 127 {
134 m_elapsedSeconds += seconds; 128 m_elapsedSeconds += seconds;
135 } 129 }
136 130
137 WebThread* currentThread() override
138 {
139 return m_platform->currentThread();
140 }
141
142 private: 131 private:
143 // From blink::Platform: 132 // From blink::Platform:
144 double currentTimeSeconds() override 133 double currentTimeSeconds() override
145 { 134 {
146 return kOriginalRequestDateAsDouble + m_elapsedSeconds; 135 return kOriginalRequestDateAsDouble + m_elapsedSeconds;
147 } 136 }
148 137
149 // These blink::Platform methods must be overriden to make a usable obje ct.
150 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
151 {
152 RELEASE_ASSERT_NOT_REACHED();
153 }
154 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* cat egoryName)
155 {
156 return &kAConstUnsignedCharZero;
157 }
158
159 blink::Platform* m_platform; // Not owned.
160 double m_elapsedSeconds; 138 double m_elapsedSeconds;
161 }; 139 };
162 140
163 virtual void SetUp() 141 virtual void SetUp()
164 { 142 {
165 blink::Platform::initialize(&m_proxyPlatform);
166
167 // Save the global memory cache to restore it upon teardown. 143 // Save the global memory cache to restore it upon teardown.
168 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create() ); 144 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create() );
169 145
170 m_fetcher = ResourceFetcher::create(MockFetchContext::create()); 146 m_fetcher = ResourceFetcher::create(MockFetchContext::create());
171 } 147 }
172 148
173 virtual void TearDown() 149 virtual void TearDown()
174 { 150 {
175 memoryCache()->evictResources(); 151 memoryCache()->evictResources();
176 152
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 firstResource->setResponse(fresh200Response); 553 firstResource->setResponse(fresh200Response);
578 memoryCache()->add(firstResource.get()); 554 memoryCache()->add(firstResource.get());
579 555
580 advanceClock(500.); 556 advanceClock(500.);
581 557
582 ResourcePtr<Resource> fetched = fetch(); 558 ResourcePtr<Resource> fetched = fetch();
583 EXPECT_EQ(firstResource, fetched); 559 EXPECT_EQ(firstResource, fetched);
584 } 560 }
585 561
586 } // namespace blink 562 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp ('k') | third_party/WebKit/Source/core/fetch/ResourceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698