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

Side by Side Diff: chrome/browser/chromeos/lock_screen_apps/state_controller_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698