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

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: @r171008 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 MockDownloadOpeningObserver mock_open_observer(GetCurrentManager());
846 DownloadItem* download_item = CreateSlowTestDownload();
847 ASSERT_TRUE(download_item);
848 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
849 RunFunctionAndReturnError(
850 new DownloadsOpenFunction(),
851 DownloadItemIdAsArgList(download_item)).c_str());
852 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
853 RunFunctionAndReturnError(
854 new DownloadsOpenFunction(),
855 "[-42]").c_str());
856 FinishPendingSlowDownloads();
857 EXPECT_TRUE(RunFunction(new DownloadsOpenFunction(),
858 DownloadItemIdAsArgList(download_item)));
859 EXPECT_TRUE(download_item->GetOpened());
860 }
861
862 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
820 DownloadExtensionTest_PauseResumeCancel) { 863 DownloadExtensionTest_PauseResumeCancel) {
821 DownloadItem* download_item = CreateSlowTestDownload(); 864 DownloadItem* download_item = CreateSlowTestDownload();
822 ASSERT_TRUE(download_item); 865 ASSERT_TRUE(download_item);
823 866
824 // Call pause(). It should succeed and the download should be paused on 867 // Call pause(). It should succeed and the download should be paused on
825 // return. 868 // return.
826 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), 869 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(),
827 DownloadItemIdAsArgList(download_item))); 870 DownloadItemIdAsArgList(download_item)));
828 EXPECT_TRUE(download_item->IsPaused()); 871 EXPECT_TRUE(download_item->IsPaused());
829 872
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 " \"state\": {" 2116 " \"state\": {"
2074 " \"previous\": \"in_progress\"," 2117 " \"previous\": \"in_progress\","
2075 " \"current\": \"complete\"}}]", 2118 " \"current\": \"complete\"}}]",
2076 result_id, 2119 result_id,
2077 GetFilename("on_record.txt.crdownload").c_str(), 2120 GetFilename("on_record.txt.crdownload").c_str(),
2078 GetFilename("on_record.txt").c_str()))); 2121 GetFilename("on_record.txt").c_str())));
2079 std::string disk_data; 2122 std::string disk_data;
2080 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2123 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2081 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2124 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2082 } 2125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698