Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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, i s idle. | |
|
haraken
2016/08/22 05:28:48
system, => system
alex clarke (OOO till 29th)
2016/08/22 17:43:01
Done.
| |
| 117 // If you need to ensure delayed tasks run, try runForPeriodSeconds() instea d. | |
| 118 void runUntilIdle(); | |
| 119 | |
| 120 // Runs all currently queued immediate tasks and delayed tasks whose delay h as expired. | |
| 121 // Tasks that get posted after calling this won't run. | |
| 122 void runPendingTasks(); | |
|
haraken
2016/08/22 05:28:48
I'm just curious but when do we need this function
alex clarke (OOO till 29th)
2016/08/22 17:43:01
Looks like only one test in TimerTest.cpp was usin
| |
| 123 | |
| 124 // Runs for |seconds|. Note we use a testing clock rather than the wall cloc k here. | |
| 125 void runForPeriodSeconds(double seconds); | |
| 126 | |
| 127 // Advances |m_clock| by |seconds|. | |
| 128 void advanceClockSeconds(double seconds); | |
| 129 | |
| 130 scheduler::RendererScheduler* rendererScheduler() const; | |
| 131 | |
| 132 // Controls the behavior of |m_mockTaskRunner| if true, then |m_clock| will | |
| 133 // be advanced to the next timer when there's no more immediate work to do. | |
| 134 void setAutoAdvanceNowToPendingTasks(bool); | |
| 122 | 135 |
| 123 protected: | 136 protected: |
| 124 std::unique_ptr<TestingPlatformMockWebThread> m_mockWebThread; | 137 static double getTestTime(); |
| 138 | |
| 139 std::unique_ptr<base::SimpleTestTickClock> m_clock; | |
| 140 scoped_refptr<cc::OrderedSimpleTaskRunner> m_mockTaskRunner; | |
| 141 std::unique_ptr<scheduler::RendererSchedulerImpl> m_scheduler; | |
| 142 std::unique_ptr<WebThread> m_thread; | |
| 125 }; | 143 }; |
| 126 | 144 |
| 127 class ScopedUnittestsEnvironmentSetup { | 145 class ScopedUnittestsEnvironmentSetup { |
| 128 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup); | 146 WTF_MAKE_NONCOPYABLE(ScopedUnittestsEnvironmentSetup); |
| 129 public: | 147 public: |
| 130 ScopedUnittestsEnvironmentSetup(int argc, char** argv); | 148 ScopedUnittestsEnvironmentSetup(int argc, char** argv); |
| 131 ~ScopedUnittestsEnvironmentSetup(); | 149 ~ScopedUnittestsEnvironmentSetup(); |
| 132 | 150 |
| 133 private: | 151 private: |
| 134 class DummyPlatform; | 152 class DummyPlatform; |
| 135 std::unique_ptr<base::TestDiscardableMemoryAllocator> m_discardableMemoryAll ocator; | 153 std::unique_ptr<base::TestDiscardableMemoryAllocator> m_discardableMemoryAll ocator; |
| 136 std::unique_ptr<DummyPlatform> m_platform; | 154 std::unique_ptr<DummyPlatform> m_platform; |
| 137 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport; | 155 std::unique_ptr<cc_blink::WebCompositorSupportImpl> m_compositorSupport; |
| 138 TestingPlatformSupport::Config m_testingPlatformConfig; | 156 TestingPlatformSupport::Config m_testingPlatformConfig; |
| 139 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; | 157 std::unique_ptr<TestingPlatformSupport> m_testingPlatformSupport; |
| 140 }; | 158 }; |
| 141 | 159 |
| 142 } // namespace blink | 160 } // namespace blink |
| 143 | 161 |
| 144 #endif // TestingPlatformSupport_h | 162 #endif // TestingPlatformSupport_h |
| OLD | NEW |