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 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1511 ScopedCancellingItem canceller(item); | 1511 ScopedCancellingItem canceller(item); |
1512 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1512 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
1513 ASSERT_EQ(GetExtensionURL(), item->GetSiteUrl().spec()); | 1513 ASSERT_EQ(GetExtensionURL(), item->GetSiteUrl().spec()); |
1514 | 1514 |
1515 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, | 1515 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
1516 base::StringPrintf( | 1516 base::StringPrintf( |
1517 "[{\"danger\": \"safe\"," | 1517 "[{\"danger\": \"safe\"," |
1518 " \"incognito\": false," | 1518 " \"incognito\": false," |
1519 " \"mime\": \"text/plain\"," | 1519 " \"mime\": \"text/plain\"," |
1520 " \"paused\": false," | 1520 " \"paused\": false," |
| 1521 " \"finalUrl\": \"%s\"," |
1521 " \"url\": \"%s\"}]", | 1522 " \"url\": \"%s\"}]", |
| 1523 download_url.c_str(), |
1522 download_url.c_str()))); | 1524 download_url.c_str()))); |
1523 ASSERT_TRUE( | 1525 ASSERT_TRUE( |
1524 WaitFor(downloads::OnChanged::kEventName, | 1526 WaitFor(downloads::OnChanged::kEventName, |
1525 base::StringPrintf("[{\"id\": %d," | 1527 base::StringPrintf("[{\"id\": %d," |
1526 " \"filename\": {" | 1528 " \"filename\": {" |
1527 " \"previous\": \"\"," | 1529 " \"previous\": \"\"," |
1528 " \"current\": \"%s\"}}]", | 1530 " \"current\": \"%s\"}}]", |
1529 result_id, GetFilename("slow.txt").c_str()))); | 1531 result_id, GetFilename("slow.txt").c_str()))); |
1530 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, | 1532 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
1531 base::StringPrintf( | 1533 base::StringPrintf( |
1532 "[{\"id\": %d," | 1534 "[{\"id\": %d," |
1533 " \"state\": {" | 1535 " \"state\": {" |
1534 " \"previous\": \"in_progress\"," | 1536 " \"previous\": \"in_progress\"," |
1535 " \"current\": \"complete\"}}]", | 1537 " \"current\": \"complete\"}}]", |
1536 result_id))); | 1538 result_id))); |
1537 } | 1539 } |
1538 | 1540 |
| 1541 // Test that we can start a download that gets redirected and that the correct |
| 1542 // sequence of events is fired for it. |
| 1543 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1544 DownloadExtensionTest_Download_Redirect) { |
| 1545 LoadExtension("downloads_split"); |
| 1546 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1547 GURL download_final_url(embedded_test_server()->GetURL("/slow?0")); |
| 1548 GURL download_url(embedded_test_server()->GetURL( |
| 1549 "/server-redirect?" + download_final_url.spec())); |
| 1550 |
| 1551 GoOnTheRecord(); |
| 1552 |
| 1553 // Start downloading a file. |
| 1554 std::unique_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1555 new DownloadsDownloadFunction(), |
| 1556 base::StringPrintf("[{\"url\": \"%s\"}]", download_url.spec().c_str()))); |
| 1557 ASSERT_TRUE(result.get()); |
| 1558 int result_id = -1; |
| 1559 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1560 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1561 ASSERT_TRUE(item); |
| 1562 ScopedCancellingItem canceller(item); |
| 1563 ASSERT_EQ(download_url, item->GetOriginalUrl()); |
| 1564 ASSERT_EQ(GetExtensionURL(), item->GetSiteUrl().spec()); |
| 1565 |
| 1566 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1567 base::StringPrintf( |
| 1568 "[{\"danger\": \"safe\"," |
| 1569 " \"incognito\": false," |
| 1570 " \"mime\": \"text/plain\"," |
| 1571 " \"paused\": false," |
| 1572 " \"finalUrl\": \"%s\"," |
| 1573 " \"url\": \"%s\"}]", |
| 1574 download_final_url.spec().c_str(), |
| 1575 download_url.spec().c_str()))); |
| 1576 ASSERT_TRUE( |
| 1577 WaitFor(downloads::OnChanged::kEventName, |
| 1578 base::StringPrintf("[{\"id\": %d," |
| 1579 " \"filename\": {" |
| 1580 " \"previous\": \"\"," |
| 1581 " \"current\": \"%s\"}}]", |
| 1582 result_id, GetFilename("slow.txt").c_str()))); |
| 1583 ASSERT_TRUE(WaitFor(downloads::OnChanged::kEventName, |
| 1584 base::StringPrintf( |
| 1585 "[{\"id\": %d," |
| 1586 " \"state\": {" |
| 1587 " \"previous\": \"in_progress\"," |
| 1588 " \"current\": \"complete\"}}]", |
| 1589 result_id))); |
| 1590 } |
| 1591 |
1539 // Test that we can start a download from an incognito context, and that the | 1592 // Test that we can start a download from an incognito context, and that the |
1540 // download knows that it's incognito. | 1593 // download knows that it's incognito. |
1541 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1594 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1542 DownloadExtensionTest_Download_Incognito) { | 1595 DownloadExtensionTest_Download_Incognito) { |
1543 LoadExtension("downloads_split"); | 1596 LoadExtension("downloads_split"); |
1544 ASSERT_TRUE(StartEmbeddedTestServer()); | 1597 ASSERT_TRUE(StartEmbeddedTestServer()); |
1545 GoOffTheRecord(); | 1598 GoOffTheRecord(); |
1546 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); | 1599 std::string download_url = embedded_test_server()->GetURL("/slow?0").spec(); |
1547 | 1600 |
1548 // Start downloading a file. | 1601 // Start downloading a file. |
(...skipping 2679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4228 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4281 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4229 EXPECT_FALSE(warnings.empty()); | 4282 EXPECT_FALSE(warnings.empty()); |
4230 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4283 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
4231 warnings.begin()->warning_type()); | 4284 warnings.begin()->warning_type()); |
4232 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4285 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4233 } | 4286 } |
4234 | 4287 |
4235 } // namespace extensions | 4288 } // namespace extensions |
4236 | 4289 |
4237 #endif // http://crbug.com/306144 | 4290 #endif // http://crbug.com/306144 |
OLD | NEW |