OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 } // namespace | 34 } // namespace |
35 | 35 |
36 TEST(WriteFile, WithData) { | 36 TEST(WriteFile, WithData) { |
37 Scheduler scheduler; | 37 Scheduler scheduler; |
38 TestWithScope setup; | 38 TestWithScope setup; |
39 | 39 |
40 // Make a real directory for writing the files. | 40 // Make a real directory for writing the files. |
41 base::ScopedTempDir temp_dir; | 41 base::ScopedTempDir temp_dir; |
42 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 42 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
43 setup.build_settings()->SetRootPath(temp_dir.path()); | 43 setup.build_settings()->SetRootPath(temp_dir.GetPath()); |
44 setup.build_settings()->SetBuildDir(SourceDir("//out/")); | 44 setup.build_settings()->SetBuildDir(SourceDir("//out/")); |
45 | 45 |
46 Value some_string(nullptr, "some string contents"); | 46 Value some_string(nullptr, "some string contents"); |
47 | 47 |
48 // Should refuse to write files outside of the output dir. | 48 // Should refuse to write files outside of the output dir. |
49 EXPECT_FALSE(CallWriteFile(setup.scope(), "//in_root.txt", some_string)); | 49 EXPECT_FALSE(CallWriteFile(setup.scope(), "//in_root.txt", some_string)); |
50 EXPECT_FALSE(CallWriteFile(setup.scope(), "//other_dir/foo.txt", | 50 EXPECT_FALSE(CallWriteFile(setup.scope(), "//other_dir/foo.txt", |
51 some_string)); | 51 some_string)); |
52 | 52 |
53 // Should be able to write to a new dir inside the out dir. | 53 // Should be able to write to a new dir inside the out dir. |
54 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_string)); | 54 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_string)); |
55 base::FilePath foo_name = temp_dir.path().Append(FILE_PATH_LITERAL("out")) | 55 base::FilePath foo_name = temp_dir.GetPath() |
56 .Append(FILE_PATH_LITERAL("foo.txt")); | 56 .Append(FILE_PATH_LITERAL("out")) |
| 57 .Append(FILE_PATH_LITERAL("foo.txt")); |
57 std::string result_contents; | 58 std::string result_contents; |
58 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); | 59 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); |
59 EXPECT_EQ(some_string.string_value(), result_contents); | 60 EXPECT_EQ(some_string.string_value(), result_contents); |
60 | 61 |
61 // Update the contents with a list of a string and a number. | 62 // Update the contents with a list of a string and a number. |
62 Value some_list(nullptr, Value::LIST); | 63 Value some_list(nullptr, Value::LIST); |
63 some_list.list_value().push_back(Value(nullptr, "line 1")); | 64 some_list.list_value().push_back(Value(nullptr, "line 1")); |
64 some_list.list_value().push_back(Value(nullptr, static_cast<int64_t>(2))); | 65 some_list.list_value().push_back(Value(nullptr, static_cast<int64_t>(2))); |
65 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); | 66 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); |
66 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); | 67 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); |
(...skipping 14 matching lines...) Expand all Loading... |
81 base::File::Info original_info; | 82 base::File::Info original_info; |
82 foo_file.GetInfo(&original_info); | 83 foo_file.GetInfo(&original_info); |
83 | 84 |
84 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); | 85 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); |
85 | 86 |
86 // Verify that the last modified time is the same as before. | 87 // Verify that the last modified time is the same as before. |
87 base::File::Info new_info; | 88 base::File::Info new_info; |
88 foo_file.GetInfo(&new_info); | 89 foo_file.GetInfo(&new_info); |
89 EXPECT_EQ(original_info.last_modified, new_info.last_modified); | 90 EXPECT_EQ(original_info.last_modified, new_info.last_modified); |
90 } | 91 } |
OLD | NEW |