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/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h"
13 #include "base/prefs/scoped_user_pref_update.h"
14 #include "base/strings/stringprintf.h"
15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/app_mode/fake_cws.h"
18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
19 #include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
21 #include "chrome/browser/chromeos/policy/device_local_account.h"
22 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chromeos/settings/cros_settings_names.h"
28 #include "content/public/test/test_utils.h"
29 #include "extensions/common/extension.h"
30 #include "net/base/host_port_pair.h"
31 #include "net/dns/mock_host_resolver.h"
32 #include "net/test/embedded_test_server/embedded_test_server.h"
34 using content::BrowserThread
;
40 // An app to test local fs data persistence across app update. V1 app writes
41 // data into local fs. V2 app reads and verifies the data.
42 // Webstore data json is in
43 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/
44 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf
45 // The version 1.0.0 installed is in
46 // chrome/test/data/chromeos/app_mode/webstore/downloads/
47 // bmbpicmpniaclbbpdkfglgipkkebnbjf.crx
48 // The version 2.0.0 crx is in
49 // chrome/test/data/chromeos/app_mode/webstore/downloads/
50 // bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx
51 const char kTestLocalFsKioskApp
[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf";
52 const char kTestLocalFsKioskAppName
[] = "Kiosk App With Local Data";
54 // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback
56 void ConsumerKioskAutoLaunchStatusCheck(
57 KioskAppManager::ConsumerKioskAutoLaunchStatus
* out_status
,
58 const base::Closure
& runner_quit_task
,
59 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status
) {
60 LOG(INFO
) << "ConsumerKioskAutoLaunchStatus = " << in_status
;
61 *out_status
= in_status
;
62 runner_quit_task
.Run();
65 // Helper KioskAppManager::EnableKioskModeCallback implementation.
66 void ConsumerKioskModeLockCheck(
68 const base::Closure
& runner_quit_task
,
70 LOG(INFO
) << "kiosk locked = " << in_locked
;
71 *out_locked
= in_locked
;
72 runner_quit_task
.Run();
75 // Helper EnterpriseInstallAttributes::LockResultCallback implementation.
76 void OnEnterpriseDeviceLock(
77 policy::EnterpriseInstallAttributes::LockResult
* out_locked
,
78 const base::Closure
& runner_quit_task
,
79 policy::EnterpriseInstallAttributes::LockResult in_locked
) {
80 LOG(INFO
) << "Enterprise lock = " << in_locked
;
81 *out_locked
= in_locked
;
82 runner_quit_task
.Run();
85 scoped_refptr
<extensions::Extension
> MakeApp(const std::string
& name
,
86 const std::string
& version
,
87 const std::string
& url
,
88 const std::string
& id
) {
90 base::DictionaryValue value
;
91 value
.SetString("name", name
);
92 value
.SetString("version", version
);
93 value
.SetString("app.launch.web_url", url
);
94 scoped_refptr
<extensions::Extension
> app
=
95 extensions::Extension::Create(
97 extensions::Manifest::INTERNAL
,
99 extensions::Extension::WAS_INSTALLED_BY_DEFAULT
,
106 class AppDataLoadWaiter
: public KioskAppManagerObserver
{
108 AppDataLoadWaiter(KioskAppManager
* manager
, int data_loaded_threshold
)
113 data_change_count_(0),
114 data_loaded_threshold_(data_loaded_threshold
) {
115 manager_
->AddObserver(this);
118 ~AppDataLoadWaiter() override
{ manager_
->RemoveObserver(this); }
123 runner_
= new content::MessageLoopRunner
;
127 bool loaded() const { return loaded_
; }
130 // KioskAppManagerObserver overrides:
131 void OnKioskAppDataChanged(const std::string
& app_id
) override
{
132 ++data_change_count_
;
133 if (data_change_count_
< data_loaded_threshold_
)
141 void OnKioskAppDataLoadFailure(const std::string
& app_id
) override
{
148 void OnKioskExtensionLoadedInCache(const std::string
& app_id
) override
{
149 OnKioskAppDataChanged(app_id
);
152 void OnKioskExtensionDownloadFailed(const std::string
& app_id
) override
{
153 OnKioskAppDataLoadFailure(app_id
);
156 scoped_refptr
<content::MessageLoopRunner
> runner_
;
157 KioskAppManager
* manager_
;
160 int data_change_count_
;
161 int data_loaded_threshold_
;
163 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter
);
168 class KioskAppManagerTest
: public InProcessBrowserTest
{
170 KioskAppManagerTest() : settings_helper_(false), fake_cws_(new FakeCWS()) {}
171 ~KioskAppManagerTest() override
{}
173 // InProcessBrowserTest overrides:
174 void SetUp() override
{
175 base::FilePath test_data_dir
;
176 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
177 embedded_test_server()->ServeFilesFromDirectory(test_data_dir
);
178 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
179 // Stop IO thread here because no threads are allowed while
180 // spawning sandbox host process. See crbug.com/322732.
181 embedded_test_server()->StopThread();
183 ASSERT_TRUE(temp_dir_
.CreateUniqueTempDir());
185 InProcessBrowserTest::SetUp();
188 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
189 InProcessBrowserTest::SetUpCommandLine(command_line
);
191 // Initialize fake_cws_ to setup web store gallery.
192 fake_cws_
->Init(embedded_test_server());
195 void SetUpOnMainThread() override
{
196 InProcessBrowserTest::SetUpOnMainThread();
198 // Restart the thread as the sandbox host process has already been spawned.
199 embedded_test_server()->RestartThreadAndListen();
201 settings_helper_
.ReplaceProvider(kAccountsPrefDeviceLocalAccounts
);
202 owner_settings_service_
=
203 settings_helper_
.CreateOwnerSettingsService(browser()->profile());
206 void TearDownOnMainThread() override
{ settings_helper_
.RestoreProvider(); }
208 void SetUpInProcessBrowserTestFixture() override
{
209 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
211 host_resolver()->AddRule("*", "127.0.0.1");
214 std::string
GetAppIds() const {
215 KioskAppManager::Apps apps
;
216 manager()->GetApps(&apps
);
219 for (size_t i
= 0; i
< apps
.size(); ++i
) {
222 str
+= apps
[i
].app_id
;
228 // Locks device for enterprise.
229 policy::EnterpriseInstallAttributes::LockResult
LockDeviceForEnterprise() {
230 scoped_ptr
<policy::EnterpriseInstallAttributes::LockResult
> lock_result(
231 new policy::EnterpriseInstallAttributes::LockResult(
232 policy::EnterpriseInstallAttributes::LOCK_NOT_READY
));
233 scoped_refptr
<content::MessageLoopRunner
> runner
=
234 new content::MessageLoopRunner
;
235 policy::BrowserPolicyConnectorChromeOS
* connector
=
236 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
237 connector
->GetInstallAttributes()->LockDevice(
239 policy::DEVICE_MODE_ENTERPRISE
,
242 &OnEnterpriseDeviceLock
, lock_result
.get(), runner
->QuitClosure()));
244 return *lock_result
.get();
247 void SetExistingApp(const std::string
& app_id
,
248 const std::string
& app_name
,
249 const std::string
& icon_file_name
) {
250 base::FilePath test_dir
;
251 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA
, &test_dir
));
252 base::FilePath data_dir
= test_dir
.AppendASCII("chromeos/app_mode/");
254 // Copy the icon file to temp dir for using because ClearAppData test
256 base::FilePath icon_path
= temp_dir_
.path().AppendASCII(icon_file_name
);
257 base::CopyFile(data_dir
.AppendASCII(icon_file_name
), icon_path
);
259 scoped_ptr
<base::DictionaryValue
> apps_dict(new base::DictionaryValue
);
260 apps_dict
->SetString(app_id
+ ".name", app_name
);
261 apps_dict
->SetString(app_id
+ ".icon", icon_path
.MaybeAsASCII());
263 PrefService
* local_state
= g_browser_process
->local_state();
264 DictionaryPrefUpdate
dict_update(local_state
,
265 KioskAppManager::kKioskDictionaryName
);
266 dict_update
->Set(KioskAppManager::kKeyApps
, apps_dict
.release());
268 // Make the app appear in device settings.
269 base::ListValue device_local_accounts
;
270 scoped_ptr
<base::DictionaryValue
> entry(new base::DictionaryValue
);
271 entry
->SetStringWithoutPathExpansion(
272 kAccountsPrefDeviceLocalAccountsKeyId
,
274 entry
->SetIntegerWithoutPathExpansion(
275 kAccountsPrefDeviceLocalAccountsKeyType
,
276 policy::DeviceLocalAccount::TYPE_KIOSK_APP
);
277 entry
->SetStringWithoutPathExpansion(
278 kAccountsPrefDeviceLocalAccountsKeyKioskAppId
,
280 device_local_accounts
.Append(entry
.release());
281 owner_settings_service_
->Set(kAccountsPrefDeviceLocalAccounts
,
282 device_local_accounts
);
285 bool GetCachedCrx(const std::string
& app_id
,
286 base::FilePath
* file_path
,
287 std::string
* version
) {
288 return manager()->GetCachedCrx(app_id
, file_path
, version
);
291 void UpdateAppData() { manager()->UpdateAppData(); }
293 void RunAddNewAppTest(const std::string
& id
,
294 const std::string
& version
,
295 const std::string
& app_name
) {
296 std::string crx_file_name
= id
+ ".crx";
297 fake_cws_
->SetUpdateCrx(id
, crx_file_name
, version
);
299 AppDataLoadWaiter
waiter(manager(), 3);
300 manager()->AddApp(id
, owner_settings_service_
.get());
302 EXPECT_TRUE(waiter
.loaded());
304 // Check CRX file is cached.
305 base::FilePath crx_path
;
306 std::string crx_version
;
307 EXPECT_TRUE(GetCachedCrx(id
, &crx_path
, &crx_version
));
308 EXPECT_TRUE(base::PathExists(crx_path
));
309 EXPECT_EQ(version
, crx_version
);
310 // Verify the original crx file is identical to the cached file.
311 base::FilePath test_data_dir
;
312 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
313 std::string src_file_path_str
=
314 std::string("chromeos/app_mode/webstore/downloads/") + crx_file_name
;
315 base::FilePath src_file_path
= test_data_dir
.Append(src_file_path_str
);
316 EXPECT_TRUE(base::PathExists(src_file_path
));
317 EXPECT_TRUE(base::ContentsEqual(src_file_path
, crx_path
));
319 // Check manifest data is cached correctly.
320 KioskAppManager::Apps apps
;
321 manager()->GetApps(&apps
);
322 ASSERT_EQ(1u, apps
.size());
323 EXPECT_EQ(id
, apps
[0].app_id
);
324 EXPECT_EQ(app_name
, apps
[0].name
);
325 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
327 // Check data is cached in local state.
328 PrefService
* local_state
= g_browser_process
->local_state();
329 const base::DictionaryValue
* dict
=
330 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
333 std::string name_key
= "apps." + id
+ ".name";
334 EXPECT_TRUE(dict
->GetString(name_key
, &name
));
335 EXPECT_EQ(apps
[0].name
, name
);
337 std::string icon_path_string
;
338 std::string icon_path_key
= "apps." + id
+ ".icon";
339 EXPECT_TRUE(dict
->GetString(icon_path_key
, &icon_path_string
));
341 base::FilePath expected_icon_path
;
342 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &expected_icon_path
));
344 expected_icon_path
.AppendASCII(KioskAppManager::kIconCacheDir
)
345 .AppendASCII(apps
[0].app_id
)
346 .AddExtension(".png");
347 EXPECT_EQ(expected_icon_path
.value(), icon_path_string
);
350 KioskAppManager
* manager() const { return KioskAppManager::Get(); }
351 FakeCWS
* fake_cws() { return fake_cws_
.get(); }
354 ScopedCrosSettingsTestHelper settings_helper_
;
355 scoped_ptr
<FakeOwnerSettingsService
> owner_settings_service_
;
358 base::ScopedTempDir temp_dir_
;
359 scoped_ptr
<FakeCWS
> fake_cws_
;
361 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest
);
364 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, Basic
) {
365 // Add a couple of apps. Use "fake_app_x" that do not have data on the test
366 // server to avoid pending data loads that could be lingering on tear down and
367 // cause DCHECK failure in utility_process_host_impl.cc.
368 manager()->AddApp("fake_app_1", owner_settings_service_
.get());
369 manager()->AddApp("fake_app_2", owner_settings_service_
.get());
370 EXPECT_EQ("fake_app_1,fake_app_2", GetAppIds());
372 // Set an auto launch app.
373 manager()->SetAutoLaunchApp("fake_app_1", owner_settings_service_
.get());
374 EXPECT_EQ("fake_app_1", manager()->GetAutoLaunchApp());
376 // Make sure that if an app was auto launched with zero delay, it is reflected
378 KioskAppManager::App app
;
379 manager()->GetApp("fake_app_1", &app
);
380 EXPECT_FALSE(app
.was_auto_launched_with_zero_delay
);
382 manager()->SetAppWasAutoLaunchedWithZeroDelay("fake_app_1");
383 manager()->GetApp("fake_app_1", &app
);
384 EXPECT_TRUE(app
.was_auto_launched_with_zero_delay
);
386 // Clear the auto launch app.
387 manager()->SetAutoLaunchApp("", owner_settings_service_
.get());
388 EXPECT_EQ("", manager()->GetAutoLaunchApp());
389 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
391 // App should still report it was auto launched with zero delay, even though
392 // it is no longer set to auto launch in the future.
393 manager()->GetApp("fake_app_1", &app
);
394 EXPECT_TRUE(app
.was_auto_launched_with_zero_delay
);
396 // Set another auto launch app.
397 manager()->SetAutoLaunchApp("fake_app_2", owner_settings_service_
.get());
398 EXPECT_EQ("fake_app_2", manager()->GetAutoLaunchApp());
400 // Check auto launch permissions.
401 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
402 manager()->SetEnableAutoLaunch(true);
403 EXPECT_TRUE(manager()->IsAutoLaunchEnabled());
405 // Remove the auto launch app.
406 manager()->RemoveApp("fake_app_2", owner_settings_service_
.get());
407 EXPECT_EQ("fake_app_1", GetAppIds());
408 EXPECT_EQ("", manager()->GetAutoLaunchApp());
410 // Add the just removed auto launch app again and it should no longer be
411 // the auto launch app.
412 manager()->AddApp("fake_app_2", owner_settings_service_
.get());
413 EXPECT_EQ("", manager()->GetAutoLaunchApp());
414 manager()->RemoveApp("fake_app_2", owner_settings_service_
.get());
415 EXPECT_EQ("fake_app_1", GetAppIds());
417 // Set a none exist app as auto launch.
418 manager()->SetAutoLaunchApp("none_exist_app", owner_settings_service_
.get());
419 EXPECT_EQ("", manager()->GetAutoLaunchApp());
420 EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
422 // Add an existing app again.
423 manager()->AddApp("fake_app_1", owner_settings_service_
.get());
424 EXPECT_EQ("fake_app_1", GetAppIds());
427 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, LoadCached
) {
428 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
430 fake_cws()->SetNoUpdate("app_1");
431 AppDataLoadWaiter
waiter(manager(), 1);
433 EXPECT_TRUE(waiter
.loaded());
435 KioskAppManager::Apps apps
;
436 manager()->GetApps(&apps
);
437 EXPECT_EQ(1u, apps
.size());
438 EXPECT_EQ("app_1", apps
[0].app_id
);
439 EXPECT_EQ("Cached App1 Name", apps
[0].name
);
440 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
443 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, ClearAppData
) {
444 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
446 PrefService
* local_state
= g_browser_process
->local_state();
447 const base::DictionaryValue
* dict
=
448 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
449 const base::DictionaryValue
* apps_dict
;
450 EXPECT_TRUE(dict
->GetDictionary(KioskAppManager::kKeyApps
, &apps_dict
));
451 EXPECT_TRUE(apps_dict
->HasKey("app_1"));
453 manager()->ClearAppData("app_1");
455 EXPECT_FALSE(apps_dict
->HasKey("app_1"));
458 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateAppDataFromProfile
) {
459 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png");
461 fake_cws()->SetNoUpdate("app_1");
462 AppDataLoadWaiter
waiter(manager(), 1);
464 EXPECT_TRUE(waiter
.loaded());
466 KioskAppManager::Apps apps
;
467 manager()->GetApps(&apps
);
468 EXPECT_EQ(1u, apps
.size());
469 EXPECT_EQ("app_1", apps
[0].app_id
);
470 EXPECT_EQ("Cached App1 Name", apps
[0].name
);
472 scoped_refptr
<extensions::Extension
> updated_app
=
473 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1");
474 manager()->UpdateAppDataFromProfile(
475 "app_1", browser()->profile(), updated_app
.get());
478 EXPECT_TRUE(waiter
.loaded());
480 manager()->GetApps(&apps
);
481 EXPECT_EQ(1u, apps
.size());
482 EXPECT_EQ("app_1", apps
[0].app_id
);
483 EXPECT_EQ("Updated App1 Name", apps
[0].name
);
486 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, BadApp
) {
487 AppDataLoadWaiter
waiter(manager(), 2);
488 manager()->AddApp("unknown_app", owner_settings_service_
.get());
490 EXPECT_FALSE(waiter
.loaded());
491 EXPECT_EQ("", GetAppIds());
494 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, GoodApp
) {
495 // Webstore data json is in
496 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1
497 fake_cws()->SetNoUpdate("app_1");
498 AppDataLoadWaiter
waiter(manager(), 2);
499 manager()->AddApp("app_1", owner_settings_service_
.get());
501 EXPECT_TRUE(waiter
.loaded());
503 // Check data is correct.
504 KioskAppManager::Apps apps
;
505 manager()->GetApps(&apps
);
506 ASSERT_EQ(1u, apps
.size());
507 EXPECT_EQ("app_1", apps
[0].app_id
);
508 EXPECT_EQ("Name of App 1", apps
[0].name
);
509 EXPECT_EQ(gfx::Size(16, 16), apps
[0].icon
.size());
511 // Check data is cached in local state.
512 PrefService
* local_state
= g_browser_process
->local_state();
513 const base::DictionaryValue
* dict
=
514 local_state
->GetDictionary(KioskAppManager::kKioskDictionaryName
);
517 EXPECT_TRUE(dict
->GetString("apps.app_1.name", &name
));
518 EXPECT_EQ(apps
[0].name
, name
);
520 std::string icon_path_string
;
521 EXPECT_TRUE(dict
->GetString("apps.app_1.icon", &icon_path_string
));
523 base::FilePath expected_icon_path
;
524 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA
, &expected_icon_path
));
525 expected_icon_path
= expected_icon_path
.
526 AppendASCII(KioskAppManager::kIconCacheDir
).
527 AppendASCII(apps
[0].app_id
).AddExtension(".png");
528 EXPECT_EQ(expected_icon_path
.value(), icon_path_string
);
531 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, DownloadNewApp
) {
532 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
535 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, RemoveApp
) {
537 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
538 KioskAppManager::Apps apps
;
539 manager()->GetApps(&apps
);
540 ASSERT_EQ(1u, apps
.size());
541 base::FilePath crx_path
;
543 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
544 EXPECT_TRUE(base::PathExists(crx_path
));
545 EXPECT_EQ("1.0.0", version
);
547 // Remove the app now.
548 manager()->RemoveApp(kTestLocalFsKioskApp
, owner_settings_service_
.get());
549 content::RunAllBlockingPoolTasksUntilIdle();
550 manager()->GetApps(&apps
);
551 ASSERT_EQ(0u, apps
.size());
552 EXPECT_FALSE(base::PathExists(crx_path
));
553 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
556 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateApp
) {
557 // Add a version 1 app first.
558 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
559 KioskAppManager::Apps apps
;
560 manager()->GetApps(&apps
);
561 ASSERT_EQ(1u, apps
.size());
562 base::FilePath crx_path
;
564 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &crx_path
, &version
));
565 EXPECT_TRUE(base::PathExists(crx_path
));
566 EXPECT_EQ("1.0.0", version
);
568 // Update to version 2.
569 fake_cws()->SetUpdateCrx(
570 kTestLocalFsKioskApp
,
571 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
573 AppDataLoadWaiter
waiter(manager(), 1);
576 EXPECT_TRUE(waiter
.loaded());
578 // Verify the app has been updated to v2.
579 manager()->GetApps(&apps
);
580 ASSERT_EQ(1u, apps
.size());
581 base::FilePath new_crx_path
;
582 std::string new_version
;
583 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &new_crx_path
, &new_version
));
584 EXPECT_EQ("2.0.0", new_version
);
585 EXPECT_TRUE(base::PathExists(new_crx_path
));
586 // Get original version 2 source download crx file path.
587 base::FilePath test_data_dir
;
588 PathService::Get(chrome::DIR_TEST_DATA
, &test_data_dir
);
589 base::FilePath v2_file_path
= test_data_dir
.Append(FILE_PATH_LITERAL(
590 "chromeos/app_mode/webstore/downloads/"
591 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx"));
592 EXPECT_TRUE(base::PathExists(v2_file_path
));
593 EXPECT_TRUE(base::ContentsEqual(v2_file_path
, new_crx_path
));
596 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, UpdateAndRemoveApp
) {
597 // Add a version 1 app first.
598 RunAddNewAppTest(kTestLocalFsKioskApp
, "1.0.0", kTestLocalFsKioskAppName
);
599 KioskAppManager::Apps apps
;
600 manager()->GetApps(&apps
);
601 ASSERT_EQ(1u, apps
.size());
602 base::FilePath v1_crx_path
;
604 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &v1_crx_path
, &version
));
605 EXPECT_TRUE(base::PathExists(v1_crx_path
));
606 EXPECT_EQ("1.0.0", version
);
608 // Update to version 2.
609 fake_cws()->SetUpdateCrx(
610 kTestLocalFsKioskApp
,
611 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx",
613 AppDataLoadWaiter
waiter(manager(), 1);
616 EXPECT_TRUE(waiter
.loaded());
618 // Verify the app has been updated to v2.
619 manager()->GetApps(&apps
);
620 ASSERT_EQ(1u, apps
.size());
621 base::FilePath v2_crx_path
;
622 std::string new_version
;
623 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp
, &v2_crx_path
, &new_version
));
624 EXPECT_EQ("2.0.0", new_version
);
625 // Verify both v1 and v2 crx files exist.
626 EXPECT_TRUE(base::PathExists(v1_crx_path
));
627 EXPECT_TRUE(base::PathExists(v2_crx_path
));
629 // Remove the app now.
630 manager()->RemoveApp(kTestLocalFsKioskApp
, owner_settings_service_
.get());
631 content::RunAllBlockingPoolTasksUntilIdle();
632 manager()->GetApps(&apps
);
633 ASSERT_EQ(0u, apps
.size());
634 // Verify both v1 and v2 crx files are removed.
635 EXPECT_FALSE(base::PathExists(v1_crx_path
));
636 EXPECT_FALSE(base::PathExists(v2_crx_path
));
637 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp
, &v2_crx_path
, &version
));
640 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
, EnableConsumerKiosk
) {
641 scoped_ptr
<KioskAppManager::ConsumerKioskAutoLaunchStatus
> status(
642 new KioskAppManager::ConsumerKioskAutoLaunchStatus(
643 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
));
644 scoped_ptr
<bool> locked(new bool(false));
646 scoped_refptr
<content::MessageLoopRunner
> runner
=
647 new content::MessageLoopRunner
;
648 manager()->GetConsumerKioskAutoLaunchStatus(
649 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
651 runner
->QuitClosure()));
653 EXPECT_EQ(*status
.get(),
654 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE
);
656 scoped_refptr
<content::MessageLoopRunner
> runner2
=
657 new content::MessageLoopRunner
;
658 manager()->EnableConsumerKioskAutoLaunch(
659 base::Bind(&ConsumerKioskModeLockCheck
,
661 runner2
->QuitClosure()));
663 EXPECT_TRUE(*locked
.get());
665 scoped_refptr
<content::MessageLoopRunner
> runner3
=
666 new content::MessageLoopRunner
;
667 manager()->GetConsumerKioskAutoLaunchStatus(
668 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
670 runner3
->QuitClosure()));
672 EXPECT_EQ(*status
.get(),
673 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED
);
676 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest
,
677 PreventEnableConsumerKioskForEnterprise
) {
678 // First, lock the device as enterprise.
679 EXPECT_EQ(LockDeviceForEnterprise(),
680 policy::EnterpriseInstallAttributes::LOCK_SUCCESS
);
682 scoped_ptr
<KioskAppManager::ConsumerKioskAutoLaunchStatus
> status(
683 new KioskAppManager::ConsumerKioskAutoLaunchStatus(
684 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
));
685 scoped_ptr
<bool> locked(new bool(true));
687 scoped_refptr
<content::MessageLoopRunner
> runner
=
688 new content::MessageLoopRunner
;
689 manager()->GetConsumerKioskAutoLaunchStatus(
690 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
692 runner
->QuitClosure()));
694 EXPECT_EQ(*status
.get(),
695 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
);
697 scoped_refptr
<content::MessageLoopRunner
> runner2
=
698 new content::MessageLoopRunner
;
699 manager()->EnableConsumerKioskAutoLaunch(
700 base::Bind(&ConsumerKioskModeLockCheck
,
702 runner2
->QuitClosure()));
704 EXPECT_FALSE(*locked
.get());
706 scoped_refptr
<content::MessageLoopRunner
> runner3
=
707 new content::MessageLoopRunner
;
708 manager()->GetConsumerKioskAutoLaunchStatus(
709 base::Bind(&ConsumerKioskAutoLaunchStatusCheck
,
711 runner3
->QuitClosure()));
713 EXPECT_EQ(*status
.get(),
714 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED
);
717 } // namespace chromeos