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 <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/public/interfaces/tray_action.mojom.h" | 12 #include "ash/public/interfaces/tray_action.mojom.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/run_loop.h" | |
16 #include "base/test/scoped_command_line.h" | 15 #include "base/test/scoped_command_line.h" |
17 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" | 16 #include "chrome/browser/chromeos/lock_screen_apps/app_manager.h" |
18 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" | 17 #include "chrome/browser/chromeos/lock_screen_apps/state_observer.h" |
18 #include "chrome/browser/extensions/extension_service.h" | |
19 #include "chrome/browser/extensions/test_extension_system.h" | |
20 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | |
19 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/test/base/browser_with_test_window_test.h" | |
20 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
21 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
22 #include "chrome/test/base/testing_profile_manager.h" | 25 #include "chrome/test/base/testing_profile_manager.h" |
23 #include "components/session_manager/core/session_manager.h" | 26 #include "components/session_manager/core/session_manager.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_observer.h" | |
29 #include "content/public/test/test_utils.h" | |
30 #include "content/public/test/web_contents_tester.h" | |
31 #include "extensions/browser/app_window/app_window.h" | |
32 #include "extensions/browser/app_window/app_window_contents.h" | |
33 #include "extensions/browser/app_window/native_app_window.h" | |
34 #include "extensions/common/api/app_runtime.h" | |
35 #include "extensions/common/extension_builder.h" | |
36 #include "extensions/common/value_builder.h" | |
25 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
26 | 38 |
27 using ash::mojom::TrayActionState; | 39 using ash::mojom::TrayActionState; |
28 | 40 |
29 namespace { | 41 namespace { |
30 | 42 |
43 // App IDs used for test apps. | |
44 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | |
45 const char kSecondaryTestAppId[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | |
46 | |
47 scoped_refptr<extensions::Extension> CreateTestNoteTakingApp( | |
48 const std::string& app_id) { | |
49 return extensions::ExtensionBuilder() | |
50 .SetManifest( | |
51 extensions::DictionaryBuilder() | |
52 .Set("name", "Test App") | |
53 .Set("version", "1.0") | |
54 .Set("manifest_version", 2) | |
55 .Set("app", | |
56 extensions::DictionaryBuilder() | |
57 .Set("background", | |
58 extensions::DictionaryBuilder() | |
59 .Set("scripts", extensions::ListBuilder() | |
60 .Append("background.js") | |
61 .Build()) | |
62 .Build()) | |
63 .Build()) | |
64 .Set("action_handlers", | |
65 extensions::ListBuilder() | |
66 .Append(extensions::DictionaryBuilder() | |
67 .Set("action", "new_note") | |
68 .SetBoolean("enabled_on_lock_screen", true) | |
69 .Build()) | |
70 .Build()) | |
71 .Build()) | |
72 .SetID(app_id) | |
73 .Build(); | |
74 } | |
75 | |
31 class TestAppManager : public lock_screen_apps::AppManager { | 76 class TestAppManager : public lock_screen_apps::AppManager { |
32 public: | 77 public: |
33 enum class State { | 78 enum class State { |
34 kNotInitialized, | 79 kNotInitialized, |
35 kStarted, | 80 kStarted, |
36 kStopped, | 81 kStopped, |
37 }; | 82 }; |
38 | 83 |
39 TestAppManager(Profile* expected_primary_profile, | 84 TestAppManager(Profile* expected_primary_profile, |
40 Profile* expected_lock_screen_profile) | 85 Profile* expected_lock_screen_profile) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 221 |
177 private: | 222 private: |
178 mojo::Binding<ash::mojom::TrayAction> binding_; | 223 mojo::Binding<ash::mojom::TrayAction> binding_; |
179 ash::mojom::TrayActionClientPtr client_; | 224 ash::mojom::TrayActionClientPtr client_; |
180 | 225 |
181 std::vector<TrayActionState> observed_states_; | 226 std::vector<TrayActionState> observed_states_; |
182 | 227 |
183 DISALLOW_COPY_AND_ASSIGN(TestTrayAction); | 228 DISALLOW_COPY_AND_ASSIGN(TestTrayAction); |
184 }; | 229 }; |
185 | 230 |
231 class TestAppWindow : public content::WebContentsObserver { | |
232 public: | |
233 TestAppWindow(Profile* profile, const extensions::Extension* extension) | |
234 : web_contents_( | |
235 content::WebContentsTester::CreateTestWebContents(profile, | |
236 nullptr)), | |
237 window_(new extensions::AppWindow(profile, | |
238 new ChromeAppDelegate(true), | |
239 extension)) {} | |
240 | |
241 ~TestAppWindow() override { | |
242 // Make sure the window is initialized, so |window_| does not get leaked. | |
243 if (!initialized_) | |
244 Initialize(false /* shown */); | |
245 | |
246 Close(); | |
247 } | |
248 | |
249 void Initialize(bool shown) { | |
250 ASSERT_FALSE(initialized_); | |
251 initialized_ = true; | |
252 | |
253 extensions::AppWindow::CreateParams params; | |
254 params.hidden = !shown; | |
255 window_->Init(GURL(std::string()), | |
256 new extensions::AppWindowContentsImpl(window_), | |
257 web_contents_->GetMainFrame(), params); | |
258 Observe(window_->web_contents()); | |
259 } | |
260 | |
261 void Close() { | |
262 if (!window_) | |
263 return; | |
264 | |
265 if (!initialized_) | |
266 return; | |
267 | |
268 content::WebContentsDestroyedWatcher destroyed_watcher( | |
269 window_->web_contents()); | |
270 window_->GetBaseWindow()->Close(); | |
271 destroyed_watcher.Wait(); | |
272 | |
273 EXPECT_FALSE(window_); | |
274 EXPECT_TRUE(closed_); | |
275 } | |
276 | |
277 void WebContentsDestroyed() override { | |
278 closed_ = true; | |
279 window_ = nullptr; | |
280 } | |
281 | |
282 extensions::AppWindow* window() { return window_; } | |
283 | |
284 bool closed() const { return closed_; } | |
285 | |
286 private: | |
287 std::unique_ptr<content::WebContents> web_contents_; | |
288 extensions::AppWindow* window_; | |
289 bool closed_ = false; | |
290 bool initialized_ = false; | |
291 | |
292 DISALLOW_COPY_AND_ASSIGN(TestAppWindow); | |
293 }; | |
294 | |
186 class LockScreenAppStateNotSupportedTest : public testing::Test { | 295 class LockScreenAppStateNotSupportedTest : public testing::Test { |
187 public: | 296 public: |
188 LockScreenAppStateNotSupportedTest() = default; | 297 LockScreenAppStateNotSupportedTest() = default; |
189 | 298 |
190 ~LockScreenAppStateNotSupportedTest() override = default; | 299 ~LockScreenAppStateNotSupportedTest() override = default; |
191 | 300 |
192 void SetUp() override { | 301 void SetUp() override { |
193 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); | 302 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
194 command_line_->GetProcessCommandLine()->InitFromArgv({""}); | 303 command_line_->GetProcessCommandLine()->InitFromArgv({""}); |
195 } | 304 } |
196 | 305 |
197 private: | 306 private: |
198 std::unique_ptr<base::test::ScopedCommandLine> command_line_; | 307 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
199 | 308 |
200 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateNotSupportedTest); | 309 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateNotSupportedTest); |
201 }; | 310 }; |
202 | 311 |
203 class LockScreenAppStateTest : public testing::Test { | 312 class LockScreenAppStateTest : public BrowserWithTestWindowTest { |
204 public: | 313 public: |
205 LockScreenAppStateTest() | 314 LockScreenAppStateTest() |
206 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} | 315 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
207 ~LockScreenAppStateTest() override = default; | 316 ~LockScreenAppStateTest() override = default; |
208 | 317 |
209 void SetUp() override { | 318 void SetUp() override { |
210 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); | 319 command_line_ = base::MakeUnique<base::test::ScopedCommandLine>(); |
211 command_line_->GetProcessCommandLine()->InitFromArgv( | 320 command_line_->GetProcessCommandLine()->InitFromArgv( |
212 {"", "--enable-lock-screen-apps"}); | 321 {"", "--enable-lock-screen-apps"}); |
213 | 322 |
214 ASSERT_TRUE(profile_manager_.SetUp()); | 323 ASSERT_TRUE(profile_manager_.SetUp()); |
215 | 324 |
325 BrowserWithTestWindowTest::SetUp(); | |
326 | |
216 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); | 327 session_manager_ = base::MakeUnique<session_manager::SessionManager>(); |
217 session_manager_->SetSessionState( | 328 session_manager_->SetSessionState( |
218 session_manager::SessionState::LOGIN_PRIMARY); | 329 session_manager::SessionState::LOGIN_PRIMARY); |
219 | 330 |
220 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); | 331 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled()); |
221 | 332 |
222 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); | 333 state_controller_ = base::MakeUnique<lock_screen_apps::StateController>(); |
223 state_controller_->SetTrayActionPtrForTesting( | 334 state_controller_->SetTrayActionPtrForTesting( |
224 tray_action_.CreateInterfacePtrAndBind()); | 335 tray_action_.CreateInterfacePtrAndBind()); |
225 state_controller_->Initialize(); | 336 state_controller_->Initialize(); |
226 state_controller_->FlushTrayActionForTesting(); | 337 state_controller_->FlushTrayActionForTesting(); |
227 | 338 |
228 state_controller_->AddObserver(&observer_); | 339 state_controller_->AddObserver(&observer_); |
229 | 340 |
230 // Create fake sign-in profile. | 341 // Create fake sign-in profile. |
231 TestingProfile::Builder builder; | 342 TestingProfile::Builder builder; |
232 builder.SetPath( | 343 builder.SetPath( |
233 profile_manager_.profiles_dir().AppendASCII(chrome::kInitialProfile)); | 344 profile_manager_.profiles_dir().AppendASCII(chrome::kInitialProfile)); |
234 TestingProfile* signin_profile = builder.BuildIncognito( | 345 signin_profile_ = builder.BuildIncognito( |
235 profile_manager_.CreateTestingProfile(chrome::kInitialProfile)); | 346 profile_manager_.CreateTestingProfile(chrome::kInitialProfile)); |
236 | 347 |
348 InitExtensionSystem(profile()); | |
349 InitExtensionSystem(signin_profile()); | |
350 | |
237 std::unique_ptr<TestAppManager> app_manager = | 351 std::unique_ptr<TestAppManager> app_manager = |
238 base::MakeUnique<TestAppManager>(&profile_, | 352 base::MakeUnique<TestAppManager>(&profile_, |
239 signin_profile->GetOriginalProfile()); | 353 signin_profile_->GetOriginalProfile()); |
240 app_manager_ = app_manager.get(); | 354 app_manager_ = app_manager.get(); |
241 state_controller_->SetAppManagerForTesting(std::move(app_manager)); | 355 state_controller_->SetAppManagerForTesting(std::move(app_manager)); |
242 } | 356 } |
243 | 357 |
244 void TearDown() override { | 358 void TearDown() override { |
359 extensions::ExtensionSystem::Get(profile())->Shutdown(); | |
360 extensions::ExtensionSystem::Get(signin_profile())->Shutdown(); | |
361 | |
245 state_controller_->RemoveObserver(&observer_); | 362 state_controller_->RemoveObserver(&observer_); |
246 state_controller_.reset(); | 363 state_controller_.reset(); |
247 session_manager_.reset(); | 364 session_manager_.reset(); |
248 app_manager_ = nullptr; | 365 app_manager_ = nullptr; |
366 BrowserWithTestWindowTest::TearDown(); | |
249 } | 367 } |
250 | 368 |
251 // Helper method to move state controller to available state. | 369 void InitExtensionSystem(Profile* profile) { |
370 extensions::TestExtensionSystem* extension_system = | |
371 static_cast<extensions::TestExtensionSystem*>( | |
372 extensions::ExtensionSystem::Get(profile)); | |
373 extension_system->CreateExtensionService( | |
374 base::CommandLine::ForCurrentProcess(), | |
375 base::FilePath() /* install_directory */, | |
376 false /* autoupdate_enabled */); | |
377 } | |
378 | |
379 void ExpectObservedStatesMatch(const std::vector<TrayActionState>& states, | |
380 const std::string& message) { | |
381 state_controller_->FlushTrayActionForTesting(); | |
382 EXPECT_EQ(states, observer()->observed_states()) << message; | |
383 EXPECT_EQ(states, tray_action()->observed_states()) << message; | |
384 } | |
385 | |
386 void ClearObservedStates() { | |
387 state_controller_->FlushTrayActionForTesting(); | |
388 observer_.ClearObservedStates(); | |
389 tray_action_.ClearObservedStates(); | |
390 } | |
391 | |
392 // Helper method to move state controller to the specified state. | |
252 // Should be called at the begining of tests, at most once. | 393 // Should be called at the begining of tests, at most once. |
253 bool EnableNoteTakingApp(bool enable_app_launch) { | 394 bool InitializeNoteTakingApp(TrayActionState target_state, |
254 app_manager_->SetInitialAppState("test_app_id", enable_app_launch); | 395 bool enable_app_launch) { |
396 app_ = CreateTestNoteTakingApp(kTestAppId); | |
397 extensions::ExtensionSystem::Get(signin_profile()) | |
398 ->extension_service() | |
399 ->AddExtension(app_.get()); | |
400 | |
401 app_manager_->SetInitialAppState(kTestAppId, enable_app_launch); | |
255 state_controller_->SetPrimaryProfile(&profile_); | 402 state_controller_->SetPrimaryProfile(&profile_); |
403 | |
404 if (target_state == TrayActionState::kNotAvailable) | |
405 return true; | |
406 | |
256 session_manager_->SetSessionState(session_manager::SessionState::LOCKED); | 407 session_manager_->SetSessionState(session_manager::SessionState::LOCKED); |
257 if (app_manager_->state() != TestAppManager::State::kStarted) { | 408 if (app_manager_->state() != TestAppManager::State::kStarted) { |
258 ADD_FAILURE() << "Lock app manager Start not invoked."; | 409 ADD_FAILURE() << "Lock app manager Start not invoked."; |
259 return false; | 410 return false; |
260 } | 411 } |
412 | |
413 ClearObservedStates(); | |
414 | |
415 if (state_controller_->GetLockScreenNoteState() != | |
416 TrayActionState::kAvailable) { | |
417 ADD_FAILURE() << "Unable to move to available state."; | |
418 return false; | |
419 } | |
420 if (target_state == TrayActionState::kAvailable) | |
421 return true; | |
422 | |
423 tray_action()->SendNewNoteRequest(); | |
261 state_controller_->FlushTrayActionForTesting(); | 424 state_controller_->FlushTrayActionForTesting(); |
262 | 425 |
263 observer_.ClearObservedStates(); | 426 ClearObservedStates(); |
264 tray_action_.ClearObservedStates(); | |
265 | 427 |
266 return state_controller_->GetLockScreenNoteState() == | 428 if (state_controller_->GetLockScreenNoteState() != |
267 TrayActionState::kAvailable; | 429 TrayActionState::kLaunching) { |
430 ADD_FAILURE() << "Unable to move to launching state."; | |
431 return false; | |
432 } | |
433 if (target_state == TrayActionState::kLaunching) | |
434 return true; | |
435 | |
436 app_window_ = base::MakeUnique<TestAppWindow>(signin_profile(), app()); | |
437 if (!state_controller_->CanCreateAppWindowForAction( | |
benwells
2017/06/13 10:30:46
This call feels a bit redundant,as RegisterAppWind
tbarzic
2017/06/13 19:17:59
Done.
| |
438 signin_profile(), app(), | |
439 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)) { | |
440 ADD_FAILURE() << "Not allowed to create app window."; | |
441 return false; | |
442 } | |
443 if (!state_controller_->RegisterAppWindowForAction( | |
444 app_window()->window(), | |
445 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)) { | |
446 ADD_FAILURE() << "Failed to register app window."; | |
447 return false; | |
448 } | |
449 | |
450 app_window()->Initialize(true /* shown */); | |
451 | |
452 ClearObservedStates(); | |
453 | |
454 return state_controller()->GetLockScreenNoteState() == | |
455 TrayActionState::kActive; | |
268 } | 456 } |
269 | 457 |
270 TestingProfile* profile() { return &profile_; } | 458 TestingProfile* profile() { return &profile_; } |
459 TestingProfile* signin_profile() { return signin_profile_; } | |
271 | 460 |
272 session_manager::SessionManager* session_manager() { | 461 session_manager::SessionManager* session_manager() { |
273 return session_manager_.get(); | 462 return session_manager_.get(); |
274 } | 463 } |
275 | 464 |
276 TestStateObserver* observer() { return &observer_; } | 465 TestStateObserver* observer() { return &observer_; } |
277 | 466 |
278 TestTrayAction* tray_action() { return &tray_action_; } | 467 TestTrayAction* tray_action() { return &tray_action_; } |
279 | 468 |
280 lock_screen_apps::StateController* state_controller() { | 469 lock_screen_apps::StateController* state_controller() { |
281 return state_controller_.get(); | 470 return state_controller_.get(); |
282 } | 471 } |
283 | 472 |
284 TestAppManager* app_manager() { return app_manager_; } | 473 TestAppManager* app_manager() { return app_manager_; } |
285 | 474 |
475 TestAppWindow* app_window() { return app_window_.get(); } | |
476 const extensions::Extension* app() { return app_.get(); } | |
477 | |
286 private: | 478 private: |
287 std::unique_ptr<base::test::ScopedCommandLine> command_line_; | 479 std::unique_ptr<base::test::ScopedCommandLine> command_line_; |
288 content::TestBrowserThreadBundle threads_; | |
289 TestingProfileManager profile_manager_; | 480 TestingProfileManager profile_manager_; |
290 TestingProfile profile_; | 481 TestingProfile profile_; |
482 TestingProfile* signin_profile_ = nullptr; | |
291 | 483 |
292 std::unique_ptr<session_manager::SessionManager> session_manager_; | 484 std::unique_ptr<session_manager::SessionManager> session_manager_; |
293 | 485 |
294 std::unique_ptr<lock_screen_apps::StateController> state_controller_; | 486 std::unique_ptr<lock_screen_apps::StateController> state_controller_; |
295 | 487 |
296 TestStateObserver observer_; | 488 TestStateObserver observer_; |
297 TestTrayAction tray_action_; | 489 TestTrayAction tray_action_; |
298 TestAppManager* app_manager_ = nullptr; | 490 TestAppManager* app_manager_ = nullptr; |
299 | 491 |
492 std::unique_ptr<TestAppWindow> app_window_; | |
493 scoped_refptr<const extensions::Extension> app_; | |
494 | |
300 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateTest); | 495 DISALLOW_COPY_AND_ASSIGN(LockScreenAppStateTest); |
301 }; | 496 }; |
302 | 497 |
303 } // namespace | 498 } // namespace |
304 | 499 |
305 TEST_F(LockScreenAppStateNotSupportedTest, NoInstance) { | 500 TEST_F(LockScreenAppStateNotSupportedTest, NoInstance) { |
306 EXPECT_FALSE(lock_screen_apps::StateController::IsEnabled()); | 501 EXPECT_FALSE(lock_screen_apps::StateController::IsEnabled()); |
307 } | 502 } |
308 | 503 |
309 TEST_F(LockScreenAppStateTest, InitialState) { | 504 TEST_F(LockScreenAppStateTest, InitialState) { |
(...skipping 20 matching lines...) Expand all Loading... | |
330 EXPECT_EQ(0u, observer()->observed_states().size()); | 525 EXPECT_EQ(0u, observer()->observed_states().size()); |
331 } | 526 } |
332 | 527 |
333 TEST_F(LockScreenAppStateTest, SetPrimaryProfileWhenSessionLocked) { | 528 TEST_F(LockScreenAppStateTest, SetPrimaryProfileWhenSessionLocked) { |
334 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 529 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
335 EXPECT_EQ(TrayActionState::kNotAvailable, | 530 EXPECT_EQ(TrayActionState::kNotAvailable, |
336 state_controller()->GetLockScreenNoteState()); | 531 state_controller()->GetLockScreenNoteState()); |
337 | 532 |
338 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); | 533 EXPECT_EQ(TestAppManager::State::kNotInitialized, app_manager()->state()); |
339 | 534 |
340 app_manager()->SetInitialAppState("app_id", true); | 535 app_manager()->SetInitialAppState(kTestAppId, true); |
341 state_controller()->SetPrimaryProfile(profile()); | 536 state_controller()->SetPrimaryProfile(profile()); |
342 | 537 |
343 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 538 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
344 | 539 |
345 EXPECT_EQ(TrayActionState::kAvailable, | 540 EXPECT_EQ(TrayActionState::kAvailable, |
346 state_controller()->GetLockScreenNoteState()); | 541 state_controller()->GetLockScreenNoteState()); |
347 | 542 |
348 state_controller()->FlushTrayActionForTesting(); | 543 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
349 ASSERT_EQ(1u, observer()->observed_states().size()); | |
350 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
351 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
352 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
353 } | 544 } |
354 | 545 |
355 TEST_F(LockScreenAppStateTest, SessionLock) { | 546 TEST_F(LockScreenAppStateTest, SessionLock) { |
356 app_manager()->SetInitialAppState("app_id", true); | 547 app_manager()->SetInitialAppState(kTestAppId, true); |
357 state_controller()->SetPrimaryProfile(profile()); | 548 state_controller()->SetPrimaryProfile(profile()); |
358 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 549 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
359 | 550 |
360 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 551 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
361 | 552 |
362 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 553 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
363 | 554 |
364 EXPECT_EQ(TrayActionState::kAvailable, | 555 EXPECT_EQ(TrayActionState::kAvailable, |
365 state_controller()->GetLockScreenNoteState()); | 556 state_controller()->GetLockScreenNoteState()); |
366 state_controller()->FlushTrayActionForTesting(); | 557 |
367 ASSERT_EQ(1u, observer()->observed_states().size()); | 558 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
368 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | 559 ClearObservedStates(); |
369 observer()->ClearObservedStates(); | |
370 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
371 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
372 tray_action()->ClearObservedStates(); | |
373 | 560 |
374 // When the session is unlocked again, app manager is stopped, and tray action | 561 // When the session is unlocked again, app manager is stopped, and tray action |
375 // disabled again. | 562 // disabled again. |
376 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | 563 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); |
377 | 564 |
378 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 565 EXPECT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
379 | 566 |
380 EXPECT_EQ(TrayActionState::kNotAvailable, | 567 EXPECT_EQ(TrayActionState::kNotAvailable, |
381 state_controller()->GetLockScreenNoteState()); | 568 state_controller()->GetLockScreenNoteState()); |
382 state_controller()->FlushTrayActionForTesting(); | 569 |
383 ASSERT_EQ(1u, observer()->observed_states().size()); | 570 ExpectObservedStatesMatch({TrayActionState::kNotAvailable}, |
384 EXPECT_EQ(TrayActionState::kNotAvailable, observer()->observed_states()[0]); | 571 "Not available on unlock"); |
385 observer()->ClearObservedStates(); | 572 ClearObservedStates(); |
386 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
387 EXPECT_EQ(TrayActionState::kNotAvailable, | |
388 tray_action()->observed_states()[0]); | |
389 tray_action()->ClearObservedStates(); | |
390 | 573 |
391 // Test that subsequent session lock works as expected. | 574 // Test that subsequent session lock works as expected. |
392 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 575 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
393 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 576 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
394 | 577 ExpectObservedStatesMatch({TrayActionState::kAvailable}, |
395 EXPECT_EQ(TrayActionState::kAvailable, | 578 "Available on second lock"); |
396 state_controller()->GetLockScreenNoteState()); | |
397 state_controller()->FlushTrayActionForTesting(); | |
398 ASSERT_EQ(1u, observer()->observed_states().size()); | |
399 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
400 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
401 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
402 } | 579 } |
403 | 580 |
404 TEST_F(LockScreenAppStateTest, SessionUnlockedWhileStartingAppManager) { | 581 TEST_F(LockScreenAppStateTest, SessionUnlockedWhileStartingAppManager) { |
405 state_controller()->SetPrimaryProfile(profile()); | 582 state_controller()->SetPrimaryProfile(profile()); |
406 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 583 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
407 | 584 |
408 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 585 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
409 | 586 |
410 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 587 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
411 | 588 |
412 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | 589 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); |
413 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 590 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
414 | 591 |
415 EXPECT_EQ(TrayActionState::kNotAvailable, | 592 EXPECT_EQ(TrayActionState::kNotAvailable, |
416 state_controller()->GetLockScreenNoteState()); | 593 state_controller()->GetLockScreenNoteState()); |
417 state_controller()->FlushTrayActionForTesting(); | 594 state_controller()->FlushTrayActionForTesting(); |
418 EXPECT_EQ(0u, observer()->observed_states().size()); | 595 EXPECT_EQ(0u, observer()->observed_states().size()); |
419 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 596 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
420 | 597 |
421 // Test that subsequent session lock works as expected. | 598 // Test that subsequent session lock works as expected. |
422 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 599 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
423 | 600 |
424 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 601 ASSERT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
425 app_manager()->UpdateApp("app_id", true); | 602 app_manager()->UpdateApp(kTestAppId, true); |
426 | 603 |
427 EXPECT_EQ(TrayActionState::kAvailable, | 604 EXPECT_EQ(TrayActionState::kAvailable, |
428 state_controller()->GetLockScreenNoteState()); | 605 state_controller()->GetLockScreenNoteState()); |
429 state_controller()->FlushTrayActionForTesting(); | 606 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
430 ASSERT_EQ(1u, observer()->observed_states().size()); | |
431 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
432 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
433 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
434 } | 607 } |
435 | 608 |
436 TEST_F(LockScreenAppStateTest, AppManagerNoApp) { | 609 TEST_F(LockScreenAppStateTest, AppManagerNoApp) { |
437 state_controller()->SetPrimaryProfile(profile()); | 610 state_controller()->SetPrimaryProfile(profile()); |
438 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 611 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
439 | 612 |
440 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 613 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
441 | 614 |
442 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 615 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
443 | 616 |
444 EXPECT_EQ(TrayActionState::kNotAvailable, | 617 EXPECT_EQ(TrayActionState::kNotAvailable, |
445 state_controller()->GetLockScreenNoteState()); | 618 state_controller()->GetLockScreenNoteState()); |
446 state_controller()->FlushTrayActionForTesting(); | 619 state_controller()->FlushTrayActionForTesting(); |
447 EXPECT_EQ(0u, observer()->observed_states().size()); | 620 EXPECT_EQ(0u, observer()->observed_states().size()); |
448 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 621 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
449 | 622 |
450 tray_action()->SendNewNoteRequest(); | 623 tray_action()->SendNewNoteRequest(); |
451 | 624 |
452 EXPECT_EQ(TrayActionState::kNotAvailable, | 625 EXPECT_EQ(TrayActionState::kNotAvailable, |
453 state_controller()->GetLockScreenNoteState()); | 626 state_controller()->GetLockScreenNoteState()); |
454 state_controller()->FlushTrayActionForTesting(); | 627 state_controller()->FlushTrayActionForTesting(); |
455 EXPECT_EQ(0u, observer()->observed_states().size()); | 628 EXPECT_EQ(0u, observer()->observed_states().size()); |
456 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 629 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
457 | 630 |
458 // App manager should be started on next session lock. | 631 // App manager should be started on next session lock. |
459 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | 632 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); |
460 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 633 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
461 app_manager()->SetInitialAppState("app_id", false); | 634 app_manager()->SetInitialAppState(kTestAppId, false); |
462 | 635 |
463 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 636 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
464 | 637 |
465 EXPECT_EQ(TrayActionState::kAvailable, | 638 EXPECT_EQ(TrayActionState::kAvailable, |
466 state_controller()->GetLockScreenNoteState()); | 639 state_controller()->GetLockScreenNoteState()); |
467 state_controller()->FlushTrayActionForTesting(); | 640 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
468 ASSERT_EQ(1u, observer()->observed_states().size()); | |
469 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
470 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
471 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
472 } | 641 } |
473 | 642 |
474 TEST_F(LockScreenAppStateTest, AppAvailabilityChanges) { | 643 TEST_F(LockScreenAppStateTest, AppAvailabilityChanges) { |
475 state_controller()->SetPrimaryProfile(profile()); | 644 state_controller()->SetPrimaryProfile(profile()); |
476 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); | 645 ASSERT_EQ(TestAppManager::State::kStopped, app_manager()->state()); |
477 | 646 |
478 app_manager()->SetInitialAppState("app_id", false); | 647 app_manager()->SetInitialAppState(kTestAppId, false); |
479 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); | 648 session_manager()->SetSessionState(session_manager::SessionState::LOCKED); |
480 | 649 |
481 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); | 650 EXPECT_EQ(TestAppManager::State::kStarted, app_manager()->state()); |
482 | 651 |
483 EXPECT_EQ(TrayActionState::kAvailable, | 652 EXPECT_EQ(TrayActionState::kAvailable, |
484 state_controller()->GetLockScreenNoteState()); | 653 state_controller()->GetLockScreenNoteState()); |
485 state_controller()->FlushTrayActionForTesting(); | 654 ExpectObservedStatesMatch({TrayActionState::kAvailable}, "Available on lock"); |
486 ASSERT_EQ(1u, observer()->observed_states().size()); | 655 ClearObservedStates(); |
487 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
488 observer()->ClearObservedStates(); | |
489 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
490 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
491 tray_action()->ClearObservedStates(); | |
492 | 656 |
493 app_manager()->UpdateApp("", false); | 657 app_manager()->UpdateApp("", false); |
494 | 658 |
495 EXPECT_EQ(TrayActionState::kNotAvailable, | 659 EXPECT_EQ(TrayActionState::kNotAvailable, |
496 state_controller()->GetLockScreenNoteState()); | 660 state_controller()->GetLockScreenNoteState()); |
497 state_controller()->FlushTrayActionForTesting(); | 661 ExpectObservedStatesMatch({TrayActionState::kNotAvailable}, |
498 ASSERT_EQ(1u, observer()->observed_states().size()); | 662 "Not available on app cleared"); |
499 EXPECT_EQ(TrayActionState::kNotAvailable, observer()->observed_states()[0]); | 663 ClearObservedStates(); |
500 observer()->ClearObservedStates(); | |
501 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
502 EXPECT_EQ(TrayActionState::kNotAvailable, | |
503 tray_action()->observed_states()[0]); | |
504 tray_action()->ClearObservedStates(); | |
505 | 664 |
506 app_manager()->UpdateApp("app_id_1", true); | 665 app_manager()->UpdateApp(kSecondaryTestAppId, true); |
507 | 666 |
508 EXPECT_EQ(TrayActionState::kAvailable, | 667 EXPECT_EQ(TrayActionState::kAvailable, |
509 state_controller()->GetLockScreenNoteState()); | 668 state_controller()->GetLockScreenNoteState()); |
510 state_controller()->FlushTrayActionForTesting(); | 669 ExpectObservedStatesMatch({TrayActionState::kAvailable}, |
511 ASSERT_EQ(1u, observer()->observed_states().size()); | 670 "Available on other app set"); |
512 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[0]); | |
513 observer()->ClearObservedStates(); | |
514 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
515 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[0]); | |
516 tray_action()->ClearObservedStates(); | |
517 } | 671 } |
518 | 672 |
519 TEST_F(LockScreenAppStateTest, MoveToBackgroundFromActive) { | 673 TEST_F(LockScreenAppStateTest, MoveToBackgroundAndForeground) { |
520 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | 674 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, |
521 | 675 true /* enable_app_launch */)); |
522 state_controller()->SetLockScreenNoteStateForTesting( | |
523 TrayActionState::kActive); | |
524 | 676 |
525 state_controller()->MoveToBackground(); | 677 state_controller()->MoveToBackground(); |
526 state_controller()->FlushTrayActionForTesting(); | 678 state_controller()->FlushTrayActionForTesting(); |
527 | 679 |
528 EXPECT_EQ(TrayActionState::kBackground, | 680 EXPECT_EQ(TrayActionState::kBackground, |
529 state_controller()->GetLockScreenNoteState()); | 681 state_controller()->GetLockScreenNoteState()); |
530 | 682 |
531 ASSERT_EQ(1u, observer()->observed_states().size()); | 683 ExpectObservedStatesMatch({TrayActionState::kBackground}, |
532 EXPECT_EQ(TrayActionState::kBackground, observer()->observed_states()[0]); | 684 "Move to background"); |
533 ASSERT_EQ(1u, tray_action()->observed_states().size()); | 685 ClearObservedStates(); |
534 EXPECT_EQ(TrayActionState::kBackground, tray_action()->observed_states()[0]); | |
535 } | |
536 | 686 |
537 TEST_F(LockScreenAppStateTest, MoveToForeground) { | 687 base::RunLoop().RunUntilIdle(); |
538 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | 688 EXPECT_FALSE(app_window()->closed()); |
539 | |
540 state_controller()->SetLockScreenNoteStateForTesting( | |
541 TrayActionState::kBackground); | |
542 | 689 |
543 state_controller()->MoveToForeground(); | 690 state_controller()->MoveToForeground(); |
544 state_controller()->FlushTrayActionForTesting(); | 691 state_controller()->FlushTrayActionForTesting(); |
545 | 692 |
546 EXPECT_EQ(TrayActionState::kActive, | 693 EXPECT_EQ(TrayActionState::kActive, |
547 state_controller()->GetLockScreenNoteState()); | 694 state_controller()->GetLockScreenNoteState()); |
548 | 695 |
549 ASSERT_EQ(1u, observer()->observed_states().size()); | 696 ExpectObservedStatesMatch({TrayActionState::kActive}, "Move to foreground"); |
550 EXPECT_EQ(TrayActionState::kActive, observer()->observed_states()[0]); | 697 |
551 ASSERT_EQ(1u, tray_action()->observed_states().size()); | 698 base::RunLoop().RunUntilIdle(); |
552 EXPECT_EQ(TrayActionState::kActive, tray_action()->observed_states()[0]); | 699 EXPECT_FALSE(app_window()->closed()); |
553 } | 700 } |
554 | 701 |
555 TEST_F(LockScreenAppStateTest, MoveToForegroundFromNonBackgroundState) { | 702 TEST_F(LockScreenAppStateTest, MoveToForegroundFromNonBackgroundState) { |
556 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | 703 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, |
704 true /* enable_app_launch */)); | |
557 | 705 |
558 state_controller()->MoveToForeground(); | 706 state_controller()->MoveToForeground(); |
559 state_controller()->FlushTrayActionForTesting(); | 707 state_controller()->FlushTrayActionForTesting(); |
560 | 708 |
561 EXPECT_EQ(TrayActionState::kAvailable, | 709 EXPECT_EQ(TrayActionState::kAvailable, |
562 state_controller()->GetLockScreenNoteState()); | 710 state_controller()->GetLockScreenNoteState()); |
563 | 711 |
564 EXPECT_EQ(0u, observer()->observed_states().size()); | 712 EXPECT_EQ(0u, observer()->observed_states().size()); |
565 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 713 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
566 } | 714 } |
567 | 715 |
568 TEST_F(LockScreenAppStateTest, HandleActionWhenNotAvaiable) { | 716 TEST_F(LockScreenAppStateTest, HandleActionWhenNotAvaiable) { |
569 ASSERT_EQ(TrayActionState::kNotAvailable, | 717 ASSERT_EQ(TrayActionState::kNotAvailable, |
570 state_controller()->GetLockScreenNoteState()); | 718 state_controller()->GetLockScreenNoteState()); |
571 | 719 |
572 tray_action()->SendNewNoteRequest(); | 720 tray_action()->SendNewNoteRequest(); |
573 state_controller()->FlushTrayActionForTesting(); | 721 state_controller()->FlushTrayActionForTesting(); |
574 | 722 |
575 EXPECT_EQ(0u, observer()->observed_states().size()); | 723 EXPECT_EQ(0u, observer()->observed_states().size()); |
576 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 724 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
577 } | 725 } |
578 | 726 |
579 TEST_F(LockScreenAppStateTest, HandleAction) { | 727 TEST_F(LockScreenAppStateTest, HandleAction) { |
580 ASSERT_TRUE(EnableNoteTakingApp(true /* enable_app_launch */)); | 728 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, |
729 true /* enable_app_launch */)); | |
581 | 730 |
582 tray_action()->SendNewNoteRequest(); | 731 tray_action()->SendNewNoteRequest(); |
583 state_controller()->FlushTrayActionForTesting(); | 732 state_controller()->FlushTrayActionForTesting(); |
584 | 733 |
585 EXPECT_EQ(TrayActionState::kLaunching, | 734 ExpectObservedStatesMatch({TrayActionState::kLaunching}, |
586 state_controller()->GetLockScreenNoteState()); | 735 "Launch on new note request"); |
587 ASSERT_EQ(1u, observer()->observed_states().size()); | 736 ClearObservedStates(); |
588 EXPECT_EQ(TrayActionState::kLaunching, observer()->observed_states()[0]); | |
589 observer()->ClearObservedStates(); | |
590 ASSERT_EQ(1u, tray_action()->observed_states().size()); | |
591 EXPECT_EQ(TrayActionState::kLaunching, tray_action()->observed_states()[0]); | |
592 tray_action()->ClearObservedStates(); | |
593 | |
594 EXPECT_EQ(1, app_manager()->launch_count()); | 737 EXPECT_EQ(1, app_manager()->launch_count()); |
595 | 738 |
596 tray_action()->SendNewNoteRequest(); | 739 tray_action()->SendNewNoteRequest(); |
597 state_controller()->FlushTrayActionForTesting(); | 740 state_controller()->FlushTrayActionForTesting(); |
598 | 741 |
599 // There should be no state change - the state_controller was already in | 742 // There should be no state change - the state_controller was already in |
600 // launching state when the request was received. | 743 // launching state when the request was received. |
601 EXPECT_EQ(0u, observer()->observed_states().size()); | 744 EXPECT_EQ(0u, observer()->observed_states().size()); |
602 EXPECT_EQ(0u, tray_action()->observed_states().size()); | 745 EXPECT_EQ(0u, tray_action()->observed_states().size()); |
603 EXPECT_EQ(1, app_manager()->launch_count()); | 746 EXPECT_EQ(1, app_manager()->launch_count()); |
604 } | 747 } |
605 | 748 |
606 TEST_F(LockScreenAppStateTest, HandleActionWithLaunchFailure) { | 749 TEST_F(LockScreenAppStateTest, HandleActionWithLaunchFailure) { |
607 ASSERT_TRUE(EnableNoteTakingApp(false /* enable_app_launch */)); | 750 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, |
751 false /* enable_app_launch */)); | |
608 | 752 |
609 tray_action()->SendNewNoteRequest(); | 753 tray_action()->SendNewNoteRequest(); |
610 state_controller()->FlushTrayActionForTesting(); | 754 state_controller()->FlushTrayActionForTesting(); |
611 | 755 |
612 EXPECT_EQ(TrayActionState::kAvailable, | 756 EXPECT_EQ(TrayActionState::kAvailable, |
613 state_controller()->GetLockScreenNoteState()); | 757 state_controller()->GetLockScreenNoteState()); |
614 ASSERT_EQ(2u, observer()->observed_states().size()); | 758 ExpectObservedStatesMatch( |
615 EXPECT_EQ(TrayActionState::kLaunching, observer()->observed_states()[0]); | 759 {TrayActionState::kLaunching, TrayActionState::kAvailable}, |
616 EXPECT_EQ(TrayActionState::kAvailable, observer()->observed_states()[1]); | 760 "Failed launch on new note request"); |
617 observer()->ClearObservedStates(); | 761 ClearObservedStates(); |
618 ASSERT_EQ(2u, tray_action()->observed_states().size()); | |
619 EXPECT_EQ(TrayActionState::kLaunching, tray_action()->observed_states()[0]); | |
620 EXPECT_EQ(TrayActionState::kAvailable, tray_action()->observed_states()[1]); | |
621 tray_action()->ClearObservedStates(); | |
622 | 762 |
623 EXPECT_EQ(1, app_manager()->launch_count()); | 763 EXPECT_EQ(1, app_manager()->launch_count()); |
624 | 764 |
625 tray_action()->SendNewNoteRequest(); | 765 tray_action()->SendNewNoteRequest(); |
626 state_controller()->FlushTrayActionForTesting(); | 766 state_controller()->FlushTrayActionForTesting(); |
627 | 767 |
628 EXPECT_EQ(TrayActionState::kAvailable, | 768 EXPECT_EQ(TrayActionState::kAvailable, |
629 state_controller()->GetLockScreenNoteState()); | 769 state_controller()->GetLockScreenNoteState()); |
630 | 770 |
631 // There should be no state change - the state_controller was already in | 771 ExpectObservedStatesMatch( |
632 // launching state when the request was received. | 772 {TrayActionState::kLaunching, TrayActionState::kAvailable}, |
633 EXPECT_EQ(2u, observer()->observed_states().size()); | 773 "Second failed launch on new note request"); |
634 EXPECT_EQ(2u, tray_action()->observed_states().size()); | |
635 EXPECT_EQ(2, app_manager()->launch_count()); | 774 EXPECT_EQ(2, app_manager()->launch_count()); |
636 } | 775 } |
776 | |
777 TEST_F(LockScreenAppStateTest, AppWindowRegistration) { | |
778 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kAvailable, | |
779 true /* enable_app_launch */)); | |
780 | |
781 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
782 signin_profile(), app(), | |
783 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
784 | |
785 TestAppWindow app_window(signin_profile(), app()); | |
786 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
787 app_window.window(), extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
788 | |
789 tray_action()->SendNewNoteRequest(); | |
790 state_controller()->FlushTrayActionForTesting(); | |
791 | |
792 EXPECT_EQ(TrayActionState::kLaunching, | |
793 state_controller()->GetLockScreenNoteState()); | |
794 observer()->ClearObservedStates(); | |
795 tray_action()->ClearObservedStates(); | |
796 | |
797 TestAppWindow non_eligible_app_window(profile(), app()); | |
798 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
799 profile(), app(), extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
800 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
801 non_eligible_app_window.window(), | |
802 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
803 | |
804 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
805 signin_profile(), app(), extensions::api::app_runtime::ACTION_TYPE_NONE)); | |
806 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
807 app_window.window(), extensions::api::app_runtime::ACTION_TYPE_NONE)); | |
808 | |
809 EXPECT_TRUE(state_controller()->CanCreateAppWindowForAction( | |
810 signin_profile(), app(), | |
811 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
812 // Repeated query should return true, until the app window is actually | |
813 // registered as the action handler. | |
814 EXPECT_TRUE(state_controller()->CanCreateAppWindowForAction( | |
815 signin_profile(), app(), | |
816 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
817 | |
818 EXPECT_TRUE(state_controller()->RegisterAppWindowForAction( | |
819 app_window.window(), extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
820 app_window.Initialize(true /* shown */); | |
821 EXPECT_EQ(TrayActionState::kActive, | |
822 state_controller()->GetLockScreenNoteState()); | |
823 | |
824 // Test that second app window cannot be registered. | |
825 TestAppWindow second_app_window(signin_profile(), app()); | |
826 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
827 signin_profile(), app(), | |
828 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
829 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
830 second_app_window.window(), | |
831 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
832 | |
833 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
834 signin_profile(), app(), | |
835 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
836 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
837 second_app_window.window(), | |
838 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
839 | |
840 // Test the app window does not get closed by itself. | |
841 base::RunLoop().RunUntilIdle(); | |
842 EXPECT_FALSE(app_window.closed()); | |
843 | |
844 EXPECT_EQ(TrayActionState::kActive, | |
845 state_controller()->GetLockScreenNoteState()); | |
846 | |
847 // Closing the second app window, will not change the state. | |
848 second_app_window.Close(); | |
849 EXPECT_EQ(TrayActionState::kActive, | |
850 state_controller()->GetLockScreenNoteState()); | |
851 | |
852 app_window.Close(); | |
853 EXPECT_EQ(TrayActionState::kAvailable, | |
854 state_controller()->GetLockScreenNoteState()); | |
855 } | |
856 | |
857 TEST_F(LockScreenAppStateTest, AppWindowClosedBeforeBeingShown) { | |
858 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kLaunching, | |
859 true /* enable_app_launch */)); | |
860 | |
861 TestAppWindow app_window(signin_profile(), app()); | |
862 ASSERT_TRUE(state_controller()->RegisterAppWindowForAction( | |
863 app_window.window(), extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
864 app_window.Initialize(false /* shown */); | |
865 | |
866 app_window.Close(); | |
867 EXPECT_EQ(TrayActionState::kAvailable, | |
868 state_controller()->GetLockScreenNoteState()); | |
869 } | |
870 | |
871 TEST_F(LockScreenAppStateTest, AppWindowClosedOnSessionUnlock) { | |
872 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | |
873 true /* enable_app_launch */)); | |
874 | |
875 session_manager()->SetSessionState(session_manager::SessionState::ACTIVE); | |
876 EXPECT_EQ(TrayActionState::kNotAvailable, | |
877 state_controller()->GetLockScreenNoteState()); | |
878 | |
879 base::RunLoop().RunUntilIdle(); | |
880 EXPECT_TRUE(app_window()->closed()); | |
881 } | |
882 | |
883 TEST_F(LockScreenAppStateTest, AppWindowClosedOnAppUnload) { | |
884 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | |
885 true /* enable_app_launch */)); | |
886 | |
887 extensions::ExtensionSystem::Get(signin_profile()) | |
888 ->extension_service() | |
889 ->UnloadExtension(app()->id(), | |
890 extensions::UnloadedExtensionReason::UNINSTALL); | |
891 app_manager()->UpdateApp("", false); | |
892 | |
893 EXPECT_EQ(TrayActionState::kNotAvailable, | |
894 state_controller()->GetLockScreenNoteState()); | |
895 | |
896 base::RunLoop().RunUntilIdle(); | |
897 EXPECT_TRUE(app_window()->closed()); | |
898 } | |
899 | |
900 TEST_F(LockScreenAppStateTest, AppWindowClosedOnNoteTakingAppChange) { | |
901 ASSERT_TRUE(InitializeNoteTakingApp(TrayActionState::kActive, | |
902 true /* enable_app_launch */)); | |
903 | |
904 scoped_refptr<extensions::Extension> secondary_app = | |
905 CreateTestNoteTakingApp(kSecondaryTestAppId); | |
906 extensions::ExtensionSystem::Get(signin_profile()) | |
907 ->extension_service() | |
908 ->AddExtension(secondary_app.get()); | |
909 | |
910 app_manager()->UpdateApp(secondary_app->id(), true); | |
911 | |
912 EXPECT_EQ(TrayActionState::kAvailable, | |
913 state_controller()->GetLockScreenNoteState()); | |
914 | |
915 base::RunLoop().RunUntilIdle(); | |
916 EXPECT_TRUE(app_window()->closed()); | |
917 | |
918 tray_action()->SendNewNoteRequest(); | |
919 state_controller()->FlushTrayActionForTesting(); | |
920 | |
921 TestAppWindow app_window(signin_profile(), app()); | |
922 EXPECT_FALSE(state_controller()->CanCreateAppWindowForAction( | |
923 signin_profile(), app(), | |
924 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
925 EXPECT_FALSE(state_controller()->RegisterAppWindowForAction( | |
926 app_window.window(), extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
927 ASSERT_EQ(TrayActionState::kLaunching, | |
928 state_controller()->GetLockScreenNoteState()); | |
929 | |
930 TestAppWindow secondary_app_window(signin_profile(), secondary_app.get()); | |
931 EXPECT_TRUE(state_controller()->CanCreateAppWindowForAction( | |
932 signin_profile(), secondary_app.get(), | |
933 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
934 EXPECT_TRUE(state_controller()->RegisterAppWindowForAction( | |
935 secondary_app_window.window(), | |
936 extensions::api::app_runtime::ACTION_TYPE_NEW_NOTE)); | |
937 secondary_app_window.Initialize(true /* shown*/); | |
938 EXPECT_EQ(TrayActionState::kActive, | |
939 state_controller()->GetLockScreenNoteState()); | |
940 | |
941 base::RunLoop().RunUntilIdle(); | |
942 EXPECT_FALSE(secondary_app_window.closed()); | |
943 | |
944 // Uninstall the app and test the secondary app window is closed. | |
945 extensions::ExtensionSystem::Get(signin_profile()) | |
946 ->extension_service() | |
947 ->UnloadExtension(secondary_app->id(), | |
948 extensions::UnloadedExtensionReason::UNINSTALL); | |
949 base::RunLoop().RunUntilIdle(); | |
950 EXPECT_TRUE(secondary_app_window.closed()); | |
951 } | |
OLD | NEW |