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

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h

Issue 1257343003: [LoaderTest] Add unit tests for Document/WorkerThreadableLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h
diff --git a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp b/third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h
similarity index 59%
copy from third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
copy to third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h
index 0d1097144fdf45efd36cad0f7cc227288f5e8cb2..0a64c67aaa5167e0798fd231d82c6236b5addc51 100644
--- a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerThreadTestHelper.h
@@ -1,33 +1,36 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/workers/WorkerThread.h"
-
#include "bindings/core/v8/ScriptCallStack.h"
+#include "bindings/core/v8/V8CacheOptions.h"
#include "bindings/core/v8/V8GCController.h"
+#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/inspector/ConsoleMessage.h"
+#include "core/workers/WorkerClients.h"
+#include "core/workers/WorkerLoaderProxy.h"
#include "core/workers/WorkerReportingProxy.h"
+#include "core/workers/WorkerThread.h"
#include "core/workers/WorkerThreadStartupData.h"
#include "platform/NotImplemented.h"
-#include "platform/Task.h"
#include "platform/ThreadSafeFunctional.h"
#include "platform/WaitableEvent.h"
+#include "platform/WebThreadSupportingGC.h"
+#include "platform/heap/Handle.h"
+#include "platform/network/ContentSecurityPolicyParsers.h"
+#include "platform/weborigin/KURL.h"
+#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/WebAddressSpace.h"
-#include "public/platform/WebScheduler.h"
#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using testing::_;
-using testing::AtMost;
-using testing::Invoke;
-using testing::Return;
-using testing::Mock;
+#include "wtf/CurrentTime.h"
+#include "wtf/Forward.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/Vector.h"
+#include <v8.h>
namespace blink {
-namespace {
-
class MockWorkerLoaderProxyProvider : public WorkerLoaderProxyProvider {
public:
MockWorkerLoaderProxyProvider() { }
@@ -105,6 +108,7 @@ public:
, m_thread(WebThreadSupportingGC::create("Test thread"))
, m_scriptLoadedEvent(adoptPtr(new WaitableEvent()))
{
+ ASSERT(m_thread);
}
~WorkerThreadForTest() override { }
@@ -112,6 +116,7 @@ public:
// WorkerThread implementation:
WebThreadSupportingGC& backingThread() override
{
+ ASSERT(m_thread);
return *m_thread;
}
void willDestroyIsolate() override
@@ -135,41 +140,7 @@ public:
m_scriptLoadedEvent->signal();
}
-private:
- OwnPtr<WebThreadSupportingGC> m_thread;
- OwnPtr<WaitableEvent> m_scriptLoadedEvent;
-};
-
-void notifyScriptLoadedEventToWorkerThreadForTest(WorkerThread* thread)
-{
- static_cast<WorkerThreadForTest*>(thread)->scriptLoaded();
-}
-
-} // namespace
-
-class WorkerThreadTest : public testing::Test {
-public:
- void SetUp() override
- {
- m_mockWorkerLoaderProxyProvider = adoptPtr(new MockWorkerLoaderProxyProvider());
- m_mockWorkerReportingProxy = adoptPtr(new MockWorkerReportingProxy());
- m_securityOrigin = SecurityOrigin::create(KURL(ParsedURLString, "http://fake.url/"));
- m_workerThread = adoptPtr(new WorkerThreadForTest(
- m_mockWorkerLoaderProxyProvider.get(),
- *m_mockWorkerReportingProxy));
- }
-
- void TearDown() override
- {
- m_workerThread->workerLoaderProxy()->detachProvider(m_mockWorkerLoaderProxyProvider.get());
- }
-
- void start()
- {
- startWithSourceCode("//fake source code");
- }
-
- void startWithSourceCode(const String& source)
+ void startWithSourceCode(SecurityOrigin* securityOrigin, const String& source)
{
OwnPtr<Vector<CSPHeaderAndType>> headers = adoptPtr(new Vector<CSPHeaderAndType>());
CSPHeaderAndType headerAndType("contentSecurityPolicy", ContentSecurityPolicyHeaderTypeReport);
@@ -177,14 +148,14 @@ public:
OwnPtrWillBeRawPtr<WorkerClients> clients = nullptr;
- m_workerThread->start(WorkerThreadStartupData::create(
+ start(WorkerThreadStartupData::create(
KURL(ParsedURLString, "http://fake.url/"),
"fake user agent",
source,
nullptr,
DontPauseWorkerGlobalScopeOnStart,
headers.release(),
- m_securityOrigin.get(),
+ securityOrigin,
clients.release(),
WebAddressSpaceLocal,
V8CacheOptionsDefault));
@@ -193,64 +164,18 @@ public:
void waitForInit()
{
OwnPtr<WaitableEvent> completionEvent = adoptPtr(new WaitableEvent());
- m_workerThread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&WaitableEvent::signal, AllowCrossThreadAccess(completionEvent.get())));
+ backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&WaitableEvent::signal, AllowCrossThreadAccess(completionEvent.get())));
completionEvent->wait();
}
-protected:
- void expectWorkerLifetimeReportingCalls()
- {
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(1);
- EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)).Times(1);
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times(1);
- EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()).Times(1);
- }
-
- RefPtr<SecurityOrigin> m_securityOrigin;
- OwnPtr<MockWorkerLoaderProxyProvider> m_mockWorkerLoaderProxyProvider;
- OwnPtr<MockWorkerReportingProxy> m_mockWorkerReportingProxy;
- OwnPtr<WorkerThreadForTest> m_workerThread;
+private:
+ OwnPtr<WebThreadSupportingGC> m_thread;
+ OwnPtr<WaitableEvent> m_scriptLoadedEvent;
};
-TEST_F(WorkerThreadTest, StartAndStop)
+inline void notifyScriptLoadedEventToWorkerThreadForTest(WorkerThread* thread)
{
- expectWorkerLifetimeReportingCalls();
- start();
- waitForInit();
- m_workerThread->terminateAndWait();
-}
-
-TEST_F(WorkerThreadTest, StartAndStopImmediately)
-{
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_))
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(_))
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated())
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope())
- .Times(AtMost(1));
- start();
- m_workerThread->terminateAndWait();
-}
-
-TEST_F(WorkerThreadTest, StartAndStopOnScriptLoaded)
-{
- // Use a JavaScript source code that makes an infinite loop so that we can
- // catch some kind of issues as a timeout.
- const String source("while(true) {}");
-
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_))
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(_))
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated())
- .Times(AtMost(1));
- EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope())
- .Times(AtMost(1));
- startWithSourceCode(source);
- m_workerThread->waitUntilScriptLoaded();
- m_workerThread->terminateAndWait();
+ static_cast<WorkerThreadForTest*>(thread)->scriptLoaded();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698