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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file_unittest.cc

Issue 7056011: Replace all usage of FileAutoDeleter with ScopedTempDir. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/scoped_temp_dir.h"
8 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_store_unittest_helper.h"
9 #include "chrome/test/file_test_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
12 12
13 namespace { 13 namespace {
14 14
15 const FilePath::CharType kFolderPrefix[] = 15 const FilePath::CharType kFolderPrefix[] =
16 FILE_PATH_LITERAL("SafeBrowsingTestStoreFile"); 16 FILE_PATH_LITERAL("SafeBrowsingTestStoreFile");
17 17
18 class SafeBrowsingStoreFileTest : public PlatformTest { 18 class SafeBrowsingStoreFileTest : public PlatformTest {
19 public: 19 public:
20 virtual void SetUp() { 20 virtual void SetUp() {
21 PlatformTest::SetUp(); 21 PlatformTest::SetUp();
22 22
23 FilePath temp_dir; 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
24 ASSERT_TRUE(file_util::CreateNewTempDirectory(kFolderPrefix, &temp_dir));
25 24
26 file_deleter_.reset(new FileAutoDeleter(temp_dir)); 25 filename_ = temp_dir_.path();
27
28 filename_ = temp_dir;
29 filename_ = filename_.AppendASCII("SafeBrowsingTestStore"); 26 filename_ = filename_.AppendASCII("SafeBrowsingTestStore");
30 file_util::Delete(filename_, false); 27 ASSERT_FALSE(file_util::PathExists(filename_));
Paweł Hajdan Jr. 2011/05/20 13:48:58 nit: Not needed, please remove.
lain Merrick 2011/05/20 14:23:32 Done.
31
32 // Make sure an old temporary file isn't hanging around.
33 const FilePath temp_file =
34 SafeBrowsingStoreFile::TemporaryFileForFilename(filename_);
35 file_util::Delete(temp_file, false);
36 28
37 store_.reset(new SafeBrowsingStoreFile()); 29 store_.reset(new SafeBrowsingStoreFile());
38 store_->Init(filename_, NULL); 30 store_->Init(filename_, NULL);
39 } 31 }
40 virtual void TearDown() { 32 virtual void TearDown() {
41 if (store_.get()) 33 if (store_.get())
42 store_->Delete(); 34 store_->Delete();
43 store_.reset(); 35 store_.reset();
44 file_deleter_.reset();
45 36
46 PlatformTest::TearDown(); 37 PlatformTest::TearDown();
47 } 38 }
48 39
49 void OnCorruptionDetected() { 40 void OnCorruptionDetected() {
50 corruption_detected_ = true; 41 corruption_detected_ = true;
51 } 42 }
52 43
53 scoped_ptr<FileAutoDeleter> file_deleter_; 44 ScopedTempDir temp_dir_;
54 FilePath filename_; 45 FilePath filename_;
55 scoped_ptr<SafeBrowsingStoreFile> store_; 46 scoped_ptr<SafeBrowsingStoreFile> store_;
56 bool corruption_detected_; 47 bool corruption_detected_;
57 }; 48 };
58 49
59 TEST_STORE(SafeBrowsingStoreFileTest, store_.get(), filename_); 50 TEST_STORE(SafeBrowsingStoreFileTest, store_.get(), filename_);
60 51
61 // Test that Delete() deletes the temporary store, if present. 52 // Test that Delete() deletes the temporary store, if present.
62 TEST_F(SafeBrowsingStoreFileTest, DeleteTemp) { 53 TEST_F(SafeBrowsingStoreFileTest, DeleteTemp) {
63 const FilePath temp_file = 54 const FilePath temp_file =
64 SafeBrowsingStoreFile::TemporaryFileForFilename(filename_); 55 SafeBrowsingStoreFile::TemporaryFileForFilename(filename_);
65 56
66 EXPECT_FALSE(file_util::PathExists(filename_)); 57 EXPECT_FALSE(file_util::PathExists(filename_));
67 EXPECT_FALSE(file_util::PathExists(temp_file)); 58 EXPECT_FALSE(file_util::PathExists(temp_file));
68 59
69 // Starting a transaction creates a temporary file. 60 // Starting a transaction creates a temporary file.
70 EXPECT_TRUE(store_->BeginUpdate()); 61 EXPECT_TRUE(store_->BeginUpdate());
71 EXPECT_TRUE(file_util::PathExists(temp_file)); 62 EXPECT_TRUE(file_util::PathExists(temp_file));
72 63
73 // Pull the rug out from under the existing store, simulating a 64 // Pull the rug out from under the existing store, simulating a
74 // crash. 65 // crash.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 EXPECT_EQ(fwrite(&kLargeCount, sizeof(kLargeCount), 1, file.get()), 1U); 130 EXPECT_EQ(fwrite(&kLargeCount, sizeof(kLargeCount), 1, file.get()), 1U);
140 file.reset(); 131 file.reset();
141 132
142 // Detects corruption and fails to even begin the update. 133 // Detects corruption and fails to even begin the update.
143 corruption_detected_ = false; 134 corruption_detected_ = false;
144 EXPECT_FALSE(test_store.BeginUpdate()); 135 EXPECT_FALSE(test_store.BeginUpdate());
145 EXPECT_TRUE(corruption_detected_); 136 EXPECT_TRUE(corruption_detected_);
146 } 137 }
147 138
148 } // namespace 139 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698