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

Side by Side Diff: chrome/installer/util/create_dir_work_item_unittest.cc

Issue 2321573002: //chrome misc: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix Win compilation Created 4 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/installer/util/create_dir_work_item.h" 5 #include "chrome/installer/util/create_dir_work_item.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chrome/installer/util/work_item.h" 15 #include "chrome/installer/util/work_item.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace { 18 namespace {
19 class CreateDirWorkItemTest : public testing::Test { 19 class CreateDirWorkItemTest : public testing::Test {
20 protected: 20 protected:
21 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); } 21 void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); }
22 22
23 base::ScopedTempDir temp_dir_; 23 base::ScopedTempDir temp_dir_;
24 }; 24 };
25 }; 25 };
26 26
27 TEST_F(CreateDirWorkItemTest, CreatePath) { 27 TEST_F(CreateDirWorkItemTest, CreatePath) {
28 base::FilePath parent_dir(temp_dir_.path()); 28 base::FilePath parent_dir(temp_dir_.GetPath());
29 parent_dir = parent_dir.AppendASCII("a"); 29 parent_dir = parent_dir.AppendASCII("a");
30 base::CreateDirectory(parent_dir); 30 base::CreateDirectory(parent_dir);
31 ASSERT_TRUE(base::PathExists(parent_dir)); 31 ASSERT_TRUE(base::PathExists(parent_dir));
32 32
33 base::FilePath top_dir_to_create(parent_dir); 33 base::FilePath top_dir_to_create(parent_dir);
34 top_dir_to_create = top_dir_to_create.AppendASCII("b"); 34 top_dir_to_create = top_dir_to_create.AppendASCII("b");
35 35
36 base::FilePath dir_to_create(top_dir_to_create); 36 base::FilePath dir_to_create(top_dir_to_create);
37 dir_to_create = dir_to_create.AppendASCII("c"); 37 dir_to_create = dir_to_create.AppendASCII("c");
38 dir_to_create = dir_to_create.AppendASCII("d"); 38 dir_to_create = dir_to_create.AppendASCII("d");
39 39
40 std::unique_ptr<CreateDirWorkItem> work_item( 40 std::unique_ptr<CreateDirWorkItem> work_item(
41 WorkItem::CreateCreateDirWorkItem(dir_to_create)); 41 WorkItem::CreateCreateDirWorkItem(dir_to_create));
42 42
43 EXPECT_TRUE(work_item->Do()); 43 EXPECT_TRUE(work_item->Do());
44 44
45 EXPECT_TRUE(base::PathExists(dir_to_create)); 45 EXPECT_TRUE(base::PathExists(dir_to_create));
46 46
47 work_item->Rollback(); 47 work_item->Rollback();
48 48
49 // Rollback should delete all the paths up to top_dir_to_create. 49 // Rollback should delete all the paths up to top_dir_to_create.
50 EXPECT_FALSE(base::PathExists(top_dir_to_create)); 50 EXPECT_FALSE(base::PathExists(top_dir_to_create));
51 EXPECT_TRUE(base::PathExists(parent_dir)); 51 EXPECT_TRUE(base::PathExists(parent_dir));
52 } 52 }
53 53
54 TEST_F(CreateDirWorkItemTest, CreateExistingPath) { 54 TEST_F(CreateDirWorkItemTest, CreateExistingPath) {
55 base::FilePath dir_to_create(temp_dir_.path()); 55 base::FilePath dir_to_create(temp_dir_.GetPath());
56 dir_to_create = dir_to_create.AppendASCII("aa"); 56 dir_to_create = dir_to_create.AppendASCII("aa");
57 base::CreateDirectory(dir_to_create); 57 base::CreateDirectory(dir_to_create);
58 ASSERT_TRUE(base::PathExists(dir_to_create)); 58 ASSERT_TRUE(base::PathExists(dir_to_create));
59 59
60 std::unique_ptr<CreateDirWorkItem> work_item( 60 std::unique_ptr<CreateDirWorkItem> work_item(
61 WorkItem::CreateCreateDirWorkItem(dir_to_create)); 61 WorkItem::CreateCreateDirWorkItem(dir_to_create));
62 62
63 EXPECT_TRUE(work_item->Do()); 63 EXPECT_TRUE(work_item->Do());
64 64
65 EXPECT_TRUE(base::PathExists(dir_to_create)); 65 EXPECT_TRUE(base::PathExists(dir_to_create));
66 66
67 work_item->Rollback(); 67 work_item->Rollback();
68 68
69 // Rollback should not remove the path since it exists before 69 // Rollback should not remove the path since it exists before
70 // the CreateDirWorkItem is called. 70 // the CreateDirWorkItem is called.
71 EXPECT_TRUE(base::PathExists(dir_to_create)); 71 EXPECT_TRUE(base::PathExists(dir_to_create));
72 } 72 }
73 73
74 TEST_F(CreateDirWorkItemTest, CreateSharedPath) { 74 TEST_F(CreateDirWorkItemTest, CreateSharedPath) {
75 base::FilePath dir_to_create_1(temp_dir_.path()); 75 base::FilePath dir_to_create_1(temp_dir_.GetPath());
76 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa"); 76 dir_to_create_1 = dir_to_create_1.AppendASCII("aaa");
77 77
78 base::FilePath dir_to_create_2(dir_to_create_1); 78 base::FilePath dir_to_create_2(dir_to_create_1);
79 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb"); 79 dir_to_create_2 = dir_to_create_2.AppendASCII("bbb");
80 80
81 base::FilePath dir_to_create_3(dir_to_create_2); 81 base::FilePath dir_to_create_3(dir_to_create_2);
82 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc"); 82 dir_to_create_3 = dir_to_create_3.AppendASCII("ccc");
83 83
84 std::unique_ptr<CreateDirWorkItem> work_item( 84 std::unique_ptr<CreateDirWorkItem> work_item(
85 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); 85 WorkItem::CreateCreateDirWorkItem(dir_to_create_3));
(...skipping 12 matching lines...) Expand all
98 98
99 // Rollback should delete dir_to_create_3. 99 // Rollback should delete dir_to_create_3.
100 EXPECT_FALSE(base::PathExists(dir_to_create_3)); 100 EXPECT_FALSE(base::PathExists(dir_to_create_3));
101 101
102 // Rollback should not delete dir_to_create_2 as it is shared. 102 // Rollback should not delete dir_to_create_2 as it is shared.
103 EXPECT_TRUE(base::PathExists(dir_to_create_2)); 103 EXPECT_TRUE(base::PathExists(dir_to_create_2));
104 EXPECT_TRUE(base::PathExists(dir_to_create_4)); 104 EXPECT_TRUE(base::PathExists(dir_to_create_4));
105 } 105 }
106 106
107 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) { 107 TEST_F(CreateDirWorkItemTest, RollbackWithMissingDir) {
108 base::FilePath dir_to_create_1(temp_dir_.path()); 108 base::FilePath dir_to_create_1(temp_dir_.GetPath());
109 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa"); 109 dir_to_create_1 = dir_to_create_1.AppendASCII("aaaa");
110 110
111 base::FilePath dir_to_create_2(dir_to_create_1); 111 base::FilePath dir_to_create_2(dir_to_create_1);
112 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb"); 112 dir_to_create_2 = dir_to_create_2.AppendASCII("bbbb");
113 113
114 base::FilePath dir_to_create_3(dir_to_create_2); 114 base::FilePath dir_to_create_3(dir_to_create_2);
115 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc"); 115 dir_to_create_3 = dir_to_create_3.AppendASCII("cccc");
116 116
117 std::unique_ptr<CreateDirWorkItem> work_item( 117 std::unique_ptr<CreateDirWorkItem> work_item(
118 WorkItem::CreateCreateDirWorkItem(dir_to_create_3)); 118 WorkItem::CreateCreateDirWorkItem(dir_to_create_3));
119 119
120 EXPECT_TRUE(work_item->Do()); 120 EXPECT_TRUE(work_item->Do());
121 121
122 EXPECT_TRUE(base::PathExists(dir_to_create_3)); 122 EXPECT_TRUE(base::PathExists(dir_to_create_3));
123 123
124 RemoveDirectory(dir_to_create_3.value().c_str()); 124 RemoveDirectory(dir_to_create_3.value().c_str());
125 ASSERT_FALSE(base::PathExists(dir_to_create_3)); 125 ASSERT_FALSE(base::PathExists(dir_to_create_3));
126 126
127 work_item->Rollback(); 127 work_item->Rollback();
128 128
129 // dir_to_create_3 has already been deleted, Rollback should delete 129 // dir_to_create_3 has already been deleted, Rollback should delete
130 // the rest. 130 // the rest.
131 EXPECT_FALSE(base::PathExists(dir_to_create_1)); 131 EXPECT_FALSE(base::PathExists(dir_to_create_1));
132 } 132 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item_unittest.cc ('k') | chrome/installer/util/delete_old_versions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698