OLD | NEW |
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); | 117 FetchRequest fetchRequest(ResourceRequest(KURL(ParsedURLString, kResourc
eURL)), FetchInitiatorInfo()); |
118 return m_fetcher->fetchImage(fetchRequest); | 118 return m_fetcher->fetchImage(fetchRequest); |
119 } | 119 } |
120 | 120 |
121 ResourceFetcher* fetcher() const { return m_fetcher.get(); } | 121 ResourceFetcher* fetcher() const { return m_fetcher.get(); } |
122 | 122 |
123 private: | 123 private: |
124 // A simple platform that mocks out the clock, for cache freshness testing. | 124 // A simple platform that mocks out the clock, for cache freshness testing. |
125 class ProxyPlatform : public blink::Platform { | 125 class ProxyPlatform : public blink::Platform { |
126 public: | 126 public: |
127 ProxyPlatform() : m_oldPlatform(blink::Platform::current()), m_elapsedSe
conds(0.) { } | 127 ProxyPlatform() : m_elapsedSeconds(0.) { } |
128 | 128 |
129 void advanceClock(double seconds) | 129 void advanceClock(double seconds) |
130 { | 130 { |
131 m_elapsedSeconds += seconds; | 131 m_elapsedSeconds += seconds; |
132 } | 132 } |
133 | 133 |
134 private: | 134 private: |
135 // From blink::Platform: | 135 // From blink::Platform: |
136 virtual double currentTime() | 136 virtual double currentTime() |
137 { | 137 { |
138 return kOriginalRequestDateAsDouble + m_elapsedSeconds; | 138 return kOriginalRequestDateAsDouble + m_elapsedSeconds; |
139 } | 139 } |
140 | 140 |
141 // These blink::Platform methods must be overriden to make a usable obje
ct. | 141 // These blink::Platform methods must be overriden to make a usable obje
ct. |
142 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } | 142 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } |
143 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* cat
egoryName) | 143 virtual const unsigned char* getTraceCategoryEnabledFlag(const char* cat
egoryName) |
144 { | 144 { |
145 return &kAConstUnsignedCharZero; | 145 return &kAConstUnsignedCharZero; |
146 } | 146 } |
147 | 147 |
148 WebThread* currentThread() override | |
149 { | |
150 return m_oldPlatform->currentThread(); | |
151 } | |
152 | |
153 blink::Platform* m_oldPlatform; // Not owned. | |
154 double m_elapsedSeconds; | 148 double m_elapsedSeconds; |
155 }; | 149 }; |
156 | 150 |
157 virtual void SetUp() | 151 virtual void SetUp() |
158 { | 152 { |
159 m_savedPlatform = blink::Platform::current(); | 153 m_savedPlatform = blink::Platform::current(); |
160 blink::Platform::initialize(&m_proxyPlatform); | 154 blink::Platform::initialize(&m_proxyPlatform); |
161 | 155 |
162 // Save the global memory cache to restore it upon teardown. | 156 // Save the global memory cache to restore it upon teardown. |
163 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); | 157 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 firstResource->setResponse(fresh200Response); | 569 firstResource->setResponse(fresh200Response); |
576 memoryCache()->add(firstResource.get()); | 570 memoryCache()->add(firstResource.get()); |
577 | 571 |
578 advanceClock(500.); | 572 advanceClock(500.); |
579 | 573 |
580 ResourcePtr<Resource> fetched = fetch(); | 574 ResourcePtr<Resource> fetched = fetch(); |
581 EXPECT_EQ(firstResource, fetched); | 575 EXPECT_EQ(firstResource, fetched); |
582 } | 576 } |
583 | 577 |
584 } // namespace | 578 } // namespace |
OLD | NEW |