| 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_elapsedSeconds(0.) { } | 127 ProxyPlatform() : m_oldPlatform(blink::Platform::current()), m_elapsedSe
conds(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 |
| 148 double m_elapsedSeconds; | 154 double m_elapsedSeconds; |
| 149 }; | 155 }; |
| 150 | 156 |
| 151 virtual void SetUp() | 157 virtual void SetUp() |
| 152 { | 158 { |
| 153 m_savedPlatform = blink::Platform::current(); | 159 m_savedPlatform = blink::Platform::current(); |
| 154 blink::Platform::initialize(&m_proxyPlatform); | 160 blink::Platform::initialize(&m_proxyPlatform); |
| 155 | 161 |
| 156 // Save the global memory cache to restore it upon teardown. | 162 // Save the global memory cache to restore it upon teardown. |
| 157 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); | 163 m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create()
); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 firstResource->setResponse(fresh200Response); | 575 firstResource->setResponse(fresh200Response); |
| 570 memoryCache()->add(firstResource.get()); | 576 memoryCache()->add(firstResource.get()); |
| 571 | 577 |
| 572 advanceClock(500.); | 578 advanceClock(500.); |
| 573 | 579 |
| 574 ResourcePtr<Resource> fetched = fetch(); | 580 ResourcePtr<Resource> fetched = fetch(); |
| 575 EXPECT_EQ(firstResource, fetched); | 581 EXPECT_EQ(firstResource, fetched); |
| 576 } | 582 } |
| 577 | 583 |
| 578 } // namespace | 584 } // namespace |
| OLD | NEW |