| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "client/crash_report_database.h" | 15 #include "client/crash_report_database.h" |
| 16 | 16 |
| 17 #include <sys/stat.h> | 17 #include <sys/stat.h> |
| 18 | 18 |
| 19 #include "gtest/gtest.h" | 19 #include "gtest/gtest.h" |
| 20 #include "util/file/file_io.h" | 20 #include "util/file/file_io.h" |
| 21 #include "util/test/errors.h" |
| 21 #include "util/test/scoped_temp_dir.h" | 22 #include "util/test/scoped_temp_dir.h" |
| 22 | 23 |
| 23 namespace crashpad { | 24 namespace crashpad { |
| 24 namespace test { | 25 namespace test { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool FileExistsAtPath(const base::FilePath& path) { | 28 bool FileExistsAtPath(const base::FilePath& path) { |
| 28 #if defined(OS_POSIX) | 29 #if defined(OS_POSIX) |
| 29 struct stat st; | 30 struct stat st; |
| 30 return lstat(path.value().c_str(), &st) == 0; | 31 return lstat(path.value().c_str(), &st) == 0; |
| 31 #elif defined(OS_WIN) | 32 #elif defined(OS_WIN) |
| 32 struct _stat st; | 33 struct _stat st; |
| 33 return _wstat(path.value().c_str(), &st) == 0; | 34 return _wstat(path.value().c_str(), &st) == 0; |
| 34 #else | 35 #else |
| 35 #error "Not implemented" | 36 #error "Not implemented" |
| 36 #endif | 37 #endif |
| 37 } | 38 } |
| 38 | 39 |
| 39 void CreateFile(const base::FilePath& path) { | 40 class CrashReportDatabaseTest : public testing::Test { |
| 40 FileHandle handle = LoggingOpenFileForWrite(path, | 41 public: |
| 41 FileWriteMode::kCreateOrFail, | 42 CrashReportDatabaseTest() { |
| 42 FilePermissions::kWorldReadable); | 43 } |
| 43 #if defined(OS_POSIX) | |
| 44 ASSERT_GE(handle, 0); | |
| 45 #elif defined(OS_WIN) | |
| 46 ASSERT_NE(handle, nullptr); | |
| 47 #endif | |
| 48 ASSERT_TRUE( | |
| 49 LoggingWriteFile(handle, path.value().c_str(), path.value().length())); | |
| 50 ASSERT_TRUE(LoggingCloseFile(handle)); | |
| 51 } | |
| 52 | 44 |
| 53 class CrashReportDatabaseTest : public testing::Test { | |
| 54 protected: | 45 protected: |
| 55 // testing::Test: | 46 // testing::Test: |
| 56 void SetUp() override { | 47 void SetUp() override { |
| 57 db_ = CrashReportDatabase::Initialize(path()); | 48 db_ = CrashReportDatabase::Initialize(path()); |
| 58 ASSERT_TRUE(db_.get()); | 49 ASSERT_TRUE(db_); |
| 59 } | 50 } |
| 60 | 51 |
| 61 void ResetDatabase() { | 52 void ResetDatabase() { |
| 62 db_.reset(); | 53 db_.reset(); |
| 63 } | 54 } |
| 64 | 55 |
| 65 CrashReportDatabase* db() const { return db_.get(); } | 56 CrashReportDatabase* db() { return db_.get(); } |
| 66 const base::FilePath& path() const { return temp_dir_.path(); } | 57 const base::FilePath& path() const { return temp_dir_.path(); } |
| 67 | 58 |
| 68 void CreateCrashReport(CrashReportDatabase::Report* report) { | 59 void CreateCrashReport(CrashReportDatabase::Report* report) { |
| 69 CrashReportDatabase::NewReport* new_report; | 60 CrashReportDatabase::NewReport* new_report = nullptr; |
| 70 EXPECT_EQ(CrashReportDatabase::kNoError, | 61 ASSERT_EQ(CrashReportDatabase::kNoError, |
| 71 db_->PrepareNewCrashReport(&new_report)); | 62 db_->PrepareNewCrashReport(&new_report)); |
| 72 const char kTest[] = "test"; | 63 const char kTest[] = "test"; |
| 73 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); | 64 ASSERT_TRUE(LoggingWriteFile(new_report->handle, kTest, sizeof(kTest))); |
| 74 | 65 |
| 75 UUID uuid; | 66 UUID uuid; |
| 76 EXPECT_EQ(CrashReportDatabase::kNoError, | 67 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 77 db_->FinishedWritingCrashReport(new_report, &uuid)); | 68 db_->FinishedWritingCrashReport(new_report, &uuid)); |
| 78 | 69 |
| 79 EXPECT_EQ(CrashReportDatabase::kNoError, | 70 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 80 db_->LookUpCrashReport(uuid, report)); | 71 db_->LookUpCrashReport(uuid, report)); |
| 81 ExpectPreparedCrashReport(*report); | 72 ExpectPreparedCrashReport(*report); |
| 82 ASSERT_TRUE(FileExistsAtPath(report->file_path)); | 73 ASSERT_TRUE(FileExistsAtPath(report->file_path)); |
| 83 } | 74 } |
| 84 | 75 |
| 85 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { | 76 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { |
| 86 const CrashReportDatabase::Report* report = nullptr; | 77 const CrashReportDatabase::Report* report = nullptr; |
| 87 EXPECT_EQ(CrashReportDatabase::kNoError, | 78 ASSERT_EQ(CrashReportDatabase::kNoError, |
| 88 db_->GetReportForUploading(uuid, &report)); | 79 db_->GetReportForUploading(uuid, &report)); |
| 89 EXPECT_TRUE(report); | |
| 90 EXPECT_NE(UUID(), report->uuid); | 80 EXPECT_NE(UUID(), report->uuid); |
| 91 EXPECT_FALSE(report->file_path.empty()); | 81 EXPECT_FALSE(report->file_path.empty()); |
| 92 EXPECT_TRUE(FileExistsAtPath(report->file_path)) | 82 EXPECT_TRUE(FileExistsAtPath(report->file_path)) |
| 93 << report->file_path.value(); | 83 << report->file_path.value(); |
| 94 EXPECT_GT(report->creation_time, 0); | 84 EXPECT_GT(report->creation_time, 0); |
| 95 EXPECT_EQ(CrashReportDatabase::kNoError, | 85 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 96 db_->RecordUploadAttempt(report, successful, id)); | 86 db_->RecordUploadAttempt(report, successful, id)); |
| 97 } | 87 } |
| 98 | 88 |
| 99 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { | 89 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { |
| 100 EXPECT_NE(UUID(), report.uuid); | 90 EXPECT_NE(UUID(), report.uuid); |
| 101 EXPECT_FALSE(report.file_path.empty()); | 91 EXPECT_FALSE(report.file_path.empty()); |
| 102 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 92 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
| 103 EXPECT_TRUE(report.id.empty()); | 93 EXPECT_TRUE(report.id.empty()); |
| 104 EXPECT_GT(report.creation_time, 0); | 94 EXPECT_GT(report.creation_time, 0); |
| 105 EXPECT_FALSE(report.uploaded); | 95 EXPECT_FALSE(report.uploaded); |
| 106 EXPECT_EQ(0, report.last_upload_attempt_time); | 96 EXPECT_EQ(0, report.last_upload_attempt_time); |
| 107 EXPECT_EQ(0, report.upload_attempts); | 97 EXPECT_EQ(0, report.upload_attempts); |
| 108 } | 98 } |
| 109 | 99 |
| 110 void RelocateDatabase() { | 100 void RelocateDatabase() { |
| 111 ResetDatabase(); | 101 ResetDatabase(); |
| 112 temp_dir_.Rename(); | 102 temp_dir_.Rename(); |
| 113 SetUp(); | 103 SetUp(); |
| 114 } | 104 } |
| 115 | 105 |
| 116 private: | 106 private: |
| 117 ScopedTempDir temp_dir_; | 107 ScopedTempDir temp_dir_; |
| 118 scoped_ptr<CrashReportDatabase> db_; | 108 scoped_ptr<CrashReportDatabase> db_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseTest); |
| 119 }; | 111 }; |
| 120 | 112 |
| 121 TEST_F(CrashReportDatabaseTest, Initialize) { | 113 TEST_F(CrashReportDatabaseTest, Initialize) { |
| 122 // Initialize the database for the first time, creating it. | 114 // Initialize the database for the first time, creating it. |
| 123 EXPECT_TRUE(db()); | 115 EXPECT_TRUE(db()); |
| 124 | 116 |
| 125 // Close and reopen the database at the same path. | 117 // Close and reopen the database at the same path. |
| 126 ResetDatabase(); | 118 ResetDatabase(); |
| 127 EXPECT_FALSE(db()); | 119 EXPECT_FALSE(db()); |
| 128 auto db = CrashReportDatabase::Initialize(path()); | 120 auto db = CrashReportDatabase::Initialize(path()); |
| 129 EXPECT_TRUE(db.get()); | 121 ASSERT_TRUE(db); |
| 130 | 122 |
| 131 std::vector<const CrashReportDatabase::Report> reports; | 123 std::vector<const CrashReportDatabase::Report> reports; |
| 132 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); | 124 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); |
| 133 EXPECT_TRUE(reports.empty()); | 125 EXPECT_TRUE(reports.empty()); |
| 126 reports.clear(); |
| 134 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); | 127 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); |
| 135 EXPECT_TRUE(reports.empty()); | 128 EXPECT_TRUE(reports.empty()); |
| 136 } | 129 } |
| 137 | 130 |
| 138 TEST_F(CrashReportDatabaseTest, NewCrashReport) { | 131 TEST_F(CrashReportDatabaseTest, NewCrashReport) { |
| 139 CrashReportDatabase::NewReport* new_report; | 132 CrashReportDatabase::NewReport* new_report; |
| 140 EXPECT_EQ(CrashReportDatabase::kNoError, | 133 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 141 db()->PrepareNewCrashReport(&new_report)); | 134 db()->PrepareNewCrashReport(&new_report)); |
| 142 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | 135 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
| 143 UUID uuid; | 136 UUID uuid; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 155 ASSERT_EQ(1u, reports.size()); | 148 ASSERT_EQ(1u, reports.size()); |
| 156 EXPECT_EQ(report.uuid, reports[0].uuid); | 149 EXPECT_EQ(report.uuid, reports[0].uuid); |
| 157 | 150 |
| 158 reports.clear(); | 151 reports.clear(); |
| 159 EXPECT_EQ(CrashReportDatabase::kNoError, | 152 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 160 db()->GetCompletedReports(&reports)); | 153 db()->GetCompletedReports(&reports)); |
| 161 EXPECT_TRUE(reports.empty()); | 154 EXPECT_TRUE(reports.empty()); |
| 162 } | 155 } |
| 163 | 156 |
| 164 TEST_F(CrashReportDatabaseTest, ErrorWritingCrashReport) { | 157 TEST_F(CrashReportDatabaseTest, ErrorWritingCrashReport) { |
| 165 CrashReportDatabase::NewReport* new_report; | 158 CrashReportDatabase::NewReport* new_report = nullptr; |
| 166 EXPECT_EQ(CrashReportDatabase::kNoError, | 159 ASSERT_EQ(CrashReportDatabase::kNoError, |
| 167 db()->PrepareNewCrashReport(&new_report)); | 160 db()->PrepareNewCrashReport(&new_report)); |
| 168 base::FilePath new_report_path = new_report->path; | 161 base::FilePath new_report_path = new_report->path; |
| 169 EXPECT_TRUE(FileExistsAtPath(new_report_path)) << new_report_path.value(); | 162 EXPECT_TRUE(FileExistsAtPath(new_report_path)) << new_report_path.value(); |
| 170 EXPECT_EQ(CrashReportDatabase::kNoError, | 163 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 171 db()->ErrorWritingCrashReport(new_report)); | 164 db()->ErrorWritingCrashReport(new_report)); |
| 172 EXPECT_FALSE(FileExistsAtPath(new_report_path)) << new_report_path.value(); | 165 EXPECT_FALSE(FileExistsAtPath(new_report_path)) << new_report_path.value(); |
| 173 } | 166 } |
| 174 | 167 |
| 175 TEST_F(CrashReportDatabaseTest, LookUpCrashReport) { | 168 TEST_F(CrashReportDatabaseTest, LookUpCrashReport) { |
| 176 UUID uuid; | 169 UUID uuid; |
| 177 | 170 |
| 178 { | 171 { |
| 179 CrashReportDatabase::Report report; | 172 CrashReportDatabase::Report report; |
| 180 CreateCrashReport(&report); | 173 CreateCrashReport(&report); |
| 181 uuid = report.uuid; | 174 uuid = report.uuid; |
| 182 } | 175 } |
| 183 | 176 |
| 184 { | 177 { |
| 185 CrashReportDatabase::Report report; | 178 CrashReportDatabase::Report report; |
| 186 EXPECT_EQ(CrashReportDatabase::kNoError, | 179 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 187 db()->LookUpCrashReport(uuid, &report)); | 180 db()->LookUpCrashReport(uuid, &report)); |
| 188 EXPECT_EQ(uuid, report.uuid); | 181 EXPECT_EQ(uuid, report.uuid); |
| 189 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); | 182 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); |
| 190 EXPECT_EQ("", report.id); | 183 EXPECT_EQ(std::string(), report.id); |
| 191 EXPECT_FALSE(report.uploaded); | 184 EXPECT_FALSE(report.uploaded); |
| 192 EXPECT_EQ(0, report.last_upload_attempt_time); | 185 EXPECT_EQ(0, report.last_upload_attempt_time); |
| 193 EXPECT_EQ(0, report.upload_attempts); | 186 EXPECT_EQ(0, report.upload_attempts); |
| 194 } | 187 } |
| 195 | 188 |
| 196 UploadReport(uuid, true, "test"); | 189 UploadReport(uuid, true, "test"); |
| 197 | 190 |
| 198 { | 191 { |
| 199 CrashReportDatabase::Report report; | 192 CrashReportDatabase::Report report; |
| 200 EXPECT_EQ(CrashReportDatabase::kNoError, | 193 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 201 db()->LookUpCrashReport(uuid, &report)); | 194 db()->LookUpCrashReport(uuid, &report)); |
| 202 EXPECT_EQ(uuid, report.uuid); | 195 EXPECT_EQ(uuid, report.uuid); |
| 203 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); | 196 EXPECT_NE(std::string::npos, report.file_path.value().find(path().value())); |
| 204 EXPECT_EQ("test", report.id); | 197 EXPECT_EQ("test", report.id); |
| 205 EXPECT_TRUE(report.uploaded); | 198 EXPECT_TRUE(report.uploaded); |
| 206 EXPECT_NE(0, report.last_upload_attempt_time); | 199 EXPECT_NE(0, report.last_upload_attempt_time); |
| 207 EXPECT_EQ(1, report.upload_attempts); | 200 EXPECT_EQ(1, report.upload_attempts); |
| 208 } | 201 } |
| 209 } | 202 } |
| 210 | 203 |
| 211 TEST_F(CrashReportDatabaseTest, RecordUploadAttempt) { | 204 TEST_F(CrashReportDatabaseTest, RecordUploadAttempt) { |
| 212 std::vector<CrashReportDatabase::Report> reports(3); | 205 std::vector<CrashReportDatabase::Report> reports(3); |
| 213 CreateCrashReport(&reports[0]); | 206 CreateCrashReport(&reports[0]); |
| 214 CreateCrashReport(&reports[1]); | 207 CreateCrashReport(&reports[1]); |
| 215 CreateCrashReport(&reports[2]); | 208 CreateCrashReport(&reports[2]); |
| 216 | 209 |
| 217 // Record two attempts: one successful, one not. | 210 // Record two attempts: one successful, one not. |
| 218 UploadReport(reports[1].uuid, false, ""); | 211 UploadReport(reports[1].uuid, false, std::string()); |
| 219 UploadReport(reports[2].uuid, true, "abc123"); | 212 UploadReport(reports[2].uuid, true, "abc123"); |
| 220 | 213 |
| 221 std::vector<CrashReportDatabase::Report> query(3); | 214 std::vector<CrashReportDatabase::Report> query(3); |
| 222 | |
| 223 EXPECT_EQ(CrashReportDatabase::kNoError, | 215 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 224 db()->LookUpCrashReport(reports[0].uuid, &query[0])); | 216 db()->LookUpCrashReport(reports[0].uuid, &query[0])); |
| 225 EXPECT_EQ(CrashReportDatabase::kNoError, | 217 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 226 db()->LookUpCrashReport(reports[1].uuid, &query[1])); | 218 db()->LookUpCrashReport(reports[1].uuid, &query[1])); |
| 227 EXPECT_EQ(CrashReportDatabase::kNoError, | 219 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 228 db()->LookUpCrashReport(reports[2].uuid, &query[2])); | 220 db()->LookUpCrashReport(reports[2].uuid, &query[2])); |
| 229 | 221 |
| 230 EXPECT_EQ("", query[0].id); | 222 EXPECT_EQ(std::string(), query[0].id); |
| 231 EXPECT_EQ("", query[1].id); | 223 EXPECT_EQ(std::string(), query[1].id); |
| 232 EXPECT_EQ("abc123", query[2].id); | 224 EXPECT_EQ("abc123", query[2].id); |
| 233 | 225 |
| 234 EXPECT_FALSE(query[0].uploaded); | 226 EXPECT_FALSE(query[0].uploaded); |
| 235 EXPECT_FALSE(query[1].uploaded); | 227 EXPECT_FALSE(query[1].uploaded); |
| 236 EXPECT_TRUE(query[2].uploaded); | 228 EXPECT_TRUE(query[2].uploaded); |
| 237 | 229 |
| 238 EXPECT_EQ(0, query[0].last_upload_attempt_time); | 230 EXPECT_EQ(0, query[0].last_upload_attempt_time); |
| 239 EXPECT_NE(0, query[1].last_upload_attempt_time); | 231 EXPECT_NE(0, query[1].last_upload_attempt_time); |
| 240 EXPECT_NE(0, query[2].last_upload_attempt_time); | 232 EXPECT_NE(0, query[2].last_upload_attempt_time); |
| 241 | 233 |
| 242 EXPECT_EQ(0, query[0].upload_attempts); | 234 EXPECT_EQ(0, query[0].upload_attempts); |
| 243 EXPECT_EQ(1, query[1].upload_attempts); | 235 EXPECT_EQ(1, query[1].upload_attempts); |
| 244 EXPECT_EQ(1, query[2].upload_attempts); | 236 EXPECT_EQ(1, query[2].upload_attempts); |
| 245 | 237 |
| 246 // Attempt to upload and fail again. | 238 // Attempt to upload and fail again. |
| 247 UploadReport(reports[1].uuid, false, ""); | 239 UploadReport(reports[1].uuid, false, std::string()); |
| 248 | 240 |
| 249 time_t report_2_upload_time = query[2].last_upload_attempt_time; | 241 time_t report_2_upload_time = query[2].last_upload_attempt_time; |
| 250 | 242 |
| 251 EXPECT_EQ(CrashReportDatabase::kNoError, | 243 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 252 db()->LookUpCrashReport(reports[0].uuid, &query[0])); | 244 db()->LookUpCrashReport(reports[0].uuid, &query[0])); |
| 253 EXPECT_EQ(CrashReportDatabase::kNoError, | 245 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 254 db()->LookUpCrashReport(reports[1].uuid, &query[1])); | 246 db()->LookUpCrashReport(reports[1].uuid, &query[1])); |
| 255 EXPECT_EQ(CrashReportDatabase::kNoError, | 247 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 256 db()->LookUpCrashReport(reports[2].uuid, &query[2])); | 248 db()->LookUpCrashReport(reports[2].uuid, &query[2])); |
| 257 | 249 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 ASSERT_EQ(1u, completed.size()); | 324 ASSERT_EQ(1u, completed.size()); |
| 333 | 325 |
| 334 for (const auto& report : pending) | 326 for (const auto& report : pending) |
| 335 EXPECT_NE(report_1_uuid, report.uuid); | 327 EXPECT_NE(report_1_uuid, report.uuid); |
| 336 EXPECT_EQ(report_1_uuid, completed[0].uuid); | 328 EXPECT_EQ(report_1_uuid, completed[0].uuid); |
| 337 EXPECT_EQ("report1", completed[0].id); | 329 EXPECT_EQ("report1", completed[0].id); |
| 338 EXPECT_EQ(true, completed[0].uploaded); | 330 EXPECT_EQ(true, completed[0].uploaded); |
| 339 EXPECT_GT(completed[0].last_upload_attempt_time, 0); | 331 EXPECT_GT(completed[0].last_upload_attempt_time, 0); |
| 340 EXPECT_EQ(1, completed[0].upload_attempts); | 332 EXPECT_EQ(1, completed[0].upload_attempts); |
| 341 | 333 |
| 342 const CrashReportDatabase::Report completed_report_1 = completed[0]; | |
| 343 | |
| 344 // Fail to upload one report. | 334 // Fail to upload one report. |
| 345 UploadReport(report_2_uuid, false, ""); | 335 UploadReport(report_2_uuid, false, std::string()); |
| 346 | 336 |
| 347 pending.clear(); | 337 pending.clear(); |
| 348 EXPECT_EQ(CrashReportDatabase::kNoError, | 338 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 349 db()->GetPendingReports(&pending)); | 339 db()->GetPendingReports(&pending)); |
| 350 completed.clear(); | 340 completed.clear(); |
| 351 EXPECT_EQ(CrashReportDatabase::kNoError, | 341 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 352 db()->GetCompletedReports(&completed)); | 342 db()->GetCompletedReports(&completed)); |
| 353 | 343 |
| 354 EXPECT_EQ(4u, pending.size()); | 344 EXPECT_EQ(4u, pending.size()); |
| 355 ASSERT_EQ(1u, completed.size()); | 345 ASSERT_EQ(1u, completed.size()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 const CrashReportDatabase::Report* upload_report; | 420 const CrashReportDatabase::Report* upload_report; |
| 431 EXPECT_EQ(CrashReportDatabase::kNoError, | 421 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 432 db()->GetReportForUploading(report.uuid, &upload_report)); | 422 db()->GetReportForUploading(report.uuid, &upload_report)); |
| 433 | 423 |
| 434 const CrashReportDatabase::Report* upload_report_2 = nullptr; | 424 const CrashReportDatabase::Report* upload_report_2 = nullptr; |
| 435 EXPECT_EQ(CrashReportDatabase::kBusyError, | 425 EXPECT_EQ(CrashReportDatabase::kBusyError, |
| 436 db()->GetReportForUploading(report.uuid, &upload_report_2)); | 426 db()->GetReportForUploading(report.uuid, &upload_report_2)); |
| 437 EXPECT_FALSE(upload_report_2); | 427 EXPECT_FALSE(upload_report_2); |
| 438 | 428 |
| 439 EXPECT_EQ(CrashReportDatabase::kNoError, | 429 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 440 db()->RecordUploadAttempt(upload_report, true, "")); | 430 db()->RecordUploadAttempt(upload_report, true, std::string())); |
| 441 } | 431 } |
| 442 | 432 |
| 443 TEST_F(CrashReportDatabaseTest, MoveDatabase) { | 433 TEST_F(CrashReportDatabaseTest, MoveDatabase) { |
| 444 CrashReportDatabase::NewReport* new_report; | 434 CrashReportDatabase::NewReport* new_report; |
| 445 EXPECT_EQ(CrashReportDatabase::kNoError, | 435 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 446 db()->PrepareNewCrashReport(&new_report)); | 436 db()->PrepareNewCrashReport(&new_report)); |
| 447 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); | 437 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
| 448 UUID uuid; | 438 UUID uuid; |
| 449 EXPECT_EQ(CrashReportDatabase::kNoError, | 439 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 450 db()->FinishedWritingCrashReport(new_report, &uuid)); | 440 db()->FinishedWritingCrashReport(new_report, &uuid)); |
| 451 | 441 |
| 452 RelocateDatabase(); | 442 RelocateDatabase(); |
| 453 | 443 |
| 454 CrashReportDatabase::Report report; | 444 CrashReportDatabase::Report report; |
| 455 EXPECT_EQ(CrashReportDatabase::kNoError, | 445 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 456 db()->LookUpCrashReport(uuid, &report)); | 446 db()->LookUpCrashReport(uuid, &report)); |
| 457 ExpectPreparedCrashReport(report); | 447 ExpectPreparedCrashReport(report); |
| 458 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); | 448 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); |
| 459 } | 449 } |
| 460 | 450 |
| 451 TEST_F(CrashReportDatabaseTest, ReportRemoved) { |
| 452 CrashReportDatabase::NewReport* new_report; |
| 453 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 454 db()->PrepareNewCrashReport(&new_report)); |
| 455 EXPECT_TRUE(FileExistsAtPath(new_report->path)) << new_report->path.value(); |
| 456 UUID uuid; |
| 457 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 458 db()->FinishedWritingCrashReport(new_report, &uuid)); |
| 459 |
| 460 CrashReportDatabase::Report report; |
| 461 EXPECT_EQ(CrashReportDatabase::kNoError, |
| 462 db()->LookUpCrashReport(uuid, &report)); |
| 463 |
| 464 #if defined(OS_WIN) |
| 465 EXPECT_EQ(0, _wunlink(report.file_path.value().c_str())); |
| 466 #else |
| 467 EXPECT_EQ(0, unlink(report.file_path.value().c_str())) |
| 468 << ErrnoMessage("unlink"); |
| 469 #endif |
| 470 |
| 471 EXPECT_EQ(CrashReportDatabase::kReportNotFound, |
| 472 db()->LookUpCrashReport(uuid, &report)); |
| 473 } |
| 474 |
| 461 } // namespace | 475 } // namespace |
| 462 } // namespace test | 476 } // namespace test |
| 463 } // namespace crashpad | 477 } // namespace crashpad |
| OLD | NEW |