Chromium Code Reviews| Index: chrome/browser/chromeos/login/demo_mode/demo_app_launcher_browsertest.cc |
| diff --git a/chrome/browser/chromeos/login/demo_mode/demo_app_launcher_browsertest.cc b/chrome/browser/chromeos/login/demo_mode/demo_app_launcher_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c65523ab8fa44b7368abdbaaa35cdbe198a34230 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/demo_mode/demo_app_launcher_browsertest.cc |
| @@ -0,0 +1,124 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "apps/app_window.h" |
|
bartfab (slow)
2014/03/25 12:52:54
Nit: Not used.
rkc
2014/03/26 21:30:40
Done.
|
| +#include "apps/app_window_registry.h" |
| +#include "base/basictypes.h" |
| +#include "base/command_line.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/files/file_path.h" |
| +#include "base/path_service.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" |
| +#include "chrome/browser/chromeos/login/test/app_window_waiter.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/extensions/extension_browsertest.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chromeos/chromeos_switches.h" |
| +#include "content/public/browser/notification_details.h" |
| +#include "content/public/browser/notification_source.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +char kDemoAppId[] = "klimoghijjogocdbaikffefjfcfheiel"; |
| + |
| +// Utility class to get the primary user's profile. If no user has logged in, |
| +// Wait() will wait till a user logs in and then return the user's profile. |
| +class UserProfileWaiter { |
| + public: |
| + UserProfileWaiter() : profile_(NULL) {} |
| + |
| + Profile* Wait() { |
| + chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| + if (user_manager && user_manager->IsUserLoggedIn()) |
| + return ProfileManager::GetActiveUserProfile(); |
| + |
| + content::WindowedNotificationObserver( |
| + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| + 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
|
| + 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.
|
| + |
| + EXPECT_TRUE(profile_); |
| + return profile_; |
| + } |
| + |
| + private: |
| + bool NotificationCallback(const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + profile_ = content::Details<Profile>(details).ptr(); |
| + return true; |
| + } |
| + |
| + Profile* profile_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UserProfileWaiter); |
| +}; |
| + |
| +} // namespace |
| + |
| +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.
|
| + |
| +class DemoAppLauncherTest : public ExtensionBrowserTest { |
| + public: |
| + DemoAppLauncherTest() : profile_(NULL) { |
| + set_exit_when_last_browser_closes(false); |
| + } |
| + |
| + virtual ~DemoAppLauncherTest() {} |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + command_line->AppendSwitch(switches::kLoginManager); |
| + command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
| + command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| + |
| + command_line->AppendSwitchASCII(switches::kDerelictIdleTimeout, "0"); |
| + command_line->AppendSwitchASCII(switches::kOobeTimerInterval, "0"); |
| + command_line->AppendSwitchASCII(switches::kDerelictDetectionTimeout, "0"); |
| + } |
| + |
| + virtual void SetUp() OVERRIDE { |
| + chromeos::DemoAppLauncher::SetDemoAppPathForTesting(GetTestDemoAppPath()); |
| + ExtensionBrowserTest::SetUp(); |
| + } |
| + |
| + 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.
|
| + ExtensionBrowserTest::SetUpOnMainThread(); |
| + } |
| + |
| + bool VerifyDemoAppLaunch() { |
| + if (!profile_) |
| + WaitForProfile(); |
| + 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.
|
| + 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.
|
| + } |
| + |
| + private: |
| + base::FilePath GetTestDemoAppPath() const { |
| + base::FilePath test_data_dir; |
| + EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
| + return test_data_dir.Append(FILE_PATH_LITERAL("chromeos/demo_app")); |
| + } |
| + |
| + void WaitForProfile() { |
| + profile_ = UserProfileWaiter().Wait(); |
| + } |
| + |
| + Profile* profile_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DemoAppLauncherTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(DemoAppLauncherTest, Basic) { |
| + // This test is fairly unique in the sense that the test actually starts as |
| + // soon as Chrome launches, so there isn't any typical "launch this test" |
| + // steps that we need to take. All we can do is verify that our demo app |
| + // did launch. |
| + EXPECT_TRUE(VerifyDemoAppLaunch()); |
| +} |
| + |
| +} // namespace chromeos |