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/html/parser/CSSPreloadScanner.h" | 5 #include "core/html/parser/CSSPreloadScanner.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
9 #include "core/html/parser/HTMLResourcePreloader.h" | 9 #include "core/html/parser/HTMLResourcePreloader.h" |
10 #include "core/testing/DummyPageHolder.h" | 10 #include "core/testing/DummyPageHolder.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 MockHTMLResourcePreloader* preloader = | 136 MockHTMLResourcePreloader* preloader = |
137 new MockHTMLResourcePreloader(dummy_page_holder->GetDocument()); | 137 new MockHTMLResourcePreloader(dummy_page_holder->GetDocument()); |
138 | 138 |
139 KURL url(kParsedURLString, "http://127.0.0.1/foo.css"); | 139 KURL url(kParsedURLString, "http://127.0.0.1/foo.css"); |
140 CSSStyleSheetResource* resource = | 140 CSSStyleSheetResource* resource = |
141 CSSStyleSheetResource::CreateForTest(ResourceRequest(url), "utf-8"); | 141 CSSStyleSheetResource::CreateForTest(ResourceRequest(url), "utf-8"); |
142 | 142 |
143 const char* data = "@import url('http://127.0.0.1/preload.css');"; | 143 const char* data = "@import url('http://127.0.0.1/preload.css');"; |
144 resource->AppendData(data, strlen(data)); | 144 resource->AppendData(data, strlen(data)); |
145 ResourceError error(kErrorDomainBlinkInternal, 0, url.GetString(), ""); | 145 ResourceError error(kErrorDomainBlinkInternal, 0, url.GetString(), ""); |
146 resource->GetError(error); | 146 resource->FinishAsError(error); |
147 | 147 |
148 // Should not crash. | 148 // Should not crash. |
149 PreloadRecordingCSSPreloaderResourceClient* resource_client = | 149 PreloadRecordingCSSPreloaderResourceClient* resource_client = |
150 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); | 150 new PreloadRecordingCSSPreloaderResourceClient(resource, preloader); |
151 | 151 |
152 EXPECT_EQ(0u, resource_client->preload_urls_.size()); | 152 EXPECT_EQ(0u, resource_client->preload_urls_.size()); |
153 } | 153 } |
154 | 154 |
155 // Regression test for crbug.com/645331, where a resource client gets callbacks | 155 // Regression test for crbug.com/645331, where a resource client gets callbacks |
156 // after the document is shutdown and we have no frame. | 156 // after the document is shutdown and we have no frame. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 EXPECT_EQ(Resource::kPreloadNotReferenced, resource->GetPreloadResult()); | 214 EXPECT_EQ(Resource::kPreloadNotReferenced, resource->GetPreloadResult()); |
215 EXPECT_EQ(1u, resource_client->preload_urls_.size()); | 215 EXPECT_EQ(1u, resource_client->preload_urls_.size()); |
216 EXPECT_EQ("http://127.0.0.1/preload.css", | 216 EXPECT_EQ("http://127.0.0.1/preload.css", |
217 resource_client->preload_urls_.front()); | 217 resource_client->preload_urls_.front()); |
218 EXPECT_EQ(kReferrerPolicyAlways, | 218 EXPECT_EQ(kReferrerPolicyAlways, |
219 resource_client->preload_referrer_policies_.front()); | 219 resource_client->preload_referrer_policies_.front()); |
220 } | 220 } |
221 | 221 |
222 } // namespace blink | 222 } // namespace blink |
OLD | NEW |