OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/platform_file.h" | |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chrome/browser/media/webrtc_log_uploader.h" | 14 #include "chrome/browser/media/webrtc_log_uploader.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 const char kTestTime[] = "time"; | 17 const char kTestTime[] = "time"; |
18 const char kTestReportId[] = "report-id"; | 18 const char kTestReportId[] = "report-id"; |
19 const char kTestLocalId[] = "local-id"; | 19 const char kTestLocalId[] = "local-id"; |
20 | 20 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_EQ(3u, line_parts.size()); | 69 EXPECT_EQ(3u, line_parts.size()); |
70 if (3u != line_parts.size()) | 70 if (3u != line_parts.size()) |
71 return false; | 71 return false; |
72 EXPECT_FALSE(line_parts[0].empty()); | 72 EXPECT_FALSE(line_parts[0].empty()); |
73 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); | 73 EXPECT_STREQ(kTestReportId, line_parts[1].c_str()); |
74 EXPECT_TRUE(line_parts[2].empty()); | 74 EXPECT_TRUE(line_parts[2].empty()); |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 bool AddLinesToTestFile(int number_of_lines) { | 78 bool AddLinesToTestFile(int number_of_lines) { |
79 int flags = base::PLATFORM_FILE_OPEN | | 79 base::File test_list_file(test_list_path_, |
80 base::PLATFORM_FILE_APPEND; | 80 base::File::FLAG_OPEN | base::File::FLAG_APPEND); |
81 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 81 EXPECT_TRUE(test_list_file.IsValid()); |
82 base::PlatformFile test_list_file = | 82 if (!test_list_file.IsValid()) |
83 base::CreatePlatformFile(test_list_path_, flags, NULL, &error); | |
84 EXPECT_EQ(base::PLATFORM_FILE_OK, error); | |
85 EXPECT_NE(base::kInvalidPlatformFileValue, test_list_file); | |
86 if (base::PLATFORM_FILE_OK != error || | |
87 base::kInvalidPlatformFileValue == test_list_file) { | |
88 return false; | 83 return false; |
89 } | |
90 | 84 |
91 for (int i = 0; i < number_of_lines; ++i) { | 85 for (int i = 0; i < number_of_lines; ++i) { |
92 EXPECT_EQ(static_cast<int>(sizeof(kTestTime)) - 1, | 86 EXPECT_EQ(static_cast<int>(sizeof(kTestTime)) - 1, |
93 base::WritePlatformFileAtCurrentPos(test_list_file, | 87 test_list_file.WriteAtCurrentPos(kTestTime, |
94 kTestTime, | 88 sizeof(kTestTime) - 1)); |
95 sizeof(kTestTime) - 1)); | 89 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); |
96 EXPECT_EQ(1, base::WritePlatformFileAtCurrentPos(test_list_file, ",", 1)); | |
97 EXPECT_EQ(static_cast<int>(sizeof(kTestReportId)) - 1, | 90 EXPECT_EQ(static_cast<int>(sizeof(kTestReportId)) - 1, |
98 base::WritePlatformFileAtCurrentPos(test_list_file, | 91 test_list_file.WriteAtCurrentPos(kTestReportId, |
99 kTestReportId, | 92 sizeof(kTestReportId) - 1)); |
100 sizeof(kTestReportId) - 1)); | 93 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos(",", 1)); |
101 EXPECT_EQ(1, base::WritePlatformFileAtCurrentPos(test_list_file, ",", 1)); | |
102 EXPECT_EQ(static_cast<int>(sizeof(kTestLocalId)) - 1, | 94 EXPECT_EQ(static_cast<int>(sizeof(kTestLocalId)) - 1, |
103 base::WritePlatformFileAtCurrentPos( | 95 test_list_file.WriteAtCurrentPos(kTestLocalId, |
104 test_list_file, kTestLocalId, sizeof(kTestLocalId) - 1)); | 96 sizeof(kTestLocalId) - 1)); |
105 EXPECT_EQ(1, base::WritePlatformFileAtCurrentPos(test_list_file, | 97 EXPECT_EQ(1, test_list_file.WriteAtCurrentPos("\n", 1)); |
106 "\n", 1)); | |
107 } | 98 } |
108 EXPECT_TRUE(base::ClosePlatformFile(test_list_file)); | |
109 | |
110 return true; | 99 return true; |
111 } | 100 } |
112 | 101 |
113 std::vector<std::string> GetLinesFromListFile() { | 102 std::vector<std::string> GetLinesFromListFile() { |
114 std::string contents; | 103 std::string contents; |
115 int read = base::ReadFileToString(test_list_path_, &contents); | 104 int read = base::ReadFileToString(test_list_path_, &contents); |
116 EXPECT_GT(read, 0); | 105 EXPECT_GT(read, 0); |
117 if (read == 0) | 106 if (read == 0) |
118 return std::vector<std::string>(); | 107 return std::vector<std::string>(); |
119 // Since every line should end with '\n', the last line should be empty. So | 108 // Since every line should end with '\n', the last line should be empty. So |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 test_list_path_, kTestLocalId, kTestReportId); | 182 test_list_path_, kTestLocalId, kTestReportId); |
194 ASSERT_TRUE(VerifyNumberOfLines(1)); | 183 ASSERT_TRUE(VerifyNumberOfLines(1)); |
195 ASSERT_TRUE(VerifyLastLineHasAllInfo()); | 184 ASSERT_TRUE(VerifyLastLineHasAllInfo()); |
196 | 185 |
197 // Use a local ID that should not be found in the list. | 186 // Use a local ID that should not be found in the list. |
198 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile( | 187 webrtc_log_uploader_->AddUploadedLogInfoToUploadListFile( |
199 test_list_path_, "dummy id", kTestReportId); | 188 test_list_path_, "dummy id", kTestReportId); |
200 ASSERT_TRUE(VerifyNumberOfLines(2)); | 189 ASSERT_TRUE(VerifyNumberOfLines(2)); |
201 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly()); | 190 ASSERT_TRUE(VerifyLastLineHasUploadTimeAndIdOnly()); |
202 } | 191 } |
OLD | NEW |