Chromium Code Reviews| Index: chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc |
| diff --git a/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc b/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc |
| index a675a7e9e40f99b3a0d893c20b577212a7154ecc..3100efdae16879eb6cd90aa389c7f7542397bd03 100644 |
| --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc |
| +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc |
| @@ -14,6 +14,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| +#include "chrome/browser/chromeos/app_mode/kiosk_test_common.h" |
| #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| #include "chrome/browser/chromeos/policy/device_local_account.h" |
| #include "chrome/browser/chromeos/settings/cros_settings.h" |
| @@ -34,6 +35,23 @@ namespace { |
| const char kWebstoreDomain[] = "cws.com"; |
| +// An app to test local fs data persistence across app update. V1 app writes |
| +// data into local fs. V2 app reads and verifies the data. |
| +// Webstore data json is in |
| +// chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ |
| +// detail/bmbpicmpniaclbbpdkfglgipkkebnbjf |
| +// The version 1.0.0 installed is in |
| +// chrome/test/data/chromeos/app_mode/webstore/downloads/ |
| +// bmbpicmpniaclbbpdkfglgipkkebnbjf.crx |
| +// The version 2.0.0 crx is in |
| +// chrome/test/data/chromeos/app_mode/webstore/downloads/ |
| +// bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx |
| +const char kTestLocalFsKioskApp[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf"; |
| +const char kTestLocalFsKioskAppName[] = "Kiosk App With Local Data"; |
| + |
| +// Kiosk app crx file download path under web store site. |
| +const char kCrxDownloadPath[] = "/webstore/downloads/"; |
|
xiyuan
2014/05/09 20:49:15
This feels like part of KioskTestCommon (FakeCWS).
jennyz
2014/05/13 00:31:21
Done.
|
| + |
| // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback |
| // implementation. |
| void ConsumerKioskAutoLaunchStatusCheck( |
| @@ -126,8 +144,15 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { |
| public: |
| explicit AppDataLoadWaiter(KioskAppManager* manager) |
| : manager_(manager), |
| - loaded_(false) { |
| - } |
| + loaded_(false), |
| + data_change_count_(0), |
| + data_loaded_threshold_(1) {} |
| + |
| + AppDataLoadWaiter(KioskAppManager* manager, int data_loaded_threshold) |
|
xiyuan
2014/05/09 20:49:15
Let's keep just this one and remove the one in lin
jennyz
2014/05/13 00:31:21
Done.
|
| + : manager_(manager), |
| + loaded_(false), |
| + data_change_count_(0), |
| + data_loaded_threshold_(data_loaded_threshold) {} |
| virtual ~AppDataLoadWaiter() { |
| } |
| @@ -144,6 +169,9 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { |
| private: |
| // KioskAppManagerObserver overrides: |
| virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE { |
| + ++data_change_count_; |
| + if (data_change_count_ < data_loaded_threshold_) |
| + return; |
| loaded_ = true; |
| runner_->Quit(); |
| } |
| @@ -156,13 +184,16 @@ class AppDataLoadWaiter : public KioskAppManagerObserver { |
| scoped_refptr<content::MessageLoopRunner> runner_; |
| KioskAppManager* manager_; |
| bool loaded_; |
| + int data_change_count_; |
| + int data_loaded_threshold_; |
| DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); |
| }; |
| } // namespace |
| -class KioskAppManagerTest : public InProcessBrowserTest { |
| +class KioskAppManagerTest : public InProcessBrowserTest, |
| + public KioskTestCommon { |
| public: |
| KioskAppManagerTest() {} |
| virtual ~KioskAppManagerTest() {} |
| @@ -193,10 +224,10 @@ class KioskAppManagerTest : public InProcessBrowserTest { |
| std::string google_host(kWebstoreDomain); |
| GURL::Replacements replace_google_host; |
| replace_google_host.SetHostStr(google_host); |
| - GURL google_url = server_url.ReplaceComponents(replace_google_host); |
| - GURL fake_store_url = google_url.Resolve("/webstore"); |
| + web_store_url_ = server_url.ReplaceComponents(replace_google_host); |
| + GURL gallery_url = web_store_url_.Resolve("/webstore"); |
| command_line->AppendSwitchASCII(switches::kAppsGalleryURL, |
| - fake_store_url.spec()); |
| + gallery_url.spec()); |
| } |
| virtual void SetUpOnMainThread() OVERRIDE { |
| @@ -283,10 +314,94 @@ class KioskAppManagerTest : public InProcessBrowserTest { |
| device_local_accounts); |
| } |
| + void SetupCrxDownloads() { |
| + GURL downloads_url = web_store_url_.Resolve(kCrxDownloadPath); |
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + ::switches::kAppsGalleryDownloadURL, downloads_url.spec()); |
| + } |
| + |
| + void SetupCrxUpdate() { |
| + GURL update_url = web_store_url_.Resolve("/webstore/update_check.xml"); |
| + CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + ::switches::kAppsGalleryUpdateURL, update_url.spec()); |
| + |
| + embedded_test_server()->RegisterRequestHandler(base::Bind( |
| + &KioskAppManagerTest::HandleRequest, base::Unretained(this))); |
| + } |
| + |
| + bool GetKioskAppExtension(const std::string& app_id, |
| + base::FilePath* file_path, |
| + std::string* version) { |
| + return manager()->GetKioskAppExtension(app_id, file_path, version); |
| + } |
| + |
| + void UpdateAppData() { manager()->UpdateAppData(); } |
| + |
| + void RunAddNewAppTest(const std::string& id, |
| + const std::string& version, |
| + const std::string& app_name) { |
| + SetupCrxDownloads(); |
| + SetupCrxUpdate(); |
| + std::string crx_file_name = id + ".crx"; |
| + SetUpdateCrx(web_store_url_, kCrxDownloadPath, id, crx_file_name, version); |
| + |
| + AppDataLoadWaiter waiter(manager(), 2); |
| + manager()->AddApp(id); |
| + waiter.Wait(); |
| + EXPECT_TRUE(waiter.loaded()); |
| + |
| + // Check CRX file is cached. |
| + base::FilePath crx_path; |
| + std::string crx_version; |
| + EXPECT_TRUE(GetKioskAppExtension(id, &crx_path, &crx_version)); |
| + EXPECT_TRUE(base::PathExists(crx_path)); |
| + EXPECT_EQ(version, crx_version); |
| + // Verify the original crx file is identical to the cached file. |
| + base::FilePath test_data_dir; |
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| + std::string src_file_path_str = |
| + std::string("chromeos/app_mode/webstore/downloads/") + crx_file_name; |
| + base::FilePath src_file_path = test_data_dir.Append(src_file_path_str); |
| + EXPECT_TRUE(base::PathExists(src_file_path)); |
| + EXPECT_TRUE(base::ContentsEqual(src_file_path, crx_path)); |
| + |
| + // Check manifest data is cached correctly. |
| + KioskAppManager::Apps apps; |
| + manager()->GetApps(&apps); |
| + ASSERT_EQ(1u, apps.size()); |
| + EXPECT_EQ(id, apps[0].app_id); |
| + EXPECT_EQ(app_name, apps[0].name); |
| + EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| + |
| + // Check data is cached in local state. |
| + PrefService* local_state = g_browser_process->local_state(); |
| + const base::DictionaryValue* dict = |
| + local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| + |
| + std::string name; |
| + std::string name_key = "apps." + id + ".name"; |
| + EXPECT_TRUE(dict->GetString(name_key, &name)); |
| + EXPECT_EQ(apps[0].name, name); |
| + |
| + std::string icon_path_string; |
| + std::string icon_path_key = "apps." + id + ".icon"; |
| + EXPECT_TRUE(dict->GetString(icon_path_key, &icon_path_string)); |
| + |
| + base::FilePath expected_icon_path; |
| + ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| + expected_icon_path = |
| + expected_icon_path.AppendASCII(KioskAppManager::kIconCacheDir) |
| + .AppendASCII(apps[0].app_id) |
| + .AddExtension(".png"); |
| + EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| + } |
| + |
| KioskAppManager* manager() const { return KioskAppManager::Get(); } |
| + GURL web_store_url() const { return web_store_url_; } |
| private: |
| base::ScopedTempDir temp_dir_; |
| + GURL web_store_url_; |
| DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); |
| }; |
| @@ -446,6 +561,73 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { |
| EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| } |
| +IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, DownloadNewApp) { |
| + base::FilePath crx_path; |
| + RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, RemoveApp) { |
| + // Add a new app. |
| + RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| + KioskAppManager::Apps apps; |
| + manager()->GetApps(&apps); |
| + ASSERT_EQ(1u, apps.size()); |
| + base::FilePath crx_path; |
| + std::string version; |
| + EXPECT_TRUE(GetKioskAppExtension(kTestLocalFsKioskApp, &crx_path, &version)); |
| + EXPECT_TRUE(base::PathExists(crx_path)); |
| + EXPECT_EQ("1.0.0", version); |
| + |
| + // Remove the app now. |
| + manager()->RemoveApp(kTestLocalFsKioskApp); |
| + manager()->GetApps(&apps); |
| + ASSERT_EQ(0u, apps.size()); |
| + EXPECT_FALSE(base::PathExists(crx_path)); |
| + EXPECT_FALSE(GetKioskAppExtension(kTestLocalFsKioskApp, &crx_path, &version)); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateApp) { |
| + // Add a version 1 app first. |
| + RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| + KioskAppManager::Apps apps; |
| + manager()->GetApps(&apps); |
| + ASSERT_EQ(1u, apps.size()); |
| + base::FilePath crx_path; |
| + std::string version; |
| + EXPECT_TRUE(GetKioskAppExtension(kTestLocalFsKioskApp, &crx_path, &version)); |
| + EXPECT_TRUE(base::PathExists(crx_path)); |
| + EXPECT_EQ("1.0.0", version); |
| + |
| + // Update to version 2. |
| + SetUpdateCrx(web_store_url(), |
| + kCrxDownloadPath, |
| + kTestLocalFsKioskApp, |
| + "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", |
| + "2.0.0"); |
| + AppDataLoadWaiter waiter(manager()); |
| + UpdateAppData(); |
| + waiter.Wait(); |
| + EXPECT_TRUE(waiter.loaded()); |
| + |
| + // Verify the app has been updated to v2. |
| + manager()->GetApps(&apps); |
| + ASSERT_EQ(1u, apps.size()); |
| + base::FilePath new_crx_path; |
| + std::string new_version; |
| + EXPECT_TRUE( |
| + GetKioskAppExtension(kTestLocalFsKioskApp, &new_crx_path, &new_version)); |
| + EXPECT_EQ("2.0.0", new_version); |
| + EXPECT_TRUE(base::PathExists(new_crx_path)); |
| + // Get original version 2 source download crx file path. |
| + base::FilePath test_data_dir; |
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| + base::FilePath v2_file_path = test_data_dir.Append(FILE_PATH_LITERAL( |
| + "chromeos/app_mode/webstore/downloads/" |
| + "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx")); |
| + EXPECT_TRUE(base::PathExists(v2_file_path)); |
| + EXPECT_TRUE(base::ContentsEqual(v2_file_path, new_crx_path)); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { |
| scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| new KioskAppManager::ConsumerKioskAutoLaunchStatus( |