| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
| 28 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 | 30 |
| 31 namespace chromeos { | 31 namespace chromeos { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kWebstoreDomain[] = "cws.com"; | 35 const char kWebstoreDomain[] = "cws.com"; |
| 36 | 36 |
| 37 // Helper KioskAppManager::GetConsumerKioskModeStatusCallback implementation. | 37 // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback |
| 38 void ConsumerKioskModeStatusCheck( | 38 // implementation. |
| 39 KioskAppManager::ConsumerKioskModeStatus* out_status, | 39 void ConsumerKioskAutoLaunchStatusCheck( |
| 40 KioskAppManager::ConsumerKioskAutoLaunchStatus* out_status, |
| 40 const base::Closure& runner_quit_task, | 41 const base::Closure& runner_quit_task, |
| 41 KioskAppManager::ConsumerKioskModeStatus in_status) { | 42 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status) { |
| 42 LOG(INFO) << "ConsumerKioskModeStatus = " << in_status; | 43 LOG(INFO) << "ConsumerKioskAutoLaunchStatus = " << in_status; |
| 43 *out_status = in_status; | 44 *out_status = in_status; |
| 44 runner_quit_task.Run(); | 45 runner_quit_task.Run(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 // Helper KioskAppManager::EnableKioskModeCallback implementation. | 48 // Helper KioskAppManager::EnableKioskModeCallback implementation. |
| 48 void ConsumerKioskModeLockCheck( | 49 void ConsumerKioskModeLockCheck( |
| 49 bool* out_locked, | 50 bool* out_locked, |
| 50 const base::Closure& runner_quit_task, | 51 const base::Closure& runner_quit_task, |
| 51 bool in_locked) { | 52 bool in_locked) { |
| 52 LOG(INFO) << "kioks locked = " << in_locked; | 53 LOG(INFO) << "kioks locked = " << in_locked; |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 | 440 |
| 440 base::FilePath expected_icon_path; | 441 base::FilePath expected_icon_path; |
| 441 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); | 442 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| 442 expected_icon_path = expected_icon_path. | 443 expected_icon_path = expected_icon_path. |
| 443 AppendASCII(KioskAppManager::kIconCacheDir). | 444 AppendASCII(KioskAppManager::kIconCacheDir). |
| 444 AppendASCII(apps[0].app_id).AddExtension(".png"); | 445 AppendASCII(apps[0].app_id).AddExtension(".png"); |
| 445 EXPECT_EQ(expected_icon_path.value(), icon_path_string); | 446 EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| 446 } | 447 } |
| 447 | 448 |
| 448 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { | 449 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { |
| 449 scoped_ptr<KioskAppManager::ConsumerKioskModeStatus> status( | 450 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 450 new KioskAppManager::ConsumerKioskModeStatus( | 451 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 451 KioskAppManager::CONSUMER_KIOSK_MODE_DISABLED)); | 452 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 452 scoped_ptr<bool> locked(new bool(false)); | 453 scoped_ptr<bool> locked(new bool(false)); |
| 453 | 454 |
| 454 scoped_refptr<content::MessageLoopRunner> runner = | 455 scoped_refptr<content::MessageLoopRunner> runner = |
| 455 new content::MessageLoopRunner; | 456 new content::MessageLoopRunner; |
| 456 manager()->GetConsumerKioskModeStatus( | 457 manager()->GetConsumerKioskAutoLaunchStatus( |
| 457 base::Bind(&ConsumerKioskModeStatusCheck, | 458 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 458 status.get(), | 459 status.get(), |
| 459 runner->QuitClosure())); | 460 runner->QuitClosure())); |
| 460 runner->Run(); | 461 runner->Run(); |
| 461 EXPECT_EQ(*status.get(), KioskAppManager::CONSUMER_KIOSK_MODE_CONFIGURABLE); | 462 EXPECT_EQ(*status.get(), |
| 463 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_CONFIGURABLE); |
| 462 | 464 |
| 463 scoped_refptr<content::MessageLoopRunner> runner2 = | 465 scoped_refptr<content::MessageLoopRunner> runner2 = |
| 464 new content::MessageLoopRunner; | 466 new content::MessageLoopRunner; |
| 465 manager()->EnableConsumerModeKiosk( | 467 manager()->EnableConsumerModeKioskAutoStart( |
| 466 base::Bind(&ConsumerKioskModeLockCheck, | 468 base::Bind(&ConsumerKioskModeLockCheck, |
| 467 locked.get(), | 469 locked.get(), |
| 468 runner2->QuitClosure())); | 470 runner2->QuitClosure())); |
| 469 runner2->Run(); | 471 runner2->Run(); |
| 470 EXPECT_TRUE(*locked.get()); | 472 EXPECT_TRUE(*locked.get()); |
| 471 | 473 |
| 472 scoped_refptr<content::MessageLoopRunner> runner3 = | 474 scoped_refptr<content::MessageLoopRunner> runner3 = |
| 473 new content::MessageLoopRunner; | 475 new content::MessageLoopRunner; |
| 474 manager()->GetConsumerKioskModeStatus( | 476 manager()->GetConsumerKioskAutoLaunchStatus( |
| 475 base::Bind(&ConsumerKioskModeStatusCheck, | 477 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 476 status.get(), | 478 status.get(), |
| 477 runner3->QuitClosure())); | 479 runner3->QuitClosure())); |
| 478 runner3->Run(); | 480 runner3->Run(); |
| 479 EXPECT_EQ(*status.get(), KioskAppManager::CONSUMER_KIOSK_MODE_ENABLED); | 481 EXPECT_EQ(*status.get(), |
| 482 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_ENABLED); |
| 480 } | 483 } |
| 481 | 484 |
| 482 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, | 485 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, |
| 483 PreventEnableConsumerKioskForEnterprise) { | 486 PreventEnableConsumerKioskForEnterprise) { |
| 484 // First, lock the device as enterprise. | 487 // First, lock the device as enterprise. |
| 485 EXPECT_EQ(LockDeviceForEnterprise(), | 488 EXPECT_EQ(LockDeviceForEnterprise(), |
| 486 policy::EnterpriseInstallAttributes::LOCK_SUCCESS); | 489 policy::EnterpriseInstallAttributes::LOCK_SUCCESS); |
| 487 | 490 |
| 488 scoped_ptr<KioskAppManager::ConsumerKioskModeStatus> status( | 491 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 489 new KioskAppManager::ConsumerKioskModeStatus( | 492 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 490 KioskAppManager::CONSUMER_KIOSK_MODE_DISABLED)); | 493 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 491 scoped_ptr<bool> locked(new bool(true)); | 494 scoped_ptr<bool> locked(new bool(true)); |
| 492 | 495 |
| 493 scoped_refptr<content::MessageLoopRunner> runner = | 496 scoped_refptr<content::MessageLoopRunner> runner = |
| 494 new content::MessageLoopRunner; | 497 new content::MessageLoopRunner; |
| 495 manager()->GetConsumerKioskModeStatus( | 498 manager()->GetConsumerKioskAutoLaunchStatus( |
| 496 base::Bind(&ConsumerKioskModeStatusCheck, | 499 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 497 status.get(), | 500 status.get(), |
| 498 runner->QuitClosure())); | 501 runner->QuitClosure())); |
| 499 runner->Run(); | 502 runner->Run(); |
| 500 EXPECT_EQ(*status.get(), KioskAppManager::CONSUMER_KIOSK_MODE_DISABLED); | 503 EXPECT_EQ(*status.get(), |
| 504 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 501 | 505 |
| 502 scoped_refptr<content::MessageLoopRunner> runner2 = | 506 scoped_refptr<content::MessageLoopRunner> runner2 = |
| 503 new content::MessageLoopRunner; | 507 new content::MessageLoopRunner; |
| 504 manager()->EnableConsumerModeKiosk( | 508 manager()->EnableConsumerModeKioskAutoStart( |
| 505 base::Bind(&ConsumerKioskModeLockCheck, | 509 base::Bind(&ConsumerKioskModeLockCheck, |
| 506 locked.get(), | 510 locked.get(), |
| 507 runner2->QuitClosure())); | 511 runner2->QuitClosure())); |
| 508 runner2->Run(); | 512 runner2->Run(); |
| 509 EXPECT_FALSE(*locked.get()); | 513 EXPECT_FALSE(*locked.get()); |
| 510 | 514 |
| 511 scoped_refptr<content::MessageLoopRunner> runner3 = | 515 scoped_refptr<content::MessageLoopRunner> runner3 = |
| 512 new content::MessageLoopRunner; | 516 new content::MessageLoopRunner; |
| 513 manager()->GetConsumerKioskModeStatus( | 517 manager()->GetConsumerKioskAutoLaunchStatus( |
| 514 base::Bind(&ConsumerKioskModeStatusCheck, | 518 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 515 status.get(), | 519 status.get(), |
| 516 runner3->QuitClosure())); | 520 runner3->QuitClosure())); |
| 517 runner3->Run(); | 521 runner3->Run(); |
| 518 EXPECT_EQ(*status.get(), KioskAppManager::CONSUMER_KIOSK_MODE_DISABLED); | 522 EXPECT_EQ(*status.get(), |
| 523 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 519 } | 524 } |
| 520 | 525 |
| 521 } // namespace chromeos | 526 } // namespace chromeos |
| OLD | NEW |