 Chromium Code Reviews
 Chromium Code Reviews Issue 137493003:
  Appcache::OnCorruptionDetected handling  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 137493003:
  Appcache::OnCorruptionDetected handling  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| Index: webkit/browser/appcache/appcache_storage_impl_unittest.cc | 
| diff --git a/webkit/browser/appcache/appcache_storage_impl_unittest.cc b/webkit/browser/appcache/appcache_storage_impl_unittest.cc | 
| index d2ae51d0a378707f32f239c0a1152687df492487..2b56f6497a3b1d33bf0759c5fab69aae8f0d34bc 100644 | 
| --- a/webkit/browser/appcache/appcache_storage_impl_unittest.cc | 
| +++ b/webkit/browser/appcache/appcache_storage_impl_unittest.cc | 
| @@ -20,6 +20,7 @@ | 
| #include "net/url_request/url_request_job_factory_impl.h" | 
| #include "net/url_request/url_request_test_job.h" | 
| #include "net/url_request/url_request_test_util.h" | 
| +#include "sql/test/test_helpers.h" | 
| #include "testing/gtest/include/gtest/gtest.h" | 
| #include "webkit/browser/appcache/appcache.h" | 
| #include "webkit/browser/appcache/appcache_backend_impl.h" | 
| @@ -263,7 +264,6 @@ class AppCacheStorageImplTest : public testing::Test { | 
| const GURL& origin, | 
| quota::StorageType type, | 
| const GetUsageAndQuotaCallback& callback) OVERRIDE { | 
| - EXPECT_EQ(kOrigin, origin); | 
| EXPECT_EQ(quota::kStorageTypeTemporary, type); | 
| if (async_) { | 
| base::MessageLoop::current()->PostTask( | 
| @@ -1571,9 +1571,9 @@ class AppCacheStorageImplTest : public testing::Test { | 
| TestFinished(); | 
| } | 
| - // Reinitialize ------------------------------- | 
| - // This test is somewhat of a system integration test. | 
| - // It relies on running a mock http server on our IO thread, | 
| + // Reinitialize ------------------------------- | 
| + // These tests are somewhat of a system integration test. | 
| + // They rely on running a mock http server on our IO thread, | 
| // and involves other appcache classes to get some code | 
| // coverage thruout when Reinitialize happens. | 
| @@ -1619,29 +1619,44 @@ class AppCacheStorageImplTest : public testing::Test { | 
| }; | 
| void Reinitialize1() { | 
| + // Recover from a corrupt disk cache discovered while | 
| + // installing a new appcache. | 
| Reinitialize(1); | 
| } | 
| void Reinitialize2() { | 
| + // Recover from a corrupt disk cache discovered while | 
| + // trying to load a resource from an existing appcache. | 
| Reinitialize(2); | 
| } | 
| + void Reinitialize3() { | 
| + // Recover from a corrupt sql database discovered while | 
| + // installing a new appcache. | 
| + Reinitialize(3); | 
| + } | 
| + | 
| void Reinitialize(int test_case) { | 
| // Unlike all of the other tests, this one actually read/write files. | 
| ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); | 
| - // Create a corrupt/unopenable disk_cache index file. | 
| - const std::string kCorruptData("deadbeef"); | 
| - base::FilePath disk_cache_directory = | 
| - temp_directory_.path().AppendASCII("Cache"); | 
| - ASSERT_TRUE(base::CreateDirectory(disk_cache_directory)); | 
| - base::FilePath index_file = disk_cache_directory.AppendASCII("index"); | 
| - EXPECT_EQ(static_cast<int>(kCorruptData.length()), | 
| - file_util::WriteFile( | 
| - index_file, kCorruptData.data(), kCorruptData.length())); | 
| - | 
| - // Create records for a degenerate cached manifest that only contains | 
| - // one entry for the manifest file resource. | 
| + AppCacheDatabase db(temp_directory_.path().AppendASCII("Index")); | 
| + EXPECT_TRUE(db.LazyOpen(true)); | 
| + | 
| + if (test_case == 1 || test_case == 2) { | 
| + // Create a corrupt/unopenable disk_cache index file. | 
| + const std::string kCorruptData("deadbeef"); | 
| + base::FilePath disk_cache_directory = | 
| + temp_directory_.path().AppendASCII("Cache"); | 
| + ASSERT_TRUE(base::CreateDirectory(disk_cache_directory)); | 
| + base::FilePath index_file = disk_cache_directory.AppendASCII("index"); | 
| + EXPECT_EQ(static_cast<int>(kCorruptData.length()), | 
| + file_util::WriteFile( | 
| + index_file, kCorruptData.data(), kCorruptData.length())); | 
| + } | 
| + | 
| + // Create records for a degenerate cached manifest that only contains | 
| 
jsbell
2014/01/27 21:21:51
Nit: indentation
 
michaeln
2014/01/28 22:12:16
Done.
 | 
| + // one entry for the manifest file resource. | 
| if (test_case == 2) { | 
| AppCacheDatabase db(temp_directory_.path().AppendASCII("Index")); | 
| GURL manifest_url = MockHttpServer::GetMockUrl("manifest"); | 
| @@ -1697,7 +1712,14 @@ class AppCacheStorageImplTest : public testing::Test { | 
| backend_.reset(new AppCacheBackendImpl); | 
| backend_->Initialize(service_.get(), &frontend_, kMockProcessId); | 
| - if (test_case == 1) { | 
| + if (test_case == 3) { | 
| + // Break the db file | 
| + EXPECT_FALSE(database()->was_corruption_detected()); | 
| + ASSERT_TRUE(sql::test::CorruptSizeInHeader( | 
| + temp_directory_.path().AppendASCII("Index"))); | 
| + } | 
| + | 
| + if (test_case == 1 || test_case == 3) { | 
| // Try to create a new appcache, the resulting update job will | 
| // eventually fail when it gets to disk cache initialization. | 
| backend_->RegisterHost(1); | 
| @@ -1740,8 +1762,14 @@ class AppCacheStorageImplTest : public testing::Test { | 
| EXPECT_FALSE(PathExists( | 
| temp_directory_.path().AppendASCII("Index"))); | 
| + if (test_case == 3) { | 
| + AppCacheStorageImpl* storage = static_cast<AppCacheStorageImpl*>( | 
| + observer_->observed_old_storage_->storage()); | 
| + EXPECT_TRUE(storage->database_->was_corruption_detected()); | 
| + } | 
| + | 
| // Verify that the hosts saw appropriate events. | 
| - if (test_case == 1) { | 
| + if (test_case == 1 || test_case == 3) { | 
| EXPECT_TRUE(frontend_.error_event_was_raised_); | 
| AppCacheHost* host1 = backend_->GetHost(1); | 
| EXPECT_FALSE(host1->associated_cache()); | 
| @@ -1963,6 +1991,10 @@ TEST_F(AppCacheStorageImplTest, Reinitialize2) { | 
| RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize2); | 
| } | 
| +TEST_F(AppCacheStorageImplTest, Reinitialize3) { | 
| + RunTestOnIOThread(&AppCacheStorageImplTest::Reinitialize3); | 
| +} | 
| + | 
| // That's all folks! | 
| } // namespace appcache |