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

Unified Diff: third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp

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, 10 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/WorkerThreadTest.cpp
diff --git a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp b/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
index ee004373e27cb1feb36b7c5d63f1aaac245ad1ca..e939b0f835f2d67b7493f631bd9928197541080f 100644
--- a/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerThreadTest.cpp
@@ -4,17 +4,9 @@
#include "core/workers/WorkerThread.h"
-#include "bindings/core/v8/ScriptCallStack.h"
-#include "bindings/core/v8/V8GCController.h"
-#include "core/inspector/ConsoleMessage.h"
-#include "core/workers/WorkerReportingProxy.h"
-#include "core/workers/WorkerThreadStartupData.h"
tyoshino (SeeGerritForStatus) 2016/03/02 07:57:59 WorkerThreadStartupData is used in the code that r
hiroshige 2016/03/08 23:40:59 I moved the code to WorkerThreadTestHelper.h so Wo
-#include "platform/NotImplemented.h"
-#include "platform/Task.h"
+#include "core/workers/WorkerThreadTestHelper.h"
#include "platform/ThreadSafeFunctional.h"
-#include "platform/WaitableEvent.h"
#include "public/platform/WebScheduler.h"
-#include "testing/gmock/include/gmock/gmock.h"
tyoshino (SeeGerritForStatus) 2016/03/02 07:57:59 EXPECT_CALL is used in the code that remains in th
hiroshige 2016/03/08 23:40:59 Done.
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
@@ -25,127 +17,6 @@ using testing::Mock;
namespace blink {
-namespace {
-
-class MockWorkerLoaderProxyProvider : public WorkerLoaderProxyProvider {
-public:
- MockWorkerLoaderProxyProvider() { }
- ~MockWorkerLoaderProxyProvider() override { }
-
- void postTaskToLoader(PassOwnPtr<ExecutionContextTask>) override
- {
- notImplemented();
- }
-
- bool postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContextTask>) override
- {
- notImplemented();
- return false;
- }
-};
-
-class MockWorkerReportingProxy : public WorkerReportingProxy {
-public:
- MockWorkerReportingProxy() { }
- ~MockWorkerReportingProxy() override { }
-
- MOCK_METHOD5(reportException, void(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, int exceptionId));
- MOCK_METHOD1(reportConsoleMessage, void(PassRefPtrWillBeRawPtr<ConsoleMessage>));
- MOCK_METHOD1(postMessageToPageInspector, void(const String&));
- MOCK_METHOD0(postWorkerConsoleAgentEnabled, void());
- MOCK_METHOD1(didEvaluateWorkerScript, void(bool success));
- MOCK_METHOD1(workerGlobalScopeStarted, void(WorkerGlobalScope*));
- MOCK_METHOD0(workerGlobalScopeClosed, void());
- MOCK_METHOD0(workerThreadTerminated, void());
- MOCK_METHOD0(willDestroyWorkerGlobalScope, void());
-};
-
-void notifyScriptLoadedEventToWorkerThreadForTest(WorkerThread*);
-
-class FakeWorkerGlobalScope : public WorkerGlobalScope {
-public:
- typedef WorkerGlobalScope Base;
-
- FakeWorkerGlobalScope(const KURL& url, const String& userAgent, WorkerThread* thread, PassOwnPtr<SecurityOrigin::PrivilegeData> starterOriginPrivilegeData, PassOwnPtrWillBeRawPtr<WorkerClients> workerClients)
- : WorkerGlobalScope(url, userAgent, thread, monotonicallyIncreasingTime(), starterOriginPrivilegeData, workerClients)
- , m_thread(thread)
- {
- }
-
- ~FakeWorkerGlobalScope() override
- {
- }
-
- void scriptLoaded(size_t, size_t) override
- {
- notifyScriptLoadedEventToWorkerThreadForTest(m_thread);
- }
-
- // EventTarget
- const AtomicString& interfaceName() const override
- {
- return EventTargetNames::DedicatedWorkerGlobalScope;
- }
-
- void logExceptionToConsole(const String&, int, const String&, int, int, PassRefPtr<ScriptCallStack>) override
- {
- }
-
-private:
- WorkerThread* m_thread;
-};
-
-class WorkerThreadForTest : public WorkerThread {
-public:
- WorkerThreadForTest(
- WorkerLoaderProxyProvider* mockWorkerLoaderProxyProvider,
- WorkerReportingProxy& mockWorkerReportingProxy)
- : WorkerThread(WorkerLoaderProxy::create(mockWorkerLoaderProxyProvider), mockWorkerReportingProxy)
- , m_thread(WebThreadSupportingGC::create("Test thread"))
- , m_scriptLoadedEvent(adoptPtr(new WaitableEvent()))
- {
- }
-
- ~WorkerThreadForTest() override { }
-
- // WorkerThread implementation:
- WebThreadSupportingGC& backingThread() override
- {
- return *m_thread;
- }
- void willDestroyIsolate() override
- {
- V8GCController::collectAllGarbageForTesting(v8::Isolate::GetCurrent());
- WorkerThread::willDestroyIsolate();
- }
-
- PassRefPtrWillBeRawPtr<WorkerGlobalScope> createWorkerGlobalScope(PassOwnPtr<WorkerThreadStartupData> startupData) override
- {
- return adoptRefWillBeNoop(new FakeWorkerGlobalScope(startupData->m_scriptURL, startupData->m_userAgent, this, startupData->m_starterOriginPrivilegeData.release(), startupData->m_workerClients.release()));
- }
-
- void waitUntilScriptLoaded()
- {
- m_scriptLoadedEvent->wait();
- }
-
- void scriptLoaded()
- {
- 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

Powered by Google App Engine
This is Rietveld 408576698