Index: chrome/browser/download/chrome_download_manager_delegate_unittest.cc |
diff --git a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc |
index abc43122af4ce1835dd02ef366c56c5c3f6e0a95..5af35f7f5e4d406b1504e14b9eb9e70c5ae56fe2 100644 |
--- a/chrome/browser/download/chrome_download_manager_delegate_unittest.cc |
+++ b/chrome/browser/download/chrome_download_manager_delegate_unittest.cc |
@@ -20,9 +20,13 @@ |
#include "chrome/common/pref_names.h" |
#include "chrome/test/base/testing_pref_service.h" |
#include "chrome/test/base/testing_profile.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_contents_delegate.h" |
#include "content/public/test/mock_download_item.h" |
#include "content/public/test/mock_download_manager.h" |
#include "content/public/test/test_browser_thread.h" |
+#include "content/public/test/test_renderer_host.h" |
+#include "content/public/test/web_contents_tester.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -39,6 +43,11 @@ using ::testing::_; |
namespace { |
+class MockWebContentsDelegate : public content::WebContentsDelegate { |
+ public: |
+ virtual ~MockWebContentsDelegate() {} |
+}; |
+ |
// Google Mock action that posts a task to the current message loop that invokes |
// the first argument of the mocked method as a callback. Said argument must be |
// a base::Callback<void(ParamType)>. |result| must be of |ParamType| and is |
@@ -276,6 +285,8 @@ class ChromeDownloadManagerDelegateTest : public ::testing::Test { |
content::TestBrowserThread file_thread_; |
scoped_refptr<content::MockDownloadManager> download_manager_; |
scoped_refptr<TestChromeDownloadManagerDelegate> delegate_; |
+ scoped_ptr<content::WebContents> web_contents_; |
+ MockWebContentsDelegate web_contents_delegate_; |
}; |
ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
@@ -285,6 +296,9 @@ ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
delegate_(new TestChromeDownloadManagerDelegate(&profile_)) { |
delegate_->SetDownloadManager(download_manager_.get()); |
pref_service_ = profile_.GetTestingPrefService(); |
+ web_contents_.reset(content::WebContentsTester::CreateTestWebContentsNoInit( |
+ &profile_)); |
+ web_contents_->SetDelegate(&web_contents_delegate_); |
} |
void ChromeDownloadManagerDelegateTest::SetUp() { |
@@ -320,6 +334,8 @@ content::MockDownloadItem* |
.WillByDefault(Return(false)); |
ON_CALL(*item, IsTemporary()) |
.WillByDefault(Return(false)); |
+ ON_CALL(*item, GetWebContents()) |
+ .WillByDefault(Return(web_contents_.get())); |
EXPECT_CALL(*item, GetId()) |
.WillRepeatedly(Return(id)); |
EXPECT_CALL(*download_manager_, GetActiveDownloadItem(id)) |
@@ -877,6 +893,42 @@ TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_LastSavePath) { |
RunTestCases(kLastSavePathTestCases, 1); |
} |
+TEST_F(ChromeDownloadManagerDelegateTest, StartDownload_WebIntents) { |
+ const DownloadTestCase kWebIntentsTestCases[] = { |
+ { |
+ // 1: A file which would be dangerous, but is handled by web intents. |
+ // The name will be unaltered (the actual save name will have the |
+ // .webintents extension). |
+ AUTOMATIC, |
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
+ "http://example.com/feed.exe", "application/rss+xml", |
+ FILE_PATH_LITERAL(""), |
+ |
+ FILE_PATH_LITERAL("feed.exe.webintents"), |
+ FILE_PATH_LITERAL(""), |
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
+ |
+ EXPECT_CRDOWNLOAD |
+ }, |
+ |
+ { |
+ // 2: A download with a forced path won't be handled by web intents. |
+ FORCED, |
+ content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
+ "http://example.com/feed.exe", "application/rss+xml", |
+ FILE_PATH_LITERAL("forced.feed.exe"), |
+ |
+ FILE_PATH_LITERAL("forced.feed.exe"), |
+ FILE_PATH_LITERAL(""), |
+ DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
+ |
+ EXPECT_CRDOWNLOAD |
+ }, |
+ }; |
+ |
+ RunTestCases(kWebIntentsTestCases, arraysize(kWebIntentsTestCases)); |
+} |
+ |
// TODO(asanka): Add more tests. |
// * Default download path is not writable. |
// * Download path doesn't exist. |