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

Side by Side Diff: Source/core/html/StableStateTest.cpp

Issue 153813002: Support "await a stable state" and "provide a stable state" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: assert more Created 6 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 | Annotate | Revision Log
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 "core/html/StableState.h"
7
8 #include "wtf/Functional.h"
9
10 #include <gmock/gmock.h>
11 #include <gtest/gtest.h>
12
13 using WebCore::StableState;
14
15 namespace {
16
17 class MockAwaiter : public StableState::Awaiter {
18 public:
19 MOCK_METHOD0(didAwaitStableState, void());
20 };
21
22 TEST(StableState, Await)
23 {
24 MockAwaiter awaiter;
25 EXPECT_CALL(awaiter, didAwaitStableState()).Times(0);
26 StableState::await(awaiter);
27 }
28
29 TEST(StableState, AwaitProvide)
30 {
31 MockAwaiter awaiter;
32 EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
33 StableState::await(awaiter);
34 StableState::provide();
35 }
36
37 TEST(StableState, AwaitProvideTwice)
38 {
39 MockAwaiter awaiter;
40 EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
41 StableState::await(awaiter);
42 StableState::provide();
43 StableState::provide();
44 }
45
46 TEST(StableState, AwaitTwiceProvide)
47 {
48 MockAwaiter awaiter;
49 EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
50 StableState::await(awaiter);
51 StableState::await(awaiter);
52 StableState::provide();
53 }
54
55 TEST(StableState, AwaitProvideAwaitProvide)
56 {
57 MockAwaiter awaiter;
58 EXPECT_CALL(awaiter, didAwaitStableState()).Times(2);
59 StableState::await(awaiter);
60 StableState::provide();
61 StableState::await(awaiter);
62 StableState::provide();
63 }
64
65 TEST(StableState, TwoAwaiters)
66 {
67 MockAwaiter awaiter1;
68 MockAwaiter awaiter2;
69 EXPECT_CALL(awaiter1, didAwaitStableState()).Times(1);
70 EXPECT_CALL(awaiter2, didAwaitStableState()).Times(1);
71 StableState::await(awaiter1);
72 StableState::await(awaiter2);
73 StableState::provide();
74 }
75
76 // Test that a class can await a stable state and invoke one of two callbacks
77 // without having state bites by using a self-deleting StableState::Awaiter
78 // object. Deleting the awaiter inside the callback must not crash or influence
79 // any other awaiter.
80
81 class MockCallbacks {
82 public:
83 MOCK_METHOD0(callback1, void());
84 MOCK_METHOD0(callback2, void());
85 };
86
87 class ClosureAwaiter : public StableState::Awaiter {
88 public:
89 ClosureAwaiter(const Closure& closure) : m_closure(closure) { }
90 virtual void didAwaitStableState() OVERRIDE
91 {
92 m_closure();
93 delete this;
94 }
95 private:
96 Closure m_closure;
97 };
98
99 TEST(StableState, ClosureAwaiter)
100 {
101 MockCallbacks callbacks;
102 EXPECT_CALL(callbacks, callback1()).Times(2);
103 EXPECT_CALL(callbacks, callback2()).Times(1);
104 StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback1, &call backs)));
105 StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback2, &call backs)));
106 StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback1, &call backs)));
107 StableState::provide();
108 }
109
110 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698