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

Unified Diff: remoting/host/mock_callback_unittest.cc

Issue 719983002: Reporting of policy errors via host-offline-reason: part 3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: git cl format Created 6 years 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: remoting/host/mock_callback_unittest.cc
diff --git a/remoting/host/mock_callback_unittest.cc b/remoting/host/mock_callback_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cfc053d22c0c5bc95cd8a742edde779229303847
--- /dev/null
+++ b/remoting/host/mock_callback_unittest.cc
@@ -0,0 +1,67 @@
+// 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 "remoting/host/mock_callback.h"
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest-spi.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+TEST(MockCallbackTest, SimpleExampleFromHeader) {
+ EXPECT_NONFATAL_FAILURE({
+ MockCallback<void(int)> mock_callback;
+ EXPECT_CALL(mock_callback, Run(123)).Times(2);
+ base::Callback<void(int)> callback =
+ mock_callback.GetCallback();
+
+ callback.Run(123);
+ callback.Run(123);
+ callback.Run(123); // Called too many times.
+ },
+ "Mock function called more times than expected");
+}
+
+TEST(MockCallbackTest, HasRemainingCallbacks) {
+ MockCallback<int()> mock_callback;
+ EXPECT_CALL(mock_callback, Run()).WillOnce(testing::Return(123));
+
+ {
+ base::Callback<int()> callback = mock_callback.GetCallback();
+ EXPECT_TRUE(mock_callback.HasRemainingCallbacks());
+ EXPECT_EQ(123, callback.Run());
+ }
+
+ EXPECT_FALSE(mock_callback.HasRemainingCallbacks());
+}
+
+TEST(MockCallbackTest, CallbackRunAfterMockAlreadyDestroyed) {
+ EXPECT_NONFATAL_FAILURE(
+ {
+ base::Callback<int(int)> long_lived_callback;
+ {
+ MockCallback<int(int)> short_lived_mock_callback;
+
+ EXPECT_CALL(short_lived_mock_callback, Run(123))
+ .WillOnce(testing::Return(456));
+ long_lived_callback = short_lived_mock_callback.GetCallback();
+
+ int actual_result1 = long_lived_callback.Run(123);
+ ASSERT_EQ(456, actual_result1);
+ }
+
+ // This |Run| invocation happens when short_lived_mock_callback is
+ // already
+ // destroyed. Such |Run| invocation should cause a test failure (that
+ // we
+ // are verifying via the outer EXPECT_NONFATAL_FAILURE).
+ testing::DefaultValue<int>::Set(42);
+ int actual_result2 = long_lived_callback.Run(789);
+ ASSERT_EQ(42, actual_result2);
+ },
+ "MockCallback should be alive when Callback::Run happens.");
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698