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

Side by Side 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 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 "remoting/host/mock_callback.h"
6
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest-spi.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace remoting {
12
13 TEST(MockCallbackTest, SimpleExampleFromHeader) {
14 EXPECT_NONFATAL_FAILURE({
15 MockCallback<void(int)> mock_callback;
16 EXPECT_CALL(mock_callback, Run(123)).Times(2);
17 base::Callback<void(int)> callback =
18 mock_callback.GetCallback();
19
20 callback.Run(123);
21 callback.Run(123);
22 callback.Run(123); // Called too many times.
23 },
24 "Mock function called more times than expected");
25 }
26
27 TEST(MockCallbackTest, HasRemainingCallbacks) {
28 MockCallback<int()> mock_callback;
29 EXPECT_CALL(mock_callback, Run()).WillOnce(testing::Return(123));
30
31 {
32 base::Callback<int()> callback = mock_callback.GetCallback();
33 EXPECT_TRUE(mock_callback.HasRemainingCallbacks());
34 EXPECT_EQ(123, callback.Run());
35 }
36
37 EXPECT_FALSE(mock_callback.HasRemainingCallbacks());
38 }
39
40 TEST(MockCallbackTest, CallbackRunAfterMockAlreadyDestroyed) {
41 EXPECT_NONFATAL_FAILURE(
42 {
43 base::Callback<int(int)> long_lived_callback;
44 {
45 MockCallback<int(int)> short_lived_mock_callback;
46
47 EXPECT_CALL(short_lived_mock_callback, Run(123))
48 .WillOnce(testing::Return(456));
49 long_lived_callback = short_lived_mock_callback.GetCallback();
50
51 int actual_result1 = long_lived_callback.Run(123);
52 ASSERT_EQ(456, actual_result1);
53 }
54
55 // This |Run| invocation happens when short_lived_mock_callback is
56 // already
57 // destroyed. Such |Run| invocation should cause a test failure (that
58 // we
59 // are verifying via the outer EXPECT_NONFATAL_FAILURE).
60 testing::DefaultValue<int>::Set(42);
61 int actual_result2 = long_lived_callback.Run(789);
62 ASSERT_EQ(42, actual_result2);
63 },
64 "MockCallback should be alive when Callback::Run happens.");
65 }
66
67 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698