1 // Copyright 2013 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.
5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/prefs/scoped_user_pref_update.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
17 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
19 #include "chrome/browser/chromeos/policy/device_local_account.h"
20 #include "chrome/browser/chromeos/settings/cros_settings.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chromeos/settings/cros_settings_names.h"
26 #include "content/public/test/test_utils.h"
27 #include "extensions/common/extension.h"
28 #include "net/base/host_port_pair.h"
29 #include "net/dns/mock_host_resolver.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h"
32 using content::BrowserThread
;
38 // An app to test local fs data persistence across app update. V1 app writes
39 // data into local fs. V2 app reads and verifies the data.
40 // Webstore data json is in
41 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
42 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf
43 // The version 1.0.0 installed is in
44 // chrome/test/data/chromeos/app_mode/webstore/downloads/
45 // bmbpicmpniaclbbpdkfglgipkkebnbjf.crx
46 // The version 2.0.0 crx is in
47 // chrome/test/data/chromeos/app_mode/webstore/downloads/
48 // bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx
49 const char kTestLocalFsKioskApp
[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf";
50 const char kTestLocalFsKioskAppName
[] = "Kiosk App With Local Data";
52 // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback
54 void ConsumerKioskAutoLaunchStatusCheck(
55 KioskAppManager::ConsumerKioskAutoLaunchStatus
* out_status
,
56 const base::Closure
& runner_quit_task
,
57 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status
) {
58 LOG(INFO
) << "ConsumerKioskAutoLaunchStatus = " << in_status
;
59 *out_status
= in_status
;
60 runner_quit_task
.Run();
63 // Helper KioskAppManager::EnableKioskModeCallback implementation.
64 void ConsumerKioskModeLockCheck(
66 const base::Closure
& runner_quit_task
,
68 LOG(INFO
) << "kiosk locked = " << in_locked
;
69 *out_locked
= in_locked
;
70 runner_quit_task
.Run();
73 // Helper EnterpriseInstallAttributes::LockResultCallback implementation.
74 void OnEnterpriseDeviceLock(
75 policy::EnterpriseInstallAttributes::LockResult
* out_locked
,
76 const base::Closure
& runner_quit_task
,
77 policy::EnterpriseInstallAttributes::LockResult in_locked
) {
78 LOG(INFO
) << "Enterprise lock = " << in_locked
;
79 *out_locked
= in_locked
;
80 runner_quit_task
.Run();
83 scoped_refptr
<extensions::Extension
> MakeApp(const std::string
& name
,
84 const std::string
& version
,
85 const std::string
& url
,
86 const std::string
& id
) {
88 base::DictionaryValue value
;
89 value
.SetString("name", name
);
90 value
.SetString("version", version
);
91 value
.SetString("app.launch.web_url", url
);
92 scoped_refptr
<extensions::Extension
> app
=
93 extensions::Extension::Create(
95 extensions::Manifest::INTERNAL
,
97 extensions::Extension::WAS_INSTALLED_BY_DEFAULT
,
104 class AppDataLoadWaiter
: public KioskAppManagerObserver
{
106 AppDataLoadWaiter(KioskAppManager
* manager
, int data_loaded_threshold
)
111 data_change_count_(0),
112 data_loaded_threshold_(data_loaded_threshold
) {
113 manager_
->AddObserver(this);
116 ~AppDataLoadWaiter() override
{ manager_
->RemoveObserver(this); }
121 runner_
= new content::MessageLoopRunner
;
125 bool loaded() const { return loaded_
; }
128 // KioskAppManagerObserver overrides:
129 void OnKioskAppDataChanged(const std::string
& app_id
) override
{
130 ++data_change_count_
;
131 if (data_change_count_
< data_loaded_threshold_
)
139 void OnKioskAppDataLoadFailure(const std::string
& app_id
) override
{
146 void OnKioskExtensionLoadedInCache(const std::string
& app_id
) override
{
147 OnKioskAppDataChanged(app_id
);
150 void OnKioskExtensionDownloadFailed(const std::string
& app_id
) override
{
151 OnKioskAppDataLoadFailure(app_id
);
154 scoped_refptr
<content::MessageLoopRunner
> runner_
;
155 KioskAppManager
* manager_
;
158 int data_change_count_
;
159 int data_loaded_threshold_
;
161 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter
);
166 class KioskAppManagerTest
: public InProcessBrowserTest
{
168 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {}
169 ~KioskAppManagerTest() override
{}
171 // InProcessBrowserTest overrides:
172 void SetUp() override
{
173 base::FilePath test_data_dir
;
174 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
175 embedded_test_server()->ServeFilesFromDirectory(test_data_dir
);
176 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
177 // Stop IO thread here because no threads are allowed while
178 // spawning sandbox host process. See crbug.com/322732.
179 embedded_test_server()->StopThread();
181 ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir());
183 InProcessBrowserTest::SetUp();
186 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
187 InProcessBrowserTest::SetUpCommandLine(command_line
);
189 // Initialize fake_cws_ to setup web store gallery.
190 fake_cws_
->Init(embedded_test_server());
193 void SetUpOnMainThread() override
{
194 InProcessBrowserTest::SetUpOnMainThread();
196 // Restart the thread as the sandbox host process has already been spawned.
197 embedded_test_server()->RestartThreadAndListen();
200 void SetUpInProcessBrowserTestFixture() override
{
201 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
203 host_resolver()->AddRule("*", "127.0.0.1");
206 std::string
GetAppIds() const {
207 KioskAppManager::Apps apps
;
208 manager()->GetApps(&apps
);
211 for (size_t i
= 0; i
< apps
.size(); ++i
) {
214 str
+= apps
[i
].app_id
;
220 // Locks device for enterprise.
221 policy::EnterpriseInstallAttributes::LockResult
LockDeviceForEnterprise() {
222 scoped_ptr
<policy::EnterpriseInstallAttributes::LockResult
> lock_result(
223 new policy::EnterpriseInstallAttributes::LockResult(
224 policy::EnterpriseInstallAttributes::LOCK_NOT_READY
));
225 scoped_refptr
<content::MessageLoopRunner
> runner
=
226 new content::MessageLoopRunner
;
227 policy::BrowserPolicyConnectorChromeOS
* connector
=
228 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
229 connector
->GetInstallAttributes()->LockDevice(
231 policy::DEVICE_MODE_ENTERPRISE
,
234 &OnEnterpriseDeviceLock
, lock_result
.get(), runner
->QuitClosure()));
236 return *lock_result
.get();
239 void SetExistingApp(const std::string
& app_id
,
240 const std::string
& app_name
,
241 const std::string
& icon_file_name
) {
242 base::FilePath test_dir
;
243 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &test_dir
));
244 base::FilePath data_dir
= test_dir
.AppendASCII("chromeos/app_mode/");
246 // Copy the icon file to temp dir for using because ClearAppData test
248 base::FilePath icon_path
= temp_dir_
.path().AppendASCII(icon_file_name
);
249 base::CopyFile(data_dir
.AppendASCII(icon_file_name
), icon_path
);
251 scoped_ptr
<base::DictionaryValue
> apps_dict(new base::DictionaryValue
);
252 apps_dict
->SetString(app_id
+ ".name", app_name
);
253 apps_dict
->SetString(app_id
+ ".icon", icon_path
.MaybeAsASCII());
255 PrefService
* local_state
= g_browser_process
->local_state();
256 DictionaryPrefUpdate
dict_update(local_state
,
257 KioskAppManager::kKioskDictionaryName
);
258 dict_update
->Set(KioskAppManager::kKeyApps
, apps_dict
.release());
260 // Make the app appear in device settings.
261 base::ListValue device_local_accounts
;
262 scoped_ptr
<base::DictionaryValue
> entry(new base::DictionaryValue
);
263 entry
->SetStringWithoutPathExpansion(
264 kAccountsPrefDeviceLocalAccountsKeyId
,
266 entry
->SetIntegerWithoutPathExpansion(
267 kAccountsPrefDeviceLocalAccountsKeyType
,
268 policy::DeviceLocalAccount::TYPE_KIOSK_APP
);
269 entry
->SetStringWithoutPathExpansion(
270 kAccountsPrefDeviceLocalAccountsKeyKioskAppId
,
272 device_local_accounts
.Append(entry
.release());
273 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts
,
274 device_local_accounts
);
277 bool GetCachedCrx(const std::string
& app_id
,
278 base::FilePath
* file_path
,
279 std::string
* version
) {
280 return manager()->GetCachedCrx(app_id
, file_path
, version
);
283 void UpdateAppData() { manager()->UpdateAppData(); }
285 void RunAddNewAppTest(const std::string
& id
,
286 const std::string
& version
,
287 const std::string
& app_name
) {
288 std::string crx_file_name
= id
+ ".crx";
289 fake_cws_
->SetUpdateCrx(id
, crx_file_name
, version
);
291 AppDataLoadWaiter
waiter(manager(), 3);
292 manager()->AddApp(id
);
294 EXPECT_TRUE(waiter
.loaded());
296 // Check CRX file is cached.
297 base::FilePath crx_path
;
298 std::string crx_version
;
299 EXPECT_TRUE(GetCachedCrx(id
, &crx_path
, &crx_version
));
300 EXPECT_TRUE(base::PathExists(crx_path
));
301 EXPECT_EQ(version
, crx_version
);
302 // Verify the original crx file is identical to the cached file.
303 base::FilePath test_data_dir
;
304 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
305 std::string src_file_path_str
=
306 std::string("chromeos/app_mode/webstore/downloads/") + crx_file_name
;
307 base::FilePath src_file_path
= test_data_dir
.Append(src_file_path_str
);
308 EXPECT_TRUE(base::PathExists(src_file_path
));
309 EXPECT_TRUE(base::ContentsEqual(src_file_path
, crx_path
));
311 // Check manifest data is cached correctly.
312 KioskAppManager::Apps apps
;
313 manager()->GetApps(&apps
);
314 ASSERT_EQ(1u, apps
.size());
315 EXPECT_EQ(id
, apps
[0].app_id
);
316 EXPECT_EQ(app_name
, apps
[0].name
);
317 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
319 // Check data is cached in local state.
320 PrefService
* local_state
= g_browser_process
->local_state();
321 const base::DictionaryValue
* dict
=
322 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
325 std::string name_key
= "apps." + id
+ ".name";
326 EXPECT_TRUE(dict
->GetString(name_key
, &name
));
327 EXPECT_EQ(apps
[0].name
, name
);
329 std::string icon_path_string
;
330 std::string icon_path_key
= "apps." + id
+ ".icon";
331 EXPECT_TRUE(dict
->GetString(icon_path_key
, &icon_path_string
));
333 base::FilePath expected_icon_path
;
334 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &expected_icon_path
));
336 expected_icon_path
.AppendASCII(KioskAppManager::kIconCacheDir
)
337 .AppendASCII(apps
[0].app_id
)
338 .AddExtension(".png");
339 EXPECT_EQ(expected_icon_path
.value(), icon_path_string
);
342 KioskAppManager
* manager() const { return KioskAppManager::Get(); }
343 FakeCWS
* fake_cws() { return fake_cws_
.get(); }
346 base::ScopedTempDir temp_dir_
;
347 scoped_ptr
<FakeCWS
> fake_cws_
;
349 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest
);
352 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, Basic
) {
353 // Add a couple of apps. Use "fake_app_x" that do not have data on the test
354 // server to avoid pending data loads that could be lingering on tear down and
355 // cause DCHECK failure in utility_process_host_impl.cc.
356 manager()->AddApp("fake_app_1");
357 manager()->AddApp("fake_app_2");
358 EXPECT_EQ("fake_app_1,fake_app_2", GetAppIds());
360 // Set an auto launch app.
361 manager()->SetAutoLaunchApp("fake_app_1");
362 EXPECT_EQ("fake_app_1", manager()->GetAutoLaunchApp());
364 // Make sure that if an app was auto launched with zero delay, it is reflected
366 KioskAppManager::App app
;
367 manager()->GetApp("fake_app_1", &app
);
368 EXPECT_FALSE(app
.was_auto_launched_with_zero_delay
);
370 manager()->SetAppWasAutoLaunchedWithZeroDelay("fake_app_1");
371 manager()->GetApp("fake_app_1", &app
);
372 EXPECT_TRUE(app
.was_auto_launched_with_zero_delay
);
374 // Clear the auto launch app.
375 manager()->SetAutoLaunchApp("");
376 EXPECT_EQ("", manager()->GetAutoLaunchApp());
377 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
379 // App should still report it was auto launched with zero delay, even though
380 // it is no longer set to auto launch in the future.
381 manager()->GetApp("fake_app_1", &app
);
382 EXPECT_TRUE(app
.was_auto_launched_with_zero_delay
);
384 // Set another auto launch app.
385 manager()->SetAutoLaunchApp("fake_app_2");
386 EXPECT_EQ("fake_app_2", manager()->GetAutoLaunchApp());
388 // Check auto launch permissions.
389 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
390 manager()->SetEnableAutoLaunch(true);
391 EXPECT_TRUE(manager()->IsAutoLaunchEnabled());
393 // Remove the auto launch app.
394 manager()->RemoveApp("fake_app_2");
395 EXPECT_EQ("fake_app_1", GetAppIds());
396 EXPECT_EQ("", manager()->GetAutoLaunchApp());
398 // Add the just removed auto launch app again and it should no longer be
399 // the auto launch app.
400 manager()->AddApp("fake_app_2");
401 EXPECT_EQ("", manager()->GetAutoLaunchApp());
402 manager()->RemoveApp("fake_app_2");
403 EXPECT_EQ("fake_app_1", GetAppIds());
405 // Set a none exist app as auto launch.
406 manager()->SetAutoLaunchApp("none_exist_app");
407 EXPECT_EQ("", manager()->GetAutoLaunchApp());
408 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
410 // Add an existing app again.
411 manager()->AddApp("fake_app_1");
412 EXPECT_EQ("fake_app_1", GetAppIds());
415 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, LoadCached
) {
416 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
418 fake_cws()->SetNoUpdate("app_1");
419 AppDataLoadWaiter
waiter(manager(), 1);
421 EXPECT_TRUE(waiter
.loaded());
423 KioskAppManager::Apps apps
;
424 manager()->GetApps(&apps
);
425 EXPECT_EQ(1u, apps
.size());
426 EXPECT_EQ("app_1", apps
[0].app_id
);
427 EXPECT_EQ("Cached App1 Name", apps
[0].name
);
428 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
431 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, ClearAppData
) {
432 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
434 PrefService
* local_state
= g_browser_process
->local_state();
435 const base::DictionaryValue
* dict
=
436 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
437 const base::DictionaryValue
* apps_dict
;
438 EXPECT_TRUE(dict
->GetDictionary(KioskAppManager::kKeyApps
, &apps_dict
));
439 EXPECT_TRUE(apps_dict
->HasKey("app_1"));
441 manager()->ClearAppData("app_1");
443 EXPECT_FALSE(apps_dict
->HasKey("app_1"));
446 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateAppDataFromProfile
) {
447 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
449 fake_cws()->SetNoUpdate("app_1");
450 AppDataLoadWaiter
waiter(manager(), 1);
452 EXPECT_TRUE(waiter
.loaded());
454 KioskAppManager::Apps apps
;
455 manager()->GetApps(&apps
);
456 EXPECT_EQ(1u, apps
.size());
457 EXPECT_EQ("app_1", apps
[0].app_id
);
458 EXPECT_EQ("Cached App1 Name", apps
[0].name
);
460 scoped_refptr
<extensions::Extension
> updated_app
=
461 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1");
462 manager()->UpdateAppDataFromProfile(
463 "app_1", browser()->profile(), updated_app
.get());
466 EXPECT_TRUE(waiter
.loaded());
468 manager()->GetApps(&apps
);
469 EXPECT_EQ(1u, apps
.size());
470 EXPECT_EQ("app_1", apps
[0].app_id
);
471 EXPECT_EQ("Updated App1 Name", apps
[0].name
);
474 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, BadApp
) {
475 AppDataLoadWaiter
waiter(manager(), 2);
476 manager()->AddApp("unknown_app");
478 EXPECT_FALSE(waiter
.loaded());
479 EXPECT_EQ("", GetAppIds());
482 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, GoodApp
) {
483 // Webstore data json is in
484 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1
485 fake_cws()->SetNoUpdate("app_1");
486 AppDataLoadWaiter
waiter(manager(), 2);
487 manager()->AddApp("app_1");
489 EXPECT_TRUE(waiter
.loaded());
491 // Check data is correct.
492 KioskAppManager::Apps apps
;
493 manager()->GetApps(&apps
);
494 ASSERT_EQ(1u, apps
.size());
495 EXPECT_EQ("app_1", apps
[0].app_id
);
496 EXPECT_EQ("Name of App 1", apps
[0].name
);
497 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
499 // Check data is cached in local state.
500 PrefService
* local_state
= g_browser_process
->local_state();
501 const base::DictionaryValue
* dict
=
502 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
505 EXPECT_TRUE(dict
->GetString("apps.app_1.name", &name
));
506 EXPECT_EQ(apps
[0].name
, name
);
508 std::string icon_path_string
;
509 EXPECT_TRUE(dict
->GetString("apps.app_1.icon", &icon_path_string
));
511 base::FilePath expected_icon_path
;
512 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &expected_icon_path
));
513 expected_icon_path
= expected_icon_path
.
514 AppendASCII(KioskAppManager::kIconCacheDir
).
515 AppendASCII(apps
[0].app_id
).AddExtension(".png");
516 EXPECT_EQ(expected_icon_path
.value(), icon_path_string
);
519 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, DownloadNewApp
) {
520 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
523 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, RemoveApp
) {
525 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
526 KioskAppManager::Apps apps
;
527 manager()->GetApps(&apps
);
528 ASSERT_EQ(1u, apps
.size());
529 base::FilePath crx_path
;
531 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
532 EXPECT_TRUE(base::PathExists(crx_path
));
533 EXPECT_EQ("1.0.0", version
);
535 // Remove the app now.
536 manager()->RemoveApp(kTestLocalFsKioskApp
);
537 content::RunAllBlockingPoolTasksUntilIdle();
538 manager()->GetApps(&apps
);
539 ASSERT_EQ(0u, apps
.size());
540 EXPECT_FALSE(base::PathExists(crx_path
));
541 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
544 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateApp
) {
545 // Add a version 1 app first.
546 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
547 KioskAppManager::Apps apps
;
548 manager()->GetApps(&apps
);
549 ASSERT_EQ(1u, apps
.size());
550 base::FilePath crx_path
;
552 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
553 EXPECT_TRUE(base::PathExists(crx_path
));
554 EXPECT_EQ("1.0.0", version
);
556 // Update to version 2.
557 fake_cws()->SetUpdateCrx(
558 kTestLocalFsKioskApp
,
559 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
561 AppDataLoadWaiter
waiter(manager(), 1);
564 EXPECT_TRUE(waiter
.loaded());
566 // Verify the app has been updated to v2.
567 manager()->GetApps(&apps
);
568 ASSERT_EQ(1u, apps
.size());
569 base::FilePath new_crx_path
;
570 std::string new_version
;
571 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &new_crx_path
, &new_version
));
572 EXPECT_EQ("2.0.0", new_version
);
573 EXPECT_TRUE(base::PathExists(new_crx_path
));
574 // Get original version 2 source download crx file path.
575 base::FilePath test_data_dir
;
576 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
577 base::FilePath v2_file_path
= test_data_dir
.Append(FILE_PATH_LITERAL(
578 "chromeos/app_mode/webstore/downloads/"
579 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx"));
580 EXPECT_TRUE(base::PathExists(v2_file_path
));
581 EXPECT_TRUE(base::ContentsEqual(v2_file_path
, new_crx_path
));
584 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateAndRemoveApp
) {
585 // Add a version 1 app first.
586 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
587 KioskAppManager::Apps apps
;
588 manager()->GetApps(&apps
);
589 ASSERT_EQ(1u, apps
.size());
590 base::FilePath v1_crx_path
;
592 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &v1_crx_path
, &version
));
593 EXPECT_TRUE(base::PathExists(v1_crx_path
));
594 EXPECT_EQ("1.0.0", version
);
596 // Update to version 2.
597 fake_cws()->SetUpdateCrx(
598 kTestLocalFsKioskApp
,
599 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
601 AppDataLoadWaiter
waiter(manager(), 1);
604 EXPECT_TRUE(waiter
.loaded());
606 // Verify the app has been updated to v2.
607 manager()->GetApps(&apps
);
608 ASSERT_EQ(1u, apps
.size());
609 base::FilePath v2_crx_path
;
610 std::string new_version
;
611 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &v2_crx_path
, &new_version
));
612 EXPECT_EQ("2.0.0", new_version
);
613 // Verify both v1 and v2 crx files exist.
614 EXPECT_TRUE(base::PathExists(v1_crx_path
));
615 EXPECT_TRUE(base::PathExists(v2_crx_path
));
617 // Remove the app now.
618 manager()->RemoveApp(kTestLocalFsKioskApp
);
619 content::RunAllBlockingPoolTasksUntilIdle();
620 manager()->GetApps(&apps
);
621 ASSERT_EQ(0u, apps
.size());
622 // Verify both v1 and v2 crx files are removed.
623 EXPECT_FALSE(base::PathExists(v1_crx_path
));
624 EXPECT_FALSE(base::PathExists(v2_crx_path
));
625 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp
, &v2_crx_path
, &version
));
628 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, EnableConsumerKiosk
) {
629 scoped_ptr
<KioskAppManager::ConsumerKioskAutoLaunchStatus
> status(
630 new KioskAppManager::ConsumerKioskAutoLaunchStatus(
631 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
));
632 scoped_ptr
<bool> locked(new bool(false));
634 scoped_refptr
<content::MessageLoopRunner
> runner
=
635 new content::MessageLoopRunner
;
636 manager()->GetConsumerKioskAutoLaunchStatus(
637 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
639 runner
->QuitClosure()));
641 EXPECT_EQ(*status
.get(),
642 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
);
644 scoped_refptr
<content::MessageLoopRunner
> runner2
=
645 new content::MessageLoopRunner
;
646 manager()->EnableConsumerKioskAutoLaunch(
647 base::Bind(&ConsumerKioskModeLockCheck
,
649 runner2
->QuitClosure()));
651 EXPECT_TRUE(*locked
.get());
653 scoped_refptr
<content::MessageLoopRunner
> runner3
=
654 new content::MessageLoopRunner
;
655 manager()->GetConsumerKioskAutoLaunchStatus(
656 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
658 runner3
->QuitClosure()));
660 EXPECT_EQ(*status
.get(),
661 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED
);
664 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
,
665 PreventEnableConsumerKioskForEnterprise
) {
666 // First, lock the device as enterprise.
667 EXPECT_EQ(LockDeviceForEnterprise(),
668 policy::EnterpriseInstallAttributes::LOCK_SUCCESS
);
670 scoped_ptr
<KioskAppManager::ConsumerKioskAutoLaunchStatus
> status(
671 new KioskAppManager::ConsumerKioskAutoLaunchStatus(
672 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
));
673 scoped_ptr
<bool> locked(new bool(true));
675 scoped_refptr
<content::MessageLoopRunner
> runner
=
676 new content::MessageLoopRunner
;
677 manager()->GetConsumerKioskAutoLaunchStatus(
678 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
680 runner
->QuitClosure()));
682 EXPECT_EQ(*status
.get(),
683 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
);
685 scoped_refptr
<content::MessageLoopRunner
> runner2
=
686 new content::MessageLoopRunner
;
687 manager()->EnableConsumerKioskAutoLaunch(
688 base::Bind(&ConsumerKioskModeLockCheck
,
690 runner2
->QuitClosure()));
692 EXPECT_FALSE(*locked
.get());
694 scoped_refptr
<content::MessageLoopRunner
> runner3
=
695 new content::MessageLoopRunner
;
696 manager()->GetConsumerKioskAutoLaunchStatus(
697 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
699 runner3
->QuitClosure()));
701 EXPECT_EQ(*status
.get(),
702 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
);
705 } // namespace chromeos