Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fetch/CSSStyleSheetResource.h" | 5 #include "core/fetch/CSSStyleSheetResource.h" |
| 6 | 6 |
| 7 #include "core/css/CSSCrossfadeValue.h" | 7 #include "core/css/CSSCrossfadeValue.h" |
| 8 #include "core/css/CSSImageValue.h" | 8 #include "core/css/CSSImageValue.h" |
| 9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/CSSProperty.h" | 10 #include "core/css/CSSProperty.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 ~CSSStyleSheetResourceTest() override { | 53 ~CSSStyleSheetResourceTest() override { |
| 54 replaceMemoryCacheForTesting(m_originalMemoryCache.release()); | 54 replaceMemoryCacheForTesting(m_originalMemoryCache.release()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 Document& document() { return m_page->document(); } | 57 Document& document() { return m_page->document(); } |
| 58 | 58 |
| 59 Persistent<MemoryCache> m_originalMemoryCache; | 59 Persistent<MemoryCache> m_originalMemoryCache; |
| 60 std::unique_ptr<DummyPageHolder> m_page; | 60 std::unique_ptr<DummyPageHolder> m_page; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction) { | 63 TEST_F(CSSStyleSheetResourceTest, PruneCanCauseEviction) { |
|
yhirano
2016/10/24 08:14:00
According to https://codereview.chromium.org/15373
hiroshige
2016/10/24 10:48:25
Done.
| |
| 64 { | 64 { |
| 65 // We need this scope to remove all references. | 65 // We need this scope to remove all references. |
| 66 KURL imageURL(KURL(), "https://localhost/image"); | 66 KURL imageURL(KURL(), "https://localhost/image"); |
| 67 KURL cssURL(KURL(), "https://localhost/style.css"); | 67 KURL cssURL(KURL(), "https://localhost/style.css"); |
| 68 | 68 |
| 69 // We need to disable loading because we manually give a response to | 69 // We need to disable loading because we manually give a response to |
| 70 // the image resource. | 70 // the image resource. |
| 71 document().fetcher()->setAutoLoadImages(false); | 71 document().fetcher()->setAutoLoadImages(false); |
| 72 | 72 |
| 73 CSSStyleSheetResource* cssResource = | 73 CSSStyleSheetResource* cssResource = |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 98 Resource* imageResource = memoryCache()->resourceForURL( | 98 Resource* imageResource = memoryCache()->resourceForURL( |
| 99 imageURL, MemoryCache::defaultCacheIdentifier()); | 99 imageURL, MemoryCache::defaultCacheIdentifier()); |
| 100 ASSERT_TRUE(imageResource); | 100 ASSERT_TRUE(imageResource); |
| 101 ResourceResponse imageResponse; | 101 ResourceResponse imageResponse; |
| 102 imageResponse.setURL(imageURL); | 102 imageResponse.setURL(imageURL); |
| 103 imageResponse.setHTTPHeaderField("cache-control", "no-store"); | 103 imageResponse.setHTTPHeaderField("cache-control", "no-store"); |
| 104 imageResource->responseReceived(imageResponse, nullptr); | 104 imageResource->responseReceived(imageResponse, nullptr); |
| 105 | 105 |
| 106 contents->checkLoaded(); | 106 contents->checkLoaded(); |
| 107 cssResource->saveParsedStyleSheet(contents); | 107 cssResource->saveParsedStyleSheet(contents); |
| 108 | |
| 109 memoryCache()->update(cssResource, cssResource->size(), cssResource->size(), | |
| 110 false); | |
| 111 memoryCache()->update(imageResource, imageResource->size(), | |
| 112 imageResource->size(), false); | |
| 113 if (!memoryCache()->isInSameLRUListForTest(cssResource, imageResource)) { | |
| 114 // We assume that the LRU list is determined by |size / accessCount|. | |
| 115 for (size_t i = 0; i < cssResource->size() + 1; ++i) | |
| 116 memoryCache()->update(cssResource, cssResource->size(), | |
| 117 cssResource->size(), true); | |
| 118 for (size_t i = 0; i < imageResource->size() + 1; ++i) | |
| 119 memoryCache()->update(imageResource, imageResource->size(), | |
| 120 imageResource->size(), true); | |
| 121 } | |
| 122 ASSERT_TRUE( | |
| 123 memoryCache()->isInSameLRUListForTest(cssResource, imageResource)); | |
| 124 } | 108 } |
| 125 ThreadState::current()->collectAllGarbage(); | 109 ThreadState::current()->collectAllGarbage(); |
| 126 // This operation should not lead to crash! | 110 // This operation should not lead to crash! |
| 127 memoryCache()->pruneAll(); | 111 memoryCache()->pruneAll(); |
| 128 } | 112 } |
| 129 | 113 |
| 130 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) { | 114 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) { |
| 131 const char url[] = "https://localhost/style.css"; | 115 const char url[] = "https://localhost/style.css"; |
| 132 KURL imageURL(KURL(), url); | 116 KURL imageURL(KURL(), url); |
| 133 KURL cssURL(KURL(), url); | 117 KURL cssURL(KURL(), url); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 157 // The underlying |contents| for the stylesheet resource must have a | 141 // The underlying |contents| for the stylesheet resource must have a |
| 158 // matching reference status. | 142 // matching reference status. |
| 159 EXPECT_TRUE(memoryCache()->contains(imageResource)); | 143 EXPECT_TRUE(memoryCache()->contains(imageResource)); |
| 160 EXPECT_FALSE(memoryCache()->contains(cssResource)); | 144 EXPECT_FALSE(memoryCache()->contains(cssResource)); |
| 161 EXPECT_FALSE(contents->isReferencedFromResource()); | 145 EXPECT_FALSE(contents->isReferencedFromResource()); |
| 162 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext)); | 146 EXPECT_FALSE(cssResource->restoreParsedStyleSheet(parserContext)); |
| 163 } | 147 } |
| 164 | 148 |
| 165 } // namespace | 149 } // namespace |
| 166 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |