OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | 5 #include "ash/system/chromeos/session/logout_confirmation_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/test/test_mock_time_task_runner.h" | 10 #include "base/test/test_mock_time_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/tick_clock.h" | |
bartfab (slow)
2015/02/12 09:50:55
Nit: No need for this include. The type is never d
engedy
2015/02/12 11:27:03
It is needed for passing the scoped_ptr returned b
bartfab (slow)
2015/02/12 12:36:07
You do not need to define the types you pass aroun
engedy
2015/02/13 11:08:04
Note that this is not a raw pointer, but a scoped_
bartfab (slow)
2015/02/16 13:40:34
Aye, your analysis is correct. I had missed the fa
| |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace ash { | 15 namespace ash { |
15 | 16 |
16 class LogoutConfirmationControllerTest : public testing::Test { | 17 class LogoutConfirmationControllerTest : public testing::Test { |
17 protected: | 18 protected: |
18 LogoutConfirmationControllerTest(); | 19 LogoutConfirmationControllerTest(); |
19 ~LogoutConfirmationControllerTest() override; | 20 ~LogoutConfirmationControllerTest() override; |
20 | 21 |
21 void LogOut(); | 22 void LogOut(); |
(...skipping 21 matching lines...) Expand all Loading... | |
43 LogoutConfirmationControllerTest::~LogoutConfirmationControllerTest() { | 44 LogoutConfirmationControllerTest::~LogoutConfirmationControllerTest() { |
44 } | 45 } |
45 | 46 |
46 void LogoutConfirmationControllerTest::LogOut() { | 47 void LogoutConfirmationControllerTest::LogOut() { |
47 log_out_called_ = true; | 48 log_out_called_ = true; |
48 } | 49 } |
49 | 50 |
50 // Verifies that the user is logged out immediately if logout confirmation with | 51 // Verifies that the user is logged out immediately if logout confirmation with |
51 // a zero-length countdown is requested. | 52 // a zero-length countdown is requested. |
52 TEST_F(LogoutConfirmationControllerTest, ZeroDuration) { | 53 TEST_F(LogoutConfirmationControllerTest, ZeroDuration) { |
53 controller_.ConfirmLogout(runner_->GetCurrentMockTime()); | 54 controller_.ConfirmLogout(runner_->NowTicks()); |
54 EXPECT_FALSE(log_out_called_); | 55 EXPECT_FALSE(log_out_called_); |
55 runner_->FastForwardBy(base::TimeDelta()); | 56 runner_->FastForwardBy(base::TimeDelta()); |
56 EXPECT_TRUE(log_out_called_); | 57 EXPECT_TRUE(log_out_called_); |
57 } | 58 } |
58 | 59 |
59 // Verifies that the user is logged out when the countdown expires. | 60 // Verifies that the user is logged out when the countdown expires. |
60 TEST_F(LogoutConfirmationControllerTest, DurationExpired) { | 61 TEST_F(LogoutConfirmationControllerTest, DurationExpired) { |
61 controller_.ConfirmLogout( | 62 controller_.ConfirmLogout(runner_->NowTicks() + |
62 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 63 base::TimeDelta::FromSeconds(10)); |
63 EXPECT_FALSE(log_out_called_); | 64 EXPECT_FALSE(log_out_called_); |
64 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); | 65 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); |
65 EXPECT_FALSE(log_out_called_); | 66 EXPECT_FALSE(log_out_called_); |
66 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); | 67 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); |
67 EXPECT_TRUE(log_out_called_); | 68 EXPECT_TRUE(log_out_called_); |
68 } | 69 } |
69 | 70 |
70 // Verifies that when a second request to confirm logout is made and the second | 71 // Verifies that when a second request to confirm logout is made and the second |
71 // request's countdown ends before the original request's, the user is logged | 72 // request's countdown ends before the original request's, the user is logged |
72 // out when the new countdown expires. | 73 // out when the new countdown expires. |
73 TEST_F(LogoutConfirmationControllerTest, DurationShortened) { | 74 TEST_F(LogoutConfirmationControllerTest, DurationShortened) { |
74 controller_.ConfirmLogout( | 75 controller_.ConfirmLogout(runner_->NowTicks() + |
75 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(30)); | 76 base::TimeDelta::FromSeconds(30)); |
76 EXPECT_FALSE(log_out_called_); | 77 EXPECT_FALSE(log_out_called_); |
77 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); | 78 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); |
78 EXPECT_FALSE(log_out_called_); | 79 EXPECT_FALSE(log_out_called_); |
79 controller_.ConfirmLogout( | 80 controller_.ConfirmLogout(runner_->NowTicks() + |
80 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 81 base::TimeDelta::FromSeconds(10)); |
81 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); | 82 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); |
82 EXPECT_FALSE(log_out_called_); | 83 EXPECT_FALSE(log_out_called_); |
83 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); | 84 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); |
84 EXPECT_TRUE(log_out_called_); | 85 EXPECT_TRUE(log_out_called_); |
85 } | 86 } |
86 | 87 |
87 // Verifies that when a second request to confirm logout is made and the second | 88 // Verifies that when a second request to confirm logout is made and the second |
88 // request's countdown ends after the original request's, the user is logged | 89 // request's countdown ends after the original request's, the user is logged |
89 // out when the original countdown expires. | 90 // out when the original countdown expires. |
90 TEST_F(LogoutConfirmationControllerTest, DurationExtended) { | 91 TEST_F(LogoutConfirmationControllerTest, DurationExtended) { |
91 controller_.ConfirmLogout( | 92 controller_.ConfirmLogout(runner_->NowTicks() + |
92 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 93 base::TimeDelta::FromSeconds(10)); |
93 EXPECT_FALSE(log_out_called_); | 94 EXPECT_FALSE(log_out_called_); |
94 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); | 95 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); |
95 EXPECT_FALSE(log_out_called_); | 96 EXPECT_FALSE(log_out_called_); |
96 controller_.ConfirmLogout( | 97 controller_.ConfirmLogout(runner_->NowTicks() + |
97 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 98 base::TimeDelta::FromSeconds(10)); |
98 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); | 99 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); |
99 EXPECT_TRUE(log_out_called_); | 100 EXPECT_TRUE(log_out_called_); |
100 } | 101 } |
101 | 102 |
102 // Verifies that when the screen is locked while the countdown is running, the | 103 // Verifies that when the screen is locked while the countdown is running, the |
103 // user is not logged out, even when the original countdown expires. | 104 // user is not logged out, even when the original countdown expires. |
104 TEST_F(LogoutConfirmationControllerTest, Lock) { | 105 TEST_F(LogoutConfirmationControllerTest, Lock) { |
105 controller_.ConfirmLogout( | 106 controller_.ConfirmLogout(runner_->NowTicks() + |
106 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 107 base::TimeDelta::FromSeconds(10)); |
107 EXPECT_FALSE(log_out_called_); | 108 EXPECT_FALSE(log_out_called_); |
108 controller_.OnLockStateChanged(true); | 109 controller_.OnLockStateChanged(true); |
109 runner_->FastForwardUntilNoTasksRemain(); | 110 runner_->FastForwardUntilNoTasksRemain(); |
110 EXPECT_FALSE(log_out_called_); | 111 EXPECT_FALSE(log_out_called_); |
111 } | 112 } |
112 | 113 |
113 // Verifies that when the user confirms the logout request, the user is logged | 114 // Verifies that when the user confirms the logout request, the user is logged |
114 // out immediately. | 115 // out immediately. |
115 TEST_F(LogoutConfirmationControllerTest, UserAccepted) { | 116 TEST_F(LogoutConfirmationControllerTest, UserAccepted) { |
116 controller_.ConfirmLogout( | 117 controller_.ConfirmLogout(runner_->NowTicks() + |
117 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 118 base::TimeDelta::FromSeconds(10)); |
118 EXPECT_FALSE(log_out_called_); | 119 EXPECT_FALSE(log_out_called_); |
119 controller_.OnLogoutConfirmed(); | 120 controller_.OnLogoutConfirmed(); |
120 EXPECT_TRUE(log_out_called_); | 121 EXPECT_TRUE(log_out_called_); |
121 } | 122 } |
122 | 123 |
123 // Verifies that when the user denies the logout request, the user is not logged | 124 // Verifies that when the user denies the logout request, the user is not logged |
124 // out, even when the original countdown expires. | 125 // out, even when the original countdown expires. |
125 TEST_F(LogoutConfirmationControllerTest, UserDenied) { | 126 TEST_F(LogoutConfirmationControllerTest, UserDenied) { |
126 controller_.ConfirmLogout( | 127 controller_.ConfirmLogout(runner_->NowTicks() + |
127 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 128 base::TimeDelta::FromSeconds(10)); |
128 EXPECT_FALSE(log_out_called_); | 129 EXPECT_FALSE(log_out_called_); |
129 controller_.OnDialogClosed(); | 130 controller_.OnDialogClosed(); |
130 runner_->FastForwardUntilNoTasksRemain(); | 131 runner_->FastForwardUntilNoTasksRemain(); |
131 EXPECT_FALSE(log_out_called_); | 132 EXPECT_FALSE(log_out_called_); |
132 } | 133 } |
133 | 134 |
134 // Verifies that after the user has denied a logout request, a subsequent logout | 135 // Verifies that after the user has denied a logout request, a subsequent logout |
135 // request is handled correctly and the user is logged out when the countdown | 136 // request is handled correctly and the user is logged out when the countdown |
136 // expires. | 137 // expires. |
137 TEST_F(LogoutConfirmationControllerTest, DurationExpiredAfterDeniedRequest) { | 138 TEST_F(LogoutConfirmationControllerTest, DurationExpiredAfterDeniedRequest) { |
138 controller_.ConfirmLogout( | 139 controller_.ConfirmLogout(runner_->NowTicks() + |
139 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 140 base::TimeDelta::FromSeconds(10)); |
140 EXPECT_FALSE(log_out_called_); | 141 EXPECT_FALSE(log_out_called_); |
141 controller_.OnDialogClosed(); | 142 controller_.OnDialogClosed(); |
142 runner_->FastForwardUntilNoTasksRemain(); | 143 runner_->FastForwardUntilNoTasksRemain(); |
143 EXPECT_FALSE(log_out_called_); | 144 EXPECT_FALSE(log_out_called_); |
144 | 145 |
145 controller_.ConfirmLogout( | 146 controller_.ConfirmLogout(runner_->NowTicks() + |
146 runner_->GetCurrentMockTime() + base::TimeDelta::FromSeconds(10)); | 147 base::TimeDelta::FromSeconds(10)); |
147 EXPECT_FALSE(log_out_called_); | 148 EXPECT_FALSE(log_out_called_); |
148 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); | 149 runner_->FastForwardBy(base::TimeDelta::FromSeconds(9)); |
149 EXPECT_FALSE(log_out_called_); | 150 EXPECT_FALSE(log_out_called_); |
150 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); | 151 runner_->FastForwardBy(base::TimeDelta::FromSeconds(2)); |
151 EXPECT_TRUE(log_out_called_); | 152 EXPECT_TRUE(log_out_called_); |
152 } | 153 } |
153 | 154 |
154 } // namespace ash | 155 } // namespace ash |
OLD | NEW |