Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3112)

Unified Diff: chrome/browser/appcache/chrome_appcache_service_unittest.cc

Issue 6077005: Refactored app cache clear on exit code to happen in the object owning the files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dates all updated to 2011. Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/appcache/chrome_appcache_service.cc ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/appcache/chrome_appcache_service_unittest.cc
diff --git a/chrome/browser/appcache/chrome_appcache_service_unittest.cc b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44bdcf610828fcbf69bb888789bf822654c2a3d3
--- /dev/null
+++ b/chrome/browser/appcache/chrome_appcache_service_unittest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/ref_counted.h"
+#include "base/scoped_temp_dir.h"
+#include "chrome/browser/appcache/chrome_appcache_service.h"
+#include "chrome/browser/browser_thread.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/test/thread_test_helper.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class ChromeAppCacheServiceTest : public testing::Test {
+ public:
+ ChromeAppCacheServiceTest()
+ : db_thread_(BrowserThread::DB, &message_loop_),
+ file_thread_(BrowserThread::FILE, &message_loop_),
+ io_thread_(BrowserThread::IO, &message_loop_) {
+ }
+
+ protected:
+ MessageLoop message_loop_;
+ ScopedTempDir temp_dir_;
+
+ private:
+ BrowserThread db_thread_;
+ BrowserThread file_thread_;
+ BrowserThread io_thread_;
+};
+
+TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ new ChromeAppCacheService;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(appcache_service.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ temp_dir_.path(), false,
+ scoped_refptr<HostContentSettingsMap>(NULL),
+ false));
+ // Create some fake cache index.
+ ASSERT_TRUE(file_util::CreateDirectory(appcache_path));
+ ASSERT_EQ(0, file_util::WriteFile(
+ appcache_path.AppendASCII("Index"), NULL, 0));
+
+ appcache_service = NULL;
+ message_loop_.RunAllPending();
+
+ ASSERT_TRUE(file_util::PathExists(appcache_path));
+}
+
+TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) {
michaeln 2011/01/05 21:03:05 The ChromeAppCacheService code looks great, I like
pastarmovj 2011/01/07 13:28:21 Done.
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
+ scoped_refptr<ChromeAppCacheService> appcache_service =
+ new ChromeAppCacheService;
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(appcache_service.get(),
+ &ChromeAppCacheService::InitializeOnIOThread,
+ temp_dir_.path(), false,
+ scoped_refptr<HostContentSettingsMap>(NULL),
+ true));
+ // Create some fake cache index.
+ ASSERT_TRUE(file_util::CreateDirectory(appcache_path));
+ ASSERT_EQ(0, file_util::WriteFile(
+ appcache_path.AppendASCII("Index"), NULL, 0));
+
+ appcache_service = NULL;
+ message_loop_.RunAllPending();
+
+ ASSERT_FALSE(file_util::PathExists(appcache_path));
+}
+
+} // namespace
« no previous file with comments | « chrome/browser/appcache/chrome_appcache_service.cc ('k') | chrome/browser/browser_process_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698