Chromium Code Reviews| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chromeos/app_mode/fake_cws.h" | |
| 16 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/policy/device_local_account.h" | 19 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 24 #include "chromeos/settings/cros_settings_names.h" | 25 #include "chromeos/settings/cros_settings_names.h" |
| 25 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "net/base/host_port_pair.h" | 28 #include "net/base/host_port_pair.h" |
| 28 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
| 29 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 | 31 |
| 31 namespace chromeos { | 32 namespace chromeos { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const char kWebstoreDomain[] = "cws.com"; | 36 // An app to test local fs data persistence across app update. V1 app writes |
| 37 // data into local fs. V2 app reads and verifies the data. | |
| 38 // Webstore data json is in | |
| 39 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/ | |
| 40 // detail/bmbpicmpniaclbbpdkfglgipkkebnbjf | |
| 41 // The version 1.0.0 installed is in | |
| 42 // chrome/test/data/chromeos/app_mode/webstore/downloads/ | |
| 43 // bmbpicmpniaclbbpdkfglgipkkebnbjf.crx | |
| 44 // The version 2.0.0 crx is in | |
| 45 // chrome/test/data/chromeos/app_mode/webstore/downloads/ | |
| 46 // bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx | |
| 47 const char kTestLocalFsKioskApp[] = "bmbpicmpniaclbbpdkfglgipkkebnbjf"; | |
| 48 const char kTestLocalFsKioskAppName[] = "Kiosk App With Local Data"; | |
| 36 | 49 |
| 37 // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback | 50 // Helper KioskAppManager::GetConsumerKioskAutoLaunchStatusCallback |
| 38 // implementation. | 51 // implementation. |
| 39 void ConsumerKioskAutoLaunchStatusCheck( | 52 void ConsumerKioskAutoLaunchStatusCheck( |
| 40 KioskAppManager::ConsumerKioskAutoLaunchStatus* out_status, | 53 KioskAppManager::ConsumerKioskAutoLaunchStatus* out_status, |
| 41 const base::Closure& runner_quit_task, | 54 const base::Closure& runner_quit_task, |
| 42 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status) { | 55 KioskAppManager::ConsumerKioskAutoLaunchStatus in_status) { |
| 43 LOG(INFO) << "ConsumerKioskAutoLaunchStatus = " << in_status; | 56 LOG(INFO) << "ConsumerKioskAutoLaunchStatus = " << in_status; |
| 44 *out_status = in_status; | 57 *out_status = in_status; |
| 45 runner_quit_task.Run(); | 58 runner_quit_task.Run(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 130 |
| 118 KioskAppManager* manager_; | 131 KioskAppManager* manager_; |
| 119 int data_changed_count_; | 132 int data_changed_count_; |
| 120 int load_failure_count_; | 133 int load_failure_count_; |
| 121 | 134 |
| 122 DISALLOW_COPY_AND_ASSIGN(TestKioskAppManagerObserver); | 135 DISALLOW_COPY_AND_ASSIGN(TestKioskAppManagerObserver); |
| 123 }; | 136 }; |
| 124 | 137 |
| 125 class AppDataLoadWaiter : public KioskAppManagerObserver { | 138 class AppDataLoadWaiter : public KioskAppManagerObserver { |
| 126 public: | 139 public: |
| 127 explicit AppDataLoadWaiter(KioskAppManager* manager) | 140 AppDataLoadWaiter(KioskAppManager* manager, int data_loaded_threshold) |
| 128 : manager_(manager), | 141 : runner_(NULL), |
| 129 loaded_(false) { | 142 manager_(manager), |
| 143 loaded_(false), | |
| 144 quit_(false), | |
| 145 data_change_count_(0), | |
| 146 data_loaded_threshold_(data_loaded_threshold) { | |
| 147 manager_->AddObserver(this); | |
| 130 } | 148 } |
| 131 | 149 |
| 132 virtual ~AppDataLoadWaiter() { | 150 virtual ~AppDataLoadWaiter() { manager_->RemoveObserver(this); } |
| 133 } | |
| 134 | 151 |
| 135 void Wait() { | 152 void Wait() { |
| 136 manager_->AddObserver(this); | 153 if (quit_) |
|
xiyuan
2014/05/13 16:43:35
Can we use |loaded_| and get rid of |quit_|?
jennyz
2014/05/13 18:36:11
In OnKioskAppDataLoadFailure case, loaded will be
| |
| 154 return; | |
| 137 runner_ = new content::MessageLoopRunner; | 155 runner_ = new content::MessageLoopRunner; |
| 138 runner_->Run(); | 156 runner_->Run(); |
| 139 manager_->RemoveObserver(this); | |
| 140 } | 157 } |
| 141 | 158 |
| 142 bool loaded() const { return loaded_; } | 159 bool loaded() const { return loaded_; } |
| 143 | 160 |
| 144 private: | 161 private: |
| 145 // KioskAppManagerObserver overrides: | 162 // KioskAppManagerObserver overrides: |
| 146 virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE { | 163 virtual void OnKioskAppDataChanged(const std::string& app_id) OVERRIDE { |
| 164 ++data_change_count_; | |
| 165 if (data_change_count_ < data_loaded_threshold_) | |
| 166 return; | |
| 147 loaded_ = true; | 167 loaded_ = true; |
| 148 runner_->Quit(); | 168 quit_ = true; |
| 169 if (runner_) | |
| 170 runner_->Quit(); | |
| 149 } | 171 } |
| 150 | 172 |
| 151 virtual void OnKioskAppDataLoadFailure(const std::string& app_id) OVERRIDE { | 173 virtual void OnKioskAppDataLoadFailure(const std::string& app_id) OVERRIDE { |
| 152 loaded_ = false; | 174 loaded_ = false; |
| 153 runner_->Quit(); | 175 quit_ = true; |
| 176 if (runner_) | |
| 177 runner_->Quit(); | |
| 154 } | 178 } |
| 155 | 179 |
| 156 scoped_refptr<content::MessageLoopRunner> runner_; | 180 scoped_refptr<content::MessageLoopRunner> runner_; |
| 157 KioskAppManager* manager_; | 181 KioskAppManager* manager_; |
| 158 bool loaded_; | 182 bool loaded_; |
| 183 bool quit_; | |
| 184 int data_change_count_; | |
| 185 int data_loaded_threshold_; | |
| 159 | 186 |
| 160 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); | 187 DISALLOW_COPY_AND_ASSIGN(AppDataLoadWaiter); |
| 161 }; | 188 }; |
| 162 | 189 |
| 163 } // namespace | 190 } // namespace |
| 164 | 191 |
| 165 class KioskAppManagerTest : public InProcessBrowserTest { | 192 class KioskAppManagerTest : public InProcessBrowserTest { |
| 166 public: | 193 public: |
| 167 KioskAppManagerTest() {} | 194 KioskAppManagerTest() : fake_cws_(new FakeCWS()) {} |
| 168 virtual ~KioskAppManagerTest() {} | 195 virtual ~KioskAppManagerTest() {} |
| 169 | 196 |
| 170 // InProcessBrowserTest overrides: | 197 // InProcessBrowserTest overrides: |
| 171 virtual void SetUp() OVERRIDE { | 198 virtual void SetUp() OVERRIDE { |
| 172 base::FilePath test_data_dir; | 199 base::FilePath test_data_dir; |
| 173 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 200 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 174 base::FilePath webstore_dir = | 201 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 175 test_data_dir.Append(FILE_PATH_LITERAL("chromeos/app_mode/")); | |
| 176 embedded_test_server()->ServeFilesFromDirectory(webstore_dir); | |
| 177 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 202 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 178 // Stop IO thread here because no threads are allowed while | 203 // Stop IO thread here because no threads are allowed while |
| 179 // spawning sandbox host process. See crbug.com/322732. | 204 // spawning sandbox host process. See crbug.com/322732. |
| 180 embedded_test_server()->StopThread(); | 205 embedded_test_server()->StopThread(); |
| 181 | 206 |
| 182 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 207 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 183 | 208 |
| 184 InProcessBrowserTest::SetUp(); | 209 InProcessBrowserTest::SetUp(); |
| 185 } | 210 } |
| 186 | 211 |
| 187 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 212 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 188 InProcessBrowserTest::SetUpCommandLine(command_line); | 213 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 189 | 214 |
| 190 // Get fake webstore gallery URL. At the end, it should look something like | 215 // Initialize fake_cws_ to setup web store gallery. |
| 191 // http://cws.com:<test_server_port>/webstore. | 216 fake_cws_->Init(embedded_test_server(), true); // Set up gallery url only. |
| 192 const GURL& server_url = embedded_test_server()->base_url(); | |
| 193 std::string google_host(kWebstoreDomain); | |
| 194 GURL::Replacements replace_google_host; | |
| 195 replace_google_host.SetHostStr(google_host); | |
| 196 GURL google_url = server_url.ReplaceComponents(replace_google_host); | |
| 197 GURL fake_store_url = google_url.Resolve("/webstore"); | |
| 198 command_line->AppendSwitchASCII(switches::kAppsGalleryURL, | |
| 199 fake_store_url.spec()); | |
| 200 } | 217 } |
| 201 | 218 |
| 202 virtual void SetUpOnMainThread() OVERRIDE { | 219 virtual void SetUpOnMainThread() OVERRIDE { |
| 203 InProcessBrowserTest::SetUpOnMainThread(); | 220 InProcessBrowserTest::SetUpOnMainThread(); |
| 204 | 221 |
| 205 // Restart the thread as the sandbox host process has already been spawned. | 222 // Restart the thread as the sandbox host process has already been spawned. |
| 206 embedded_test_server()->RestartThreadAndListen(); | 223 embedded_test_server()->RestartThreadAndListen(); |
| 207 } | 224 } |
| 208 | 225 |
| 209 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 226 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 210 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | 227 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 211 | 228 |
| 212 host_resolver()->AddRule(kWebstoreDomain, "127.0.0.1"); | 229 host_resolver()->AddRule(fake_cws_->GetWebStoreDomain(), "127.0.0.1"); |
|
xiyuan
2014/05/13 16:43:35
We can just map "*" to 127.0.0.1. No need to just
jennyz
2014/05/13 18:36:11
Done.
| |
| 213 } | 230 } |
| 214 | 231 |
| 215 std::string GetAppIds() const { | 232 std::string GetAppIds() const { |
| 216 KioskAppManager::Apps apps; | 233 KioskAppManager::Apps apps; |
| 217 manager()->GetApps(&apps); | 234 manager()->GetApps(&apps); |
| 218 | 235 |
| 219 std::string str; | 236 std::string str; |
| 220 for (size_t i = 0; i < apps.size(); ++i) { | 237 for (size_t i = 0; i < apps.size(); ++i) { |
| 221 if (i > 0) | 238 if (i > 0) |
| 222 str += ','; | 239 str += ','; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 kAccountsPrefDeviceLocalAccountsKeyType, | 293 kAccountsPrefDeviceLocalAccountsKeyType, |
| 277 policy::DeviceLocalAccount::TYPE_KIOSK_APP); | 294 policy::DeviceLocalAccount::TYPE_KIOSK_APP); |
| 278 entry->SetStringWithoutPathExpansion( | 295 entry->SetStringWithoutPathExpansion( |
| 279 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 296 kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| 280 app_id); | 297 app_id); |
| 281 device_local_accounts.Append(entry.release()); | 298 device_local_accounts.Append(entry.release()); |
| 282 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, | 299 CrosSettings::Get()->Set(kAccountsPrefDeviceLocalAccounts, |
| 283 device_local_accounts); | 300 device_local_accounts); |
| 284 } | 301 } |
| 285 | 302 |
| 303 bool GetCachedCrx(const std::string& app_id, | |
| 304 base::FilePath* file_path, | |
| 305 std::string* version) { | |
| 306 return manager()->GetCachedCrx(app_id, file_path, version); | |
| 307 } | |
| 308 | |
| 309 void UpdateAppData() { manager()->UpdateAppData(); } | |
| 310 | |
| 311 void RunAddNewAppTest(const std::string& id, | |
| 312 const std::string& version, | |
| 313 const std::string& app_name) { | |
| 314 fake_cws_->SetupCrxDownloadAndUpdateUrls(embedded_test_server()); | |
| 315 std::string crx_file_name = id + ".crx"; | |
| 316 fake_cws_->SetUpdateCrx(id, crx_file_name, version); | |
| 317 | |
| 318 AppDataLoadWaiter waiter(manager(), 3); | |
| 319 manager()->AddApp(id); | |
| 320 waiter.Wait(); | |
| 321 EXPECT_TRUE(waiter.loaded()); | |
| 322 | |
| 323 // Check CRX file is cached. | |
| 324 base::FilePath crx_path; | |
| 325 std::string crx_version; | |
| 326 EXPECT_TRUE(GetCachedCrx(id, &crx_path, &crx_version)); | |
| 327 EXPECT_TRUE(base::PathExists(crx_path)); | |
| 328 EXPECT_EQ(version, crx_version); | |
| 329 // Verify the original crx file is identical to the cached file. | |
| 330 base::FilePath test_data_dir; | |
| 331 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | |
| 332 std::string src_file_path_str = | |
| 333 std::string("chromeos/app_mode/webstore/downloads/") + crx_file_name; | |
| 334 base::FilePath src_file_path = test_data_dir.Append(src_file_path_str); | |
| 335 EXPECT_TRUE(base::PathExists(src_file_path)); | |
| 336 EXPECT_TRUE(base::ContentsEqual(src_file_path, crx_path)); | |
| 337 | |
| 338 // Check manifest data is cached correctly. | |
| 339 KioskAppManager::Apps apps; | |
| 340 manager()->GetApps(&apps); | |
| 341 ASSERT_EQ(1u, apps.size()); | |
| 342 EXPECT_EQ(id, apps[0].app_id); | |
| 343 EXPECT_EQ(app_name, apps[0].name); | |
| 344 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | |
| 345 | |
| 346 // Check data is cached in local state. | |
| 347 PrefService* local_state = g_browser_process->local_state(); | |
| 348 const base::DictionaryValue* dict = | |
| 349 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); | |
| 350 | |
| 351 std::string name; | |
| 352 std::string name_key = "apps." + id + ".name"; | |
| 353 EXPECT_TRUE(dict->GetString(name_key, &name)); | |
| 354 EXPECT_EQ(apps[0].name, name); | |
| 355 | |
| 356 std::string icon_path_string; | |
| 357 std::string icon_path_key = "apps." + id + ".icon"; | |
| 358 EXPECT_TRUE(dict->GetString(icon_path_key, &icon_path_string)); | |
| 359 | |
| 360 base::FilePath expected_icon_path; | |
| 361 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); | |
| 362 expected_icon_path = | |
| 363 expected_icon_path.AppendASCII(KioskAppManager::kIconCacheDir) | |
| 364 .AppendASCII(apps[0].app_id) | |
| 365 .AddExtension(".png"); | |
| 366 EXPECT_EQ(expected_icon_path.value(), icon_path_string); | |
| 367 } | |
| 368 | |
| 286 KioskAppManager* manager() const { return KioskAppManager::Get(); } | 369 KioskAppManager* manager() const { return KioskAppManager::Get(); } |
| 370 FakeCWS* fake_cws() { return fake_cws_.get(); } | |
| 287 | 371 |
| 288 private: | 372 private: |
| 289 base::ScopedTempDir temp_dir_; | 373 base::ScopedTempDir temp_dir_; |
| 374 scoped_ptr<FakeCWS> fake_cws_; | |
| 290 | 375 |
| 291 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); | 376 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); |
| 292 }; | 377 }; |
| 293 | 378 |
| 294 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { | 379 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { |
| 295 // Add a couple of apps. Use "fake_app_x" that do not have data on the test | 380 // Add a couple of apps. Use "fake_app_x" that do not have data on the test |
| 296 // server to avoid pending data loads that could be lingering on tear down and | 381 // server to avoid pending data loads that could be lingering on tear down and |
| 297 // cause DCHECK failure in utility_process_host_impl.cc. | 382 // cause DCHECK failure in utility_process_host_impl.cc. |
| 298 manager()->AddApp("fake_app_1"); | 383 manager()->AddApp("fake_app_1"); |
| 299 manager()->AddApp("fake_app_2"); | 384 manager()->AddApp("fake_app_2"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); | 420 EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); |
| 336 | 421 |
| 337 // Add an existing app again. | 422 // Add an existing app again. |
| 338 manager()->AddApp("fake_app_1"); | 423 manager()->AddApp("fake_app_1"); |
| 339 EXPECT_EQ("fake_app_1", GetAppIds()); | 424 EXPECT_EQ("fake_app_1", GetAppIds()); |
| 340 } | 425 } |
| 341 | 426 |
| 342 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, LoadCached) { | 427 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, LoadCached) { |
| 343 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); | 428 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); |
| 344 | 429 |
| 345 AppDataLoadWaiter waiter(manager()); | 430 AppDataLoadWaiter waiter(manager(), 1); |
| 346 waiter.Wait(); | 431 waiter.Wait(); |
| 347 EXPECT_TRUE(waiter.loaded()); | 432 EXPECT_TRUE(waiter.loaded()); |
| 348 | 433 |
| 349 KioskAppManager::Apps apps; | 434 KioskAppManager::Apps apps; |
| 350 manager()->GetApps(&apps); | 435 manager()->GetApps(&apps); |
| 351 EXPECT_EQ(1u, apps.size()); | 436 EXPECT_EQ(1u, apps.size()); |
| 352 EXPECT_EQ("app_1", apps[0].app_id); | 437 EXPECT_EQ("app_1", apps[0].app_id); |
| 353 EXPECT_EQ("Cached App1 Name", apps[0].name); | 438 EXPECT_EQ("Cached App1 Name", apps[0].name); |
| 354 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | 439 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| 355 } | 440 } |
| 356 | 441 |
| 357 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, ClearAppData) { | 442 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, ClearAppData) { |
| 358 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); | 443 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); |
| 359 | 444 |
| 360 PrefService* local_state = g_browser_process->local_state(); | 445 PrefService* local_state = g_browser_process->local_state(); |
| 361 const base::DictionaryValue* dict = | 446 const base::DictionaryValue* dict = |
| 362 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); | 447 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 363 const base::DictionaryValue* apps_dict; | 448 const base::DictionaryValue* apps_dict; |
| 364 EXPECT_TRUE(dict->GetDictionary(KioskAppManager::kKeyApps, &apps_dict)); | 449 EXPECT_TRUE(dict->GetDictionary(KioskAppManager::kKeyApps, &apps_dict)); |
| 365 EXPECT_TRUE(apps_dict->HasKey("app_1")); | 450 EXPECT_TRUE(apps_dict->HasKey("app_1")); |
| 366 | 451 |
| 367 manager()->ClearAppData("app_1"); | 452 manager()->ClearAppData("app_1"); |
| 368 | 453 |
| 369 EXPECT_FALSE(apps_dict->HasKey("app_1")); | 454 EXPECT_FALSE(apps_dict->HasKey("app_1")); |
| 370 } | 455 } |
| 371 | 456 |
| 372 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateAppDataFromProfile) { | 457 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateAppDataFromProfile) { |
| 373 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); | 458 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); |
| 374 | 459 |
| 375 AppDataLoadWaiter waiter(manager()); | 460 AppDataLoadWaiter waiter(manager(), 1); |
| 376 waiter.Wait(); | 461 waiter.Wait(); |
| 377 EXPECT_TRUE(waiter.loaded()); | 462 EXPECT_TRUE(waiter.loaded()); |
| 378 | 463 |
| 379 KioskAppManager::Apps apps; | 464 KioskAppManager::Apps apps; |
| 380 manager()->GetApps(&apps); | 465 manager()->GetApps(&apps); |
| 381 EXPECT_EQ(1u, apps.size()); | 466 EXPECT_EQ(1u, apps.size()); |
| 382 EXPECT_EQ("app_1", apps[0].app_id); | 467 EXPECT_EQ("app_1", apps[0].app_id); |
| 383 EXPECT_EQ("Cached App1 Name", apps[0].name); | 468 EXPECT_EQ("Cached App1 Name", apps[0].name); |
| 384 | 469 |
| 385 scoped_refptr<extensions::Extension> updated_app = | 470 scoped_refptr<extensions::Extension> updated_app = |
| 386 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1"); | 471 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1"); |
| 387 manager()->UpdateAppDataFromProfile( | 472 manager()->UpdateAppDataFromProfile( |
| 388 "app_1", browser()->profile(), updated_app.get()); | 473 "app_1", browser()->profile(), updated_app.get()); |
| 389 | 474 |
| 390 waiter.Wait(); | 475 waiter.Wait(); |
| 391 EXPECT_TRUE(waiter.loaded()); | 476 EXPECT_TRUE(waiter.loaded()); |
| 392 | 477 |
| 393 manager()->GetApps(&apps); | 478 manager()->GetApps(&apps); |
| 394 EXPECT_EQ(1u, apps.size()); | 479 EXPECT_EQ(1u, apps.size()); |
| 395 EXPECT_EQ("app_1", apps[0].app_id); | 480 EXPECT_EQ("app_1", apps[0].app_id); |
| 396 EXPECT_EQ("Updated App1 Name", apps[0].name); | 481 EXPECT_EQ("Updated App1 Name", apps[0].name); |
| 397 } | 482 } |
| 398 | 483 |
| 399 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { | 484 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { |
| 400 manager()->AddApp("unknown_app"); | 485 manager()->AddApp("unknown_app"); |
| 401 | 486 |
| 402 TestKioskAppManagerObserver observer(manager()); | 487 TestKioskAppManagerObserver observer(manager()); |
| 403 | 488 |
| 404 AppDataLoadWaiter waiter(manager()); | 489 AppDataLoadWaiter waiter(manager(), 1); |
| 405 waiter.Wait(); | 490 waiter.Wait(); |
| 406 EXPECT_FALSE(waiter.loaded()); | 491 EXPECT_FALSE(waiter.loaded()); |
| 407 | 492 |
| 408 EXPECT_EQ("", GetAppIds()); | 493 EXPECT_EQ("", GetAppIds()); |
| 409 EXPECT_EQ(1, observer.load_failure_count()); | 494 EXPECT_EQ(1, observer.load_failure_count()); |
| 410 } | 495 } |
| 411 | 496 |
| 412 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { | 497 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { |
| 413 // Webstore data json is in | 498 // Webstore data json is in |
| 414 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1 | 499 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1 |
| 415 manager()->AddApp("app_1"); | 500 manager()->AddApp("app_1"); |
| 416 | 501 |
| 417 AppDataLoadWaiter waiter(manager()); | 502 AppDataLoadWaiter waiter(manager(), 1); |
| 418 waiter.Wait(); | 503 waiter.Wait(); |
| 419 EXPECT_TRUE(waiter.loaded()); | 504 EXPECT_TRUE(waiter.loaded()); |
| 420 | 505 |
| 421 // Check data is correct. | 506 // Check data is correct. |
| 422 KioskAppManager::Apps apps; | 507 KioskAppManager::Apps apps; |
| 423 manager()->GetApps(&apps); | 508 manager()->GetApps(&apps); |
| 424 ASSERT_EQ(1u, apps.size()); | 509 ASSERT_EQ(1u, apps.size()); |
| 425 EXPECT_EQ("app_1", apps[0].app_id); | 510 EXPECT_EQ("app_1", apps[0].app_id); |
| 426 EXPECT_EQ("Name of App 1", apps[0].name); | 511 EXPECT_EQ("Name of App 1", apps[0].name); |
| 427 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | 512 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 439 EXPECT_TRUE(dict->GetString("apps.app_1.icon", &icon_path_string)); | 524 EXPECT_TRUE(dict->GetString("apps.app_1.icon", &icon_path_string)); |
| 440 | 525 |
| 441 base::FilePath expected_icon_path; | 526 base::FilePath expected_icon_path; |
| 442 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); | 527 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| 443 expected_icon_path = expected_icon_path. | 528 expected_icon_path = expected_icon_path. |
| 444 AppendASCII(KioskAppManager::kIconCacheDir). | 529 AppendASCII(KioskAppManager::kIconCacheDir). |
| 445 AppendASCII(apps[0].app_id).AddExtension(".png"); | 530 AppendASCII(apps[0].app_id).AddExtension(".png"); |
| 446 EXPECT_EQ(expected_icon_path.value(), icon_path_string); | 531 EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| 447 } | 532 } |
| 448 | 533 |
| 534 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, DownloadNewApp) { | |
| 535 base::FilePath crx_path; | |
| 536 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); | |
| 537 } | |
| 538 | |
| 539 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, RemoveApp) { | |
| 540 // Add a new app. | |
| 541 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); | |
| 542 KioskAppManager::Apps apps; | |
| 543 manager()->GetApps(&apps); | |
| 544 ASSERT_EQ(1u, apps.size()); | |
| 545 base::FilePath crx_path; | |
| 546 std::string version; | |
| 547 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); | |
| 548 EXPECT_TRUE(base::PathExists(crx_path)); | |
| 549 EXPECT_EQ("1.0.0", version); | |
| 550 | |
| 551 // Remove the app now. | |
| 552 manager()->RemoveApp(kTestLocalFsKioskApp); | |
| 553 manager()->GetApps(&apps); | |
| 554 ASSERT_EQ(0u, apps.size()); | |
| 555 EXPECT_FALSE(base::PathExists(crx_path)); | |
| 556 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); | |
| 557 } | |
| 558 | |
| 559 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateApp) { | |
| 560 // Add a version 1 app first. | |
| 561 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); | |
| 562 KioskAppManager::Apps apps; | |
| 563 manager()->GetApps(&apps); | |
| 564 ASSERT_EQ(1u, apps.size()); | |
| 565 base::FilePath crx_path; | |
| 566 std::string version; | |
| 567 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); | |
| 568 EXPECT_TRUE(base::PathExists(crx_path)); | |
| 569 EXPECT_EQ("1.0.0", version); | |
| 570 | |
| 571 // Update to version 2. | |
| 572 fake_cws()->SetUpdateCrx( | |
| 573 kTestLocalFsKioskApp, | |
| 574 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", | |
| 575 "2.0.0"); | |
| 576 AppDataLoadWaiter waiter(manager(), 1); | |
| 577 UpdateAppData(); | |
| 578 waiter.Wait(); | |
| 579 EXPECT_TRUE(waiter.loaded()); | |
| 580 | |
| 581 // Verify the app has been updated to v2. | |
| 582 manager()->GetApps(&apps); | |
| 583 ASSERT_EQ(1u, apps.size()); | |
| 584 base::FilePath new_crx_path; | |
| 585 std::string new_version; | |
| 586 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &new_crx_path, &new_version)); | |
| 587 EXPECT_EQ("2.0.0", new_version); | |
| 588 EXPECT_TRUE(base::PathExists(new_crx_path)); | |
| 589 // Get original version 2 source download crx file path. | |
| 590 base::FilePath test_data_dir; | |
| 591 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | |
| 592 base::FilePath v2_file_path = test_data_dir.Append(FILE_PATH_LITERAL( | |
| 593 "chromeos/app_mode/webstore/downloads/" | |
| 594 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx")); | |
| 595 EXPECT_TRUE(base::PathExists(v2_file_path)); | |
| 596 EXPECT_TRUE(base::ContentsEqual(v2_file_path, new_crx_path)); | |
| 597 } | |
| 598 | |
| 449 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { | 599 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { |
| 450 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( | 600 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 451 new KioskAppManager::ConsumerKioskAutoLaunchStatus( | 601 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 452 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); | 602 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 453 scoped_ptr<bool> locked(new bool(false)); | 603 scoped_ptr<bool> locked(new bool(false)); |
| 454 | 604 |
| 455 scoped_refptr<content::MessageLoopRunner> runner = | 605 scoped_refptr<content::MessageLoopRunner> runner = |
| 456 new content::MessageLoopRunner; | 606 new content::MessageLoopRunner; |
| 457 manager()->GetConsumerKioskAutoLaunchStatus( | 607 manager()->GetConsumerKioskAutoLaunchStatus( |
| 458 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 608 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 manager()->GetConsumerKioskAutoLaunchStatus( | 667 manager()->GetConsumerKioskAutoLaunchStatus( |
| 518 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 668 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 519 status.get(), | 669 status.get(), |
| 520 runner3->QuitClosure())); | 670 runner3->QuitClosure())); |
| 521 runner3->Run(); | 671 runner3->Run(); |
| 522 EXPECT_EQ(*status.get(), | 672 EXPECT_EQ(*status.get(), |
| 523 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); | 673 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 524 } | 674 } |
| 525 | 675 |
| 526 } // namespace chromeos | 676 } // namespace chromeos |
| OLD | NEW |