Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/lock_screen_apps/state_controller.h" | 5 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | |
| 8 #include <utility> | 9 #include <utility> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "ash/public/interfaces/tray_action.mojom.h" | 12 #include "ash/public/interfaces/tray_action.mojom.h" |
| 13 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 13 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 14 #include "base/test/scoped_command_line.h" | 16 #include "base/test/scoped_command_line.h" |
| 17 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" | |
| 15 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" | 18 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
| 19 #include "chrome/common/chrome_constants.h" | |
| 20 #include "chrome/test/base/testing_browser_process.h" | |
| 21 #include "chrome/test/base/testing_profile.h" | |
| 22 #include "chrome/test/base/testing_profile_manager.h" | |
| 23 #include "components/session_manager/core/session_manager.h" | |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 26 |
| 19 using ash::mojom::TrayActionState; | 27 using ash::mojom::TrayActionState; |
| 20 | 28 |
| 21 namespace { | 29 namespace { |
| 22 | 30 |
| 31 class TestAppManager : public lock_screen_apps::AppManager { | |
| 32 public: | |
| 33 enum class State { | |
| 34 kNotInitialized, | |
| 35 kStarted, | |
| 36 kStopped, | |
| 37 }; | |
| 38 | |
| 39 TestAppManager(Profile* expected_primary_profile, | |
| 40 Profile* expected_lock_screen_profile) | |
| 41 : expected_primary_profile_(expected_primary_profile), | |
| 42 expected_lock_screen_profile_(expected_lock_screen_profile) {} | |
| 43 | |
| 44 ~TestAppManager() override = default; | |
| 45 | |
| 46 void Initialize(Profile* primary_profile, | |
| 47 Profile* lock_screen_profile) override { | |
| 48 ASSERT_EQ(State::kNotInitialized, state_); | |
| 49 ASSERT_EQ(expected_primary_profile_, primary_profile); | |
| 50 ASSERT_EQ(expected_lock_screen_profile_, lock_screen_profile); | |
| 51 | |
| 52 state_ = State::kStopped; | |
| 53 } | |
| 54 | |
| 55 void Start(Observer* observer) override { | |
| 56 ASSERT_FALSE(observer_); | |
| 57 observer_ = observer; | |
| 58 state_ = State::kStarted; | |
| 59 } | |
| 60 | |
| 61 void Stop() override { | |
| 62 observer_ = nullptr; | |
| 63 state_ = State::kStopped; | |
| 64 } | |
| 65 | |
| 66 bool LaunchNoteTaking() override { | |
| 67 EXPECT_EQ(State::kStarted, state_); | |
| 68 launch_count_++; | |
|
xiyuan
2017/05/26 22:44:52
nit: ++launch_count_;
tbarzic
2017/05/27 00:48:35
Done.
| |
| 69 return app_launchable_; | |
| 70 } | |
| 71 | |
| 72 bool IsNoteTakingAppAvailable() const override { | |
| 73 return state_ == State::kStarted && !app_id_.empty(); | |
| 74 } | |
| 75 | |
| 76 std::string GetNoteTakingAppId() const override { | |
| 77 if (state_ != State::kStarted) | |
| 78 return std::string(); | |
| 79 return app_id_; | |
| 80 } | |
| 81 | |
| 82 void SetInitialAppState(const std::string& app_id, bool app_launchable) { | |
| 83 ASSERT_NE(State::kStarted, state_); | |
| 84 | |
| 85 app_launchable_ = app_launchable; | |
| 86 app_id_ = app_id; | |
| 87 } | |
| 88 | |
| 89 void UpdateApp(const std::string& app_id, bool app_launchable) { | |
| 90 ASSERT_EQ(State::kStarted, state_); | |
| 91 | |
| 92 app_launchable_ = app_launchable; | |
| 93 if (app_id == app_id_) | |
| 94 return; | |
| 95 app_id_ = app_id; | |
| 96 | |
| 97 if (observer_) | |
| 98 observer_->OnNoteTakingAvailabilityChanged(); | |
| 99 } | |
| 100 | |
| 101 State state() const { return state_; } | |
| 102 | |
| 103 int launch_count() const { return launch_count_; } | |
| 104 | |
| 105 private: | |
| 106 Profile* expected_primary_profile_; | |
| 107 Profile* expected_lock_screen_profile_; | |
|
xiyuan
2017/05/26 22:44:52
nit: Profile* const for the two above
tbarzic
2017/05/27 00:48:35
Done.
| |
| 108 | |
| 109 Observer* observer_ = nullptr; | |
| 110 | |
| 111 State state_ = State::kNotInitialized; | |
| 112 | |
| 113 // Number of requested app launches. | |
| 114 int launch_count_ = 0; | |
| 115 | |
| 116 // Information about the test app: | |
| 117 // The app ID. | |
| 118 std::string app_id_; | |
| 119 // Whether app launch should succeed. | |
| 120 bool app_launchable_ = false; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(TestAppManager); | |
| 123 }; | |
| 124 | |
| 23 class TestStateObserver : public lock_screen_apps::StateObserver { | 125 class TestStateObserver : public lock_screen_apps::StateObserver { |
| 24 public: | 126 public: |
| 25 TestStateObserver() = default; | 127 TestStateObserver() = default; |
| 26 ~TestStateObserver() override = default; | 128 ~TestStateObserver() override = default; |
| 27 | 129 |
| 28 void OnLockScreenNoteStateChanged(TrayActionState state) override { | 130 void OnLockScreenNoteStateChanged(TrayActionState state) override { |
| 29 observed_states_.push_back(state); | 131 observed_states_.push_back(state); |
| 30 } | 132 } |
| 31 | 133 |
| 32 const std::vector<TrayActionState> observed_states() const { | 134 const std::vector<TrayActionState>& observed_states() const { |
| 33 return observed_states_; | 135 return observed_states_; |
| 34 } | 136 } |
| 35 | 137 |
| 36 void ClearObservedStates() { observed_states_.clear(); } | 138 void ClearObservedStates() { observed_states_.clear(); } |
| 37 | 139 |
| 38 private: | 140 private: |
| 39 std::vector<TrayActionState> observed_states_; | 141 std::vector<TrayActionState> observed_states_; |
| 40 | 142 |
| 41 DISALLOW_COPY_AND_ASSIGN(TestStateObserver); | 143 DISALLOW_COPY_AND_ASSIGN(TestStateObserver); |
| 42 }; | 144 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 } | 195 } |
| 94 | 196 |
| 95 private: | 197 private: |
| 96 std::unique_ptr<base::test::ScopedCommandLine> command_line_; | 198 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
| 97 | 199 |
| 98 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateNotSupportedTest); | 200 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateNotSupportedTest); |
| 99 }; | 201 }; |
| 100 | 202 |
| 101 class LockScreenAppStateTest : public testing::Test { | 203 class LockScreenAppStateTest : public testing::Test { |
| 102 public: | 204 public: |
| 103 LockScreenAppStateTest() = default; | 205 LockScreenAppStateTest() |
| 206 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} | |
| 104 ~LockScreenAppStateTest() override = default; | 207 ~LockScreenAppStateTest() override = default; |
| 105 | 208 |
| 106 void SetUp() override { | 209 void SetUp() override { |
| 107 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); | 210 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
| 108 command_line_->GetProcessCommandLine()->InitFromArgv( | 211 command_line_->GetProcessCommandLine()->InitFromArgv( |
| 109 {"", "--enable-lock-screen-apps"}); | 212 {"", "--enable-lock-screen-apps"}); |
| 110 | 213 |
| 214 ASSERT_TRUE(profile_manager_.SetUp()); | |
| 215 | |
| 216 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); | |
| 217 session_manager_->SetSessionState( | |
| 218 session_manager::SessionState::LOGIN_PRIMARY); | |
| 219 | |
| 111 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); | 220 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); |
| 112 | 221 |
| 113 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); | 222 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); |
| 114 state_controller_->SetTrayActionPtrForTesting( | 223 state_controller_->SetTrayActionPtrForTesting( |
| 115 tray_action_.CreateInterfacePtrAndBind()); | 224 tray_action_.CreateInterfacePtrAndBind()); |
| 116 state_controller_->Initialize(); | 225 state_controller_->Initialize(); |
| 117 state_controller_->FlushTrayActionForTesting(); | 226 state_controller_->FlushTrayActionForTesting(); |
| 118 | 227 |
| 119 state_controller_->AddObserver(&observer_); | 228 state_controller_->AddObserver(&observer_); |
| 229 | |
| 230 // Create fake sign-in profile. | |
| 231 TestingProfile::Builder builder; | |
| 232 builder.SetPath( | |
| 233 profile_manager_.profiles_dir().AppendASCII(chrome::kInitialProfile)); | |
| 234 TestingProfile* signin_profile = builder.BuildIncognito( | |
| 235 profile_manager_.CreateTestingProfile(chrome::kInitialProfile)); | |
| 236 | |
| 237 std::unique_ptr<TestAppManager> app_manager = | |
| 238 base::MakeUnique<TestAppManager>(&profile_, signin_profile); | |
| 239 app_manager_ = app_manager.get(); | |
| 240 state_controller_->SetAppManagerForTesting(std::move(app_manager)); | |
| 120 } | 241 } |
| 121 | 242 |
| 122 void TearDown() override { | 243 void TearDown() override { |
| 123 state_controller_->RemoveObserver(&observer_); | 244 state_controller_->RemoveObserver(&observer_); |
| 124 state_controller_.reset(); | 245 state_controller_.reset(); |
| 246 session_manager_.reset(); | |
| 247 app_manager_ = nullptr; | |
| 248 } | |
| 249 | |
| 250 // Helper method to move state controller to available state. | |
| 251 // Should be called at the begining of tests, at most once. | |
| 252 bool EnableNoteTakingApp(bool enable_app_launch) { | |
| 253 app_manager_->SetInitialAppState("test_app_id", enable_app_launch); | |
| 254 state_controller_->SetPrimaryProfile(&profile_); | |
| 255 session_manager_->SetSessionState(session_manager::SessionState::LOCKED); | |
| 256 if (app_manager_->state() != TestAppManager::State::kStarted) { | |
| 257 ADD_FAILURE() << "Lock app manager Start not invoked."; | |
| 258 return false; | |
| 259 } | |
| 260 state_controller_->FlushTrayActionForTesting(); | |
| 261 | |
| 262 observer_.ClearObservedStates(); | |
| 263 tray_action_.ClearObservedStates(); | |
| 264 | |
| 265 return state_controller_->GetLockScreenNoteState() == | |
| 266 TrayActionState::kAvailable; | |
| 267 } | |
| 268 | |
| 269 TestingProfile* profile() { return &profile_; } | |
| 270 | |
| 271 session_manager::SessionManager* session_manager() { | |
| 272 return session_manager_.get(); | |
| 125 } | 273 } |
| 126 | 274 |
| 127 TestStateObserver* observer() { return &observer_; } | 275 TestStateObserver* observer() { return &observer_; } |
| 128 | 276 |
| 129 TestTrayAction* tray_action() { return &tray_action_; } | 277 TestTrayAction* tray_action() { return &tray_action_; } |
| 130 | 278 |
| 131 lock_screen_apps::StateController* state_controller() { | 279 lock_screen_apps::StateController* state_controller() { |
| 132 return state_controller_.get(); | 280 return state_controller_.get(); |
| 133 } | 281 } |
| 134 | 282 |
| 283 TestAppManager* app_manager() { return app_manager_; } | |
| 284 | |
| 135 private: | 285 private: |
| 136 std::unique_ptr<base::test::ScopedCommandLine> command_line_; | 286 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
| 137 content::TestBrowserThreadBundle threads_; | 287 content::TestBrowserThreadBundle threads_; |
| 288 TestingProfileManager profile_manager_; | |
| 289 TestingProfile profile_; | |
| 290 | |
| 291 std::unique_ptr<session_manager::SessionManager> session_manager_; | |
| 138 | 292 |
| 139 std::unique_ptr<lock_screen_apps::StateController> state_controller_; | 293 std::unique_ptr<lock_screen_apps::StateController> state_controller_; |
| 294 | |
| 140 TestStateObserver observer_; | 295 TestStateObserver observer_; |
| 141 TestTrayAction tray_action_; | 296 TestTrayAction tray_action_; |
| 297 TestAppManager* app_manager_ = nullptr; | |
| 142 | 298 |
| 143 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateTest); | 299 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateTest); |
| 144 }; | 300 }; |
| 145 | 301 |
| 146 } // namespace | 302 } // namespace |
| 147 | 303 |
| 148 TEST_F(LockScreenAppStateNotSupportedTest, NoInstance) { | 304 TEST_F(LockScreenAppStateNotSupportedTest, NoInstance) { |
| 149 EXPECT_FALSE(lock_screen_apps::StateController::IsEnabled()); | 305 EXPECT_FALSE(lock_screen_apps::StateController::IsEnabled()); |
| 150 } | 306 } |
| 151 | 307 |
| 152 TEST_F(LockScreenAppStateTest, InitialState) { | 308 TEST_F(LockScreenAppStateTest, InitialState) { |
| 153 EXPECT_EQ(TrayActionState::kNotAvailable, | 309 EXPECT_EQ(TrayActionState::kNotAvailable, |
| 154 state_controller()->GetLockScreenNoteState()); | 310 state_controller()->GetLockScreenNoteState()); |
| 155 | 311 |
| 312 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | |
| 156 state_controller()->MoveToBackground(); | 313 state_controller()->MoveToBackground(); |
| 157 | 314 |
| 158 EXPECT_EQ(TrayActionState::kNotAvailable, | 315 EXPECT_EQ(TrayActionState::kNotAvailable, |
| 159 state_controller()->GetLockScreenNoteState()); | 316 state_controller()->GetLockScreenNoteState()); |
| 160 | 317 |
| 161 EXPECT_EQ(0u, observer()->observed_states().size()); | 318 EXPECT_EQ(0u, observer()->observed_states().size()); |
| 162 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 319 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
| 163 } | 320 } |
| 164 | 321 |
| 322 TEST_F(LockScreenAppStateTest, SetPrimaryProfile) { | |
| 323 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | |
| 324 state_controller()->SetPrimaryProfile(profile()); | |
| 325 | |
| 326 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 327 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 328 state_controller()->GetLockScreenNoteState()); | |
| 329 EXPECT_EQ(0u, observer()->observed_states().size()); | |
| 330 } | |
| 331 | |
| 332 TEST_F(LockScreenAppStateTest, SetPrimaryProfileWhenSessionLocked) { | |
| 333 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 334 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 335 state_controller()->GetLockScreenNoteState()); | |
| 336 | |
| 337 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | |
| 338 | |
| 339 app_manager()->SetInitialAppState("app_id", true); | |
| 340 state_controller()->SetPrimaryProfile(profile()); | |
| 341 | |
| 342 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 343 | |
| 344 EXPECT_EQ(TrayActionState::kAvailable, | |
| 345 state_controller()->GetLockScreenNoteState()); | |
| 346 | |
| 347 state_controller()->FlushTrayActionForTesting(); | |
| 348 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 349 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 350 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 351 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 352 } | |
| 353 | |
| 354 TEST_F(LockScreenAppStateTest, SessionLock) { | |
| 355 app_manager()->SetInitialAppState("app_id", true); | |
| 356 state_controller()->SetPrimaryProfile(profile()); | |
| 357 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 358 | |
| 359 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 360 | |
| 361 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 362 | |
| 363 EXPECT_EQ(TrayActionState::kAvailable, | |
| 364 state_controller()->GetLockScreenNoteState()); | |
| 365 state_controller()->FlushTrayActionForTesting(); | |
| 366 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 367 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 368 observer()->ClearObservedStates(); | |
| 369 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 370 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 371 tray_action()->ClearObservedStates(); | |
| 372 | |
| 373 // When the session is unlocked again, app manager is stopped, and tray action | |
| 374 // disabled again. | |
| 375 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | |
| 376 | |
| 377 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 378 | |
| 379 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 380 state_controller()->GetLockScreenNoteState()); | |
| 381 state_controller()->FlushTrayActionForTesting(); | |
| 382 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 383 EXPECT_EQ(TrayActionState::kNotAvailable, observer()->observed_states()[0]); | |
| 384 observer()->ClearObservedStates(); | |
| 385 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 386 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 387 tray_action()->observed_states()[0]); | |
| 388 tray_action()->ClearObservedStates(); | |
| 389 | |
| 390 // Test that subsequent session lock works as expected. | |
| 391 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 392 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 393 | |
| 394 EXPECT_EQ(TrayActionState::kAvailable, | |
| 395 state_controller()->GetLockScreenNoteState()); | |
| 396 state_controller()->FlushTrayActionForTesting(); | |
| 397 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 398 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 399 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 400 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 401 } | |
| 402 | |
| 403 TEST_F(LockScreenAppStateTest, SessionUnlockedWhileStartingAppManager) { | |
| 404 state_controller()->SetPrimaryProfile(profile()); | |
| 405 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 406 | |
| 407 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 408 | |
| 409 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 410 | |
| 411 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | |
| 412 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 413 | |
| 414 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 415 state_controller()->GetLockScreenNoteState()); | |
| 416 state_controller()->FlushTrayActionForTesting(); | |
| 417 EXPECT_EQ(0u, observer()->observed_states().size()); | |
| 418 EXPECT_EQ(0u, tray_action()->observed_states().size()); | |
| 419 | |
| 420 // Test that subsequent session lock works as expected. | |
| 421 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 422 | |
| 423 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 424 app_manager()->UpdateApp("app_id", true); | |
| 425 | |
| 426 EXPECT_EQ(TrayActionState::kAvailable, | |
| 427 state_controller()->GetLockScreenNoteState()); | |
| 428 state_controller()->FlushTrayActionForTesting(); | |
| 429 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 430 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 431 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 432 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 433 } | |
| 434 | |
| 435 TEST_F(LockScreenAppStateTest, AppManagerNoApp) { | |
| 436 state_controller()->SetPrimaryProfile(profile()); | |
| 437 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 438 | |
| 439 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 440 | |
| 441 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 442 | |
| 443 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 444 state_controller()->GetLockScreenNoteState()); | |
| 445 state_controller()->FlushTrayActionForTesting(); | |
| 446 EXPECT_EQ(0u, observer()->observed_states().size()); | |
| 447 EXPECT_EQ(0u, tray_action()->observed_states().size()); | |
| 448 | |
| 449 tray_action()->SendNewNoteRequest(); | |
| 450 | |
| 451 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 452 state_controller()->GetLockScreenNoteState()); | |
| 453 state_controller()->FlushTrayActionForTesting(); | |
| 454 EXPECT_EQ(0u, observer()->observed_states().size()); | |
| 455 EXPECT_EQ(0u, tray_action()->observed_states().size()); | |
| 456 | |
| 457 // App manager should be started on next session lock. | |
| 458 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | |
| 459 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 460 app_manager()->SetInitialAppState("app_id", false); | |
| 461 | |
| 462 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 463 | |
| 464 EXPECT_EQ(TrayActionState::kAvailable, | |
| 465 state_controller()->GetLockScreenNoteState()); | |
| 466 state_controller()->FlushTrayActionForTesting(); | |
| 467 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 468 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 469 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 470 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 471 } | |
| 472 | |
| 473 TEST_F(LockScreenAppStateTest, AppAvailabilityChanges) { | |
| 474 state_controller()->SetPrimaryProfile(profile()); | |
| 475 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | |
| 476 | |
| 477 app_manager()->SetInitialAppState("app_id", false); | |
| 478 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | |
| 479 | |
| 480 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | |
| 481 | |
| 482 EXPECT_EQ(TrayActionState::kAvailable, | |
| 483 state_controller()->GetLockScreenNoteState()); | |
| 484 state_controller()->FlushTrayActionForTesting(); | |
| 485 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 486 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 487 observer()->ClearObservedStates(); | |
| 488 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 489 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 490 tray_action()->ClearObservedStates(); | |
| 491 | |
| 492 app_manager()->UpdateApp("", false); | |
| 493 | |
| 494 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 495 state_controller()->GetLockScreenNoteState()); | |
| 496 state_controller()->FlushTrayActionForTesting(); | |
| 497 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 498 EXPECT_EQ(TrayActionState::kNotAvailable, observer()->observed_states()[0]); | |
| 499 observer()->ClearObservedStates(); | |
| 500 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 501 EXPECT_EQ(TrayActionState::kNotAvailable, | |
| 502 tray_action()->observed_states()[0]); | |
| 503 tray_action()->ClearObservedStates(); | |
| 504 | |
| 505 app_manager()->UpdateApp("app_id_1", true); | |
| 506 | |
| 507 EXPECT_EQ(TrayActionState::kAvailable, | |
| 508 state_controller()->GetLockScreenNoteState()); | |
| 509 state_controller()->FlushTrayActionForTesting(); | |
| 510 ASSERT_EQ(1u, observer()->observed_states().size()); | |
| 511 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
| 512 observer()->ClearObservedStates(); | |
| 513 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
| 514 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
| 515 tray_action()->ClearObservedStates(); | |
| 516 } | |
| 517 | |
| 165 TEST_F(LockScreenAppStateTest, MoveToBackgroundFromActive) { | 518 TEST_F(LockScreenAppStateTest, MoveToBackgroundFromActive) { |
| 519 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | |
| 520 | |
| 166 state_controller()->SetLockScreenNoteStateForTesting( | 521 state_controller()->SetLockScreenNoteStateForTesting( |
| 167 TrayActionState::kActive); | 522 TrayActionState::kActive); |
| 168 | 523 |
| 169 state_controller()->MoveToBackground(); | 524 state_controller()->MoveToBackground(); |
| 170 state_controller()->FlushTrayActionForTesting(); | 525 state_controller()->FlushTrayActionForTesting(); |
| 171 | 526 |
| 172 EXPECT_EQ(TrayActionState::kBackground, | 527 EXPECT_EQ(TrayActionState::kBackground, |
| 173 state_controller()->GetLockScreenNoteState()); | 528 state_controller()->GetLockScreenNoteState()); |
| 174 | 529 |
| 175 ASSERT_EQ(1u, observer()->observed_states().size()); | 530 ASSERT_EQ(1u, observer()->observed_states().size()); |
| 176 EXPECT_EQ(TrayActionState::kBackground, observer()->observed_states()[0]); | 531 EXPECT_EQ(TrayActionState::kBackground, observer()->observed_states()[0]); |
| 177 ASSERT_EQ(1u, tray_action()->observed_states().size()); | 532 ASSERT_EQ(1u, tray_action()->observed_states().size()); |
| 178 EXPECT_EQ(TrayActionState::kBackground, tray_action()->observed_states()[0]); | 533 EXPECT_EQ(TrayActionState::kBackground, tray_action()->observed_states()[0]); |
| 179 } | 534 } |
| 180 | 535 |
| 181 TEST_F(LockScreenAppStateTest, MoveToForeground) { | 536 TEST_F(LockScreenAppStateTest, MoveToForeground) { |
| 537 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | |
| 538 | |
| 182 state_controller()->SetLockScreenNoteStateForTesting( | 539 state_controller()->SetLockScreenNoteStateForTesting( |
| 183 TrayActionState::kBackground); | 540 TrayActionState::kBackground); |
| 184 | 541 |
| 185 state_controller()->MoveToForeground(); | 542 state_controller()->MoveToForeground(); |
| 186 state_controller()->FlushTrayActionForTesting(); | 543 state_controller()->FlushTrayActionForTesting(); |
| 187 | 544 |
| 188 EXPECT_EQ(TrayActionState::kActive, | 545 EXPECT_EQ(TrayActionState::kActive, |
| 189 state_controller()->GetLockScreenNoteState()); | 546 state_controller()->GetLockScreenNoteState()); |
| 190 | 547 |
| 191 ASSERT_EQ(1u, observer()->observed_states().size()); | 548 ASSERT_EQ(1u, observer()->observed_states().size()); |
| 192 EXPECT_EQ(TrayActionState::kActive, observer()->observed_states()[0]); | 549 EXPECT_EQ(TrayActionState::kActive, observer()->observed_states()[0]); |
| 193 ASSERT_EQ(1u, tray_action()->observed_states().size()); | 550 ASSERT_EQ(1u, tray_action()->observed_states().size()); |
| 194 EXPECT_EQ(TrayActionState::kActive, tray_action()->observed_states()[0]); | 551 EXPECT_EQ(TrayActionState::kActive, tray_action()->observed_states()[0]); |
| 195 } | 552 } |
| 196 | 553 |
| 197 TEST_F(LockScreenAppStateTest, MoveToForegroundFromNonBackgroundState) { | 554 TEST_F(LockScreenAppStateTest, MoveToForegroundFromNonBackgroundState) { |
| 198 state_controller()->SetLockScreenNoteStateForTesting( | 555 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); |
| 199 TrayActionState::kAvailable); | |
| 200 | 556 |
| 201 state_controller()->MoveToForeground(); | 557 state_controller()->MoveToForeground(); |
| 202 state_controller()->FlushTrayActionForTesting(); | 558 state_controller()->FlushTrayActionForTesting(); |
| 203 | 559 |
| 204 EXPECT_EQ(TrayActionState::kAvailable, | 560 EXPECT_EQ(TrayActionState::kAvailable, |
| 205 state_controller()->GetLockScreenNoteState()); | 561 state_controller()->GetLockScreenNoteState()); |
| 206 | 562 |
| 207 EXPECT_EQ(0u, observer()->observed_states().size()); | 563 EXPECT_EQ(0u, observer()->observed_states().size()); |
| 208 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 564 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
| 209 } | 565 } |
| 210 | 566 |
| 211 TEST_F(LockScreenAppStateTest, HandleActionWhenNotAvaiable) { | 567 TEST_F(LockScreenAppStateTest, HandleActionWhenNotAvaiable) { |
| 212 ASSERT_EQ(TrayActionState::kNotAvailable, | 568 ASSERT_EQ(TrayActionState::kNotAvailable, |
| 213 state_controller()->GetLockScreenNoteState()); | 569 state_controller()->GetLockScreenNoteState()); |
| 214 | 570 |
| 215 tray_action()->SendNewNoteRequest(); | 571 tray_action()->SendNewNoteRequest(); |
| 216 state_controller()->FlushTrayActionForTesting(); | 572 state_controller()->FlushTrayActionForTesting(); |
| 217 | 573 |
| 218 EXPECT_EQ(0u, observer()->observed_states().size()); | 574 EXPECT_EQ(0u, observer()->observed_states().size()); |
| 219 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 575 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
| 220 } | 576 } |
| 221 | 577 |
| 222 TEST_F(LockScreenAppStateTest, HandleAction) { | 578 TEST_F(LockScreenAppStateTest, HandleAction) { |
| 223 state_controller()->SetLockScreenNoteStateForTesting( | 579 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); |
| 224 TrayActionState::kAvailable); | |
| 225 | 580 |
| 226 tray_action()->SendNewNoteRequest(); | 581 tray_action()->SendNewNoteRequest(); |
| 227 state_controller()->FlushTrayActionForTesting(); | 582 state_controller()->FlushTrayActionForTesting(); |
| 228 | 583 |
| 229 EXPECT_EQ(TrayActionState::kActive, | 584 EXPECT_EQ(TrayActionState::kLaunching, |
| 230 state_controller()->GetLockScreenNoteState()); | 585 state_controller()->GetLockScreenNoteState()); |
| 231 ASSERT_EQ(1u, observer()->observed_states().size()); | 586 ASSERT_EQ(1u, observer()->observed_states().size()); |
| 232 EXPECT_EQ(TrayActionState::kActive, observer()->observed_states()[0]); | 587 EXPECT_EQ(TrayActionState::kLaunching, observer()->observed_states()[0]); |
| 233 observer()->ClearObservedStates(); | 588 observer()->ClearObservedStates(); |
| 234 ASSERT_EQ(1u, tray_action()->observed_states().size()); | 589 ASSERT_EQ(1u, tray_action()->observed_states().size()); |
| 235 EXPECT_EQ(TrayActionState::kActive, tray_action()->observed_states()[0]); | 590 EXPECT_EQ(TrayActionState::kLaunching, tray_action()->observed_states()[0]); |
| 236 tray_action()->ClearObservedStates(); | 591 tray_action()->ClearObservedStates(); |
| 237 | 592 |
| 593 EXPECT_EQ(1, app_manager()->launch_count()); | |
| 594 | |
| 238 tray_action()->SendNewNoteRequest(); | 595 tray_action()->SendNewNoteRequest(); |
| 239 state_controller()->FlushTrayActionForTesting(); | 596 state_controller()->FlushTrayActionForTesting(); |
| 240 | 597 |
| 241 // There should be no state change - the state_controller was already in | 598 // There should be no state change - the state_controller was already in |
| 242 // active state when the request was received. | 599 // launching state when the request was received. |
| 243 EXPECT_EQ(0u, observer()->observed_states().size()); | 600 EXPECT_EQ(0u, observer()->observed_states().size()); |
| 244 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 601 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
| 602 EXPECT_EQ(1, app_manager()->launch_count()); | |
| 245 } | 603 } |
| 604 | |
| 605 TEST_F(LockScreenAppStateTest, HandleActionWithLaunchFailure) { | |
| 606 ASSERT_TRUE(EnableNoteTakingApp(false /* enable_app_launch */)); | |
| 607 | |
| 608 tray_action()->SendNewNoteRequest(); | |
| 609 state_controller()->FlushTrayActionForTesting(); | |
| 610 | |
| 611 EXPECT_EQ(TrayActionState::kAvailable, | |
| 612 state_controller()->GetLockScreenNoteState()); | |
| 613 ASSERT_EQ(2u, observer()->observed_states().size()); | |
| 614 EXPECT_EQ(TrayActionState::kLaunching, observer()->observed_states()[0]); | |
| 615 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[1]); | |
| 616 observer()->ClearObservedStates(); | |
| 617 ASSERT_EQ(2u, tray_action()->observed_states().size()); | |
| 618 EXPECT_EQ(TrayActionState::kLaunching, tray_action()->observed_states()[0]); | |
| 619 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[1]); | |
| 620 tray_action()->ClearObservedStates(); | |
| 621 | |
| 622 EXPECT_EQ(1, app_manager()->launch_count()); | |
| 623 | |
| 624 tray_action()->SendNewNoteRequest(); | |
| 625 state_controller()->FlushTrayActionForTesting(); | |
| 626 | |
| 627 EXPECT_EQ(TrayActionState::kAvailable, | |
| 628 state_controller()->GetLockScreenNoteState()); | |
| 629 | |
| 630 // There should be no state change - the state_controller was already in | |
| 631 // launching state when the request was received. | |
| 632 EXPECT_EQ(2u, observer()->observed_states().size()); | |
| 633 EXPECT_EQ(2u, tray_action()->observed_states().size()); | |
| 634 EXPECT_EQ(2, app_manager()->launch_count()); | |
| 635 } | |
| OLD | NEW |