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

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 11363222: Persist download interrupt reason, both target and current paths, and url_chain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged to r180302 Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 19 matching lines...) Expand all
30 #include "base/compiler_specific.h" 30 #include "base/compiler_specific.h"
31 #include "base/file_path.h" 31 #include "base/file_path.h"
32 #include "base/file_util.h" 32 #include "base/file_util.h"
33 #include "base/files/scoped_temp_dir.h" 33 #include "base/files/scoped_temp_dir.h"
34 #include "base/logging.h" 34 #include "base/logging.h"
35 #include "base/memory/scoped_ptr.h" 35 #include "base/memory/scoped_ptr.h"
36 #include "base/memory/scoped_vector.h" 36 #include "base/memory/scoped_vector.h"
37 #include "base/message_loop.h" 37 #include "base/message_loop.h"
38 #include "base/path_service.h" 38 #include "base/path_service.h"
39 #include "base/string_util.h" 39 #include "base/string_util.h"
40 #include "base/stringprintf.h"
40 #include "base/time.h" 41 #include "base/time.h"
41 #include "base/utf_string_conversions.h" 42 #include "base/utf_string_conversions.h"
42 #include "chrome/browser/history/download_row.h" 43 #include "chrome/browser/history/download_row.h"
43 #include "chrome/browser/history/history_backend.h" 44 #include "chrome/browser/history/history_backend.h"
44 #include "chrome/browser/history/history_database.h" 45 #include "chrome/browser/history/history_database.h"
45 #include "chrome/browser/history/history_notifications.h" 46 #include "chrome/browser/history/history_notifications.h"
46 #include "chrome/browser/history/history_service.h" 47 #include "chrome/browser/history/history_service.h"
48 #include "chrome/browser/history/history_unittest_base.h"
47 #include "chrome/browser/history/in_memory_database.h" 49 #include "chrome/browser/history/in_memory_database.h"
48 #include "chrome/browser/history/in_memory_history_backend.h" 50 #include "chrome/browser/history/in_memory_history_backend.h"
49 #include "chrome/browser/history/page_usage_data.h" 51 #include "chrome/browser/history/page_usage_data.h"
50 #include "chrome/common/chrome_constants.h" 52 #include "chrome/common/chrome_constants.h"
51 #include "chrome/common/chrome_paths.h" 53 #include "chrome/common/chrome_paths.h"
52 #include "chrome/common/thumbnail_score.h" 54 #include "chrome/common/thumbnail_score.h"
53 #include "chrome/tools/profiles/thumbnail-inl.h" 55 #include "chrome/tools/profiles/thumbnail-inl.h"
54 #include "content/public/browser/download_item.h" 56 #include "content/public/browser/download_item.h"
55 #include "content/public/browser/notification_details.h" 57 #include "content/public/browser/notification_details.h"
56 #include "content/public/browser/notification_source.h" 58 #include "content/public/browser/notification_source.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 virtual void DBLoaded(int backend_id) OVERRIDE {} 94 virtual void DBLoaded(int backend_id) OVERRIDE {}
93 virtual void StartTopSitesMigration(int backend_id) OVERRIDE {} 95 virtual void StartTopSitesMigration(int backend_id) OVERRIDE {}
94 virtual void NotifyVisitDBObserversOnAddVisit( 96 virtual void NotifyVisitDBObserversOnAddVisit(
95 const BriefVisitInfo& info) OVERRIDE {} 97 const BriefVisitInfo& info) OVERRIDE {}
96 private: 98 private:
97 HistoryBackendDBTest* history_test_; 99 HistoryBackendDBTest* history_test_;
98 }; 100 };
99 101
100 // This must be outside the anonymous namespace for the friend statement in 102 // This must be outside the anonymous namespace for the friend statement in
101 // HistoryBackend to work. 103 // HistoryBackend to work.
102 class HistoryBackendDBTest : public testing::Test { 104 class HistoryBackendDBTest : public HistoryUnitTestBase {
103 public: 105 public:
104 HistoryBackendDBTest() : db_(NULL) { 106 HistoryBackendDBTest() : db_(NULL) {
105 } 107 }
106 108
107 ~HistoryBackendDBTest() { 109 ~HistoryBackendDBTest() {
108 } 110 }
109 111
110 protected: 112 protected:
111 friend class BackendDelegate; 113 friend class BackendDelegate;
112 114
113 // Creates the HistoryBackend and HistoryDatabase on the current thread, 115 // Creates the HistoryBackend and HistoryDatabase on the current thread,
114 // assigning the values to backend_ and db_. 116 // assigning the values to backend_ and db_.
115 void CreateBackendAndDatabase() { 117 void CreateBackendAndDatabase() {
116 backend_ = new HistoryBackend(history_dir_, 0, new BackendDelegate(this), 118 backend_ = new HistoryBackend(history_dir_, 0, new BackendDelegate(this),
117 NULL); 119 NULL);
118 backend_->Init(std::string(), false); 120 backend_->Init(std::string(), false);
119 db_ = backend_->db_.get(); 121 db_ = backend_->db_.get();
120 DCHECK(in_mem_backend_.get()) << "Mem backend should have been set by " 122 DCHECK(in_mem_backend_.get()) << "Mem backend should have been set by "
121 "HistoryBackend::Init"; 123 "HistoryBackend::Init";
122 } 124 }
123 125
126 void CreateDBVersion(int version) {
127 FilePath data_path;
128 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
129 data_path = data_path.AppendASCII("History");
130 data_path = data_path.AppendASCII(StringPrintf("history.%d.sql", version));
131 ASSERT_NO_FATAL_FAILURE(
132 ExecuteSQLScript(data_path, history_dir_.Append(
133 chrome::kHistoryFilename)));
134 }
135
124 // testing::Test 136 // testing::Test
125 virtual void SetUp() { 137 virtual void SetUp() {
126 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 138 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
127 history_dir_ = temp_dir_.path().AppendASCII("HistoryBackendDBTest"); 139 history_dir_ = temp_dir_.path().AppendASCII("HistoryBackendDBTest");
128 ASSERT_TRUE(file_util::CreateDirectory(history_dir_)); 140 ASSERT_TRUE(file_util::CreateDirectory(history_dir_));
129 } 141 }
130 142
131 void DeleteBackend() { 143 void DeleteBackend() {
132 if (backend_) { 144 if (backend_) {
133 backend_->Closing(); 145 backend_->Closing();
134 backend_ = NULL; 146 backend_ = NULL;
135 } 147 }
136 } 148 }
137 149
138 virtual void TearDown() { 150 virtual void TearDown() {
139 DeleteBackend(); 151 DeleteBackend();
140 152
141 // Make sure we don't have any event pending that could disrupt the next 153 // Make sure we don't have any event pending that could disrupt the next
142 // test. 154 // test.
143 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 155 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
144 MessageLoop::current()->Run(); 156 MessageLoop::current()->Run();
145 } 157 }
146 158
147 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) { 159 int64 AddDownload(DownloadItem::DownloadState state, const Time& time) {
160 std::vector<GURL> url_chain;
161 url_chain.push_back(GURL("foo-url"));
162
148 DownloadRow download( 163 DownloadRow download(
149 FilePath(FILE_PATH_LITERAL("foo-path")), 164 FilePath(FILE_PATH_LITERAL("foo-path")),
150 GURL("foo-url"), 165 FilePath(FILE_PATH_LITERAL("foo-path")),
166 url_chain,
151 GURL(""), 167 GURL(""),
152 time, 168 time,
153 time, 169 time,
154 0, 170 0,
155 512, 171 512,
156 state, 172 state,
173 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
174 content::DOWNLOAD_INTERRUPT_REASON_NONE,
157 0, 175 0,
158 0); 176 0);
159 return db_->CreateDownload(download); 177 return db_->CreateDownload(download);
160 } 178 }
161 179
162 base::ScopedTempDir temp_dir_; 180 base::ScopedTempDir temp_dir_;
163 181
164 MessageLoopForUI message_loop_; 182 MessageLoopForUI message_loop_;
165 183
166 // names of the database files 184 // names of the database files
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 DownloadID handle; 224 DownloadID handle;
207 EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, Time())); 225 EXPECT_NE(0, handle = AddDownload(DownloadItem::COMPLETE, Time()));
208 db_->QueryDownloads(&downloads); 226 db_->QueryDownloads(&downloads);
209 EXPECT_EQ(1U, downloads.size()); 227 EXPECT_EQ(1U, downloads.size());
210 db_->RemoveDownload(handle); 228 db_->RemoveDownload(handle);
211 db_->QueryDownloads(&downloads); 229 db_->QueryDownloads(&downloads);
212 EXPECT_EQ(0U, downloads.size()); 230 EXPECT_EQ(0U, downloads.size());
213 } 231 }
214 232
215 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) { 233 TEST_F(HistoryBackendDBTest, MigrateDownloadsState) {
216 // Create the db and close it so that we can reopen it directly. 234 // Create the db we want.
217 CreateBackendAndDatabase(); 235 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
218 DeleteBackend();
219 { 236 {
220 // Re-open the db for manual manipulation. 237 // Open the db for manual manipulation.
221 sql::Connection db; 238 sql::Connection db;
222 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); 239 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
223 { 240
224 // Manually force the version to 22.
225 sql::Statement version22(db.GetUniqueStatement(
226 "UPDATE meta SET value=22 WHERE key='version'"));
227 ASSERT_TRUE(version22.Run());
228 }
229 // Manually insert corrupted rows; there's infrastructure in place now to 241 // Manually insert corrupted rows; there's infrastructure in place now to
230 // make this impossible, at least according to the test above. 242 // make this impossible, at least according to the test above.
231 for (int state = 0; state < 5; ++state) { 243 for (int state = 0; state < 5; ++state) {
232 sql::Statement s(db.GetUniqueStatement( 244 sql::Statement s(db.GetUniqueStatement(
233 "INSERT INTO downloads (id, full_path, url, start_time, " 245 "INSERT INTO downloads (id, full_path, url, start_time, "
234 "received_bytes, total_bytes, state, end_time, opened) VALUES " 246 "received_bytes, total_bytes, state, end_time, opened) VALUES "
235 "(?, ?, ?, ?, ?, ?, ?, ?, ?)")); 247 "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
236 s.BindInt64(0, 1 + state); 248 s.BindInt64(0, 1 + state);
237 s.BindString(1, "path"); 249 s.BindString(1, "path");
238 s.BindString(2, "url"); 250 s.BindString(2, "url");
239 s.BindInt64(3, base::Time::Now().ToTimeT()); 251 s.BindInt64(3, base::Time::Now().ToTimeT());
240 s.BindInt64(4, 100); 252 s.BindInt64(4, 100);
241 s.BindInt64(5, 100); 253 s.BindInt64(5, 100);
242 s.BindInt(6, state); 254 s.BindInt(6, state);
243 s.BindInt64(7, base::Time::Now().ToTimeT()); 255 s.BindInt64(7, base::Time::Now().ToTimeT());
244 s.BindInt(8, state % 2); 256 s.BindInt(8, state % 2);
245 ASSERT_TRUE(s.Run()); 257 ASSERT_TRUE(s.Run());
246 } 258 }
247 } 259 }
248 260
249 // Re-open the db using the HistoryDatabase, which should migrate from version 261 // Re-open the db using the HistoryDatabase, which should migrate from version
250 // 22 to 23, fixing just the row whose state was 3. Then close the db so that 262 // 22 to the current version, fixing just the row whose state was 3.
251 // we can re-open it directly. 263 // Then close the db so that we can re-open it directly.
252 CreateBackendAndDatabase(); 264 CreateBackendAndDatabase();
253 DeleteBackend(); 265 DeleteBackend();
254 { 266 {
255 // Re-open the db for manual manipulation. 267 // Re-open the db for manual manipulation.
256 sql::Connection db; 268 sql::Connection db;
257 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename))); 269 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
258 { 270 {
259 // The version should have been updated. 271 // The version should have been updated.
260 int cur_version = HistoryDatabase::GetCurrentVersion(); 272 int cur_version = HistoryDatabase::GetCurrentVersion();
261 ASSERT_LT(22, cur_version); 273 ASSERT_LT(22, cur_version);
(...skipping 14 matching lines...) Expand all
276 // 4. 288 // 4.
277 EXPECT_EQ(((counter == 3) ? 4 : counter), statement.ColumnInt(1)); 289 EXPECT_EQ(((counter == 3) ? 4 : counter), statement.ColumnInt(1));
278 EXPECT_EQ(counter % 2, statement.ColumnInt(2)); 290 EXPECT_EQ(counter % 2, statement.ColumnInt(2));
279 ++counter; 291 ++counter;
280 } 292 }
281 EXPECT_EQ(5, counter); 293 EXPECT_EQ(5, counter);
282 } 294 }
283 } 295 }
284 } 296 }
285 297
298 TEST_F(HistoryBackendDBTest, MigrateDownloadsReasonPathsAndDangerType) {
299 Time now(base::Time::Now());
300
301 // Create the db we want. The schema didn't change from 22->23, so just
302 // re-use the v22 file.
303 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(22));
304 {
305 // Re-open the db for manual manipulation.
306 sql::Connection db;
307 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
308
309 // Manually insert some rows.
310 sql::Statement s(db.GetUniqueStatement(
311 "INSERT INTO downloads (id, full_path, url, start_time, "
312 "received_bytes, total_bytes, state, end_time, opened) VALUES "
313 "(?, ?, ?, ?, ?, ?, ?, ?, ?)"));
314
315 int64 db_handle = 0;
316 // Null path.
317 s.BindInt64(0, ++db_handle);
318 s.BindString(1, "");
319 s.BindString(2, "http://whatever.com/index.html");
320 s.BindInt64(3, now.ToTimeT());
321 s.BindInt64(4, 100);
322 s.BindInt64(5, 100);
323 s.BindInt(6, 1);
324 s.BindInt64(7, now.ToTimeT());
325 s.BindInt(8, 1);
326 ASSERT_TRUE(s.Run());
327 s.Reset(true);
328
329 // Non-null path.
330 s.BindInt64(0, ++db_handle);
331 s.BindString(1, "/path/to/some/file");
332 s.BindString(2, "http://whatever.com/index1.html");
333 s.BindInt64(3, now.ToTimeT());
334 s.BindInt64(4, 100);
335 s.BindInt64(5, 100);
336 s.BindInt(6, 1);
337 s.BindInt64(7, now.ToTimeT());
338 s.BindInt(8, 1);
339 ASSERT_TRUE(s.Run());
340 }
341
342 // Re-open the db using the HistoryDatabase, which should migrate from version
343 // 23 to 24, creating the new tables and creating the new path, reason,
344 // and danger columns.
345 CreateBackendAndDatabase();
346 DeleteBackend();
347 {
348 // Re-open the db for manual manipulation.
349 sql::Connection db;
350 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
351 {
352 // The version should have been updated.
353 int cur_version = HistoryDatabase::GetCurrentVersion();
354 ASSERT_LT(23, cur_version);
355 sql::Statement s(db.GetUniqueStatement(
356 "SELECT value FROM meta WHERE key = 'version'"));
357 EXPECT_TRUE(s.Step());
358 EXPECT_EQ(cur_version, s.ColumnInt(0));
359 }
360 {
361 base::Time nowish(base::Time::FromTimeT(now.ToTimeT()));
362
363 // Confirm downloads table is valid.
364 sql::Statement statement(db.GetUniqueStatement(
365 "SELECT id, interrupt_reason, current_path, target_path, "
366 " danger_type, start_time, end_time "
367 "FROM downloads ORDER BY id"));
368 EXPECT_TRUE(statement.Step());
369 EXPECT_EQ(1, statement.ColumnInt64(0));
370 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
371 statement.ColumnInt(1));
372 EXPECT_EQ("", statement.ColumnString(2));
373 EXPECT_EQ("", statement.ColumnString(3));
374 // Implicit dependence on value of kDangerTypeNotDangerous from
375 // download_database.cc.
376 EXPECT_EQ(0, statement.ColumnInt(4));
377 EXPECT_EQ(nowish.ToInternalValue(), statement.ColumnInt64(5));
378 EXPECT_EQ(nowish.ToInternalValue(), statement.ColumnInt64(6));
379
380 EXPECT_TRUE(statement.Step());
381 EXPECT_EQ(2, statement.ColumnInt64(0));
382 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
383 statement.ColumnInt(1));
384 EXPECT_EQ("/path/to/some/file", statement.ColumnString(2));
385 EXPECT_EQ("/path/to/some/file", statement.ColumnString(3));
386 EXPECT_EQ(0, statement.ColumnInt(4));
387 EXPECT_EQ(nowish.ToInternalValue(), statement.ColumnInt64(5));
388 EXPECT_EQ(nowish.ToInternalValue(), statement.ColumnInt64(6));
389
390 EXPECT_FALSE(statement.Step());
391 }
392 {
393 // Confirm downloads_url_chains table is valid.
394 sql::Statement statement(db.GetUniqueStatement(
395 "SELECT id, chain_index, url FROM downloads_url_chains "
396 " ORDER BY id, chain_index"));
397 EXPECT_TRUE(statement.Step());
398 EXPECT_EQ(1, statement.ColumnInt64(0));
399 EXPECT_EQ(0, statement.ColumnInt(1));
400 EXPECT_EQ("http://whatever.com/index.html", statement.ColumnString(2));
401
402 EXPECT_TRUE(statement.Step());
403 EXPECT_EQ(2, statement.ColumnInt64(0));
404 EXPECT_EQ(0, statement.ColumnInt(1));
405 EXPECT_EQ("http://whatever.com/index1.html", statement.ColumnString(2));
406
407 EXPECT_FALSE(statement.Step());
408 }
409 }
410 }
411
412 TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {
413 // Create the DB.
414 CreateBackendAndDatabase();
415
416 base::Time now(base::Time::Now());
417
418 // Add some downloads.
419 AddDownload(DownloadItem::COMPLETE, now);
420 int64 did2 = AddDownload(DownloadItem::COMPLETE, now +
421 base::TimeDelta::FromDays(2));
422 int64 did3 = AddDownload(DownloadItem::COMPLETE, now -
423 base::TimeDelta::FromDays(2));
424
425 // Confirm that resulted in the correct number of rows in the DB.
426 DeleteBackend();
427 {
428 sql::Connection db;
429 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
430 sql::Statement statement(db.GetUniqueStatement(
431 "Select Count(*) from downloads"));
432 EXPECT_TRUE(statement.Step());
433 EXPECT_EQ(3, statement.ColumnInt(0));
434
435 sql::Statement statement1(db.GetUniqueStatement(
436 "Select Count(*) from downloads_url_chains"));
437 EXPECT_TRUE(statement1.Step());
438 EXPECT_EQ(3, statement1.ColumnInt(0));
439 }
440
441 // Delete some rows and make sure the results are still correct.
442 CreateBackendAndDatabase();
443 db_->RemoveDownload(did2);
444 db_->RemoveDownload(did3);
445 DeleteBackend();
446 {
447 sql::Connection db;
448 ASSERT_TRUE(db.Open(history_dir_.Append(chrome::kHistoryFilename)));
449 sql::Statement statement(db.GetUniqueStatement(
450 "Select Count(*) from downloads"));
451 EXPECT_TRUE(statement.Step());
452 EXPECT_EQ(1, statement.ColumnInt(0));
453
454 sql::Statement statement1(db.GetUniqueStatement(
455 "Select Count(*) from downloads_url_chains"));
456 EXPECT_TRUE(statement1.Step());
457 EXPECT_EQ(1, statement1.ColumnInt(0));
458 }
459 }
460
461 struct InterruptReasonAssociation {
462 std::string name;
463 int value;
464 };
465
466 // Test is dependent on interrupt reasons being listed in header file
467 // in order.
468 const InterruptReasonAssociation current_reasons[] = {
469 #define INTERRUPT_REASON(a, b) { #a, b },
470 #include "content/public/browser/download_interrupt_reason_values.h"
471 #undef INTERRUPT_REASON
472 };
473
474 // This represents a list of all reasons we've previously used;
475 // Do Not Remove Any Entries From This List.
476 const InterruptReasonAssociation historical_reasons[] = {
477 {"FILE_FAILED", 1},
478 {"FILE_ACCESS_DENIED", 2},
479 {"FILE_NO_SPACE", 3},
480 {"FILE_NAME_TOO_LONG", 5},
481 {"FILE_TOO_LARGE", 6},
482 {"FILE_VIRUS_INFECTED", 7},
483 {"FILE_TRANSIENT_ERROR", 10},
484 {"FILE_BLOCKED", 11},
485 {"FILE_SECURITY_CHECK_FAILED", 12},
486 {"FILE_TOO_SHORT", 13},
487 {"NETWORK_FAILED", 20},
488 {"NETWORK_TIMEOUT", 21},
489 {"NETWORK_DISCONNECTED", 22},
490 {"NETWORK_SERVER_DOWN", 23},
491 {"SERVER_FAILED", 30},
492 {"SERVER_NO_RANGE", 31},
493 {"SERVER_PRECONDITION", 32},
494 {"SERVER_BAD_CONTENT", 33},
495 {"USER_CANCELED", 40},
496 {"USER_SHUTDOWN", 41},
497 {"CRASH", 50},
498 };
499
500 // Make sure no one has changed a DownloadInterruptReason we've previously
501 // persisted.
502 TEST_F(HistoryBackendDBTest,
503 ConfirmDownloadInterruptReasonBackwardsCompatible) {
504 // Are there any cases in which a historical number has been repurposed
505 // for an error other than it's original?
506 for (size_t i = 0; i < arraysize(current_reasons); i++) {
507 const InterruptReasonAssociation& cur_reason(current_reasons[i]);
508 bool found = false;
509
510 for (size_t j = 0; j < arraysize(historical_reasons); ++j) {
511 const InterruptReasonAssociation& hist_reason(historical_reasons[j]);
512
513 if (hist_reason.value == cur_reason.value) {
514 EXPECT_EQ(cur_reason.name, hist_reason.name)
515 << "Same integer value used for old error \""
516 << hist_reason.name
517 << "\" as for new error \""
518 << cur_reason.name
519 << "\"." << std::endl
520 << "**This will cause database conflicts with persisted values**"
521 << std::endl
522 << "Please assign a new, non-conflicting value for the new error.";
523 }
524
525 if (hist_reason.name == cur_reason.name) {
526 EXPECT_EQ(cur_reason.value, hist_reason.value)
527 << "Same name (\"" << hist_reason.name
528 << "\") maps to a different value historically ("
529 << hist_reason.value << ") and currently ("
530 << cur_reason.value << ")" << std::endl
531 << "This may cause database conflicts with persisted values"
532 << std::endl
533 << "If this error is the same as the old one, you should"
534 << std::endl
535 << "use the old value, and if it is different, you should"
536 << std::endl
537 << "use a new name.";
538
539 found = true;
540 }
541 }
542
543 EXPECT_TRUE(found)
544 << "Error \"" << cur_reason.name << "\" not found in historical list."
545 << std::endl
546 << "Please add it.";
547 }
548 }
549
286 // The tracker uses RenderProcessHost pointers for scoping but never 550 // The tracker uses RenderProcessHost pointers for scoping but never
287 // dereferences them. We use ints because it's easier. This function converts 551 // dereferences them. We use ints because it's easier. This function converts
288 // between the two. 552 // between the two.
289 static void* MakeFakeHost(int id) { 553 static void* MakeFakeHost(int id) {
290 void* host = 0; 554 void* host = 0;
291 memcpy(&host, &id, sizeof(id)); 555 memcpy(&host, &id, sizeof(id));
292 return host; 556 return host;
293 } 557 }
294 558
295 class HistoryTest : public testing::Test { 559 class HistoryTest : public testing::Test {
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 1439
1176 history_service_->StopSyncing(syncer::HISTORY_DELETE_DIRECTIVES); 1440 history_service_->StopSyncing(syncer::HISTORY_DELETE_DIRECTIVES);
1177 EXPECT_TRUE( 1441 EXPECT_TRUE(
1178 history_service_->ProcessLocalDeleteDirective(delete_directive).IsSet()); 1442 history_service_->ProcessLocalDeleteDirective(delete_directive).IsSet());
1179 EXPECT_EQ(1u, change_processor.GetChanges().size()); 1443 EXPECT_EQ(1u, change_processor.GetChanges().size());
1180 } 1444 }
1181 1445
1182 } // namespace 1446 } // namespace
1183 1447
1184 } // namespace history 1448 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_database.cc ('k') | chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698