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/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 scoped_ptr<TestURLRequestContext> url_request_context_; | 808 scoped_ptr<TestURLRequestContext> url_request_context_; |
809 fileapi::FileSystemContext* fs_; | 809 fileapi::FileSystemContext* fs_; |
810 | 810 |
811 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter); | 811 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter); |
812 }; | 812 }; |
813 | 813 |
814 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written"; | 814 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written"; |
815 const char HTML5FileWriter::kURLRequestContextToreDown[] = | 815 const char HTML5FileWriter::kURLRequestContextToreDown[] = |
816 "url_request_context_tore_down"; | 816 "url_request_context_tore_down"; |
817 | 817 |
| 818 // While an object of this class exists, it will mock out download |
| 819 // opening for all downloads created on the specified download manager. |
| 820 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
| 821 public: |
| 822 explicit MockDownloadOpeningObserver(DownloadManager* manager) |
| 823 : download_manager_(manager) { |
| 824 download_manager_->AddObserver(this); |
| 825 } |
| 826 |
| 827 ~MockDownloadOpeningObserver() { |
| 828 download_manager_->RemoveObserver(this); |
| 829 } |
| 830 |
| 831 virtual void OnDownloadCreated( |
| 832 DownloadManager* manager, DownloadItem* item) OVERRIDE { |
| 833 item->MockDownloadOpenForTesting(); |
| 834 } |
| 835 |
| 836 private: |
| 837 DownloadManager* download_manager_; |
| 838 |
| 839 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); |
| 840 }; |
| 841 |
818 } // namespace | 842 } // namespace |
819 | 843 |
820 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 844 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 845 DownloadExtensionTest_Open) { |
| 846 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 847 RunFunctionAndReturnError( |
| 848 new DownloadsOpenFunction(), |
| 849 "[-42]").c_str()); |
| 850 |
| 851 MockDownloadOpeningObserver mock_open_observer(GetCurrentManager()); |
| 852 DownloadItem* download_item = CreateSlowTestDownload(); |
| 853 ASSERT_TRUE(download_item); |
| 854 EXPECT_FALSE(download_item->GetOpened()); |
| 855 EXPECT_FALSE(download_item->GetOpenWhenComplete()); |
| 856 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, |
| 857 base::StringPrintf("[{\"danger\": \"safe\"," |
| 858 " \"incognito\": false," |
| 859 " \"mime\": \"application/octet-stream\"," |
| 860 " \"paused\": false," |
| 861 " \"url\": \"%s\"}]", |
| 862 download_item->GetURL().spec().c_str()))); |
| 863 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, |
| 864 RunFunctionAndReturnError( |
| 865 new DownloadsOpenFunction(), |
| 866 DownloadItemIdAsArgList(download_item)).c_str()); |
| 867 |
| 868 FinishPendingSlowDownloads(); |
| 869 EXPECT_FALSE(download_item->GetOpened()); |
| 870 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(), |
| 871 DownloadItemIdAsArgList(download_item))); |
| 872 EXPECT_TRUE(download_item->GetOpened()); |
| 873 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, |
| 874 base::StringPrintf("[{\"id\": %d," |
| 875 " \"opened\": {" |
| 876 " \"previous\": false," |
| 877 " \"current\": true}}]", |
| 878 download_item->GetId()))); |
| 879 } |
| 880 |
| 881 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
821 DownloadExtensionTest_PauseResumeCancel) { | 882 DownloadExtensionTest_PauseResumeCancel) { |
822 DownloadItem* download_item = CreateSlowTestDownload(); | 883 DownloadItem* download_item = CreateSlowTestDownload(); |
823 ASSERT_TRUE(download_item); | 884 ASSERT_TRUE(download_item); |
824 | 885 |
825 // Call pause(). It should succeed and the download should be paused on | 886 // Call pause(). It should succeed and the download should be paused on |
826 // return. | 887 // return. |
827 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), | 888 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), |
828 DownloadItemIdAsArgList(download_item))); | 889 DownloadItemIdAsArgList(download_item))); |
829 EXPECT_TRUE(download_item->IsPaused()); | 890 EXPECT_TRUE(download_item->IsPaused()); |
830 | 891 |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 " \"state\": {" | 2135 " \"state\": {" |
2075 " \"previous\": \"in_progress\"," | 2136 " \"previous\": \"in_progress\"," |
2076 " \"current\": \"complete\"}}]", | 2137 " \"current\": \"complete\"}}]", |
2077 result_id, | 2138 result_id, |
2078 GetFilename("on_record.txt.crdownload").c_str(), | 2139 GetFilename("on_record.txt.crdownload").c_str(), |
2079 GetFilename("on_record.txt").c_str()))); | 2140 GetFilename("on_record.txt").c_str()))); |
2080 std::string disk_data; | 2141 std::string disk_data; |
2081 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2142 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2082 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2143 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2083 } | 2144 } |
OLD | NEW |