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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) | 120 TEST_F(CSSStyleSheetResourceTest, DuplicateResourceNotCached) |
121 { | 121 { |
122 const char url[] = "https://localhost/style.css"; | 122 const char url[] = "https://localhost/style.css"; |
123 KURL imageURL(KURL(), url); | 123 KURL imageURL(KURL(), url); |
124 KURL cssURL(KURL(), url); | 124 KURL cssURL(KURL(), url); |
125 | 125 |
126 // Emulate using <img> to do async stylesheet preloads. | 126 // Emulate using <img> to do async stylesheet preloads. |
127 | 127 |
128 Resource* imageResource = ImageResource::create(ResourceRequest(imageURL), n
ullptr); | 128 Resource* imageResource = ImageResource::create(ResourceRequest(imageURL)); |
129 ASSERT_TRUE(imageResource); | 129 ASSERT_TRUE(imageResource); |
130 memoryCache()->add(imageResource); | 130 memoryCache()->add(imageResource); |
131 ASSERT_TRUE(memoryCache()->contains(imageResource)); | 131 ASSERT_TRUE(memoryCache()->contains(imageResource)); |
132 | 132 |
133 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTest(Re
sourceRequest(cssURL), "utf-8"); | 133 CSSStyleSheetResource* cssResource = CSSStyleSheetResource::createForTest(Re
sourceRequest(cssURL), "utf-8"); |
134 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, nullA
tom, String()), nullptr); | 134 cssResource->responseReceived(ResourceResponse(cssURL, "style/css", 0, nullA
tom, String()), nullptr); |
135 cssResource->finish(); | 135 cssResource->finish(); |
136 | 136 |
137 StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(H
TMLStandardMode, nullptr)); | 137 StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(H
TMLStandardMode, nullptr)); |
138 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document()); | 138 CSSStyleSheet* sheet = CSSStyleSheet::create(contents, document()); |
139 EXPECT_TRUE(sheet); | 139 EXPECT_TRUE(sheet); |
140 | 140 |
141 contents->checkLoaded(); | 141 contents->checkLoaded(); |
142 cssResource->saveParsedStyleSheet(contents); | 142 cssResource->saveParsedStyleSheet(contents); |
143 | 143 |
144 // Verify that the cache will have a mapping for |imageResource| at |url|. | 144 // Verify that the cache will have a mapping for |imageResource| at |url|. |
145 // The underlying |contents| for the stylesheet resource must have a | 145 // The underlying |contents| for the stylesheet resource must have a |
146 // matching cache status. | 146 // matching cache status. |
147 ASSERT_TRUE(memoryCache()->contains(imageResource)); | 147 ASSERT_TRUE(memoryCache()->contains(imageResource)); |
148 ASSERT_FALSE(memoryCache()->contains(cssResource)); | 148 ASSERT_FALSE(memoryCache()->contains(cssResource)); |
149 ASSERT_FALSE(contents->isInMemoryCache()); | 149 ASSERT_FALSE(contents->isInMemoryCache()); |
150 } | 150 } |
151 | 151 |
152 } // namespace | 152 } // namespace |
153 } // namespace blink | 153 } // namespace blink |
OLD | NEW |