| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 #include "content/public/common/context_menu_params.h" | 57 #include "content/public/common/context_menu_params.h" |
| 58 #include "content/public/common/page_transition_types.h" | 58 #include "content/public/common/page_transition_types.h" |
| 59 #include "content/public/test/test_file_error_injector.h" | 59 #include "content/public/test/test_file_error_injector.h" |
| 60 #include "content/public/test/test_navigation_observer.h" | 60 #include "content/public/test/test_navigation_observer.h" |
| 61 #include "content/test/net/url_request_mock_http_job.h" | 61 #include "content/test/net/url_request_mock_http_job.h" |
| 62 #include "content/test/net/url_request_slow_download_job.h" | 62 #include "content/test/net/url_request_slow_download_job.h" |
| 63 #include "net/base/net_util.h" | 63 #include "net/base/net_util.h" |
| 64 #include "net/test/test_server.h" | 64 #include "net/test/test_server.h" |
| 65 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
| 66 | 66 |
| 67 using content::BrowserContext; |
| 67 using content::BrowserThread; | 68 using content::BrowserThread; |
| 68 using content::DownloadItem; | 69 using content::DownloadItem; |
| 69 using content::DownloadManager; | 70 using content::DownloadManager; |
| 70 using content::DownloadPersistentStoreInfo; | 71 using content::DownloadPersistentStoreInfo; |
| 71 using content::DownloadUrlParameters; | 72 using content::DownloadUrlParameters; |
| 72 using content::WebContents; | 73 using content::WebContents; |
| 73 using extensions::Extension; | 74 using extensions::Extension; |
| 74 | 75 |
| 75 namespace { | 76 namespace { |
| 76 | 77 |
| 77 // IDs and paths of CRX files used in tests. | 78 // IDs and paths of CRX files used in tests. |
| 78 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 79 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 79 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 80 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
| 80 | 81 |
| 81 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 82 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 82 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 83 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
| 83 | 84 |
| 84 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { | 85 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate { |
| 85 public: | 86 public: |
| 86 explicit PickSuggestedFileDelegate(Profile* profile) | 87 explicit PickSuggestedFileDelegate(Profile* profile) |
| 87 : ChromeDownloadManagerDelegate(profile) { | 88 : ChromeDownloadManagerDelegate(profile) { |
| 88 SetDownloadManager( | |
| 89 DownloadServiceFactory::GetForProfile(profile)->GetDownloadManager()); | |
| 90 } | 89 } |
| 91 | 90 |
| 92 virtual void ChooseDownloadPath(WebContents* web_contents, | 91 virtual void ChooseDownloadPath(WebContents* web_contents, |
| 93 const FilePath& suggested_path, | 92 const FilePath& suggested_path, |
| 94 int32 download_id) OVERRIDE { | 93 int32 download_id) OVERRIDE { |
| 95 if (download_manager_) | 94 if (download_manager_) |
| 96 download_manager_->FileSelected(suggested_path, download_id); | 95 download_manager_->FileSelected(suggested_path, download_id); |
| 97 } | 96 } |
| 98 | 97 |
| 99 protected: | 98 protected: |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // Proceed without confirmation prompt. | 178 // Proceed without confirmation prompt. |
| 180 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 179 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
| 181 delegate->InstallUIProceed(); | 180 delegate->InstallUIProceed(); |
| 182 } | 181 } |
| 183 | 182 |
| 184 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} | 183 virtual void OnInstallSuccess(const Extension* extension, SkBitmap* icon) {} |
| 185 virtual void OnInstallFailure(const string16& error) {} | 184 virtual void OnInstallFailure(const string16& error) {} |
| 186 }; | 185 }; |
| 187 | 186 |
| 188 static DownloadManager* DownloadManagerForBrowser(Browser* browser) { | 187 static DownloadManager* DownloadManagerForBrowser(Browser* browser) { |
| 189 return DownloadServiceFactory::GetForProfile(browser->profile()) | 188 return BrowserContext::GetDownloadManager(browser->profile()); |
| 190 ->GetDownloadManager(); | |
| 191 } | 189 } |
| 192 | 190 |
| 193 class TestRenderViewContextMenu : public RenderViewContextMenu { | 191 class TestRenderViewContextMenu : public RenderViewContextMenu { |
| 194 public: | 192 public: |
| 195 TestRenderViewContextMenu(WebContents* web_contents, | 193 TestRenderViewContextMenu(WebContents* web_contents, |
| 196 const content::ContextMenuParams& params) | 194 const content::ContextMenuParams& params) |
| 197 : RenderViewContextMenu(web_contents, params) { | 195 : RenderViewContextMenu(web_contents, params) { |
| 198 } | 196 } |
| 199 virtual ~TestRenderViewContextMenu() {} | 197 virtual ~TestRenderViewContextMenu() {} |
| 200 | 198 |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 | 1392 |
| 1395 // Create a download, wait until it's started, and confirm | 1393 // Create a download, wait until it's started, and confirm |
| 1396 // we're in the expected state. | 1394 // we're in the expected state. |
| 1397 scoped_ptr<DownloadTestObserver> observer1( | 1395 scoped_ptr<DownloadTestObserver> observer1( |
| 1398 CreateInProgressWaiter(browser(), 1)); | 1396 CreateInProgressWaiter(browser(), 1)); |
| 1399 ui_test_utils::NavigateToURL( | 1397 ui_test_utils::NavigateToURL( |
| 1400 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1398 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 1401 observer1->WaitForFinished(); | 1399 observer1->WaitForFinished(); |
| 1402 | 1400 |
| 1403 std::vector<DownloadItem*> downloads; | 1401 std::vector<DownloadItem*> downloads; |
| 1404 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1402 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1405 string16(), &downloads); | 1403 string16(), &downloads); |
| 1406 ASSERT_EQ(1u, downloads.size()); | 1404 ASSERT_EQ(1u, downloads.size()); |
| 1407 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1405 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 1408 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1406 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1409 DownloadItem* download1 = downloads[0]; // The only download. | 1407 DownloadItem* download1 = downloads[0]; // The only download. |
| 1410 | 1408 |
| 1411 // Start the second download and wait until it's done. | 1409 // Start the second download and wait until it's done. |
| 1412 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1410 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1413 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1411 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1414 // Download the file and wait. We do not expect the Select File dialog. | 1412 // Download the file and wait. We do not expect the Select File dialog. |
| 1415 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1413 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
| 1416 | 1414 |
| 1417 // Should now have 2 items on the download shelf. | 1415 // Should now have 2 items on the download shelf. |
| 1418 downloads.clear(); | 1416 downloads.clear(); |
| 1419 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1417 DownloadManagerForBrowser(browser())->SearchDownloads( |
| 1420 string16(), &downloads); | 1418 string16(), &downloads); |
| 1421 ASSERT_EQ(2u, downloads.size()); | 1419 ASSERT_EQ(2u, downloads.size()); |
| 1422 // We don't know the order of the downloads. | 1420 // We don't know the order of the downloads. |
| 1423 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 1421 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
| 1424 | 1422 |
| 1425 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 1423 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
| 1426 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | 1424 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); |
| 1427 // The download shelf should be open. | 1425 // The download shelf should be open. |
| 1428 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1426 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 1429 | 1427 |
| (...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2455 GetDownloads(browser(), &download_items); | 2453 GetDownloads(browser(), &download_items); |
| 2456 ASSERT_EQ(1u, download_items.size()); | 2454 ASSERT_EQ(1u, download_items.size()); |
| 2457 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2455 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2458 download_items[0]->GetOriginalUrl()); | 2456 download_items[0]->GetOriginalUrl()); |
| 2459 | 2457 |
| 2460 // Check that the file contains the expected referrer. | 2458 // Check that the file contains the expected referrer. |
| 2461 FilePath file(download_items[0]->GetFullPath()); | 2459 FilePath file(download_items[0]->GetFullPath()); |
| 2462 std::string expected_contents = test_server()->GetURL("").spec(); | 2460 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2463 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2461 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2464 } | 2462 } |
| OLD | NEW |