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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 scoped_ptr<TestURLRequestContext> url_request_context_; | 806 scoped_ptr<TestURLRequestContext> url_request_context_; |
807 fileapi::FileSystemContext* fs_; | 807 fileapi::FileSystemContext* fs_; |
808 | 808 |
809 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter); | 809 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter); |
810 }; | 810 }; |
811 | 811 |
812 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written"; | 812 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written"; |
813 const char HTML5FileWriter::kURLRequestContextToreDown[] = | 813 const char HTML5FileWriter::kURLRequestContextToreDown[] = |
814 "url_request_context_tore_down"; | 814 "url_request_context_tore_down"; |
815 | 815 |
816 // While an object of this class exists, it will mock out download | |
817 // opening for all downloads created on the specified download manager. | |
818 class MockDownloadOpeningObserver : public DownloadManager::Observer { | |
819 public: | |
820 explicit MockDownloadOpeningObserver(DownloadManager* manager) | |
821 : download_manager_(manager) { | |
822 download_manager_->AddObserver(this); | |
823 } | |
824 | |
825 ~MockDownloadOpeningObserver() { | |
826 download_manager_->RemoveObserver(this); | |
827 } | |
828 | |
829 virtual void OnDownloadCreated( | |
830 DownloadManager* manager, DownloadItem* item) OVERRIDE { | |
831 item->MockDownloadOpenForTesting(); | |
832 } | |
833 | |
834 private: | |
835 DownloadManager* download_manager_; | |
836 | |
837 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); | |
838 }; | |
839 | |
840 } // namespace | 816 } // namespace |
841 | 817 |
842 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 818 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
843 DownloadExtensionTest_Open) { | 819 DownloadExtensionTest_Open) { |
844 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, | 820 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
845 RunFunctionAndReturnError( | 821 RunFunctionAndReturnError( |
846 new DownloadsOpenFunction(), | 822 new DownloadsOpenFunction(), |
847 "[-42]").c_str()); | 823 "[-42]").c_str()); |
848 | 824 |
849 MockDownloadOpeningObserver mock_open_observer(GetCurrentManager()); | 825 GetCurrentManager()->MockDownloadOpenForTesting(); |
850 DownloadItem* download_item = CreateSlowTestDownload(); | 826 DownloadItem* download_item = CreateSlowTestDownload(); |
851 ASSERT_TRUE(download_item); | 827 ASSERT_TRUE(download_item); |
852 EXPECT_FALSE(download_item->GetOpened()); | 828 EXPECT_FALSE(download_item->GetOpened()); |
853 EXPECT_FALSE(download_item->GetOpenWhenComplete()); | 829 EXPECT_FALSE(download_item->GetOpenWhenComplete()); |
854 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | 830 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
855 base::StringPrintf("[{\"danger\": \"safe\"," | 831 base::StringPrintf("[{\"danger\": \"safe\"," |
856 " \"incognito\": false," | 832 " \"incognito\": false," |
857 " \"mime\": \"application/octet-stream\"," | 833 " \"mime\": \"application/octet-stream\"," |
858 " \"paused\": false," | 834 " \"paused\": false," |
859 " \"url\": \"%s\"}]", | 835 " \"url\": \"%s\"}]", |
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2149 " \"state\": {" | 2125 " \"state\": {" |
2150 " \"previous\": \"in_progress\"," | 2126 " \"previous\": \"in_progress\"," |
2151 " \"current\": \"complete\"}}]", | 2127 " \"current\": \"complete\"}}]", |
2152 result_id, | 2128 result_id, |
2153 GetFilename("on_record.txt.crdownload").c_str(), | 2129 GetFilename("on_record.txt.crdownload").c_str(), |
2154 GetFilename("on_record.txt").c_str()))); | 2130 GetFilename("on_record.txt").c_str()))); |
2155 std::string disk_data; | 2131 std::string disk_data; |
2156 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2132 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2157 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2133 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2158 } | 2134 } |
OLD | NEW |