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

Unified Diff: Source/modules/serviceworkers/WaitUntilObserverTest.cpp

Issue 896043004: Tests for WaitUntilObserver and focus/openining windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_focus_cleanup
Patch Set: Created 5 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: 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

Powered by Google App Engine
This is Rietveld 408576698