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

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

Issue 10834129: Implement chrome.downloads.erase() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: @r172329 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"
11 #include "base/message_loop.h" 10 #include "base/message_loop.h"
12 #include "base/stl_util.h" 11 #include "base/stl_util.h"
13 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
14 #include "chrome/browser/download/download_file_icon_extractor.h" 13 #include "chrome/browser/download/download_file_icon_extractor.h"
15 #include "chrome/browser/download/download_service.h" 14 #include "chrome/browser/download/download_service.h"
16 #include "chrome/browser/download/download_service_factory.h" 15 #include "chrome/browser/download/download_service_factory.h"
17 #include "chrome/browser/download/download_test_file_chooser_observer.h" 16 #include "chrome/browser/download/download_test_file_chooser_observer.h"
18 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 17 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
19 #include "chrome/browser/extensions/event_names.h" 18 #include "chrome/browser/extensions/event_names.h"
20 #include "chrome/browser/extensions/extension_apitest.h" 19 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 EXPECT_TRUE(download_item->GetOpened()); 871 EXPECT_TRUE(download_item->GetOpened());
873 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, 872 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged,
874 base::StringPrintf("[{\"id\": %d," 873 base::StringPrintf("[{\"id\": %d,"
875 " \"opened\": {" 874 " \"opened\": {"
876 " \"previous\": false," 875 " \"previous\": false,"
877 " \"current\": true}}]", 876 " \"current\": true}}]",
878 download_item->GetId()))); 877 download_item->GetId())));
879 } 878 }
880 879
881 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 880 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
882 DownloadExtensionTest_PauseResumeCancel) { 881 DownloadExtensionTest_PauseResumeCancelErase) {
883 DownloadItem* download_item = CreateSlowTestDownload(); 882 DownloadItem* download_item = CreateSlowTestDownload();
884 ASSERT_TRUE(download_item); 883 ASSERT_TRUE(download_item);
885 884
886 // Call pause(). It should succeed and the download should be paused on 885 // Call pause(). It should succeed and the download should be paused on
887 // return. 886 // return.
888 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(), 887 EXPECT_TRUE(RunFunction(new DownloadsPauseFunction(),
889 DownloadItemIdAsArgList(download_item))); 888 DownloadItemIdAsArgList(download_item)));
890 EXPECT_TRUE(download_item->IsPaused()); 889 EXPECT_TRUE(download_item->IsPaused());
891 890
892 // Calling pause() twice shouldn't be an error. 891 // Calling pause() twice shouldn't be an error.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 error = RunFunctionAndReturnError( 934 error = RunFunctionAndReturnError(
936 new DownloadsPauseFunction(), "[-42]"); 935 new DownloadsPauseFunction(), "[-42]");
937 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 936 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
938 error.c_str()); 937 error.c_str());
939 938
940 // Calling resume on a non-existent download yields kInvalidOperationError 939 // Calling resume on a non-existent download yields kInvalidOperationError
941 error = RunFunctionAndReturnError( 940 error = RunFunctionAndReturnError(
942 new DownloadsResumeFunction(), "[-42]"); 941 new DownloadsResumeFunction(), "[-42]");
943 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 942 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
944 error.c_str()); 943 error.c_str());
944
945 int id = download_item->GetId();
946 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
947 new DownloadsEraseFunction(),
948 base::StringPrintf("[{\"id\": %d}]", id)));
949 DownloadManager::DownloadVector items;
950 GetCurrentManager()->GetAllDownloads(&items);
951 EXPECT_EQ(0UL, items.size());
952 ASSERT_TRUE(result);
953 download_item = NULL;
954 base::ListValue* result_list = NULL;
955 ASSERT_TRUE(result->GetAsList(&result_list));
956 ASSERT_EQ(1UL, result_list->GetSize());
957 int element = -1;
958 ASSERT_TRUE(result_list->GetInteger(0, &element));
959 EXPECT_EQ(id, element);
945 } 960 }
946 961
947 scoped_refptr<UIThreadExtensionFunction> MockedGetFileIconFunction( 962 scoped_refptr<UIThreadExtensionFunction> MockedGetFileIconFunction(
948 const FilePath& expected_path, 963 const FilePath& expected_path,
949 IconLoader::IconSize icon_size, 964 IconLoader::IconSize icon_size,
950 const std::string& response) { 965 const std::string& response) {
951 scoped_refptr<DownloadsGetFileIconFunction> function( 966 scoped_refptr<DownloadsGetFileIconFunction> function(
952 new DownloadsGetFileIconFunction()); 967 new DownloadsGetFileIconFunction());
953 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 968 function->SetIconExtractorForTesting(new MockIconExtractorImpl(
954 expected_path, icon_size, response)); 969 expected_path, icon_size, response));
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 " \"state\": {" 2150 " \"state\": {"
2136 " \"previous\": \"in_progress\"," 2151 " \"previous\": \"in_progress\","
2137 " \"current\": \"complete\"}}]", 2152 " \"current\": \"complete\"}}]",
2138 result_id, 2153 result_id,
2139 GetFilename("on_record.txt.crdownload").c_str(), 2154 GetFilename("on_record.txt.crdownload").c_str(),
2140 GetFilename("on_record.txt").c_str()))); 2155 GetFilename("on_record.txt").c_str())));
2141 std::string disk_data; 2156 std::string disk_data;
2142 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2157 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2143 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2158 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2144 } 2159 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | chrome/common/extensions/api/downloads.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698