OLD | NEW |
---|---|
(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: | |
jochen (gone - plz use gerrit)
2011/01/05 12:29:51
why protected and not private?
pastarmovj
2011/01/05 13:47:38
At least message_loop_ and temp_dir_ are used in t
| |
26 MessageLoop message_loop_; | |
27 BrowserThread db_thread_; | |
28 BrowserThread file_thread_; | |
29 BrowserThread io_thread_; | |
30 ScopedTempDir temp_dir_; | |
31 }; | |
32 | |
33 TEST_F(ChromeAppCacheServiceTest, KeepOnDestruction) { | |
34 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
35 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
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(appcache_path)); | |
47 ASSERT_EQ(0, file_util::WriteFile( | |
48 appcache_path.AppendASCII("Index"), NULL, 0)); | |
49 | |
50 appcache_service = NULL; | |
51 message_loop_.RunAllPending(); | |
52 | |
53 ASSERT_TRUE(file_util::PathExists(appcache_path)); | |
54 } | |
55 | |
56 TEST_F(ChromeAppCacheServiceTest, RemoveOnDestruction) { | |
57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
58 FilePath appcache_path = temp_dir_.path().Append(chrome::kAppCacheDirname); | |
59 scoped_refptr<ChromeAppCacheService> appcache_service = | |
60 new ChromeAppCacheService; | |
61 BrowserThread::PostTask( | |
62 BrowserThread::IO, FROM_HERE, | |
63 NewRunnableMethod(appcache_service.get(), | |
64 &ChromeAppCacheService::InitializeOnIOThread, | |
65 temp_dir_.path(), false, | |
66 scoped_refptr<HostContentSettingsMap>(NULL), | |
67 true)); | |
68 // Create some fake cache index. | |
jochen (gone - plz use gerrit)
2011/01/05 12:29:51
duplicate line
pastarmovj
2011/01/05 13:47:38
Done.
| |
69 // Create some fake cache index. | |
70 ASSERT_TRUE(file_util::CreateDirectory(appcache_path)); | |
71 ASSERT_EQ(0, file_util::WriteFile( | |
72 appcache_path.AppendASCII("Index"), NULL, 0)); | |
73 | |
74 appcache_service = NULL; | |
75 message_loop_.RunAllPending(); | |
76 | |
77 ASSERT_FALSE(file_util::PathExists(appcache_path)); | |
78 } | |
79 | |
80 } // namespace | |
OLD | NEW |