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 // Disable everything on windows only. http://crbug.com/306144 | 5 // Disable everything on windows only. http://crbug.com/306144 |
6 #ifndef OS_WIN | 6 #ifndef OS_WIN |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "components/prefs/pref_service.h" | 39 #include "components/prefs/pref_service.h" |
40 #include "content/public/browser/browser_context.h" | 40 #include "content/public/browser/browser_context.h" |
41 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/download_item.h" | 42 #include "content/public/browser/download_item.h" |
43 #include "content/public/browser/download_manager.h" | 43 #include "content/public/browser/download_manager.h" |
44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/storage_partition.h" | 45 #include "content/public/browser/storage_partition.h" |
46 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
47 #include "content/public/common/content_features.h" | 47 #include "content/public/common/content_features.h" |
48 #include "content/public/test/download_test_observer.h" | 48 #include "content/public/test/download_test_observer.h" |
| 49 #include "content/public/test/test_download_request_handler.h" |
49 #include "extensions/browser/event_router.h" | 50 #include "extensions/browser/event_router.h" |
50 #include "extensions/browser/notification_types.h" | 51 #include "extensions/browser/notification_types.h" |
51 #include "net/base/data_url.h" | 52 #include "net/base/data_url.h" |
52 #include "net/test/embedded_test_server/embedded_test_server.h" | 53 #include "net/test/embedded_test_server/embedded_test_server.h" |
53 #include "net/test/url_request/url_request_slow_download_job.h" | 54 #include "net/test/url_request/url_request_slow_download_job.h" |
54 #include "net/url_request/url_request.h" | 55 #include "net/url_request/url_request.h" |
55 #include "net/url_request/url_request_context.h" | 56 #include "net/url_request/url_request_context.h" |
56 #include "net/url_request/url_request_job.h" | 57 #include "net/url_request/url_request_job.h" |
57 #include "net/url_request/url_request_job_factory.h" | 58 #include "net/url_request/url_request_job_factory.h" |
58 #include "net/url_request/url_request_job_factory_impl.h" | 59 #include "net/url_request/url_request_job_factory_impl.h" |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 DownloadManager::DownloadVector* items) { | 421 DownloadManager::DownloadVector* items) { |
421 DownloadIdComparator download_id_comparator; | 422 DownloadIdComparator download_id_comparator; |
422 base::Time current = base::Time::Now(); | 423 base::Time current = base::Time::Now(); |
423 items->clear(); | 424 items->clear(); |
424 GetOnRecordManager()->GetAllDownloads(items); | 425 GetOnRecordManager()->GetAllDownloads(items); |
425 CHECK_EQ(0, static_cast<int>(items->size())); | 426 CHECK_EQ(0, static_cast<int>(items->size())); |
426 std::vector<GURL> url_chain; | 427 std::vector<GURL> url_chain; |
427 url_chain.push_back(GURL()); | 428 url_chain.push_back(GURL()); |
428 for (size_t i = 0; i < count; ++i) { | 429 for (size_t i = 0; i < count; ++i) { |
429 DownloadItem* item = GetOnRecordManager()->CreateDownloadItem( | 430 DownloadItem* item = GetOnRecordManager()->CreateDownloadItem( |
430 base::GenerateGUID(), | 431 base::GenerateGUID(), content::DownloadItem::kInvalidId + 1 + i, |
431 content::DownloadItem::kInvalidId + 1 + i, | |
432 downloads_directory().Append(history_info[i].filename), | 432 downloads_directory().Append(history_info[i].filename), |
433 downloads_directory().Append(history_info[i].filename), | 433 downloads_directory().Append(history_info[i].filename), url_chain, |
434 url_chain, | 434 GURL(), GURL(), GURL(), GURL(), std::string(), |
435 GURL(), | |
436 GURL(), | |
437 GURL(), | |
438 std::string(), | |
439 std::string(), // mime_type, original_mime_type | 435 std::string(), // mime_type, original_mime_type |
440 current, | 436 current, |
441 current, // start_time, end_time | 437 current, // start_time, end_time |
442 std::string(), | 438 std::string(), |
443 std::string(), // etag, last_modified | 439 std::string(), // etag, last_modified |
444 1, | 440 1, |
445 1, // received_bytes, total_bytes | 441 1, // received_bytes, total_bytes |
446 std::string(), // hash | 442 std::string(), // hash |
447 history_info[i].state, // state | 443 history_info[i].state, // state |
448 history_info[i].danger_type, | 444 history_info[i].danger_type, |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( | 1507 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
1512 new DownloadsDownloadFunction(), | 1508 new DownloadsDownloadFunction(), |
1513 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); | 1509 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.c_str()))); |
1514 ASSERT_TRUE(result.get()); | 1510 ASSERT_TRUE(result.get()); |
1515 int result_id = -1; | 1511 int result_id = -1; |
1516 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1512 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1517 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1513 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
1518 ASSERT_TRUE(item); | 1514 ASSERT_TRUE(item); |
1519 ScopedCancellingItem canceller(item); | 1515 ScopedCancellingItem canceller(item); |
1520 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1516 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1517 ASSERT_EQ(GetExtensionURL(), item->GetSiteUrl().spec()); |
1521 | 1518 |
1522 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1519 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1523 base::StringPrintf( | 1520 base::StringPrintf( |
1524 "[{\"danger\": \"safe\"," | 1521 "[{\"danger\": \"safe\"," |
1525 " \"incognito\": false," | 1522 " \"incognito\": false," |
1526 " \"mime\": \"text/plain\"," | 1523 " \"mime\": \"text/plain\"," |
1527 " \"paused\": false," | 1524 " \"paused\": false," |
1528 " \"url\": \"%s\"}]", | 1525 " \"url\": \"%s\"}]", |
1529 download_url.c_str()))); | 1526 download_url.c_str()))); |
1530 ASSERT_TRUE( | 1527 ASSERT_TRUE( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 result_id, GetFilename("slow.txt").c_str()))); | 1578 result_id, GetFilename("slow.txt").c_str()))); |
1582 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 1579 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
1583 base::StringPrintf( | 1580 base::StringPrintf( |
1584 "[{\"id\":%d," | 1581 "[{\"id\":%d," |
1585 " \"state\": {" | 1582 " \"state\": {" |
1586 " \"current\": \"complete\"," | 1583 " \"current\": \"complete\"," |
1587 " \"previous\": \"in_progress\"}}]", | 1584 " \"previous\": \"in_progress\"}}]", |
1588 result_id))); | 1585 result_id))); |
1589 } | 1586 } |
1590 | 1587 |
| 1588 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1589 DownloadExtensionTest_Download_InterruptAndResume) { |
| 1590 LoadExtension("downloads_split"); |
| 1591 content::TestDownloadRequestHandler download_request_handler; |
| 1592 download_request_handler.StartServing( |
| 1593 content::TestDownloadRequestHandler::Parameters:: |
| 1594 WithSingleInterruption()); |
| 1595 GURL download_url = download_request_handler.url(); |
| 1596 |
| 1597 // Start downloading a file. |
| 1598 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1599 new DownloadsDownloadFunction(), |
| 1600 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.spec().c_str()))); |
| 1601 ASSERT_TRUE(result.get()); |
| 1602 int result_id = -1; |
| 1603 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1604 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1605 ASSERT_TRUE(item); |
| 1606 ScopedCancellingItem canceller(item); |
| 1607 ASSERT_EQ(download_url, item->GetOriginalUrl()); |
| 1608 EXPECT_EQ(GetExtensionURL(), item->GetSiteUrl().spec()); |
| 1609 |
| 1610 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1611 base::StringPrintf("[{\"id\":%d," |
| 1612 " \"state\": {" |
| 1613 " \"current\": \"interrupted\"," |
| 1614 " \"previous\": \"in_progress\"}}]", |
| 1615 result_id))); |
| 1616 |
| 1617 EXPECT_TRUE(RunFunction(new DownloadsResumeFunction(), |
| 1618 DownloadItemIdAsArgList(item))); |
| 1619 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1620 base::StringPrintf("[{\"id\":%d," |
| 1621 " \"state\": {" |
| 1622 " \"current\": \"in_progress\"," |
| 1623 " \"previous\": \"interrupted\"}}]", |
| 1624 result_id))); |
| 1625 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1626 base::StringPrintf("[{\"id\":%d," |
| 1627 " \"state\": {" |
| 1628 " \"current\": \"complete\"," |
| 1629 " \"previous\": \"in_progress\"}}]", |
| 1630 result_id))); |
| 1631 } |
| 1632 |
1591 #if defined(OS_WIN) | 1633 #if defined(OS_WIN) |
1592 // This test is very flaky on Win. http://crbug.com/248438 | 1634 // This test is very flaky on Win. http://crbug.com/248438 |
1593 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ | 1635 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ |
1594 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders | 1636 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders |
1595 #else | 1637 #else |
1596 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ | 1638 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ |
1597 DownloadExtensionTest_Download_UnsafeHeaders | 1639 DownloadExtensionTest_Download_UnsafeHeaders |
1598 #endif | 1640 #endif |
1599 | 1641 |
1600 // Test that we disallow certain headers case-insensitively. | 1642 // Test that we disallow certain headers case-insensitively. |
(...skipping 2589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4190 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4232 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4191 EXPECT_FALSE(warnings.empty()); | 4233 EXPECT_FALSE(warnings.empty()); |
4192 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4234 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
4193 warnings.begin()->warning_type()); | 4235 warnings.begin()->warning_type()); |
4194 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4236 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4195 } | 4237 } |
4196 | 4238 |
4197 } // namespace extensions | 4239 } // namespace extensions |
4198 | 4240 |
4199 #endif // http://crbug.com/306144 | 4241 #endif // http://crbug.com/306144 |
OLD | NEW |