| 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_) |
| 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()); |
| 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("*", "127.0.0.1"); |
| 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 std::string crx_file_name = id + ".crx"; |
| 315 fake_cws_->SetUpdateCrx(id, crx_file_name, version); |
| 316 |
| 317 AppDataLoadWaiter waiter(manager(), 3); |
| 318 manager()->AddApp(id); |
| 319 waiter.Wait(); |
| 320 EXPECT_TRUE(waiter.loaded()); |
| 321 |
| 322 // Check CRX file is cached. |
| 323 base::FilePath crx_path; |
| 324 std::string crx_version; |
| 325 EXPECT_TRUE(GetCachedCrx(id, &crx_path, &crx_version)); |
| 326 EXPECT_TRUE(base::PathExists(crx_path)); |
| 327 EXPECT_EQ(version, crx_version); |
| 328 // Verify the original crx file is identical to the cached file. |
| 329 base::FilePath test_data_dir; |
| 330 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 331 std::string src_file_path_str = |
| 332 std::string("chromeos/app_mode/webstore/downloads/") + crx_file_name; |
| 333 base::FilePath src_file_path = test_data_dir.Append(src_file_path_str); |
| 334 EXPECT_TRUE(base::PathExists(src_file_path)); |
| 335 EXPECT_TRUE(base::ContentsEqual(src_file_path, crx_path)); |
| 336 |
| 337 // Check manifest data is cached correctly. |
| 338 KioskAppManager::Apps apps; |
| 339 manager()->GetApps(&apps); |
| 340 ASSERT_EQ(1u, apps.size()); |
| 341 EXPECT_EQ(id, apps[0].app_id); |
| 342 EXPECT_EQ(app_name, apps[0].name); |
| 343 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); |
| 344 |
| 345 // Check data is cached in local state. |
| 346 PrefService* local_state = g_browser_process->local_state(); |
| 347 const base::DictionaryValue* dict = |
| 348 local_state->GetDictionary(KioskAppManager::kKioskDictionaryName); |
| 349 |
| 350 std::string name; |
| 351 std::string name_key = "apps." + id + ".name"; |
| 352 EXPECT_TRUE(dict->GetString(name_key, &name)); |
| 353 EXPECT_EQ(apps[0].name, name); |
| 354 |
| 355 std::string icon_path_string; |
| 356 std::string icon_path_key = "apps." + id + ".icon"; |
| 357 EXPECT_TRUE(dict->GetString(icon_path_key, &icon_path_string)); |
| 358 |
| 359 base::FilePath expected_icon_path; |
| 360 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| 361 expected_icon_path = |
| 362 expected_icon_path.AppendASCII(KioskAppManager::kIconCacheDir) |
| 363 .AppendASCII(apps[0].app_id) |
| 364 .AddExtension(".png"); |
| 365 EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| 366 } |
| 367 |
| 286 KioskAppManager* manager() const { return KioskAppManager::Get(); } | 368 KioskAppManager* manager() const { return KioskAppManager::Get(); } |
| 369 FakeCWS* fake_cws() { return fake_cws_.get(); } |
| 287 | 370 |
| 288 private: | 371 private: |
| 289 base::ScopedTempDir temp_dir_; | 372 base::ScopedTempDir temp_dir_; |
| 373 scoped_ptr<FakeCWS> fake_cws_; |
| 290 | 374 |
| 291 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); | 375 DISALLOW_COPY_AND_ASSIGN(KioskAppManagerTest); |
| 292 }; | 376 }; |
| 293 | 377 |
| 294 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) { | 378 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 | 379 // 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 | 380 // server to avoid pending data loads that could be lingering on tear down and |
| 297 // cause DCHECK failure in utility_process_host_impl.cc. | 381 // cause DCHECK failure in utility_process_host_impl.cc. |
| 298 manager()->AddApp("fake_app_1"); | 382 manager()->AddApp("fake_app_1"); |
| 299 manager()->AddApp("fake_app_2"); | 383 manager()->AddApp("fake_app_2"); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); | 419 EXPECT_FALSE(manager()->IsAutoLaunchEnabled()); |
| 336 | 420 |
| 337 // Add an existing app again. | 421 // Add an existing app again. |
| 338 manager()->AddApp("fake_app_1"); | 422 manager()->AddApp("fake_app_1"); |
| 339 EXPECT_EQ("fake_app_1", GetAppIds()); | 423 EXPECT_EQ("fake_app_1", GetAppIds()); |
| 340 } | 424 } |
| 341 | 425 |
| 342 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, LoadCached) { | 426 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, LoadCached) { |
| 343 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); | 427 SetExistingApp("app_1", "Cached App1 Name", "red16x16.png"); |
| 344 | 428 |
| 345 AppDataLoadWaiter waiter(manager()); | 429 fake_cws()->SetNoUpdate("app_1"); |
| 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 fake_cws()->SetNoUpdate("app_1"); |
| 461 AppDataLoadWaiter waiter(manager(), 1); |
| 376 waiter.Wait(); | 462 waiter.Wait(); |
| 377 EXPECT_TRUE(waiter.loaded()); | 463 EXPECT_TRUE(waiter.loaded()); |
| 378 | 464 |
| 379 KioskAppManager::Apps apps; | 465 KioskAppManager::Apps apps; |
| 380 manager()->GetApps(&apps); | 466 manager()->GetApps(&apps); |
| 381 EXPECT_EQ(1u, apps.size()); | 467 EXPECT_EQ(1u, apps.size()); |
| 382 EXPECT_EQ("app_1", apps[0].app_id); | 468 EXPECT_EQ("app_1", apps[0].app_id); |
| 383 EXPECT_EQ("Cached App1 Name", apps[0].name); | 469 EXPECT_EQ("Cached App1 Name", apps[0].name); |
| 384 | 470 |
| 385 scoped_refptr<extensions::Extension> updated_app = | 471 scoped_refptr<extensions::Extension> updated_app = |
| 386 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1"); | 472 MakeApp("Updated App1 Name", "2.0", "http://localhost/", "app_1"); |
| 387 manager()->UpdateAppDataFromProfile( | 473 manager()->UpdateAppDataFromProfile( |
| 388 "app_1", browser()->profile(), updated_app.get()); | 474 "app_1", browser()->profile(), updated_app.get()); |
| 389 | 475 |
| 390 waiter.Wait(); | 476 waiter.Wait(); |
| 391 EXPECT_TRUE(waiter.loaded()); | 477 EXPECT_TRUE(waiter.loaded()); |
| 392 | 478 |
| 393 manager()->GetApps(&apps); | 479 manager()->GetApps(&apps); |
| 394 EXPECT_EQ(1u, apps.size()); | 480 EXPECT_EQ(1u, apps.size()); |
| 395 EXPECT_EQ("app_1", apps[0].app_id); | 481 EXPECT_EQ("app_1", apps[0].app_id); |
| 396 EXPECT_EQ("Updated App1 Name", apps[0].name); | 482 EXPECT_EQ("Updated App1 Name", apps[0].name); |
| 397 } | 483 } |
| 398 | 484 |
| 399 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { | 485 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, BadApp) { |
| 486 AppDataLoadWaiter waiter(manager(), 2); |
| 400 manager()->AddApp("unknown_app"); | 487 manager()->AddApp("unknown_app"); |
| 401 | |
| 402 TestKioskAppManagerObserver observer(manager()); | 488 TestKioskAppManagerObserver observer(manager()); |
| 403 | |
| 404 AppDataLoadWaiter waiter(manager()); | |
| 405 waiter.Wait(); | 489 waiter.Wait(); |
| 406 EXPECT_FALSE(waiter.loaded()); | 490 EXPECT_FALSE(waiter.loaded()); |
| 407 | 491 |
| 408 EXPECT_EQ("", GetAppIds()); | 492 EXPECT_EQ("", GetAppIds()); |
| 409 EXPECT_EQ(1, observer.load_failure_count()); | 493 EXPECT_EQ(1, observer.load_failure_count()); |
| 410 } | 494 } |
| 411 | 495 |
| 412 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { | 496 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, GoodApp) { |
| 413 // Webstore data json is in | 497 // Webstore data json is in |
| 414 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1 | 498 // chrome/test/data/chromeos/app_mode/webstore/inlineinstall/detail/app_1 |
| 499 fake_cws()->SetNoUpdate("app_1"); |
| 500 AppDataLoadWaiter waiter(manager(), 2); |
| 415 manager()->AddApp("app_1"); | 501 manager()->AddApp("app_1"); |
| 416 | |
| 417 AppDataLoadWaiter waiter(manager()); | |
| 418 waiter.Wait(); | 502 waiter.Wait(); |
| 419 EXPECT_TRUE(waiter.loaded()); | 503 EXPECT_TRUE(waiter.loaded()); |
| 420 | 504 |
| 421 // Check data is correct. | 505 // Check data is correct. |
| 422 KioskAppManager::Apps apps; | 506 KioskAppManager::Apps apps; |
| 423 manager()->GetApps(&apps); | 507 manager()->GetApps(&apps); |
| 424 ASSERT_EQ(1u, apps.size()); | 508 ASSERT_EQ(1u, apps.size()); |
| 425 EXPECT_EQ("app_1", apps[0].app_id); | 509 EXPECT_EQ("app_1", apps[0].app_id); |
| 426 EXPECT_EQ("Name of App 1", apps[0].name); | 510 EXPECT_EQ("Name of App 1", apps[0].name); |
| 427 EXPECT_EQ(gfx::Size(16, 16), apps[0].icon.size()); | 511 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)); | 523 EXPECT_TRUE(dict->GetString("apps.app_1.icon", &icon_path_string)); |
| 440 | 524 |
| 441 base::FilePath expected_icon_path; | 525 base::FilePath expected_icon_path; |
| 442 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); | 526 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &expected_icon_path)); |
| 443 expected_icon_path = expected_icon_path. | 527 expected_icon_path = expected_icon_path. |
| 444 AppendASCII(KioskAppManager::kIconCacheDir). | 528 AppendASCII(KioskAppManager::kIconCacheDir). |
| 445 AppendASCII(apps[0].app_id).AddExtension(".png"); | 529 AppendASCII(apps[0].app_id).AddExtension(".png"); |
| 446 EXPECT_EQ(expected_icon_path.value(), icon_path_string); | 530 EXPECT_EQ(expected_icon_path.value(), icon_path_string); |
| 447 } | 531 } |
| 448 | 532 |
| 533 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, DownloadNewApp) { |
| 534 base::FilePath crx_path; |
| 535 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| 536 } |
| 537 |
| 538 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, RemoveApp) { |
| 539 // Add a new app. |
| 540 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| 541 KioskAppManager::Apps apps; |
| 542 manager()->GetApps(&apps); |
| 543 ASSERT_EQ(1u, apps.size()); |
| 544 base::FilePath crx_path; |
| 545 std::string version; |
| 546 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); |
| 547 EXPECT_TRUE(base::PathExists(crx_path)); |
| 548 EXPECT_EQ("1.0.0", version); |
| 549 |
| 550 // Remove the app now. |
| 551 manager()->RemoveApp(kTestLocalFsKioskApp); |
| 552 manager()->GetApps(&apps); |
| 553 ASSERT_EQ(0u, apps.size()); |
| 554 EXPECT_FALSE(base::PathExists(crx_path)); |
| 555 EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); |
| 556 } |
| 557 |
| 558 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateApp) { |
| 559 // Add a version 1 app first. |
| 560 RunAddNewAppTest(kTestLocalFsKioskApp, "1.0.0", kTestLocalFsKioskAppName); |
| 561 KioskAppManager::Apps apps; |
| 562 manager()->GetApps(&apps); |
| 563 ASSERT_EQ(1u, apps.size()); |
| 564 base::FilePath crx_path; |
| 565 std::string version; |
| 566 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &crx_path, &version)); |
| 567 EXPECT_TRUE(base::PathExists(crx_path)); |
| 568 EXPECT_EQ("1.0.0", version); |
| 569 |
| 570 // Update to version 2. |
| 571 fake_cws()->SetUpdateCrx( |
| 572 kTestLocalFsKioskApp, |
| 573 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", |
| 574 "2.0.0"); |
| 575 AppDataLoadWaiter waiter(manager(), 1); |
| 576 UpdateAppData(); |
| 577 waiter.Wait(); |
| 578 EXPECT_TRUE(waiter.loaded()); |
| 579 |
| 580 // Verify the app has been updated to v2. |
| 581 manager()->GetApps(&apps); |
| 582 ASSERT_EQ(1u, apps.size()); |
| 583 base::FilePath new_crx_path; |
| 584 std::string new_version; |
| 585 EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &new_crx_path, &new_version)); |
| 586 EXPECT_EQ("2.0.0", new_version); |
| 587 EXPECT_TRUE(base::PathExists(new_crx_path)); |
| 588 // Get original version 2 source download crx file path. |
| 589 base::FilePath test_data_dir; |
| 590 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 591 base::FilePath v2_file_path = test_data_dir.Append(FILE_PATH_LITERAL( |
| 592 "chromeos/app_mode/webstore/downloads/" |
| 593 "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx")); |
| 594 EXPECT_TRUE(base::PathExists(v2_file_path)); |
| 595 EXPECT_TRUE(base::ContentsEqual(v2_file_path, new_crx_path)); |
| 596 } |
| 597 |
| 449 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { | 598 IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { |
| 450 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( | 599 scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( |
| 451 new KioskAppManager::ConsumerKioskAutoLaunchStatus( | 600 new KioskAppManager::ConsumerKioskAutoLaunchStatus( |
| 452 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); | 601 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED)); |
| 453 scoped_ptr<bool> locked(new bool(false)); | 602 scoped_ptr<bool> locked(new bool(false)); |
| 454 | 603 |
| 455 scoped_refptr<content::MessageLoopRunner> runner = | 604 scoped_refptr<content::MessageLoopRunner> runner = |
| 456 new content::MessageLoopRunner; | 605 new content::MessageLoopRunner; |
| 457 manager()->GetConsumerKioskAutoLaunchStatus( | 606 manager()->GetConsumerKioskAutoLaunchStatus( |
| 458 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 607 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 manager()->GetConsumerKioskAutoLaunchStatus( | 666 manager()->GetConsumerKioskAutoLaunchStatus( |
| 518 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, | 667 base::Bind(&ConsumerKioskAutoLaunchStatusCheck, |
| 519 status.get(), | 668 status.get(), |
| 520 runner3->QuitClosure())); | 669 runner3->QuitClosure())); |
| 521 runner3->Run(); | 670 runner3->Run(); |
| 522 EXPECT_EQ(*status.get(), | 671 EXPECT_EQ(*status.get(), |
| 523 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); | 672 KioskAppManager::CONSUMER_KIOSK_AUTO_LAUNCH_DISABLED); |
| 524 } | 673 } |
| 525 | 674 |
| 526 } // namespace chromeos | 675 } // namespace chromeos |
| OLD | NEW |