Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/download/download_target_determiner_unittest.cc

Issue 2641063002: Fix a problem that user validated dangerous download cannot resume (Closed)
Patch Set: remove dependencies Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/download/download_target_determiner.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/at_exit.h" 8 #include "base/at_exit.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 const MIMETypeTestCase& test_case = kMIMETypeTestCases[i]; 1905 const MIMETypeTestCase& test_case = kMIMETypeTestCases[i];
1906 std::unique_ptr<content::MockDownloadItem> item( 1906 std::unique_ptr<content::MockDownloadItem> item(
1907 CreateActiveDownloadItem(i, test_case.general)); 1907 CreateActiveDownloadItem(i, test_case.general));
1908 std::unique_ptr<DownloadTargetInfo> target_info = 1908 std::unique_ptr<DownloadTargetInfo> target_info =
1909 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath), 1909 RunDownloadTargetDeterminer(GetPathInDownloadDir(kInitialPath),
1910 item.get()); 1910 item.get());
1911 EXPECT_EQ(test_case.expected_mime_type, target_info->mime_type); 1911 EXPECT_EQ(test_case.expected_mime_type, target_info->mime_type);
1912 } 1912 }
1913 } 1913 }
1914 1914
1915 // Test that a user validated download won't be treated as dangerous.
1916 TEST_F(DownloadTargetDeterminerTest, ResumedWithUserValidatedDownload) {
1917 const base::FilePath::CharType kInitialPath[] =
1918 FILE_PATH_LITERAL("some_path/bar.txt");
1919 const base::FilePath::CharType* kIntermediatePath =
1920 FILE_PATH_LITERAL("foo.crx.crdownload");
1921
1922 const DownloadTestCase kUserValidatedTestCase = {
1923 AUTOMATIC,
1924 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED,
1925 DownloadFileType::NOT_DANGEROUS,
1926 "http://example.com/foo.crx",
1927 "",
1928 FILE_PATH_LITERAL(""),
1929 FILE_PATH_LITERAL("foo.crx"),
1930 DownloadItem::TARGET_DISPOSITION_OVERWRITE,
1931 EXPECT_CRDOWNLOAD};
1932
1933 const DownloadTestCase& test_case = kUserValidatedTestCase;
1934 std::unique_ptr<content::MockDownloadItem> item(
1935 CreateActiveDownloadItem(0, test_case));
1936 base::FilePath expected_path =
1937 GetPathInDownloadDir(test_case.expected_local_path);
1938 ON_CALL(*item.get(), GetDangerType())
1939 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED));
1940 ON_CALL(*item.get(), GetFullPath())
1941 .WillByDefault(ReturnRefOfCopy(GetPathInDownloadDir(kIntermediatePath)));
1942 ON_CALL(*item.get(), GetLastReason())
1943 .WillByDefault(Return(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED));
1944 EXPECT_CALL(*delegate(), NotifyExtensions(_, _, _));
1945 EXPECT_CALL(*delegate(), ReserveVirtualPath(_, expected_path, false, _, _));
1946 EXPECT_CALL(*delegate(), PromptUserForDownloadPath(_, expected_path, _))
1947 .Times(0);
1948 EXPECT_CALL(*delegate(), DetermineLocalPath(_, expected_path, _));
1949 EXPECT_CALL(*delegate(), CheckDownloadUrl(_, expected_path, _)).Times(0);
1950 RunTestCase(test_case, GetPathInDownloadDir(kInitialPath), item.get());
1951 }
1952
1915 #if BUILDFLAG(ENABLE_PLUGINS) 1953 #if BUILDFLAG(ENABLE_PLUGINS)
1916 1954
1917 void DummyGetPluginsCallback( 1955 void DummyGetPluginsCallback(
1918 const base::Closure& closure, 1956 const base::Closure& closure,
1919 const std::vector<content::WebPluginInfo>& plugins) { 1957 const std::vector<content::WebPluginInfo>& plugins) {
1920 closure.Run(); 1958 closure.Run();
1921 } 1959 }
1922 1960
1923 void ForceRefreshOfPlugins() { 1961 void ForceRefreshOfPlugins() {
1924 #if !defined(OS_WIN) 1962 #if !defined(OS_WIN)
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2156 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path())) 2194 EXPECT_CALL(mock_plugin_filter_, MockPluginAvailable(browser_plugin.path()))
2157 .WillRepeatedly(Return(false)); 2195 .WillRepeatedly(Return(false));
2158 target_info = RunDownloadTargetDeterminer( 2196 target_info = RunDownloadTargetDeterminer(
2159 GetPathInDownloadDir(kInitialPath), item.get()); 2197 GetPathInDownloadDir(kInitialPath), item.get());
2160 EXPECT_FALSE(target_info->is_filetype_handled_safely); 2198 EXPECT_FALSE(target_info->is_filetype_handled_safely);
2161 } 2199 }
2162 2200
2163 #endif // BUILDFLAG(ENABLE_PLUGINS) 2201 #endif // BUILDFLAG(ENABLE_PLUGINS)
2164 2202
2165 } // namespace 2203 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698