| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/session_length_limiter.h" | 5 #include "chrome/browser/chromeos/session_length_limiter.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/test/test_mock_time_task_runner.h" | 13 #include "base/test/test_mock_time_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "components/prefs/testing_pref_service.h" | 18 #include "components/prefs/testing_pref_service.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 97 } |
| 97 | 98 |
| 98 void SessionLengthLimiterTest::TearDown() { | 99 void SessionLengthLimiterTest::TearDown() { |
| 99 session_length_limiter_.reset(); | 100 session_length_limiter_.reset(); |
| 100 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 101 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void SessionLengthLimiterTest::SetSessionUserActivitySeenPref( | 104 void SessionLengthLimiterTest::SetSessionUserActivitySeenPref( |
| 104 bool user_activity_seen) { | 105 bool user_activity_seen) { |
| 105 local_state_.SetUserPref(prefs::kSessionUserActivitySeen, | 106 local_state_.SetUserPref(prefs::kSessionUserActivitySeen, |
| 106 new base::Value(user_activity_seen)); | 107 base::MakeUnique<base::Value>(user_activity_seen)); |
| 107 } | 108 } |
| 108 | 109 |
| 109 void SessionLengthLimiterTest::ClearSessionUserActivitySeenPref() { | 110 void SessionLengthLimiterTest::ClearSessionUserActivitySeenPref() { |
| 110 local_state_.ClearPref(prefs::kSessionUserActivitySeen); | 111 local_state_.ClearPref(prefs::kSessionUserActivitySeen); |
| 111 } | 112 } |
| 112 | 113 |
| 113 bool SessionLengthLimiterTest::IsSessionUserActivitySeenPrefSet() { | 114 bool SessionLengthLimiterTest::IsSessionUserActivitySeenPrefSet() { |
| 114 return local_state_.HasPrefPath(prefs::kSessionUserActivitySeen); | 115 return local_state_.HasPrefPath(prefs::kSessionUserActivitySeen); |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool SessionLengthLimiterTest::GetSessionUserActivitySeenPref() { | 118 bool SessionLengthLimiterTest::GetSessionUserActivitySeenPref() { |
| 118 EXPECT_TRUE(IsSessionUserActivitySeenPrefSet()); | 119 EXPECT_TRUE(IsSessionUserActivitySeenPrefSet()); |
| 119 return local_state_.GetBoolean(prefs::kSessionUserActivitySeen); | 120 return local_state_.GetBoolean(prefs::kSessionUserActivitySeen); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void SessionLengthLimiterTest::SetSessionStartTimePref( | 123 void SessionLengthLimiterTest::SetSessionStartTimePref( |
| 123 const base::TimeTicks& session_start_time) { | 124 const base::TimeTicks& session_start_time) { |
| 124 local_state_.SetUserPref(prefs::kSessionStartTime, | 125 local_state_.SetUserPref(prefs::kSessionStartTime, |
| 125 new base::Value(base::Int64ToString( | 126 base::MakeUnique<base::Value>(base::Int64ToString( |
| 126 session_start_time.ToInternalValue()))); | 127 session_start_time.ToInternalValue()))); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void SessionLengthLimiterTest::ClearSessionStartTimePref() { | 130 void SessionLengthLimiterTest::ClearSessionStartTimePref() { |
| 130 local_state_.ClearPref(prefs::kSessionStartTime); | 131 local_state_.ClearPref(prefs::kSessionStartTime); |
| 131 } | 132 } |
| 132 | 133 |
| 133 bool SessionLengthLimiterTest::IsSessionStartTimePrefSet() { | 134 bool SessionLengthLimiterTest::IsSessionStartTimePrefSet() { |
| 134 return local_state_.HasPrefPath(prefs::kSessionStartTime); | 135 return local_state_.HasPrefPath(prefs::kSessionStartTime); |
| 135 } | 136 } |
| 136 | 137 |
| 137 base::TimeTicks SessionLengthLimiterTest::GetSessionStartTimePref() { | 138 base::TimeTicks SessionLengthLimiterTest::GetSessionStartTimePref() { |
| 138 EXPECT_TRUE(IsSessionStartTimePrefSet()); | 139 EXPECT_TRUE(IsSessionStartTimePrefSet()); |
| 139 return base::TimeTicks::FromInternalValue( | 140 return base::TimeTicks::FromInternalValue( |
| 140 local_state_.GetInt64(prefs::kSessionStartTime)); | 141 local_state_.GetInt64(prefs::kSessionStartTime)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 void SessionLengthLimiterTest::SetSessionLengthLimitPref( | 144 void SessionLengthLimiterTest::SetSessionLengthLimitPref( |
| 144 const base::TimeDelta& session_length_limit) { | 145 const base::TimeDelta& session_length_limit) { |
| 145 local_state_.SetUserPref( | 146 local_state_.SetUserPref(prefs::kSessionLengthLimit, |
| 146 prefs::kSessionLengthLimit, | 147 base::MakeUnique<base::Value>(static_cast<int>( |
| 147 new base::Value(static_cast<int>(session_length_limit.InMilliseconds()))); | 148 session_length_limit.InMilliseconds()))); |
| 148 UpdateSessionStartTimeIfWaitingForUserActivity(); | 149 UpdateSessionStartTimeIfWaitingForUserActivity(); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void SessionLengthLimiterTest::ClearSessionLengthLimitPref() { | 152 void SessionLengthLimiterTest::ClearSessionLengthLimitPref() { |
| 152 local_state_.RemoveUserPref(prefs::kSessionLengthLimit); | 153 local_state_.RemoveUserPref(prefs::kSessionLengthLimit); |
| 153 UpdateSessionStartTimeIfWaitingForUserActivity(); | 154 UpdateSessionStartTimeIfWaitingForUserActivity(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 void SessionLengthLimiterTest::SetWaitForInitialUserActivityPref( | 157 void SessionLengthLimiterTest::SetWaitForInitialUserActivityPref( |
| 157 bool wait_for_initial_user_activity) { | 158 bool wait_for_initial_user_activity) { |
| 158 UpdateSessionStartTimeIfWaitingForUserActivity(); | 159 UpdateSessionStartTimeIfWaitingForUserActivity(); |
| 159 local_state_.SetUserPref(prefs::kSessionWaitForInitialUserActivity, | 160 local_state_.SetUserPref( |
| 160 new base::Value(wait_for_initial_user_activity)); | 161 prefs::kSessionWaitForInitialUserActivity, |
| 162 base::MakeUnique<base::Value>(wait_for_initial_user_activity)); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void SessionLengthLimiterTest::SimulateUserActivity() { | 165 void SessionLengthLimiterTest::SimulateUserActivity() { |
| 164 if (session_length_limiter_) | 166 if (session_length_limiter_) |
| 165 session_length_limiter_->OnUserActivity(NULL); | 167 session_length_limiter_->OnUserActivity(NULL); |
| 166 UpdateSessionStartTimeIfWaitingForUserActivity(); | 168 UpdateSessionStartTimeIfWaitingForUserActivity(); |
| 167 user_activity_seen_ = true; | 169 user_activity_seen_ = true; |
| 168 } | 170 } |
| 169 | 171 |
| 170 void SessionLengthLimiterTest:: | 172 void SessionLengthLimiterTest:: |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 runner_->FastForwardBy(base::TimeDelta::FromSeconds(50)); | 732 runner_->FastForwardBy(base::TimeDelta::FromSeconds(50)); |
| 731 | 733 |
| 732 // Remove the session length limit. | 734 // Remove the session length limit. |
| 733 ClearSessionLengthLimitPref(); | 735 ClearSessionLengthLimitPref(); |
| 734 | 736 |
| 735 // Verify that no timer fires to terminate the session. | 737 // Verify that no timer fires to terminate the session. |
| 736 runner_->FastForwardUntilNoTasksRemain(); | 738 runner_->FastForwardUntilNoTasksRemain(); |
| 737 } | 739 } |
| 738 | 740 |
| 739 } // namespace chromeos | 741 } // namespace chromeos |
| OLD | NEW |