Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: third_party/WebKit/Source/core/loader/resource/FontResourceTest.cpp

Issue 2501543002: Loading: move FontResource to core/loader/resource (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/loader/resource/FontResource.h"
6
7 #include "core/fetch/FetchInitiatorInfo.h"
8 #include "core/fetch/FetchRequest.h"
9 #include "core/fetch/MemoryCache.h"
10 #include "core/fetch/MockFetchContext.h"
11 #include "core/fetch/ResourceFetcher.h"
12 #include "platform/WebTaskRunner.h"
13 #include "platform/exported/WrappedResourceResponse.h"
14 #include "platform/network/ResourceRequest.h"
15 #include "platform/scheduler/test/fake_web_task_runner.h"
hiroshige 2016/11/15 10:08:34 Is this include needed?
Takashi Toyoshima 2016/11/29 08:27:06 Done.
16 #include "platform/testing/weburl_loader_mock.h"
hiroshige 2016/11/15 10:08:34 ditto.
Takashi Toyoshima 2016/11/29 08:27:06 Done.
17 #include "platform/weborigin/KURL.h"
18 #include "public/platform/Platform.h"
19 #include "public/platform/WebURLLoaderMockFactory.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "wtf/PtrUtil.h"
22
23 namespace blink {
24
25 class FontResourceTest : public ::testing::Test {};
26
27 // Tests if ResourceFetcher works fine with FontResource that requires defered
28 // loading supports.
29 TEST_F(FontResourceTest,
30 ResourceFetcherRevalidateDeferedResourceFromTwoInitiators) {
31 KURL url(ParsedURLString, "http://127.0.0.1:8000/font.woff");
32 ResourceResponse response;
33 response.setURL(url);
34 response.setHTTPStatusCode(200);
35 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890");
36 Platform::current()->getURLLoaderMockFactory()->registerURL(
37 url, WrappedResourceResponse(response), "");
38
39 MockFetchContext* context =
40 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource);
41 ResourceFetcher* fetcher = ResourceFetcher::create(context);
42
43 // Fetch to cache a resource.
44 ResourceRequest request1(url);
45 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo());
46 Resource* resource1 = FontResource::fetch(fetchRequest1, fetcher);
47 ASSERT_TRUE(resource1);
48 fetcher->startLoad(resource1);
49 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
50 EXPECT_TRUE(resource1->isLoaded());
51 EXPECT_FALSE(resource1->errorOccurred());
52
53 // Set the context as it is on reloads.
54 context->setLoadComplete(true);
55 context->setCachePolicy(CachePolicyRevalidate);
56
57 // Revalidate the resource.
58 ResourceRequest request2(url);
59 FetchRequest fetchRequest2 = FetchRequest(request2, FetchInitiatorInfo());
60 Resource* resource2 = FontResource::fetch(fetchRequest2, fetcher);
61 ASSERT_TRUE(resource2);
62 EXPECT_EQ(resource1, resource2);
63 EXPECT_TRUE(resource2->isCacheValidator());
64 EXPECT_TRUE(resource2->stillNeedsLoad());
65
66 // Fetch the same resource again before actual load operation starts.
67 ResourceRequest request3(url);
68 FetchRequest fetchRequest3 = FetchRequest(request3, FetchInitiatorInfo());
69 Resource* resource3 = FontResource::fetch(fetchRequest3, fetcher);
70 ASSERT_TRUE(resource3);
71 EXPECT_EQ(resource2, resource3);
72 EXPECT_TRUE(resource3->isCacheValidator());
73 EXPECT_TRUE(resource3->stillNeedsLoad());
74
75 // startLoad() can be called from any initiator. Here, call it from the
76 // latter.
77 fetcher->startLoad(resource3);
78 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
79 EXPECT_TRUE(resource3->isLoaded());
80 EXPECT_FALSE(resource3->errorOccurred());
81 EXPECT_TRUE(resource2->isLoaded());
82 EXPECT_FALSE(resource2->errorOccurred());
83
84 memoryCache()->remove(resource1);
85 }
86
87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698