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

Side by Side Diff: third_party/WebKit/Source/platform/testing/TestingPlatformSupport.h

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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 22 matching lines...) Expand all
33 33
34 #include "platform/PlatformExport.h" 34 #include "platform/PlatformExport.h"
35 #include "public/platform/Platform.h" 35 #include "public/platform/Platform.h"
36 #include "public/platform/WebCompositorSupport.h" 36 #include "public/platform/WebCompositorSupport.h"
37 #include "public/platform/WebScheduler.h" 37 #include "public/platform/WebScheduler.h"
38 #include "public/platform/WebThread.h" 38 #include "public/platform/WebThread.h"
39 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
40 #include <memory> 40 #include <memory>
41 41
42 namespace base { 42 namespace base {
43 class SimpleTestTickClock;
43 class TestDiscardableMemoryAllocator; 44 class TestDiscardableMemoryAllocator;
44 } // namespace base 45 }
46
47 namespace cc {
48 class OrderedSimpleTaskRunner;
49 }
45 50
46 namespace cc_blink { 51 namespace cc_blink {
47 class WebCompositorSupportImpl; 52 class WebCompositorSupportImpl;
48 } // namespace cc_blink 53 } // namespace cc_blink
49 54
50 namespace blink { 55 namespace blink {
51 56 namespace scheduler {
57 class RendererScheduler;
58 class RendererSchedulerImpl;
59 }
52 class TestingPlatformMockWebTaskRunner; 60 class TestingPlatformMockWebTaskRunner;
53 class TestingPlatformMockWebThread; 61 class TestingPlatformMockWebThread;
54 class WebCompositorSupport; 62 class WebCompositorSupport;
55 class WebThread; 63 class WebThread;
56 64
57 class TestingCompositorSupport : public WebCompositorSupport { 65 class TestingCompositorSupport : public WebCompositorSupport {
58 }; 66 };
59 67
60 class TestingPlatformMockScheduler : public WebScheduler {
61 WTF_MAKE_NONCOPYABLE(TestingPlatformMockScheduler);
62 public:
63 TestingPlatformMockScheduler();
64 ~TestingPlatformMockScheduler() override;
65
66 void runSingleTask();
67 void runAllTasks();
68
69 // WebScheduler implementation:
70 WebTaskRunner* loadingTaskRunner() override;
71 WebTaskRunner* timerTaskRunner() override;
72 void shutdown() override {}
73 bool shouldYieldForHighPriorityWork() override { return false; }
74 bool canExceedIdleDeadlineIfRequired() override { return false; }
75 void postIdleTask(const WebTraceLocation&, WebThread::IdleTask*) override { }
76 void postNonNestableIdleTask(const WebTraceLocation&, WebThread::IdleTask*) override { }
77 void postIdleTaskAfterWakeup(const WebTraceLocation&, WebThread::IdleTask*) override { }
78 std::unique_ptr<WebViewScheduler> createWebViewScheduler(InterventionReporte r*) override { return nullptr; }
79 void suspendTimerQueue() override { }
80 void resumeTimerQueue() override { }
81 void addPendingNavigation(WebScheduler::NavigatingFrameType) override { }
82 void removePendingNavigation(WebScheduler::NavigatingFrameType) override { }
83 void onNavigationStarted() override { }
84
85 private:
86 WTF::Deque<std::unique_ptr<WebTaskRunner::Task>> m_tasks;
87 std::unique_ptr<TestingPlatformMockWebTaskRunner> m_mockWebTaskRunner;
88 };
89
90 class TestingPlatformSupport : public Platform { 68 class TestingPlatformSupport : public Platform {
91 WTF_MAKE_NONCOPYABLE(TestingPlatformSupport); 69 WTF_MAKE_NONCOPYABLE(TestingPlatformSupport);
92 public: 70 public:
93 struct Config { 71 struct Config {
94 WebCompositorSupport* compositorSupport = nullptr; 72 WebCompositorSupport* compositorSupport = nullptr;
95 }; 73 };
96 74
97 TestingPlatformSupport(); 75 TestingPlatformSupport();
98 explicit TestingPlatformSupport(const Config&); 76 explicit TestingPlatformSupport(const Config&);
99 77
100 ~TestingPlatformSupport() override; 78 ~TestingPlatformSupport() override;
101 79
102 // Platform: 80 // Platform:
103 WebString defaultLocale() override; 81 WebString defaultLocale() override;
104 WebCompositorSupport* compositorSupport() override; 82 WebCompositorSupport* compositorSupport() override;
105 WebThread* currentThread() override; 83 WebThread* currentThread() override;
84 WebBlobRegistry* blobRegistry() override;
85 WebClipboard* clipboard() override;
86 WebFileUtilities* fileUtilities() override;
87 WebIDBFactory* idbFactory() override;
88 WebMimeRegistry* mimeRegistry() override;
89 WebURLLoaderMockFactory* getURLLoaderMockFactory() override;
90 blink::WebURLLoader* createURLLoader() override;
91
92 WebData loadResource(const char* name) override;
93 WebURLError cancelledError(const WebURL&) const override;
106 94
107 protected: 95 protected:
108 const Config m_config; 96 const Config m_config;
109 Platform* const m_oldPlatform; 97 Platform* const m_oldPlatform;
110 }; 98 };
111 99
112 class TestingPlatformSupportWithMockScheduler : public TestingPlatformSupport { 100 class TestingPlatformSupportWithMockScheduler : public TestingPlatformSupport {
113 WTF_MAKE_NONCOPYABLE(TestingPlatformSupportWithMockScheduler); 101 WTF_MAKE_NONCOPYABLE(TestingPlatformSupportWithMockScheduler);
114 public: 102 public:
115 TestingPlatformSupportWithMockScheduler(); 103 TestingPlatformSupportWithMockScheduler();
116 explicit TestingPlatformSupportWithMockScheduler(const Config&); 104 explicit TestingPlatformSupportWithMockScheduler(const Config&);
117 ~TestingPlatformSupportWithMockScheduler() override; 105 ~TestingPlatformSupportWithMockScheduler() override;
118 106
119 // Platform: 107 // Platform:
120 WebThread* currentThread() override; 108 WebThread* currentThread() override;
121 TestingPlatformMockScheduler* mockWebScheduler(); 109
110 // Runs a single task.
111 void runSingleTask();
112
113 // Runs all currently queued immediate tasks and delayed tasks whose delay h as expired
114 // plus any immediate tasks that are posted as a result of running those tas ks.
115 //
116 // This function ignores future delayed tasks when deciding if the system is idle.
117 // If you need to ensure delayed tasks run, try runForPeriodSeconds() instea d.
118 void runUntilIdle();
119
120 // Runs for |seconds|. Note we use a testing clock rather than the wall cloc k here.
121 void runForPeriodSeconds(double seconds);
122
123 // Advances |m_clock| by |seconds|.
124 void advanceClockSeconds(double seconds);
125
126 scheduler::RendererScheduler* rendererScheduler() const;
127
128 // Controls the behavior of |m_mockTaskRunner| if true, then |m_clock| will
129 // be advanced to the next timer when there's no more immediate work to do.
130 void setAutoAdvanceNowToPendingTasks(bool);
122 131
123 protected: 132 protected:
124 std::unique_ptr<TestingPlatformMockWebThread> m_mockWebThread; 133 static double getTestTime();
134
135 std::unique_ptr<base::SimpleTestTickClock> m_clock;
136 scoped_refptr<cc::OrderedSimpleTaskRunner> m_mockTaskRunner;
137 std::unique_ptr<scheduler::RendererSchedulerImpl> m_scheduler;
138 std::unique_ptr<WebThread> m_thread;
125 }; 139 };
126 140
127 class ScopedUnittestsEnvironmentSetup { 141 class ScopedUnittestsEnvironmentSetup {
128 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup); 142 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup);
129 public: 143 public:
130 ScopedUnittestsEnvironmentSetup(int argc, char** argv); 144 ScopedUnittestsEnvironmentSetup(int argc, char** argv);
131 ~ScopedUnittestsEnvironmentSetup(); 145 ~ScopedUnittestsEnvironmentSetup();
132 146
133 private: 147 private:
134 class DummyPlatform; 148 class DummyPlatform;
135 std::unique_ptr<base::TestDiscardableMemoryAllocator> m_discardableMemoryAll ocator; 149 std::unique_ptr<base::TestDiscardableMemoryAllocator> m_discardableMemoryAll ocator;
136 std::unique_ptr<DummyPlatform> m_platform; 150 std::unique_ptr<DummyPlatform> m_platform;
137 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport; 151 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport;
138 TestingPlatformSupport::Config m_testingPlatformConfig; 152 TestingPlatformSupport::Config m_testingPlatformConfig;
139 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; 153 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport;
140 }; 154 };
141 155
142 } // namespace blink 156 } // namespace blink
143 157
144 #endif // TestingPlatformSupport_h 158 #endif // TestingPlatformSupport_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698