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

Side by Side Diff: client/crash_report_database_test.cc

Issue 995853003: CrashReportDatabse: set the last upload attempt time from RecordUploadAttempt() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: kDatabaseError Created 5 years, 9 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 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 "build/build_config.h"
20 #include "client/settings.h"
19 #include "gtest/gtest.h" 21 #include "gtest/gtest.h"
20 #include "util/file/file_io.h" 22 #include "util/file/file_io.h"
21 #include "util/test/errors.h" 23 #include "util/test/errors.h"
22 #include "util/test/scoped_temp_dir.h" 24 #include "util/test/scoped_temp_dir.h"
23 25
24 namespace crashpad { 26 namespace crashpad {
25 namespace test { 27 namespace test {
26 namespace { 28 namespace {
27 29
28 bool FileExistsAtPath(const base::FilePath& path) { 30 bool FileExistsAtPath(const base::FilePath& path) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 EXPECT_EQ(CrashReportDatabase::kNoError, 69 EXPECT_EQ(CrashReportDatabase::kNoError,
68 db_->FinishedWritingCrashReport(new_report, &uuid)); 70 db_->FinishedWritingCrashReport(new_report, &uuid));
69 71
70 EXPECT_EQ(CrashReportDatabase::kNoError, 72 EXPECT_EQ(CrashReportDatabase::kNoError,
71 db_->LookUpCrashReport(uuid, report)); 73 db_->LookUpCrashReport(uuid, report));
72 ExpectPreparedCrashReport(*report); 74 ExpectPreparedCrashReport(*report);
73 ASSERT_TRUE(FileExistsAtPath(report->file_path)); 75 ASSERT_TRUE(FileExistsAtPath(report->file_path));
74 } 76 }
75 77
76 void UploadReport(const UUID& uuid, bool successful, const std::string& id) { 78 void UploadReport(const UUID& uuid, bool successful, const std::string& id) {
79 #if !defined(OS_WIN)
80 // Enable when ported to Windows.
81 // https://code.google.com/p/crashpad/issues/detail?id=13
82 Settings* const settings = db_->GetSettings();
83 ASSERT_TRUE(settings);
84 time_t times[2];
85 ASSERT_TRUE(settings->GetLastUploadAttemptTime(&times[0]));
86 #endif
87
77 const CrashReportDatabase::Report* report = nullptr; 88 const CrashReportDatabase::Report* report = nullptr;
78 ASSERT_EQ(CrashReportDatabase::kNoError, 89 ASSERT_EQ(CrashReportDatabase::kNoError,
79 db_->GetReportForUploading(uuid, &report)); 90 db_->GetReportForUploading(uuid, &report));
80 EXPECT_NE(UUID(), report->uuid); 91 EXPECT_NE(UUID(), report->uuid);
81 EXPECT_FALSE(report->file_path.empty()); 92 EXPECT_FALSE(report->file_path.empty());
82 EXPECT_TRUE(FileExistsAtPath(report->file_path)) 93 EXPECT_TRUE(FileExistsAtPath(report->file_path))
83 << report->file_path.value(); 94 << report->file_path.value();
84 EXPECT_GT(report->creation_time, 0); 95 EXPECT_GT(report->creation_time, 0);
85 EXPECT_EQ(CrashReportDatabase::kNoError, 96 EXPECT_EQ(CrashReportDatabase::kNoError,
86 db_->RecordUploadAttempt(report, successful, id)); 97 db_->RecordUploadAttempt(report, successful, id));
98
99 #if !defined(OS_WIN)
100 // Enable when ported to Windows.
101 // https://code.google.com/p/crashpad/issues/detail?id=13
102 ASSERT_TRUE(settings->GetLastUploadAttemptTime(&times[1]));
103 EXPECT_NE(times[1], 0);
104 EXPECT_GE(times[1], times[0]);
105 #endif
87 } 106 }
88 107
89 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) { 108 void ExpectPreparedCrashReport(const CrashReportDatabase::Report& report) {
90 EXPECT_NE(UUID(), report.uuid); 109 EXPECT_NE(UUID(), report.uuid);
91 EXPECT_FALSE(report.file_path.empty()); 110 EXPECT_FALSE(report.file_path.empty());
92 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value(); 111 EXPECT_TRUE(FileExistsAtPath(report.file_path)) << report.file_path.value();
93 EXPECT_TRUE(report.id.empty()); 112 EXPECT_TRUE(report.id.empty());
94 EXPECT_GT(report.creation_time, 0); 113 EXPECT_GT(report.creation_time, 0);
95 EXPECT_FALSE(report.uploaded); 114 EXPECT_FALSE(report.uploaded);
96 EXPECT_EQ(0, report.last_upload_attempt_time); 115 EXPECT_EQ(0, report.last_upload_attempt_time);
97 EXPECT_EQ(0, report.upload_attempts); 116 EXPECT_EQ(0, report.upload_attempts);
98 } 117 }
99 118
100 void RelocateDatabase() { 119 void RelocateDatabase() {
101 ResetDatabase(); 120 ResetDatabase();
102 temp_dir_.Rename(); 121 temp_dir_.Rename();
103 SetUp(); 122 SetUp();
104 } 123 }
105 124
106 private: 125 private:
107 ScopedTempDir temp_dir_; 126 ScopedTempDir temp_dir_;
108 scoped_ptr<CrashReportDatabase> db_; 127 scoped_ptr<CrashReportDatabase> db_;
109 128
110 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseTest); 129 DISALLOW_COPY_AND_ASSIGN(CrashReportDatabaseTest);
111 }; 130 };
112 131
113 TEST_F(CrashReportDatabaseTest, Initialize) { 132 TEST_F(CrashReportDatabaseTest, Initialize) {
114 // Initialize the database for the first time, creating it. 133 // Initialize the database for the first time, creating it.
115 EXPECT_TRUE(db()); 134 ASSERT_TRUE(db());
135
136 #if !defined(OS_WIN)
137 // Enable when ported to Windows.
138 // https://code.google.com/p/crashpad/issues/detail?id=13
139 Settings* settings = db()->GetSettings();
140
141 UUID client_ids[2];
142 ASSERT_TRUE(settings->GetClientID(&client_ids[0]));
143 EXPECT_NE(client_ids[0], UUID());
144
145 time_t last_upload_attempt_time;
146 ASSERT_TRUE(settings->GetLastUploadAttemptTime(&last_upload_attempt_time));
147 EXPECT_EQ(0, last_upload_attempt_time);
148 #endif
116 149
117 // Close and reopen the database at the same path. 150 // Close and reopen the database at the same path.
118 ResetDatabase(); 151 ResetDatabase();
119 EXPECT_FALSE(db()); 152 EXPECT_FALSE(db());
120 auto db = CrashReportDatabase::Initialize(path()); 153 auto db = CrashReportDatabase::Initialize(path());
121 ASSERT_TRUE(db); 154 ASSERT_TRUE(db);
122 155
156 #if !defined(OS_WIN)
157 // Enable when ported to Windows.
158 // https://code.google.com/p/crashpad/issues/detail?id=13
159 settings = db->GetSettings();
160
161 ASSERT_TRUE(settings->GetClientID(&client_ids[1]));
162 EXPECT_EQ(client_ids[0], client_ids[1]);
163
164 ASSERT_TRUE(settings->GetLastUploadAttemptTime(&last_upload_attempt_time));
165 EXPECT_EQ(0, last_upload_attempt_time);
166 #endif
167
123 std::vector<CrashReportDatabase::Report> reports; 168 std::vector<CrashReportDatabase::Report> reports;
124 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports)); 169 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetPendingReports(&reports));
125 EXPECT_TRUE(reports.empty()); 170 EXPECT_TRUE(reports.empty());
126 reports.clear(); 171 reports.clear();
127 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports)); 172 EXPECT_EQ(CrashReportDatabase::kNoError, db->GetCompletedReports(&reports));
128 EXPECT_TRUE(reports.empty()); 173 EXPECT_TRUE(reports.empty());
129 } 174 }
130 175
131 TEST_F(CrashReportDatabaseTest, NewCrashReport) { 176 TEST_F(CrashReportDatabaseTest, NewCrashReport) {
132 CrashReportDatabase::NewReport* new_report; 177 CrashReportDatabase::NewReport* new_report;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 << ErrnoMessage("unlink"); 513 << ErrnoMessage("unlink");
469 #endif 514 #endif
470 515
471 EXPECT_EQ(CrashReportDatabase::kReportNotFound, 516 EXPECT_EQ(CrashReportDatabase::kReportNotFound,
472 db()->LookUpCrashReport(uuid, &report)); 517 db()->LookUpCrashReport(uuid, &report));
473 } 518 }
474 519
475 } // namespace 520 } // namespace
476 } // namespace test 521 } // namespace test
477 } // namespace crashpad 522 } // namespace crashpad
OLDNEW
« client/crash_report_database_mac.mm ('K') | « client/crash_report_database_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698