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

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: disallow await during provide 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..21a7c070657f6ac017de953bbce76da9820130ca
--- /dev/null
+++ b/Source/core/html/StableStateTest.cpp
@@ -0,0 +1,108 @@
+// 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 inheriting StableState::Awaiter or having state bits.
+
+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)));
acolwell GONE FROM CHROMIUM 2014/02/07 19:09:31 I don't quite get what this is testing. Why do you
philipj_slow 2014/02/09 17:10:17 This is verifying the "separate StableState::Await
+ 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