diff options
3 files changed, 65 insertions, 8 deletions
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 fa9f52a..1bd54e4 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc +++ b/chrome/browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc @@ -29,6 +29,8 @@ #include "net/dns/mock_host_resolver.h" #include "net/test/embedded_test_server/embedded_test_server.h" +using content::BrowserThread; + namespace chromeos { namespace { @@ -549,6 +551,7 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, RemoveApp) { // Remove the app now. manager()->RemoveApp(kTestLocalFsKioskApp); + content::RunAllPendingInMessageLoop(BrowserThread::FILE); manager()->GetApps(&apps); ASSERT_EQ(0u, apps.size()); EXPECT_FALSE(base::PathExists(crx_path)); @@ -595,6 +598,50 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateApp) { EXPECT_TRUE(base::ContentsEqual(v2_file_path, new_crx_path)); } +IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, UpdateAndRemoveApp) { + // 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 v1_crx_path; + std::string version; + EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &v1_crx_path, &version)); + EXPECT_TRUE(base::PathExists(v1_crx_path)); + EXPECT_EQ("1.0.0", version); + + // Update to version 2. + fake_cws()->SetUpdateCrx( + kTestLocalFsKioskApp, + "bmbpicmpniaclbbpdkfglgipkkebnbjf_v2_read_and_verify_data.crx", + "2.0.0"); + AppDataLoadWaiter waiter(manager(), 1); + 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 v2_crx_path; + std::string new_version; + EXPECT_TRUE(GetCachedCrx(kTestLocalFsKioskApp, &v2_crx_path, &new_version)); + EXPECT_EQ("2.0.0", new_version); + // Verify both v1 and v2 crx files exist. + EXPECT_TRUE(base::PathExists(v1_crx_path)); + EXPECT_TRUE(base::PathExists(v2_crx_path)); + + // Remove the app now. + manager()->RemoveApp(kTestLocalFsKioskApp); + content::RunAllPendingInMessageLoop(BrowserThread::FILE); + manager()->GetApps(&apps); + ASSERT_EQ(0u, apps.size()); + // Verify both v1 and v2 crx files are removed. + EXPECT_FALSE(base::PathExists(v1_crx_path)); + EXPECT_FALSE(base::PathExists(v2_crx_path)); + EXPECT_FALSE(GetCachedCrx(kTestLocalFsKioskApp, &v2_crx_path, &version)); +} + IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, EnableConsumerKiosk) { scoped_ptr<KioskAppManager::ConsumerKioskAutoLaunchStatus> status( new KioskAppManager::ConsumerKioskAutoLaunchStatus( diff --git a/chrome/browser/extensions/updater/local_extension_cache.cc b/chrome/browser/extensions/updater/local_extension_cache.cc index b6bb926..add6cdd 100644 --- a/chrome/browser/extensions/updater/local_extension_cache.cc +++ b/chrome/browser/extensions/updater/local_extension_cache.cc @@ -145,8 +145,8 @@ bool LocalExtensionCache::RemoveExtension(const std::string& id) { backend_task_runner_->PostTask( FROM_HERE, - base::Bind(&LocalExtensionCache::BackendRemoveCacheEntry, - it->second.file_path)); + base::Bind( + &LocalExtensionCache::BackendRemoveCacheEntry, cache_dir_, id)); cached_extensions_.erase(it); return true; @@ -438,9 +438,18 @@ void LocalExtensionCache::OnCacheEntryInstalled( // static void LocalExtensionCache::BackendRemoveCacheEntry( - const base::FilePath& file_path) { - base::DeleteFile(file_path, true /* recursive */); - VLOG(1) << "Removed cached file " << file_path.value(); + const base::FilePath& cache_dir, + const std::string& id) { + std::string file_pattern = id + "-*" + kCRXFileExtension; + base::FileEnumerator enumerator(cache_dir, + false /* not recursive */, + base::FileEnumerator::FILES, + file_pattern); + for (base::FilePath path = enumerator.Next(); !path.empty(); + path = enumerator.Next()) { + base::DeleteFile(path, false); + VLOG(1) << "Removed cached file " << path.value(); + } } // static diff --git a/chrome/browser/extensions/updater/local_extension_cache.h b/chrome/browser/extensions/updater/local_extension_cache.h index 63652ba..68f3109 100644 --- a/chrome/browser/extensions/updater/local_extension_cache.h +++ b/chrome/browser/extensions/updater/local_extension_cache.h @@ -164,9 +164,10 @@ class LocalExtensionCache { bool was_error, const PutExtensionCallback& callback); - // Remove crx file at |file_path| in the cache. This method is invoked via - // the |backend_task_runner_|. - static void BackendRemoveCacheEntry(const base::FilePath& file_path); + // Remove cached crx files(all versions) under |cached_dir| for extension with + // |id|. This method is invoked via the |backend_task_runner_|. + static void BackendRemoveCacheEntry(const base::FilePath& cache_dir, + const std::string& id); // Compare two cache items returns true if first item is older. static bool CompareCacheItemsAge(const CacheMap::iterator& lhs, |