Index: Source/modules/serviceworkers/WaitUntilObserverTest.cpp |
diff --git a/Source/modules/serviceworkers/WaitUntilObserverTest.cpp b/Source/modules/serviceworkers/WaitUntilObserverTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..414811c9cf38ffce2b19a52d1a4a73b7831b082c |
--- /dev/null |
+++ b/Source/modules/serviceworkers/WaitUntilObserverTest.cpp |
@@ -0,0 +1,74 @@ |
+// Copyright 2014 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 "config.h" |
+#include "modules/serviceworkers/WaitUntilObserver.h" |
+ |
+#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "bindings/core/v8/ScriptValue.h" |
+#include "bindings/core/v8/V8Binding.h" |
+#include "core/testing/NullExecutionContext.h" |
+#include "platform/PlatformThreadData.h" |
+#include "platform/ThreadTimers.h" |
+#include "public/platform/Platform.h" |
+#include <gtest/gtest.h> |
+ |
+namespace blink { |
+ |
+class WaitUntilObserverTest : public ::testing::Test { |
+public: |
+ WaitUntilObserverTest() |
+ : m_scope(v8::Isolate::GetCurrent()) |
+ {} |
+ |
+ void SetUp() override |
+ { |
+ m_executionContext = adoptRefWillBeNoop(new NullExecutionContext()); |
+ m_scope.scriptState()->setExecutionContext(m_executionContext.get()); |
+ } |
+ |
+ void TearDown() override |
+ { |
+ m_executionContext->notifyContextDestroyed(); |
+ m_scope.scriptState()->setExecutionContext(nullptr); |
+ } |
+ |
+protected: |
+ v8::Isolate* isolate() const { return m_scope.isolate(); } |
+ ScriptState* scriptState() const { return m_scope.scriptState(); } |
+ ExecutionContext* executionContext() const { return m_scope.scriptState()->executionContext(); } |
+ ExceptionState& exceptionState() { return m_exceptionState; } |
+ |
+ void overrideWindowInteractionTimeout(int timeout) |
+ { |
+ // WaitUntilObserver::overrideWindowInteractionTimeoutForTest(timeout); |
+ } |
+ |
+private: |
+ V8TestingScope m_scope; |
+ RefPtrWillBePersistent<ExecutionContext> m_executionContext; |
+ TrackExceptionState m_exceptionState; |
+}; |
+ |
+TEST_F(WaitUntilObserverTest, Basic) |
+{ |
+ overrideWindowInteractionTimeout(1); |
+ |
+ EXPECT_FALSE(executionContext()->isWindowInteractionAllowed()); |
+ |
+ Persistent<WaitUntilObserver> observer = WaitUntilObserver::create(executionContext(), WaitUntilObserver::NotificationClick, 0); |
+ observer->waitUntil(scriptState(), ScriptValue(), exceptionState()); |
+ EXPECT_TRUE(executionContext()->isWindowInteractionAllowed()); |
+ |
+ observer->didDispatchEvent(false); |
+ |
+ // for (int i = 0; i < 10000000; ++i) { |
+ // Platform::current()->yieldCurrentThread(); |
+ // PlatformThreadData::current().threadTimers().updateSharedTimer(); |
+ // } |
+ EXPECT_FALSE(executionContext()->isWindowInteractionAllowed()); |
+} |
+ |
+} // namespace blink |