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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp

Issue 1466603003: Revert of More regular Platform implementations in unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "core/dom/ScriptRunner.h" 6 #include "core/dom/ScriptRunner.h"
7 7
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/ScriptLoader.h" 10 #include "core/dom/ScriptLoader.h"
11 #include "platform/heap/Handle.h" 11 #include "platform/heap/Handle.h"
12 #include "platform/scheduler/CancellableTaskFactory.h" 12 #include "platform/scheduler/CancellableTaskFactory.h"
13 #include "platform/testing/TestingPlatformSupport.h"
14 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
15 #include "public/platform/WebViewScheduler.h" 14 #include "public/platform/WebViewScheduler.h"
16 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 using ::testing::Invoke; 18 using ::testing::Invoke;
20 using ::testing::ElementsAre; 19 using ::testing::ElementsAre;
21 using ::testing::Return; 20 using ::testing::Return;
22 using ::testing::WhenSorted; 21 using ::testing::WhenSorted;
23 using ::testing::ElementsAreArray; 22 using ::testing::ElementsAreArray;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 88
90 WebTaskRunner* clone() override 89 WebTaskRunner* clone() override
91 { 90 {
92 ASSERT_NOT_REACHED(); 91 ASSERT_NOT_REACHED();
93 return nullptr; 92 return nullptr;
94 } 93 }
95 94
96 Deque<OwnPtr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED 95 Deque<OwnPtr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED
97 }; 96 };
98 97
99 class MockPlatform : public TestingPlatformSupport, public WebScheduler { 98 class MockPlatform : public Platform, public WebScheduler {
100 public: 99 public:
101 MockPlatform() 100 MockPlatform()
102 : m_mockWebThread(this) 101 : m_mockWebThread(this)
103 , m_mockWebTaskRunner(&m_tasks) 102 , m_mockWebTaskRunner(&m_tasks)
104 { 103 {
105 } 104 }
106 105
106 void cryptographicallyRandomValues(unsigned char* buffer, size_t length) ove rride
107 {
108 RELEASE_ASSERT_NOT_REACHED();
109 }
110
111 const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) o verride
112 {
113 static const unsigned char tracingIsDisabled = 0;
114 return &tracingIsDisabled;
115 }
116
107 WebThread* currentThread() override { return &m_mockWebThread; } 117 WebThread* currentThread() override { return &m_mockWebThread; }
108 118
109 void runSingleTask() 119 void runSingleTask()
110 { 120 {
111 if (m_tasks.isEmpty()) 121 if (m_tasks.isEmpty())
112 return; 122 return;
113 m_tasks.takeFirst()->run(); 123 m_tasks.takeFirst()->run();
114 } 124 }
115 125
116 void runAllTasks() 126 void runAllTasks()
(...skipping 29 matching lines...) Expand all
146 void onNavigationStarted() override { } 156 void onNavigationStarted() override { }
147 157
148 private: 158 private:
149 MockWebThread m_mockWebThread; 159 MockWebThread m_mockWebThread;
150 Deque<OwnPtr<WebTaskRunner::Task>> m_tasks; 160 Deque<OwnPtr<WebTaskRunner::Task>> m_tasks;
151 MockWebTaskRunner m_mockWebTaskRunner; 161 MockWebTaskRunner m_mockWebTaskRunner;
152 }; 162 };
153 163
154 class ScriptRunnerTest : public testing::Test { 164 class ScriptRunnerTest : public testing::Test {
155 public: 165 public:
156 ScriptRunnerTest()
157 : m_document(Document::create())
158 , m_element(m_document->createElement("foo", ASSERT_NO_EXCEPTION))
159 {
160 }
161
162 void SetUp() override 166 void SetUp() override
163 { 167 {
168 m_document = Document::create();
169 m_element = m_document->createElement("foo", ASSERT_NO_EXCEPTION);
170
171 m_oldPlatform = Platform::current();
172
173 // Force Platform::initialize to create a new one pointing at MockPlatfo rm.
174 Platform::initialize(&m_platform);
175
164 // We have to create ScriptRunner after initializing platform, because w e need 176 // We have to create ScriptRunner after initializing platform, because w e need
165 // Platform::current()->currentThread()->scheduler()->loadingTaskRunner( ) 177 // Platform::current()->currentThread()->scheduler()->loadingTaskRunner( )
166 // to be initialized before creating ScriptRunner to save it in construc tor. 178 // to be initialized before creating ScriptRunner to save it in construc tor.
167 m_scriptRunner = ScriptRunner::create(m_document.get()); 179 m_scriptRunner = ScriptRunner::create(m_document.get());
168 } 180 }
169 181
170 void TearDown() override 182 void TearDown() override
171 { 183 {
172 m_scriptRunner.release(); 184 m_scriptRunner.release();
185 Platform::initialize(m_oldPlatform);
173 } 186 }
174 187
175 RefPtrWillBePersistent<Document> m_document; 188 RefPtrWillBePersistent<Document> m_document;
176 RefPtrWillBePersistent<Element> m_element; 189 RefPtrWillBePersistent<Element> m_element;
177 MockPlatform m_platform;
178 OwnPtrWillBePersistent<ScriptRunner> m_scriptRunner; 190 OwnPtrWillBePersistent<ScriptRunner> m_scriptRunner;
179 WTF::Vector<int> m_order; 191 WTF::Vector<int> m_order;
192 MockPlatform m_platform;
193 Platform* m_oldPlatform; // NOT OWNED
180 }; 194 };
181 195
182 TEST_F(ScriptRunnerTest, QueueSingleScript_Async) 196 TEST_F(ScriptRunnerTest, QueueSingleScript_Async)
183 { 197 {
184 OwnPtrWillBeRawPtr<MockScriptLoader> scriptLoader = MockScriptLoader::create (m_element.get()); 198 OwnPtrWillBeRawPtr<MockScriptLoader> scriptLoader = MockScriptLoader::create (m_element.get());
185 m_scriptRunner->queueScriptForExecution(scriptLoader.get(), ScriptRunner::AS YNC_EXECUTION); 199 m_scriptRunner->queueScriptForExecution(scriptLoader.get(), ScriptRunner::AS YNC_EXECUTION);
186 m_scriptRunner->notifyScriptReady(scriptLoader.get(), ScriptRunner::ASYNC_EX ECUTION); 200 m_scriptRunner->notifyScriptReady(scriptLoader.get(), ScriptRunner::ASYNC_EX ECUTION);
187 201
188 EXPECT_CALL(*scriptLoader, execute()); 202 EXPECT_CALL(*scriptLoader, execute());
189 m_platform.runAllTasks(); 203 m_platform.runAllTasks();
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 #endif 568 #endif
555 569
556 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do n ot access dead object. 570 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do n ot access dead object.
557 EXPECT_CALL(*scriptLoader1, execute()).Times(0); 571 EXPECT_CALL(*scriptLoader1, execute()).Times(0);
558 EXPECT_CALL(*scriptLoader2, execute()).Times(0); 572 EXPECT_CALL(*scriptLoader2, execute()).Times(0);
559 573
560 m_platform.runAllTasks(); 574 m_platform.runAllTasks();
561 } 575 }
562 576
563 } // namespace blink 577 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698