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

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

Issue 2927303003: Add hooks to allow lock screen app pages in sign-in profile (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
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_process_manager_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "apps/launcher.h"
6 #include "base/command_line.h"
7 #include "chrome/browser/chromeos/lock_screen_apps/state_controller.h"
8 #include "chrome/browser/chromeos/note_taking_helper.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/common/pref_names.h"
11 #include "chromeos/chromeos_switches.h"
12 #include "components/prefs/pref_service.h"
13 #include "components/session_manager/core/session_manager.h"
14 #include "extensions/common/api/app_runtime.h"
15 #include "extensions/common/switches.h"
16 #include "extensions/test/extension_test_message_listener.h"
17 #include "extensions/test/result_catcher.h"
18
19 namespace {
20
21 const char kTestAppId[] = "cadfeochfldmbdgoccgbeianhamecbae";
22
23 class LockScreenNoteTakingTest : public ExtensionBrowserTest {
24 public:
25 LockScreenNoteTakingTest() { set_chromeos_user_ = true; }
26 ~LockScreenNoteTakingTest() override = default;
27
28 void SetUpCommandLine(base::CommandLine* cmd_line) override {
29 cmd_line->AppendSwitchASCII(extensions::switches::kWhitelistedExtensionID,
30 kTestAppId);
31 cmd_line->AppendSwitchASCII(chromeos::switches::kNoteTakingAppIds,
32 kTestAppId);
33 cmd_line->AppendSwitch(chromeos::switches::kEnableLockScreenApps);
34
35 ExtensionBrowserTest::SetUpCommandLine(cmd_line);
36 }
37
38 bool EnableLockScreenAppLaunch(const std::string& app_id) {
39 chromeos::NoteTakingHelper::Get()->SetPreferredApp(profile(), app_id);
40 profile()->GetPrefs()->SetBoolean(prefs::kNoteTakingAppEnabledOnLockScreen,
41 true);
42 session_manager::SessionManager::Get()->SetSessionState(
43 session_manager::SessionState::LOCKED);
44
45 return lock_screen_apps::StateController::Get()->GetLockScreenNoteState() ==
46 ash::mojom::TrayActionState::kAvailable;
47 }
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(LockScreenNoteTakingTest);
51 };
52
53 } // namespace
54
55 IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, Launch) {
56 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled());
57
58 scoped_refptr<const extensions::Extension> app =
59 LoadExtension(test_data_dir_.AppendASCII("lock_screen_apps/app_launch"));
60 ASSERT_TRUE(EnableLockScreenAppLaunch(app->id()));
61
62 // Message the test app will send from the created app window once the tests
63 // are run and the window is ready to be closed.
64 // The test should reply to this message in order for the app window to close
65 // itself.
66 ExtensionTestMessageListener ready_to_close("readyToClose",
67 true /* will_reply */);
68
69 extensions::ResultCatcher catcher;
70 lock_screen_apps::StateController::Get()->RequestNewLockScreenNote();
71
72 ASSERT_EQ(ash::mojom::TrayActionState::kLaunching,
73 lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
74
75 // The test will run two sets of tests:
76 // * in window that gets created as the response to action launch
77 // * in the app background page - the test will launch an app window and wait
78 // for it to be closed
79 // Wait for both of those to finish.
80 if (!catcher.GetNextResult())
81 ADD_FAILURE() << catcher.message();
82
83 ASSERT_EQ(ash::mojom::TrayActionState::kActive,
84 lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
85
86 ready_to_close.WaitUntilSatisfied();
87 ready_to_close.Reply("close");
88
89 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
90
91 EXPECT_EQ(ash::mojom::TrayActionState::kAvailable,
92 lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
93 }
94
95 IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, LaunchInNonLockScreenContext) {
96 ASSERT_TRUE(lock_screen_apps::StateController::IsEnabled());
97
98 scoped_refptr<const extensions::Extension> app = LoadExtension(
99 test_data_dir_.AppendASCII("lock_screen_apps/non_lock_screen_context"));
100 ASSERT_TRUE(EnableLockScreenAppLaunch(app->id()));
101
102 extensions::ResultCatcher catcher;
103 lock_screen_apps::StateController::Get()->RequestNewLockScreenNote();
104
105 ASSERT_EQ(ash::mojom::TrayActionState::kLaunching,
106 lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
107
108 auto action_data =
109 base::MakeUnique<extensions::api::app_runtime::ActionData>();
110 action_data->action_type =
111 extensions::api::app_runtime::ActionType::ACTION_TYPE_NEW_NOTE;
112 apps::LaunchPlatformAppWithAction(profile(), app.get(),
113 std::move(action_data), base::FilePath());
114
115 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
116 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_process_manager_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698