OLD | NEW |
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 "core/dom/ScriptRunner.h" | 5 #include "core/dom/ScriptRunner.h" |
6 | 6 |
7 #include "core/dom/MockScriptElementBase.h" | 7 #include "core/dom/MockScriptElementBase.h" |
8 #include "core/dom/ScriptLoader.h" | 8 #include "core/dom/ScriptLoader.h" |
9 #include "platform/bindings/RuntimeCallStats.h" | 9 #include "platform/bindings/RuntimeCallStats.h" |
10 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ~MockScriptLoader() override {} | 28 ~MockScriptLoader() override {} |
29 | 29 |
30 MOCK_METHOD0(Execute, void()); | 30 MOCK_METHOD0(Execute, void()); |
31 MOCK_CONST_METHOD0(IsReady, bool()); | 31 MOCK_CONST_METHOD0(IsReady, bool()); |
32 | 32 |
33 private: | 33 private: |
34 explicit MockScriptLoader() | 34 explicit MockScriptLoader() |
35 : ScriptLoader(MockScriptElementBase::Create(), false, false, false) {} | 35 : ScriptLoader(MockScriptElementBase::Create(), false, false, false) {} |
36 }; | 36 }; |
37 | 37 |
38 class ScriptRunnerTest : public testing::Test { | 38 class ScriptRunnerTest : public ::testing::Test { |
39 public: | 39 public: |
40 ScriptRunnerTest() : document_(Document::Create()) {} | 40 ScriptRunnerTest() : document_(Document::Create()) {} |
41 | 41 |
42 void SetUp() override { | 42 void SetUp() override { |
43 // We have to create ScriptRunner after initializing platform, because we | 43 // We have to create ScriptRunner after initializing platform, because we |
44 // need Platform::current()->currentThread()->scheduler()-> | 44 // need Platform::current()->currentThread()->scheduler()-> |
45 // loadingTaskRunner() to be initialized before creating ScriptRunner to | 45 // loadingTaskRunner() to be initialized before creating ScriptRunner to |
46 // save it in constructor. | 46 // save it in constructor. |
47 script_runner_ = ScriptRunner::Create(document_.Get()); | 47 script_runner_ = ScriptRunner::Create(document_.Get()); |
48 RuntimeCallStats::SetRuntimeCallStatsForTesting(); | 48 RuntimeCallStats::SetRuntimeCallStatsForTesting(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 script_runner_->NotifyScriptReady(script_loaders[i], | 291 script_runner_->NotifyScriptReady(script_loaders[i], |
292 ScriptRunner::kAsync); | 292 ScriptRunner::kAsync); |
293 order_.push_back(0); | 293 order_.push_back(0); |
294 })); | 294 })); |
295 | 295 |
296 platform_->RunUntilIdle(); | 296 platform_->RunUntilIdle(); |
297 | 297 |
298 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | 298 int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
299 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; | 299 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; |
300 | 300 |
301 EXPECT_THAT(order_, testing::ElementsAreArray(expected)); | 301 EXPECT_THAT(order_, ::testing::ElementsAreArray(expected)); |
302 } | 302 } |
303 | 303 |
304 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) { | 304 TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) { |
305 MockScriptLoader* script_loader1 = MockScriptLoader::Create(); | 305 MockScriptLoader* script_loader1 = MockScriptLoader::Create(); |
306 MockScriptLoader* script_loader2 = MockScriptLoader::Create(); | 306 MockScriptLoader* script_loader2 = MockScriptLoader::Create(); |
307 MockScriptLoader* script_loader3 = MockScriptLoader::Create(); | 307 MockScriptLoader* script_loader3 = MockScriptLoader::Create(); |
308 | 308 |
309 script_runner_->QueueScriptForExecution(script_loader1, | 309 script_runner_->QueueScriptForExecution(script_loader1, |
310 ScriptRunner::kInOrder); | 310 ScriptRunner::kInOrder); |
311 script_runner_->QueueScriptForExecution(script_loader2, | 311 script_runner_->QueueScriptForExecution(script_loader2, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 427 |
428 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not | 428 // m_scriptRunner is gone. We need to make sure that ScriptRunner::Task do not |
429 // access dead object. | 429 // access dead object. |
430 EXPECT_CALL(*script_loader1, Execute()).Times(0); | 430 EXPECT_CALL(*script_loader1, Execute()).Times(0); |
431 EXPECT_CALL(*script_loader2, Execute()).Times(0); | 431 EXPECT_CALL(*script_loader2, Execute()).Times(0); |
432 | 432 |
433 platform_->RunUntilIdle(); | 433 platform_->RunUntilIdle(); |
434 } | 434 } |
435 | 435 |
436 } // namespace blink | 436 } // namespace blink |
OLD | NEW |