Chromium Code Reviews| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 #include "chrome/common/extensions/feature_switch.h" | 52 #include "chrome/common/extensions/feature_switch.h" |
| 53 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
| 54 #include "chrome/common/url_constants.h" | 54 #include "chrome/common/url_constants.h" |
| 55 #include "chrome/test/base/in_process_browser_test.h" | 55 #include "chrome/test/base/in_process_browser_test.h" |
| 56 #include "chrome/test/base/ui_test_utils.h" | 56 #include "chrome/test/base/ui_test_utils.h" |
| 57 #include "content/public/browser/download_item.h" | 57 #include "content/public/browser/download_item.h" |
| 58 #include "content/public/browser/download_manager.h" | 58 #include "content/public/browser/download_manager.h" |
| 59 #include "content/public/browser/download_save_info.h" | 59 #include "content/public/browser/download_save_info.h" |
| 60 #include "content/public/browser/download_url_parameters.h" | 60 #include "content/public/browser/download_url_parameters.h" |
| 61 #include "content/public/browser/notification_source.h" | 61 #include "content/public/browser/notification_source.h" |
| 62 #include "content/public/browser/plugin_service.h" | |
| 62 #include "content/public/browser/render_view_host.h" | 63 #include "content/public/browser/render_view_host.h" |
| 63 #include "content/public/browser/resource_context.h" | 64 #include "content/public/browser/resource_context.h" |
| 64 #include "content/public/browser/web_contents.h" | 65 #include "content/public/browser/web_contents.h" |
| 65 #include "content/public/common/context_menu_params.h" | 66 #include "content/public/common/context_menu_params.h" |
| 66 #include "content/public/common/page_transition_types.h" | 67 #include "content/public/common/page_transition_types.h" |
| 67 #include "content/public/test/browser_test_utils.h" | 68 #include "content/public/test/browser_test_utils.h" |
| 68 #include "content/public/test/download_test_observer.h" | 69 #include "content/public/test/download_test_observer.h" |
| 69 #include "content/public/test/test_file_error_injector.h" | 70 #include "content/public/test/test_file_error_injector.h" |
| 70 #include "content/public/test/test_navigation_observer.h" | 71 #include "content/public/test/test_navigation_observer.h" |
| 71 #include "content/test/net/url_request_mock_http_job.h" | 72 #include "content/test/net/url_request_mock_http_job.h" |
| 72 #include "content/test/net/url_request_slow_download_job.h" | 73 #include "content/test/net/url_request_slow_download_job.h" |
| 73 #include "net/base/net_util.h" | 74 #include "net/base/net_util.h" |
| 74 #include "net/test/test_server.h" | 75 #include "net/test/test_server.h" |
| 75 #include "testing/gtest/include/gtest/gtest.h" | 76 #include "testing/gtest/include/gtest/gtest.h" |
| 77 #include "webkit/plugins/npapi/mock_plugin_list.h" | |
| 76 | 78 |
| 77 using content::BrowserContext; | 79 using content::BrowserContext; |
| 78 using content::BrowserThread; | 80 using content::BrowserThread; |
| 79 using content::DownloadItem; | 81 using content::DownloadItem; |
| 80 using content::DownloadManager; | 82 using content::DownloadManager; |
| 81 using content::DownloadUrlParameters; | 83 using content::DownloadUrlParameters; |
| 82 using content::URLRequestMockHTTPJob; | 84 using content::URLRequestMockHTTPJob; |
| 83 using content::URLRequestSlowDownloadJob; | 85 using content::URLRequestSlowDownloadJob; |
| 84 using content::WebContents; | 86 using content::WebContents; |
| 85 using extensions::Extension; | 87 using extensions::Extension; |
| 86 using extensions::FeatureSwitch; | 88 using extensions::FeatureSwitch; |
| 87 | 89 |
| 88 namespace { | 90 namespace { |
| 89 | 91 |
| 90 // IDs and paths of CRX files used in tests. | 92 // IDs and paths of CRX files used in tests. |
| 91 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 93 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 92 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 94 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
| 93 | 95 |
| 94 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 96 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 95 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 97 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
| 96 | 98 |
| 99 // Get History Information. | |
| 100 class DownloadsHistoryDataCollector { | |
| 101 public: | |
| 102 explicit DownloadsHistoryDataCollector(Profile* profile) | |
| 103 : profile_(profile), result_valid_(false) {} | |
| 104 | |
| 105 bool WaitForDownloadInfo( | |
| 106 scoped_ptr<std::vector<history::DownloadRow> >* results) { | |
| 107 HistoryService* hs = HistoryServiceFactory::GetForProfile( | |
| 108 profile_, Profile::EXPLICIT_ACCESS); | |
| 109 DCHECK(hs); | |
| 110 hs->QueryDownloads( | |
| 111 base::Bind(&DownloadsHistoryDataCollector::OnQueryDownloadsComplete, | |
| 112 base::Unretained(this))); | |
| 113 | |
| 114 content::RunMessageLoop(); | |
| 115 if (result_valid_) { | |
| 116 *results = results_.Pass(); | |
| 117 } | |
| 118 return result_valid_; | |
| 119 } | |
| 120 | |
| 121 private: | |
| 122 void OnQueryDownloadsComplete( | |
| 123 scoped_ptr<std::vector<history::DownloadRow> > entries) { | |
| 124 result_valid_ = true; | |
| 125 results_ = entries.Pass(); | |
| 126 MessageLoopForUI::current()->Quit(); | |
| 127 } | |
| 128 | |
| 129 Profile* profile_; | |
| 130 scoped_ptr<std::vector<history::DownloadRow> > results_; | |
| 131 bool result_valid_; | |
| 132 CancelableRequestConsumer callback_consumer_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | |
| 135 }; | |
| 136 | |
| 97 // Mock that simulates a permissions dialog where the user denies | 137 // Mock that simulates a permissions dialog where the user denies |
| 98 // permission to install. TODO(skerner): This could be shared with | 138 // permission to install. TODO(skerner): This could be shared with |
| 99 // extensions tests. Find a common place for this class. | 139 // extensions tests. Find a common place for this class. |
| 100 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { | 140 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { |
| 101 public: | 141 public: |
| 102 MockAbortExtensionInstallPrompt() : | 142 MockAbortExtensionInstallPrompt() : |
| 103 ExtensionInstallPrompt(NULL) { | 143 ExtensionInstallPrompt(NULL) { |
| 104 } | 144 } |
| 105 | 145 |
| 106 // Simulate a user abort on an extension installation. | 146 // Simulate a user abort on an extension installation. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 198 |
| 159 bool WasAutoOpened(DownloadItem* item) { | 199 bool WasAutoOpened(DownloadItem* item) { |
| 160 return item->GetAutoOpened(); | 200 return item->GetAutoOpened(); |
| 161 } | 201 } |
| 162 | 202 |
| 163 // Called when a download starts. Marks the download as hidden. | 203 // Called when a download starts. Marks the download as hidden. |
| 164 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { | 204 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { |
| 165 DownloadItemModel(item).SetShouldShowInShelf(false); | 205 DownloadItemModel(item).SetShouldShowInShelf(false); |
| 166 } | 206 } |
| 167 | 207 |
| 208 // Callback for HistoryObserver; used in DownloadHistoryCheck | |
| 209 bool HasDataAndName(const history::DownloadRow& row) { | |
| 210 return row.received_bytes > 0 && !row.target_path.empty(); | |
| 211 } | |
| 212 | |
| 168 } // namespace | 213 } // namespace |
| 169 | 214 |
| 170 class HistoryObserver : public DownloadHistory::Observer { | 215 class HistoryObserver : public DownloadHistory::Observer { |
| 171 public: | 216 public: |
| 217 typedef base::Callback<bool(const history::DownloadRow&)> FilterCallback; | |
| 218 | |
| 172 explicit HistoryObserver(Profile* profile) | 219 explicit HistoryObserver(Profile* profile) |
| 173 : profile_(profile), | 220 : profile_(profile), |
| 174 waiting_(false), | 221 waiting_(false), |
| 175 seen_stored_(false) { | 222 seen_stored_(false) { |
| 176 DownloadServiceFactory::GetForProfile(profile_)-> | 223 DownloadServiceFactory::GetForProfile(profile_)-> |
| 177 GetDownloadHistory()->AddObserver(this); | 224 GetDownloadHistory()->AddObserver(this); |
| 178 } | 225 } |
| 179 | 226 |
| 180 virtual ~HistoryObserver() { | 227 virtual ~HistoryObserver() { |
| 181 DownloadService* service = DownloadServiceFactory::GetForProfile(profile_); | 228 DownloadService* service = DownloadServiceFactory::GetForProfile(profile_); |
| 182 if (service && service->GetDownloadHistory()) | 229 if (service && service->GetDownloadHistory()) |
| 183 service->GetDownloadHistory()->RemoveObserver(this); | 230 service->GetDownloadHistory()->RemoveObserver(this); |
| 184 } | 231 } |
| 185 | 232 |
| 233 void SetFilterCallback(const FilterCallback& callback) { | |
| 234 callback_ = callback; | |
| 235 } | |
| 236 | |
| 186 virtual void OnDownloadStored( | 237 virtual void OnDownloadStored( |
| 187 content::DownloadItem* item, | 238 content::DownloadItem* item, |
| 188 const history::DownloadRow& info) OVERRIDE { | 239 const history::DownloadRow& info) OVERRIDE { |
| 240 if (!callback_.is_null() && (!callback_.Run(info))) | |
| 241 return; | |
| 242 | |
| 189 seen_stored_ = true; | 243 seen_stored_ = true; |
| 190 if (waiting_) | 244 if (waiting_) |
| 191 MessageLoopForUI::current()->Quit(); | 245 MessageLoopForUI::current()->Quit(); |
| 192 } | 246 } |
| 193 | 247 |
| 194 virtual void OnDownloadHistoryDestroyed() OVERRIDE { | 248 virtual void OnDownloadHistoryDestroyed() OVERRIDE { |
| 195 DownloadServiceFactory::GetForProfile(profile_)-> | 249 DownloadServiceFactory::GetForProfile(profile_)-> |
| 196 GetDownloadHistory()->RemoveObserver(this); | 250 GetDownloadHistory()->RemoveObserver(this); |
| 197 } | 251 } |
| 198 | 252 |
| 199 void WaitForStored() { | 253 void WaitForStored() { |
| 200 if (seen_stored_) | 254 if (seen_stored_) |
| 201 return; | 255 return; |
| 202 waiting_ = true; | 256 waiting_ = true; |
| 203 content::RunMessageLoop(); | 257 content::RunMessageLoop(); |
| 204 waiting_ = false; | 258 waiting_ = false; |
| 205 } | 259 } |
| 206 | 260 |
| 207 private: | 261 private: |
| 208 Profile* profile_; | 262 Profile* profile_; |
| 209 bool waiting_; | 263 bool waiting_; |
| 210 bool seen_stored_; | 264 bool seen_stored_; |
| 265 FilterCallback callback_; | |
| 211 | 266 |
| 212 DISALLOW_COPY_AND_ASSIGN(HistoryObserver); | 267 DISALLOW_COPY_AND_ASSIGN(HistoryObserver); |
| 213 }; | 268 }; |
| 214 | 269 |
| 215 class DownloadTest : public InProcessBrowserTest { | 270 class DownloadTest : public InProcessBrowserTest { |
| 216 public: | 271 public: |
| 217 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. | 272 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. |
| 218 enum DownloadMethod { | 273 enum DownloadMethod { |
| 219 DOWNLOAD_NAVIGATE, | 274 DOWNLOAD_NAVIGATE, |
| 220 DOWNLOAD_DIRECT | 275 DOWNLOAD_DIRECT |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 SIZE_TEST_TYPE_UNKNOWN, | 345 SIZE_TEST_TYPE_UNKNOWN, |
| 291 }; | 346 }; |
| 292 | 347 |
| 293 // Location of the file source (the place from which it is downloaded). | 348 // Location of the file source (the place from which it is downloaded). |
| 294 FilePath OriginFile(FilePath file) { | 349 FilePath OriginFile(FilePath file) { |
| 295 return test_dir_.Append(file); | 350 return test_dir_.Append(file); |
| 296 } | 351 } |
| 297 | 352 |
| 298 // Location of the file destination (place to which it is downloaded). | 353 // Location of the file destination (place to which it is downloaded). |
| 299 FilePath DestinationFile(Browser* browser, FilePath file) { | 354 FilePath DestinationFile(Browser* browser, FilePath file) { |
| 300 return GetDownloadDirectory(browser).Append(file); | 355 return GetDownloadDirectory(browser).Append(file.BaseName()); |
| 301 } | 356 } |
| 302 | 357 |
| 303 // Must be called after browser creation. Creates a temporary | 358 // Must be called after browser creation. Creates a temporary |
| 304 // directory for downloads that is auto-deleted on destruction. | 359 // directory for downloads that is auto-deleted on destruction. |
| 305 // Returning false indicates a failure of the function, and should be asserted | 360 // Returning false indicates a failure of the function, and should be asserted |
| 306 // in the caller. | 361 // in the caller. |
| 307 bool CreateAndSetDownloadsDirectory(Browser* browser) { | 362 bool CreateAndSetDownloadsDirectory(Browser* browser) { |
| 308 if (!browser) | 363 if (!browser) |
| 309 return false; | 364 return false; |
| 310 | 365 |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1372 #endif | 1427 #endif |
| 1373 | 1428 |
| 1374 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1429 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1375 // Download shelf should close. Download panel stays open on ChromeOS. | 1430 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1376 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1431 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1377 | 1432 |
| 1378 CheckDownload(browser(), file, file); | 1433 CheckDownload(browser(), file, file); |
| 1379 } | 1434 } |
| 1380 | 1435 |
| 1381 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1436 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
| 1382 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1437 GURL download_url(URLRequestSlowDownloadJob::kKnownSizeUrl); |
| 1438 FilePath file(net::GenerateFileName(download_url, "", "", "", "", "")); | |
| 1439 | |
| 1440 // We use the server so that we can get a redirect and test url_chain | |
| 1441 // persistence. | |
| 1442 ASSERT_TRUE(test_server()->Start()); | |
| 1443 GURL redirect_url = test_server()->GetURL( | |
| 1444 "server-redirect?" + download_url.spec()); | |
| 1445 | |
| 1446 // Download the url and wait until the object has been stored. | |
| 1447 base::Time start(base::Time::Now()); | |
| 1448 HistoryObserver observer(browser()->profile()); | |
| 1449 observer.SetFilterCallback(base::Bind(&HasDataAndName)); | |
| 1450 ui_test_utils::NavigateToURL(browser(), redirect_url); | |
| 1451 observer.WaitForStored(); | |
| 1452 | |
| 1453 // Get the details on what was stored into the history. | |
| 1454 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; | |
| 1455 ASSERT_TRUE(DownloadsHistoryDataCollector( | |
| 1456 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | |
| 1457 ASSERT_EQ(1u, downloads_in_database->size()); | |
| 1458 | |
| 1459 // Confirm history storage is what you expect for a partially completed | |
| 1460 // slow download job. | |
| 1461 history::DownloadRow& row(downloads_in_database->at(0)); | |
| 1462 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); | |
| 1463 EXPECT_EQ(download_util::GetCrDownloadPath(DestinationFile(browser(), file)), | |
| 1464 row.current_path); | |
| 1465 ASSERT_EQ(2u, row.url_chain.size()); | |
| 1466 EXPECT_EQ(redirect_url.spec(), row.url_chain[0].spec()); | |
| 1467 EXPECT_EQ(download_url.spec(), row.url_chain[1].spec()); | |
| 1468 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, row.danger_type); | |
| 1469 EXPECT_LE(start, row.start_time); | |
| 1470 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize, row.received_bytes); | |
| 1471 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize | |
| 1472 + URLRequestSlowDownloadJob::kSecondDownloadSize, row.total_bytes); | |
| 1473 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, row.state); | |
| 1474 EXPECT_FALSE(row.opened); | |
| 1475 | |
| 1476 // Finish the download. We're ok relying on the history to be flushed | |
| 1477 // at this point as our queries will be behind the history updates | |
| 1478 // invoked by completion. | |
| 1479 scoped_ptr<content::DownloadTestObserver> download_observer( | |
| 1480 CreateWaiter(browser(), 1)); | |
| 1481 ui_test_utils::NavigateToURL(browser(), | |
| 1482 GURL(URLRequestSlowDownloadJob::kErrorDownloadUrl)); | |
| 1483 download_observer->WaitForFinished(); | |
| 1484 EXPECT_EQ(1u, download_observer->NumDownloadsSeenInState( | |
| 1485 DownloadItem::INTERRUPTED)); | |
| 1486 base::Time end(base::Time::Now()); | |
| 1487 | |
| 1488 // Get what was stored in the history. | |
| 1489 ASSERT_TRUE(DownloadsHistoryDataCollector( | |
| 1490 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | |
| 1491 ASSERT_EQ(1u, downloads_in_database->size()); | |
| 1492 | |
| 1493 // Confirm history storage is what you expect for a completed | |
| 1494 // slow download job. | |
| 1495 history::DownloadRow& row1(downloads_in_database->at(0)); | |
| 1496 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path); | |
| 1497 EXPECT_EQ(download_util::GetCrDownloadPath(DestinationFile(browser(), file)), | |
| 1498 row1.current_path); | |
| 1499 ASSERT_EQ(2u, row1.url_chain.size()); | |
| 1500 EXPECT_EQ(redirect_url.spec(), row1.url_chain[0].spec()); | |
| 1501 EXPECT_EQ(download_url.spec(), row1.url_chain[1].spec()); | |
| 1502 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, row1.danger_type); | |
| 1503 EXPECT_LE(start, row1.start_time); | |
| 1504 EXPECT_GE(end, row1.end_time); | |
| 1505 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize, | |
| 1506 row1.received_bytes); | |
| 1507 EXPECT_EQ(URLRequestSlowDownloadJob::kFirstDownloadSize | |
| 1508 + URLRequestSlowDownloadJob::kSecondDownloadSize, row1.total_bytes); | |
| 1509 EXPECT_EQ(content::DownloadItem::INTERRUPTED, row1.state); | |
| 1510 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, | |
| 1511 row1.interrupt_reason); | |
| 1512 EXPECT_FALSE(row1.opened); | |
| 1513 } | |
| 1514 | |
| 1515 // Make sure a dangerous file shows up properly in the history. | |
| 1516 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) { | |
| 1517 // .swf file so that it's dangerous on all platforms (including CrOS). | |
| 1518 FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); | |
| 1383 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1519 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1520 | |
| 1521 #if defined(ENABLE_PLUGINS) | |
| 1522 webkit::npapi::MockPluginList plugin_list; | |
| 1523 content::PluginService::GetInstance()->SetPluginListForTesting(&plugin_list); | |
|
benjhayden
2013/01/29 17:53:43
Why?
Randy Smith (Not in Mondays)
2013/01/29 18:06:30
The test was failing because there was some form o
| |
| 1524 #endif | |
| 1525 | |
| 1526 // Download the url and wait until the object has been stored. | |
| 1527 scoped_ptr<content::DownloadTestObserver> download_observer( | |
| 1528 new content::DownloadTestObserverTerminal( | |
| 1529 DownloadManagerForBrowser(browser()), 1, | |
| 1530 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_IGNORE)); | |
| 1531 base::Time start(base::Time::Now()); | |
| 1384 HistoryObserver observer(browser()->profile()); | 1532 HistoryObserver observer(browser()->profile()); |
| 1385 DownloadAndWait(browser(), download_url); | 1533 observer.SetFilterCallback(base::Bind(&HasDataAndName)); |
| 1534 ui_test_utils::NavigateToURL(browser(), download_url); | |
| 1386 observer.WaitForStored(); | 1535 observer.WaitForStored(); |
| 1536 | |
| 1537 // Get the details on what was stored into the history. | |
| 1538 scoped_ptr<std::vector<history::DownloadRow> > downloads_in_database; | |
| 1539 ASSERT_TRUE(DownloadsHistoryDataCollector( | |
| 1540 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | |
| 1541 ASSERT_EQ(1u, downloads_in_database->size()); | |
| 1542 | |
| 1543 // Confirm history storage is what you expect for an unvalidated | |
| 1544 // dangerous file. | |
| 1545 history::DownloadRow& row(downloads_in_database->at(0)); | |
| 1546 EXPECT_EQ(DestinationFile(browser(), file), row.target_path); | |
| 1547 EXPECT_NE(download_util::GetCrDownloadPath(DestinationFile(browser(), file)), | |
| 1548 row.current_path); | |
| 1549 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, row.danger_type); | |
| 1550 EXPECT_LE(start, row.start_time); | |
| 1551 EXPECT_EQ(content::DownloadItem::IN_PROGRESS, row.state); | |
| 1552 EXPECT_FALSE(row.opened); | |
| 1553 | |
| 1554 // Validate the download and wait for it to finish. | |
| 1555 std::vector<DownloadItem*> downloads; | |
| 1556 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | |
| 1557 ASSERT_EQ(1u, downloads.size()); | |
| 1558 downloads[0]->DangerousDownloadValidated(); | |
| 1559 download_observer->WaitForFinished(); | |
| 1560 | |
| 1561 // Get history details and confirm it's what you expect. | |
| 1562 downloads_in_database->clear(); | |
| 1563 ASSERT_TRUE(DownloadsHistoryDataCollector( | |
| 1564 browser()->profile()).WaitForDownloadInfo(&downloads_in_database)); | |
| 1565 ASSERT_EQ(1u, downloads_in_database->size()); | |
| 1566 history::DownloadRow& row1(downloads_in_database->at(0)); | |
| 1567 EXPECT_EQ(DestinationFile(browser(), file), row1.target_path); | |
| 1568 EXPECT_EQ(DestinationFile(browser(), file), row1.current_path); | |
| 1569 EXPECT_EQ(content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED, row1.danger_type); | |
| 1570 EXPECT_LE(start, row1.start_time); | |
| 1571 EXPECT_EQ(content::DownloadItem::COMPLETE, row1.state); | |
| 1572 EXPECT_FALSE(row1.opened); | |
| 1573 // Not checking file size--not relevant to the point of the test, and | |
| 1574 // the file size is actually different on Windows and other platforms, | |
| 1575 // because for source control simplicity it's actually a text file, and | |
| 1576 // there are CRLF transformations for those files. | |
| 1387 } | 1577 } |
| 1388 | 1578 |
| 1389 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1579 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1390 // after download of a file while viewing another chrome://. | 1580 // after download of a file while viewing another chrome://. |
| 1391 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1581 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1392 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1582 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1393 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1583 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1394 GURL flags_url(chrome::kChromeUIFlagsURL); | 1584 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1395 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1585 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1396 | 1586 |
| (...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2200 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2390 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 2201 scoped_ptr<DownloadUrlParameters> params( | 2391 scoped_ptr<DownloadUrlParameters> params( |
| 2202 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2392 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2203 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); | 2393 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); |
| 2204 download_manager->DownloadUrl(params.Pass()); | 2394 download_manager->DownloadUrl(params.Pass()); |
| 2205 observer->WaitForFinished(); | 2395 observer->WaitForFinished(); |
| 2206 | 2396 |
| 2207 // Verify that download shelf is not shown. | 2397 // Verify that download shelf is not shown. |
| 2208 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 2398 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 2209 } | 2399 } |
| OLD | NEW |