| OLD | NEW |
| 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 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 downloads_directory().Append(history_info[i].filename), | 362 downloads_directory().Append(history_info[i].filename), |
| 363 GURL(), GURL(), // URL, referrer | 363 GURL(), GURL(), // URL, referrer |
| 364 current, current, // start_time, end_time | 364 current, current, // start_time, end_time |
| 365 1, 1, // received_bytes, total_bytes | 365 1, 1, // received_bytes, total_bytes |
| 366 history_info[i].state, // state | 366 history_info[i].state, // state |
| 367 i + 1, // db_handle | 367 i + 1, // db_handle |
| 368 false); // opened | 368 false); // opened |
| 369 entries.push_back(entry); | 369 entries.push_back(entry); |
| 370 } | 370 } |
| 371 GetOnRecordManager()->OnPersistentStoreQueryComplete(&entries); | 371 GetOnRecordManager()->OnPersistentStoreQueryComplete(&entries); |
| 372 GetOnRecordManager()->GetAllDownloads(FilePath(), items); | 372 GetOnRecordManager()->GetAllDownloads(items); |
| 373 EXPECT_EQ(count, items->size()); | 373 EXPECT_EQ(count, items->size()); |
| 374 if (count != items->size()) | 374 if (count != items->size()) |
| 375 return false; | 375 return false; |
| 376 | 376 |
| 377 // Order by ID so that they are in the order that we created them. | 377 // Order by ID so that they are in the order that we created them. |
| 378 std::sort(items->begin(), items->end(), download_id_comparator); | 378 std::sort(items->begin(), items->end(), download_id_comparator); |
| 379 // Set the danger type if necessary. | 379 // Set the danger type if necessary. |
| 380 for (size_t i = 0; i < count; ++i) { | 380 for (size_t i = 0; i < count; ++i) { |
| 381 if (history_info[i].danger_type != | 381 if (history_info[i].danger_type != |
| 382 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 382 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 394 scoped_ptr<content::DownloadTestObserver> observer( | 394 scoped_ptr<content::DownloadTestObserver> observer( |
| 395 CreateInProgressDownloadObserver(1)); | 395 CreateInProgressDownloadObserver(1)); |
| 396 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 396 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 397 ui_test_utils::NavigateToURLWithDisposition( | 397 ui_test_utils::NavigateToURLWithDisposition( |
| 398 current_browser(), slow_download_url, CURRENT_TAB, | 398 current_browser(), slow_download_url, CURRENT_TAB, |
| 399 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 399 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 400 observer->WaitForFinished(); | 400 observer->WaitForFinished(); |
| 401 EXPECT_EQ( | 401 EXPECT_EQ( |
| 402 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 402 1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
| 403 } | 403 } |
| 404 GetCurrentManager()->GetAllDownloads(FilePath(), items); | 404 GetCurrentManager()->GetAllDownloads(items); |
| 405 ASSERT_EQ(count, items->size()); | 405 ASSERT_EQ(count, items->size()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 DownloadItem* CreateSlowTestDownload() { | 408 DownloadItem* CreateSlowTestDownload() { |
| 409 scoped_ptr<content::DownloadTestObserver> observer( | 409 scoped_ptr<content::DownloadTestObserver> observer( |
| 410 CreateInProgressDownloadObserver(1)); | 410 CreateInProgressDownloadObserver(1)); |
| 411 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 411 GURL slow_download_url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 412 DownloadManager* manager = GetCurrentManager(); | 412 DownloadManager* manager = GetCurrentManager(); |
| 413 | 413 |
| 414 EXPECT_EQ(0, manager->InProgressCount()); | 414 EXPECT_EQ(0, manager->InProgressCount()); |
| 415 if (manager->InProgressCount() != 0) | 415 if (manager->InProgressCount() != 0) |
| 416 return NULL; | 416 return NULL; |
| 417 | 417 |
| 418 ui_test_utils::NavigateToURLWithDisposition( | 418 ui_test_utils::NavigateToURLWithDisposition( |
| 419 current_browser(), slow_download_url, CURRENT_TAB, | 419 current_browser(), slow_download_url, CURRENT_TAB, |
| 420 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 420 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 421 | 421 |
| 422 observer->WaitForFinished(); | 422 observer->WaitForFinished(); |
| 423 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); | 423 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::IN_PROGRESS)); |
| 424 | 424 |
| 425 DownloadManager::DownloadVector items; | 425 DownloadManager::DownloadVector items; |
| 426 manager->GetAllDownloads(FilePath(), &items); | 426 manager->GetAllDownloads(&items); |
| 427 | 427 |
| 428 DownloadItem* new_item = NULL; | 428 DownloadItem* new_item = NULL; |
| 429 for (DownloadManager::DownloadVector::iterator iter = items.begin(); | 429 for (DownloadManager::DownloadVector::iterator iter = items.begin(); |
| 430 iter != items.end(); ++iter) { | 430 iter != items.end(); ++iter) { |
| 431 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { | 431 if ((*iter)->GetState() == DownloadItem::IN_PROGRESS) { |
| 432 // There should be only one IN_PROGRESS item. | 432 // There should be only one IN_PROGRESS item. |
| 433 EXPECT_EQ(NULL, new_item); | 433 EXPECT_EQ(NULL, new_item); |
| 434 new_item = *iter; | 434 new_item = *iter; |
| 435 } | 435 } |
| 436 } | 436 } |
| (...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 " \"state\": {" | 2084 " \"state\": {" |
| 2085 " \"previous\": \"in_progress\"," | 2085 " \"previous\": \"in_progress\"," |
| 2086 " \"current\": \"complete\"}}]", | 2086 " \"current\": \"complete\"}}]", |
| 2087 result_id, | 2087 result_id, |
| 2088 GetFilename("on_record.txt.crdownload").c_str(), | 2088 GetFilename("on_record.txt.crdownload").c_str(), |
| 2089 GetFilename("on_record.txt").c_str()))); | 2089 GetFilename("on_record.txt").c_str()))); |
| 2090 std::string disk_data; | 2090 std::string disk_data; |
| 2091 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2091 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
| 2092 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2092 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
| 2093 } | 2093 } |
| OLD | NEW |