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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 10836003: chrome.downloads.open() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r171249 Created 8 years 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 | Annotate | Revision Log
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 <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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 scoped_ptr<TestURLRequestContext> url_request_context_; 807 scoped_ptr<TestURLRequestContext> url_request_context_;
808 fileapi::FileSystemContext* fs_; 808 fileapi::FileSystemContext* fs_;
809 809
810 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter); 810 DISALLOW_COPY_AND_ASSIGN(HTML5FileWriter);
811 }; 811 };
812 812
813 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written"; 813 const char HTML5FileWriter::kHTML5FileWritten[] = "html5_file_written";
814 const char HTML5FileWriter::kURLRequestContextToreDown[] = 814 const char HTML5FileWriter::kURLRequestContextToreDown[] =
815 "url_request_context_tore_down"; 815 "url_request_context_tore_down";
816 816
817 // While an object of this class exists, it will mock out download
818 // opening for all downloads created on the specified download manager.
819 class MockDownloadOpeningObserver : public DownloadManager::Observer {
820 public:
821 explicit MockDownloadOpeningObserver(DownloadManager* manager)
822 : download_manager_(manager) {
823 download_manager_->AddObserver(this);
824 }
825
826 ~MockDownloadOpeningObserver() {
827 download_manager_->RemoveObserver(this);
828 }
829
830 virtual void OnDownloadCreated(
831 DownloadManager* manager, DownloadItem* item) OVERRIDE {
832 item->MockDownloadOpenForTesting();
833 }
834
835 private:
836 DownloadManager* download_manager_;
837
838 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver);
839 };
840
817 } // namespace 841 } // namespace
818 842
819 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 843 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
844 DownloadExtensionTest_Open) {
845 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
846 RunFunctionAndReturnError(
847 new DownloadsOpenFunction(),
848 "[-42]").c_str());
849
850 MockDownloadOpeningObserver mock_open_observer(GetCurrentManager());
851 DownloadItem* download_item = CreateSlowTestDownload();
852 ASSERT_TRUE(download_item);
853 EXPECT_FALSE(download_item->GetOpened());
854 EXPECT_FALSE(download_item->GetOpenWhenComplete());
855 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
856 base::StringPrintf("[{\"danger\": \"safe\","
857 " \"incognito\": false,"
858 " \"mime\": \"application/octet-stream\","
859 " \"paused\": false,"
860 " \"url\": \"%s\"}]",
861 download_item->GetURL().spec().c_str())));
862 FinishPendingSlowDownloads();
863 EXPECT_FALSE(download_item->GetOpened());
864 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(),
865 DownloadItemIdAsArgList(download_item)));
866 EXPECT_TRUE(download_item->GetOpened());
867 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
868 base::StringPrintf("[{\"id\": %d,"
869 " \"opened\": {"
870 " \"previous\": false,"
871 " \"current\": true}}]",
872 download_item->GetId())));
873
874 download_item = CreateSlowTestDownload();
875 ASSERT_TRUE(download_item);
876 EXPECT_FALSE(download_item->GetOpened());
877 EXPECT_FALSE(download_item->GetOpenWhenComplete());
878 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
879 base::StringPrintf("[{\"danger\": \"safe\","
880 " \"incognito\": false,"
881 " \"mime\": \"application/octet-stream\","
882 " \"paused\": false,"
883 " \"url\": \"%s\"}]",
884 download_item->GetURL().spec().c_str())));
885 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(),
886 DownloadItemIdAsArgList(download_item)));
887 EXPECT_TRUE(download_item->GetOpenWhenComplete());
888 EXPECT_FALSE(download_item->GetOpened());
889 FinishPendingSlowDownloads();
890 EXPECT_TRUE(download_item->GetOpened());
891 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
892 base::StringPrintf("[{\"id\": %d,"
893 " \"opened\": {"
894 " \"previous\": false,"
895 " \"current\": true}}]",
896 download_item->GetId())));
897 }
898
899 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
820 DownloadExtensionTest_PauseResumeCancel) { 900 DownloadExtensionTest_PauseResumeCancel) {
821 DownloadItem* download_item = CreateSlowTestDownload(); 901 DownloadItem* download_item = CreateSlowTestDownload();
822 ASSERT_TRUE(download_item); 902 ASSERT_TRUE(download_item);
823 903
824 // Call pause(). It should succeed and the download should be paused on 904 // Call pause(). It should succeed and the download should be paused on
825 // return. 905 // return.
826 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), 906 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(),
827 DownloadItemIdAsArgList(download_item))); 907 DownloadItemIdAsArgList(download_item)));
828 EXPECT_TRUE(download_item->IsPaused()); 908 EXPECT_TRUE(download_item->IsPaused());
829 909
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 " \"state\": {" 2153 " \"state\": {"
2074 " \"previous\": \"in_progress\"," 2154 " \"previous\": \"in_progress\","
2075 " \"current\": \"complete\"}}]", 2155 " \"current\": \"complete\"}}]",
2076 result_id, 2156 result_id,
2077 GetFilename("on_record.txt.crdownload").c_str(), 2157 GetFilename("on_record.txt.crdownload").c_str(),
2078 GetFilename("on_record.txt").c_str()))); 2158 GetFilename("on_record.txt").c_str())));
2079 std::string disk_data; 2159 std::string disk_data;
2080 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2160 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2081 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2161 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2082 } 2162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698