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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp

Issue 2266443002: Optimize posting of WTF::Closure and improve scheduler test mocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cut back to just the WTF::Closure fix plus the scheduler test mock refactor. Created 4 years, 3 months 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
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, 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 24 matching lines...) Expand all
35 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
36 #include "core/fetch/MemoryCache.h" 36 #include "core/fetch/MemoryCache.h"
37 #include "core/fetch/RawResource.h" 37 #include "core/fetch/RawResource.h"
38 #include "core/fetch/ResourceLoader.h" 38 #include "core/fetch/ResourceLoader.h"
39 #include "platform/exported/WrappedResourceResponse.h" 39 #include "platform/exported/WrappedResourceResponse.h"
40 #include "platform/heap/Handle.h" 40 #include "platform/heap/Handle.h"
41 #include "platform/heap/HeapAllocator.h" 41 #include "platform/heap/HeapAllocator.h"
42 #include "platform/heap/Member.h" 42 #include "platform/heap/Member.h"
43 #include "platform/network/ResourceRequest.h" 43 #include "platform/network/ResourceRequest.h"
44 #include "platform/network/ResourceTimingInfo.h" 44 #include "platform/network/ResourceTimingInfo.h"
45 #include "platform/scheduler/test/fake_web_task_runner.h"
45 #include "platform/testing/URLTestHelpers.h" 46 #include "platform/testing/URLTestHelpers.h"
46 #include "platform/testing/weburl_loader_mock.h" 47 #include "platform/testing/weburl_loader_mock.h"
47 #include "platform/weborigin/KURL.h" 48 #include "platform/weborigin/KURL.h"
48 #include "public/platform/Platform.h" 49 #include "public/platform/Platform.h"
49 #include "public/platform/WebTaskRunner.h" 50 #include "public/platform/WebTaskRunner.h"
50 #include "public/platform/WebURLLoaderMockFactory.h" 51 #include "public/platform/WebURLLoaderMockFactory.h"
51 #include "public/platform/WebURLResponse.h" 52 #include "public/platform/WebURLResponse.h"
52 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
53 #include "wtf/Allocator.h" 54 #include "wtf/Allocator.h"
54 #include "wtf/PtrUtil.h" 55 #include "wtf/PtrUtil.h"
55 #include "wtf/Vector.h" 56 #include "wtf/Vector.h"
56 #include <memory> 57 #include <memory>
57 58
58 namespace blink { 59 namespace blink {
59 60
60 namespace { 61 namespace {
61
62 const char testImageFilename[] = "white-1x1.png"; 62 const char testImageFilename[] = "white-1x1.png";
63 const int testImageSize = 103; // size of web/tests/data/white-1x1.png 63 const int testImageSize = 103; // size of web/tests/data/white-1x1.png
64
65 class MockTaskRunner : public blink::WebTaskRunner {
66 void postTask(const WebTraceLocation&, Task*) override { }
67 void postDelayedTask(const WebTraceLocation&, Task*, double) override { }
68 bool runsTasksOnCurrentThread() override { return true; }
69 std::unique_ptr<WebTaskRunner> clone() override { return nullptr; }
70 double virtualTimeSeconds() const override { return 0.0; }
71 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0 .0; }
72 SingleThreadTaskRunner* taskRunner() override { return nullptr; }
73 };
74
75 } 64 }
76 65
77 class ResourceFetcherTestMockFetchContext : public FetchContext { 66 class ResourceFetcherTestMockFetchContext : public FetchContext {
78 public: 67 public:
79 static ResourceFetcherTestMockFetchContext* create() 68 static ResourceFetcherTestMockFetchContext* create()
80 { 69 {
81 return new ResourceFetcherTestMockFetchContext; 70 return new ResourceFetcherTestMockFetchContext;
82 } 71 }
83 72
84 virtual ~ResourceFetcherTestMockFetchContext() { } 73 virtual ~ResourceFetcherTestMockFetchContext() { }
85 74
86 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; } 75 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; }
87 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o verride { return true; } 76 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o verride { return true; }
88 bool shouldLoadNewResource(Resource::Type) const override { return true; } 77 bool shouldLoadNewResource(Resource::Type) const override { return true; }
89 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); } 78 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); }
90 79
91 void setCachePolicy(CachePolicy policy) { m_policy = policy; } 80 void setCachePolicy(CachePolicy policy) { m_policy = policy; }
92 CachePolicy getCachePolicy() const override { return m_policy; } 81 CachePolicy getCachePolicy() const override { return m_policy; }
93 void setLoadComplete(bool complete) { m_complete = complete; } 82 void setLoadComplete(bool complete) { m_complete = complete; }
94 bool isLoadComplete() const override { return m_complete; } 83 bool isLoadComplete() const override { return m_complete; }
95 84
96 void addResourceTiming(const ResourceTimingInfo& resourceTimingInfo) overrid e { m_transferSize = resourceTimingInfo.transferSize(); } 85 void addResourceTiming(const ResourceTimingInfo& resourceTimingInfo) overrid e { m_transferSize = resourceTimingInfo.transferSize(); }
97 long long getTransferSize() const { return m_transferSize; } 86 long long getTransferSize() const { return m_transferSize; }
98 87
99 private: 88 private:
100 ResourceFetcherTestMockFetchContext() 89 ResourceFetcherTestMockFetchContext()
101 : m_policy(CachePolicyVerify) 90 : m_policy(CachePolicyVerify)
102 , m_runner(wrapUnique(new MockTaskRunner)) 91 , m_runner(wrapUnique(new scheduler::FakeWebTaskRunner))
103 , m_complete(false) 92 , m_complete(false)
104 , m_transferSize(-1) 93 , m_transferSize(-1)
105 { } 94 { }
106 95
107 CachePolicy m_policy; 96 CachePolicy m_policy;
108 std::unique_ptr<MockTaskRunner> m_runner; 97 std::unique_ptr<scheduler::FakeWebTaskRunner> m_runner;
109 bool m_complete; 98 bool m_complete;
110 long long m_transferSize; 99 long long m_transferSize;
111 }; 100 };
112 101
113 class ResourceFetcherTest : public ::testing::Test { 102 class ResourceFetcherTest : public ::testing::Test {
114 }; 103 };
115 104
116 class TestResourceFactory : public ResourceFactory { 105 class TestResourceFactory : public ResourceFactory {
117 public: 106 public:
118 TestResourceFactory(Resource::Type type = Resource::Raw) 107 TestResourceFactory(Resource::Type type = Resource::Raw)
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 FetchRequest request(url, FetchInitiatorInfo()); 510 FetchRequest request(url, FetchInitiatorInfo());
522 request.makeSynchronous(); 511 request.makeSynchronous();
523 Resource* resource = fetcher->requestResource(request, TestResourceFactory() ); 512 Resource* resource = fetcher->requestResource(request, TestResourceFactory() );
524 EXPECT_TRUE(resource->isLoaded()); 513 EXPECT_TRUE(resource->isLoaded());
525 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority( )); 514 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority( ));
526 515
527 memoryCache()->remove(resource); 516 memoryCache()->remove(resource);
528 } 517 }
529 518
530 } // namespace blink 519 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698