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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "modules/serviceworkers/WaitUntilObserver.h"
7
8 #include "bindings/core/v8/ExceptionState.h"
9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/ScriptValue.h"
11 #include "bindings/core/v8/V8Binding.h"
12 #include "core/testing/NullExecutionContext.h"
13 #include "platform/PlatformThreadData.h"
14 #include "platform/ThreadTimers.h"
15 #include "public/platform/Platform.h"
16 #include <gtest/gtest.h>
17
18 namespace blink {
19
20 class WaitUntilObserverTest : public ::testing::Test {
21 public:
22 WaitUntilObserverTest()
23 : m_scope(v8::Isolate::GetCurrent())
24 {}
25
26 void SetUp() override
27 {
28 m_executionContext = adoptRefWillBeNoop(new NullExecutionContext());
29 m_scope.scriptState()->setExecutionContext(m_executionContext.get());
30 }
31
32 void TearDown() override
33 {
34 m_executionContext->notifyContextDestroyed();
35 m_scope.scriptState()->setExecutionContext(nullptr);
36 }
37
38 protected:
39 v8::Isolate* isolate() const { return m_scope.isolate(); }
40 ScriptState* scriptState() const { return m_scope.scriptState(); }
41 ExecutionContext* executionContext() const { return m_scope.scriptState()->e xecutionContext(); }
42 ExceptionState& exceptionState() { return m_exceptionState; }
43
44 void overrideWindowInteractionTimeout(int timeout)
45 {
46 // WaitUntilObserver::overrideWindowInteractionTimeoutForTest(timeout);
47 }
48
49 private:
50 V8TestingScope m_scope;
51 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
52 TrackExceptionState m_exceptionState;
53 };
54
55 TEST_F(WaitUntilObserverTest, Basic)
56 {
57 overrideWindowInteractionTimeout(1);
58
59 EXPECT_FALSE(executionContext()->isWindowInteractionAllowed());
60
61 Persistent<WaitUntilObserver> observer = WaitUntilObserver::create(execution Context(), WaitUntilObserver::NotificationClick, 0);
62 observer->waitUntil(scriptState(), ScriptValue(), exceptionState());
63 EXPECT_TRUE(executionContext()->isWindowInteractionAllowed());
64
65 observer->didDispatchEvent(false);
66
67 // for (int i = 0; i < 10000000; ++i) {
68 // Platform::current()->yieldCurrentThread();
69 // PlatformThreadData::current().threadTimers().updateSharedTimer();
70 // }
71 EXPECT_FALSE(executionContext()->isWindowInteractionAllowed());
72 }
73
74 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698