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

Side by Side Diff: chrome/browser/chromeos/login/demo_mode/demo_app_launcher_browsertest.cc

Issue 205713002: Add a basic demo mode browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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/app_window.h"
bartfab (slow) 2014/03/25 12:52:54 Nit: Not used.
rkc 2014/03/26 21:30:40 Done.
6 #include "apps/app_window_registry.h"
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h"
11 #include "base/path_service.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
14 #include "chrome/browser/chromeos/login/test/app_window_waiter.h"
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/extensions/extension_browsertest.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/common/chrome_paths.h"
20 #include "chromeos/chromeos_switches.h"
21 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_source.h"
23 #include "content/public/test/test_utils.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 namespace {
27
28 char kDemoAppId[] = "klimoghijjogocdbaikffefjfcfheiel";
29
30 // Utility class to get the primary user's profile. If no user has logged in,
31 // Wait() will wait till a user logs in and then return the user's profile.
32 class UserProfileWaiter {
33 public:
34 UserProfileWaiter() : profile_(NULL) {}
35
36 Profile* Wait() {
37 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
38 if (user_manager && user_manager->IsUserLoggedIn())
39 return ProfileManager::GetActiveUserProfile();
40
41 content::WindowedNotificationObserver(
42 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
43 base::Bind(&UserProfileWaiter::NotificationCallback,
xiyuan 2014/03/22 04:02:42 Can we use UserManager::GetActiveUserProfile() aft
bartfab (slow) 2014/03/25 12:52:54 Nit: #include "base/bind.h"
rkc 2014/03/26 21:30:40 Done.
rkc 2014/03/26 21:30:40 base/bind not needed anymore. Changed this to no l
44 base::Unretained(this))).Wait();
bartfab (slow) 2014/03/25 12:52:54 Nit: #include "base/bind_helpers.h"
rkc 2014/03/26 21:30:40 Same as above. Code removed.
45
46 EXPECT_TRUE(profile_);
47 return profile_;
48 }
49
50 private:
51 bool NotificationCallback(const content::NotificationSource& source,
52 const content::NotificationDetails& details) {
53 profile_ = content::Details<Profile>(details).ptr();
54 return true;
55 }
56
57 Profile* profile_;
58
59 DISALLOW_COPY_AND_ASSIGN(UserProfileWaiter);
60 };
61
62 } // namespace
63
64 namespace chromeos {
bartfab (slow) 2014/03/25 12:52:54 Nit: Move this to the start of the file, right aft
rkc 2014/03/26 21:30:40 Done.
65
66 class DemoAppLauncherTest : public ExtensionBrowserTest {
67 public:
68 DemoAppLauncherTest() : profile_(NULL) {
69 set_exit_when_last_browser_closes(false);
70 }
71
72 virtual ~DemoAppLauncherTest() {}
73
74 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
75 command_line->AppendSwitch(switches::kLoginManager);
76 command_line->AppendSwitch(switches::kForceLoginManagerInTests);
77 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
78
79 command_line->AppendSwitchASCII(switches::kDerelictIdleTimeout, "0");
80 command_line->AppendSwitchASCII(switches::kOobeTimerInterval, "0");
81 command_line->AppendSwitchASCII(switches::kDerelictDetectionTimeout, "0");
82 }
83
84 virtual void SetUp() OVERRIDE {
85 chromeos::DemoAppLauncher::SetDemoAppPathForTesting(GetTestDemoAppPath());
86 ExtensionBrowserTest::SetUp();
87 }
88
89 virtual void SetUpOnMainThread() OVERRIDE {
xiyuan 2014/03/22 04:02:42 Seems no need to override it.
rkc 2014/03/26 21:30:40 Done.
90 ExtensionBrowserTest::SetUpOnMainThread();
91 }
92
93 bool VerifyDemoAppLaunch() {
94 if (!profile_)
95 WaitForProfile();
96 return AppWindowWaiter(apps::AppWindowRegistry::Get(profile_),
bartfab (slow) 2014/03/25 12:52:54 Nit: Why cache the |profile_| in DemoAppLauncherTe
rkc 2014/03/26 21:30:40 Done.
97 kDemoAppId).Wait() != NULL;
bartfab (slow) 2014/03/25 12:52:54 Nit: AppWindowWaiter always returns a non-NULL val
rkc 2014/03/26 21:30:40 Removed the EXPECT from AppWindowWaiter. Done.
98 }
99
100 private:
101 base::FilePath GetTestDemoAppPath() const {
102 base::FilePath test_data_dir;
103 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
104 return test_data_dir.Append(FILE_PATH_LITERAL("chromeos/demo_app"));
105 }
106
107 void WaitForProfile() {
108 profile_ = UserProfileWaiter().Wait();
109 }
110
111 Profile* profile_;
112
113 DISALLOW_COPY_AND_ASSIGN(DemoAppLauncherTest);
114 };
115
116 IN_PROC_BROWSER_TEST_F(DemoAppLauncherTest, Basic) {
117 // This test is fairly unique in the sense that the test actually starts as
118 // soon as Chrome launches, so there isn't any typical "launch this test"
119 // steps that we need to take. All we can do is verify that our demo app
120 // did launch.
121 EXPECT_TRUE(VerifyDemoAppLaunch());
122 }
123
124 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698