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

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: Avoid race conditions and improper destruction order. 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) 2010 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 "base/stl_util-inl.h"
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 why do you include this header?
pastarmovj 2011/01/05 12:15:14 Relict from the test I used as template for this f
10 #include "base/time.h"
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 and this?
pastarmovj 2011/01/05 12:15:14 This too.
11 #include "chrome/browser/browser_thread.h"
12 #include "chrome/browser/appcache/chrome_appcache_service.h"
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 alphabetical ordering
pastarmovj 2011/01/05 12:15:14 Done.
13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/test/thread_test_helper.h"
15 #include "googleurl/src/gurl.h"
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 isn't used either
pastarmovj 2011/01/05 12:15:14 Done.
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 class ChromeAppCacheServiceTest : public testing::Test {
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 can you move everything into an anonymous namespac
pastarmovj 2011/01/05 12:15:14 Done.
19 public:
20 ChromeAppCacheServiceTest()
21 : db_thread_(BrowserThread::DB, &message_loop_),
22 file_thread_(BrowserThread::FILE, &message_loop_),
23 io_thread_(BrowserThread::IO, &message_loop_) {
24 }
25
26 protected:
27 MessageLoop message_loop_;
28 BrowserThread db_thread_;
29 BrowserThread file_thread_;
30 BrowserThread io_thread_;
31 ScopedTempDir temp_dir_;
32 };
33
34 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) {
35 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
36 scoped_refptr<ChromeAppCacheService> appcache_service =
37 new ChromeAppCacheService;
38 BrowserThread::PostTask(
39 BrowserThread::IO, FROM_HERE,
40 NewRunnableMethod(appcache_service.get(),
41 &ChromeAppCacheService::InitializeOnIOThread,
42 temp_dir_.path(), false,
43 scoped_refptr<HostContentSettingsMap>(NULL),
44 false));
45 // Create some fake cache index.
46 ASSERT_TRUE(file_util::CreateDirectory(
47 temp_dir_.path().Append(chrome::kAppCacheDirname)));
jochen (gone - plz use gerrit) 2011/01/05 10:55:45 can you put this into a variable instead of recrea
pastarmovj 2011/01/05 12:15:14 Done.
48 ASSERT_EQ(0, file_util::WriteFile(
49 temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"),
50 NULL, 0));
51
52 appcache_service = NULL;
53 message_loop_.RunAllPending();
54
55 ASSERT_TRUE(file_util::PathExists(
56 temp_dir_.path().Append(chrome::kAppCacheDirname)));
57 }
58
59 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) {
60 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
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(
72 temp_dir_.path().Append(chrome::kAppCacheDirname)));
73 ASSERT_EQ(0, file_util::WriteFile(
74 temp_dir_.path().Append(chrome::kAppCacheDirname).AppendASCII("Index"),
75 NULL, 0));
76
77 appcache_service = NULL;
78 message_loop_.RunAllPending();
79
80 ASSERT_FALSE(file_util::PathExists(
81 temp_dir_.path().Append(chrome::kAppCacheDirname)));
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698