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

Side by Side 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, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/file_util.h"
6 #include "base/message_loop.h"
7 #include "base/ref_counted.h"
8 #include "base/scoped_temp_dir.h"
9 #include "chrome/browser/appcache/chrome_appcache_service.h"
10 #include "chrome/browser/browser_thread.h"
11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/test/thread_test_helper.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 class ChromeAppCacheServiceTest : public testing::Test {
18 public:
19 ChromeAppCacheServiceTest()
20 : db_thread_(BrowserThread::DB, &message_loop_),
21 file_thread_(BrowserThread::FILE, &message_loop_),
22 io_thread_(BrowserThread::IO, &message_loop_) {
23 }
24
25 protected:
26 MessageLoop message_loop_;
27 ScopedTempDir temp_dir_;
28
29 private:
30 BrowserThread db_thread_;
31 BrowserThread file_thread_;
32 BrowserThread io_thread_;
33 };
34
35 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
36 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
37 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
38 scoped_refptr<ChromeAppCacheService> appcache_service =
39 new ChromeAppCacheService;
40 BrowserThread::PostTask(
41 BrowserThread::IO, FROM_HERE,
42 NewRunnableMethod(appcache_service.get(),
43 &ChromeAppCacheService::InitializeOnIOThread,
44 temp_dir_.path(), false,
45 scoped_refptr<HostContentSettingsMap>(NULL),
46 false));
47 // Create some fake cache index.
48 ASSERT_TRUE(file_util::CreateDirectory(appcache_path));
49 ASSERT_EQ(0, file_util::WriteFile(
50 appcache_path.AppendASCII("Index"), NULL, 0));
51
52 appcache_service = NULL;
53 message_loop_.RunAllPending();
54
55 ASSERT_TRUE(file_util::PathExists(appcache_path));
56 }
57
58 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.
59 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
60 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname);
61 scoped_refptr<ChromeAppCacheService> appcache_service =
62 new ChromeAppCacheService;
63 BrowserThread::PostTask(
64 BrowserThread::IO, FROM_HERE,
65 NewRunnableMethod(appcache_service.get(),
66 &ChromeAppCacheService::InitializeOnIOThread,
67 temp_dir_.path(), false,
68 scoped_refptr<HostContentSettingsMap>(NULL),
69 true));
70 // Create some fake cache index.
71 ASSERT_TRUE(file_util::CreateDirectory(appcache_path));
72 ASSERT_EQ(0, file_util::WriteFile(
73 appcache_path.AppendASCII("Index"), NULL, 0));
74
75 appcache_service = NULL;
76 message_loop_.RunAllPending();
77
78 ASSERT_FALSE(file_util::PathExists(appcache_path));
79 }
80
81 } // namespace
OLDNEW
« 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