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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/StableStateTest.cpp
diff --git a/Source/core/html/StableStateTest.cpp b/Source/core/html/StableStateTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a95d4ff21325ea9efc3098c2f9679777a273c788
--- /dev/null
+++ b/Source/core/html/StableStateTest.cpp
@@ -0,0 +1,110 @@
+// 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 "core/html/StableState.h"
+
+#include "wtf/Functional.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using WebCore::StableState;
+
+namespace {
+
+class MockAwaiter : public StableState::Awaiter {
+public:
+ MOCK_METHOD0(didAwaitStableState, void());
+};
+
+TEST(StableState, Await)
+{
+ MockAwaiter awaiter;
+ EXPECT_CALL(awaiter, didAwaitStableState()).Times(0);
+ StableState::await(awaiter);
+}
+
+TEST(StableState, AwaitProvide)
+{
+ MockAwaiter awaiter;
+ EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
+ StableState::await(awaiter);
+ StableState::provide();
+}
+
+TEST(StableState, AwaitProvideTwice)
+{
+ MockAwaiter awaiter;
+ EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
+ StableState::await(awaiter);
+ StableState::provide();
+ StableState::provide();
+}
+
+TEST(StableState, AwaitTwiceProvide)
+{
+ MockAwaiter awaiter;
+ EXPECT_CALL(awaiter, didAwaitStableState()).Times(1);
+ StableState::await(awaiter);
+ StableState::await(awaiter);
+ StableState::provide();
+}
+
+TEST(StableState, AwaitProvideAwaitProvide)
+{
+ MockAwaiter awaiter;
+ EXPECT_CALL(awaiter, didAwaitStableState()).Times(2);
+ StableState::await(awaiter);
+ StableState::provide();
+ StableState::await(awaiter);
+ StableState::provide();
+}
+
+TEST(StableState, TwoAwaiters)
+{
+ MockAwaiter awaiter1;
+ MockAwaiter awaiter2;
+ EXPECT_CALL(awaiter1, didAwaitStableState()).Times(1);
+ EXPECT_CALL(awaiter2, didAwaitStableState()).Times(1);
+ StableState::await(awaiter1);
+ StableState::await(awaiter2);
+ StableState::provide();
+}
+
+// Test that a class can await a stable state and invoke one of two callbacks
+// without having state bites by using a self-deleting StableState::Awaiter
+// object. Deleting the awaiter inside the callback must not crash or influence
+// any other awaiter.
+
+class MockCallbacks {
+public:
+ MOCK_METHOD0(callback1, void());
+ MOCK_METHOD0(callback2, void());
+};
+
+class ClosureAwaiter : public StableState::Awaiter {
+public:
+ ClosureAwaiter(const Closure& closure) : m_closure(closure) { }
+ virtual void didAwaitStableState() OVERRIDE
+ {
+ m_closure();
+ delete this;
+ }
+private:
+ Closure m_closure;
+};
+
+TEST(StableState, ClosureAwaiter)
+{
+ MockCallbacks callbacks;
+ EXPECT_CALL(callbacks, callback1()).Times(2);
+ EXPECT_CALL(callbacks, callback2()).Times(1);
+ StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback1, &callbacks)));
+ StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback2, &callbacks)));
+ StableState::await(*new ClosureAwaiter(bind(&MockCallbacks::callback1, &callbacks)));
+ StableState::provide();
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698