Index: third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp |
diff --git a/third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp b/third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp |
index fe174e6cfb452b117281c0f51a396748e1cb7f34..b86f60063a01cbfc4593c671a2929caec4c7d8c8 100644 |
--- a/third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp |
+++ b/third_party/WebKit/Source/core/dom/ScriptRunnerTest.cpp |
@@ -13,6 +13,7 @@ |
#include "public/platform/WebViewScheduler.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "wtf/PtrUtil.h" |
using ::testing::Invoke; |
using ::testing::ElementsAre; |
@@ -44,6 +45,8 @@ class ScriptRunnerTest : public testing::Test { |
m_element(m_document->createElement("foo")) {} |
void SetUp() override { |
+ m_platform.reset( |
+ WTF::makeUnique<TestingPlatformSupportWithMockScheduler>()); |
// We have to create ScriptRunner after initializing platform, because we |
// need Platform::current()->currentThread()->scheduler()-> |
// loadingTaskRunner() to be initialized before creating ScriptRunner to |
@@ -55,7 +58,8 @@ class ScriptRunnerTest : public testing::Test { |
Persistent<Document> m_document; |
Persistent<Element> m_element; |
- TestingPlatformSupportWithMockScheduler m_platform; |
+ ScopedTestingPlatformSupport<TestingPlatformSupportWithMockScheduler> |
haraken
2017/01/11 13:03:38
Hmm. It looks a bit nasty to allocate a "Scoped" o
Takashi Toyoshima
2017/01/12 08:56:13
I do not feel it's nasty to use ScopedFoo in membe
|
+ m_platform; |
Persistent<ScriptRunner> m_scriptRunner; |
WTF::Vector<int> m_order; |
}; |
@@ -66,7 +70,7 @@ TEST_F(ScriptRunnerTest, QueueSingleScript_Async) { |
m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::Async); |
EXPECT_CALL(*scriptLoader, execute()); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
} |
TEST_F(ScriptRunnerTest, QueueSingleScript_InOrder) { |
@@ -78,7 +82,7 @@ TEST_F(ScriptRunnerTest, QueueSingleScript_InOrder) { |
m_scriptRunner->notifyScriptReady(scriptLoader, ScriptRunner::InOrder); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
} |
TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) { |
@@ -113,7 +117,7 @@ TEST_F(ScriptRunnerTest, QueueMultipleScripts_InOrder) { |
for (int i = 2; i >= 0; i--) { |
isReady[i] = true; |
m_scriptRunner->notifyScriptReady(scriptLoaders[i], ScriptRunner::InOrder); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
} |
// But ensure the scripts were run in the expected order. |
@@ -163,7 +167,7 @@ TEST_F(ScriptRunnerTest, QueueMixedScripts) { |
m_order.push_back(5); |
})); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
// Async tasks are expected to run first. |
EXPECT_THAT(m_order, ElementsAre(4, 5, 1, 2, 3)); |
@@ -197,13 +201,13 @@ TEST_F(ScriptRunnerTest, QueueReentrantScript_Async) { |
// Make sure that re-entrant calls to notifyScriptReady don't cause |
// ScriptRunner::execute to do more work than expected. |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1)); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1, 2)); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); |
} |
@@ -243,13 +247,13 @@ TEST_F(ScriptRunnerTest, QueueReentrantScript_InOrder) { |
// Make sure that re-entrant calls to queueScriptForExecution don't cause |
// ScriptRunner::execute to do more work than expected. |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1)); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1, 2)); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); |
} |
@@ -283,7 +287,7 @@ TEST_F(ScriptRunnerTest, QueueReentrantScript_ManyAsyncScripts) { |
m_order.push_back(0); |
})); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
int expected[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; |
@@ -324,10 +328,10 @@ TEST_F(ScriptRunnerTest, ResumeAndSuspend_InOrder) { |
EXPECT_CALL(*scriptLoader3, isReady()).WillRepeatedly(Return(true)); |
m_scriptRunner->notifyScriptReady(scriptLoader3, ScriptRunner::InOrder); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
m_scriptRunner->suspend(); |
m_scriptRunner->resume(); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
// Make sure elements are correct and in right order. |
EXPECT_THAT(m_order, ElementsAre(1, 2, 3)); |
@@ -356,10 +360,10 @@ TEST_F(ScriptRunnerTest, ResumeAndSuspend_Async) { |
m_order.push_back(3); |
})); |
- m_platform.runSingleTask(); |
+ m_platform->runSingleTask(); |
m_scriptRunner->suspend(); |
m_scriptRunner->resume(); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
// Make sure elements are correct. |
EXPECT_THAT(m_order, WhenSorted(ElementsAre(1, 2, 3))); |
@@ -383,12 +387,12 @@ TEST_F(ScriptRunnerTest, LateNotifications) { |
})); |
m_scriptRunner->notifyScriptReady(scriptLoader1, ScriptRunner::InOrder); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
// At this moment all tasks can be already executed. Make sure that we do not |
// crash here. |
m_scriptRunner->notifyScriptReady(scriptLoader2, ScriptRunner::InOrder); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
EXPECT_THAT(m_order, ElementsAre(1, 2)); |
} |
@@ -417,7 +421,7 @@ TEST_F(ScriptRunnerTest, TasksWithDeadScriptRunner) { |
EXPECT_CALL(*scriptLoader1, execute()).Times(0); |
EXPECT_CALL(*scriptLoader2, execute()).Times(0); |
- m_platform.runUntilIdle(); |
+ m_platform->runUntilIdle(); |
} |
} // namespace blink |