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

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

Issue 205713002: Add a basic demo mode browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix license Created 6 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/login/demo_mode/demo_app_launcher.h" 5 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
8 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" 10 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
11 #include "chrome/browser/chromeos/login/login_display_host.h"
9 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 12 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
10 #include "chrome/browser/chromeos/login/user_manager.h" 13 #include "chrome/browser/chromeos/login/user_manager.h"
11 #include "chrome/browser/extensions/component_loader.h" 14 #include "chrome/browser/extensions/component_loader.h"
12 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/extensions/application_launch.h" 17 #include "chrome/browser/ui/extensions/application_launch.h"
14 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/extensions/extension_constants.h"
15 #include "extensions/browser/extension_system.h" 20 #include "extensions/browser/extension_system.h"
21 #include "extensions/common/extension.h"
16 #include "grit/browser_resources.h" 22 #include "grit/browser_resources.h"
23 #include "ui/base/window_open_disposition.h"
17 24
18 namespace chromeos { 25 namespace chromeos {
19 26
20 const char DemoAppLauncher::kDemoUserName[] = "demouser@demo.app.local"; 27 const char DemoAppLauncher::kDemoUserName[] = "demouser@demo.app.local";
28 const base::FilePath::CharType kDefaultDemoAppPath[] =
29 FILE_PATH_LITERAL("/usr/share/chromeos-assets/demo_app");
21 30
22 DemoAppLauncher::DemoAppLauncher() : profile_(NULL) {} 31 // static
32 base::FilePath* DemoAppLauncher::demo_app_path_ = NULL;
23 33
24 DemoAppLauncher::~DemoAppLauncher() {} 34 DemoAppLauncher::DemoAppLauncher() {
35 if (!demo_app_path_)
36 demo_app_path_ = new base::FilePath(kDefaultDemoAppPath);
37 }
38
39 DemoAppLauncher::~DemoAppLauncher() {
40 delete demo_app_path_;
41 }
25 42
26 void DemoAppLauncher::StartDemoAppLaunch() { 43 void DemoAppLauncher::StartDemoAppLaunch() {
27 DVLOG(1) << "Launching demo app..."; 44 DVLOG(1) << "Launching demo app...";
28 // user_id = DemoAppUserId, force_emphemeral = true, delegate = this. 45 // user_id = DemoAppUserId, force_emphemeral = true, delegate = this.
29 kiosk_profile_loader_.reset( 46 kiosk_profile_loader_.reset(
30 new KioskProfileLoader(kDemoUserName, true, this)); 47 new KioskProfileLoader(kDemoUserName, true, this));
31 kiosk_profile_loader_->Start(); 48 kiosk_profile_loader_->Start();
32 } 49 }
33 50
34 // static 51 // static
35 bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) { 52 bool DemoAppLauncher::IsDemoAppSession(const std::string& user_id) {
36 return user_id == kDemoUserName ? true : false; 53 return user_id == kDemoUserName;
54 }
55
56 // static
57 void DemoAppLauncher::SetDemoAppPathForTesting(const base::FilePath& path) {
58 delete demo_app_path_;
59 demo_app_path_ = new base::FilePath(path);
37 } 60 }
38 61
39 void DemoAppLauncher::OnProfileLoaded(Profile* profile) { 62 void DemoAppLauncher::OnProfileLoaded(Profile* profile) {
40 DVLOG(1) << "Profile loaded... Starting demo app launch."; 63 DVLOG(1) << "Profile loaded... Starting demo app launch.";
41 profile_ = profile;
42 64
43 kiosk_profile_loader_.reset(); 65 kiosk_profile_loader_.reset();
44 66
45 // Load our demo app, then launch it. 67 // Load our demo app, then launch it.
46 ExtensionService* extension_service = 68 ExtensionService* extension_service =
47 extensions::ExtensionSystem::Get(profile_)->extension_service(); 69 extensions::ExtensionSystem::Get(profile)->extension_service();
48 std::string extension_id = extension_service->component_loader()->Add( 70 CHECK(demo_app_path_);
71 const std::string extension_id = extension_service->component_loader()->Add(
49 IDR_DEMO_APP_MANIFEST, 72 IDR_DEMO_APP_MANIFEST,
50 base::FilePath("/usr/share/chromeos-assets/demo_app")); 73 *demo_app_path_);
51 74
52 const extensions::Extension* extension = 75 const extensions::Extension* extension =
53 extension_service->GetExtensionById(extension_id, true); 76 extension_service->GetExtensionById(extension_id, true);
54 77
55 CommandLine* command_line = CommandLine::ForCurrentProcess(); 78 CommandLine* command_line = CommandLine::ForCurrentProcess();
56 command_line->AppendSwitch(switches::kForceAppMode); 79 command_line->AppendSwitch(switches::kForceAppMode);
57 command_line->AppendSwitchASCII(switches::kAppId, extension_id); 80 command_line->AppendSwitchASCII(switches::kAppId, extension_id);
58 81
59 OpenApplication(AppLaunchParams( 82 OpenApplication(AppLaunchParams(
60 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 83 profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
61 InitAppSession(profile_, extension_id); 84 InitAppSession(profile, extension_id);
62 85
63 UserManager::Get()->SessionStarted(); 86 UserManager::Get()->SessionStarted();
64 87
65 LoginDisplayHostImpl::default_host()->Finalize(); 88 LoginDisplayHostImpl::default_host()->Finalize();
66 } 89 }
67 90
68 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) { 91 void DemoAppLauncher::OnProfileLoadFailed(KioskAppLaunchError::Error error) {
69 LOG(ERROR) << "Loading the Kiosk Profile failed: " << 92 LOG(ERROR) << "Loading the Kiosk Profile failed: " <<
70 KioskAppLaunchError::GetErrorMessage(error); 93 KioskAppLaunchError::GetErrorMessage(error);
71 } 94 }
72 95
73 } // namespace chromeos 96 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698