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

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

Issue 12047039: download: Remove DownloadManager::MockDownloadOpenForTesting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and comment fix Created 7 years, 10 months 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/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "chrome/browser/download/download_file_icon_extractor.h" 13 #include "chrome/browser/download/download_file_icon_extractor.h"
14 #include "chrome/browser/download/download_service.h" 14 #include "chrome/browser/download/download_service.h"
15 #include "chrome/browser/download/download_service_factory.h" 15 #include "chrome/browser/download/download_service_factory.h"
16 #include "chrome/browser/download/download_test_file_chooser_observer.h" 16 #include "chrome/browser/download/download_test_file_activity_observer.h"
17 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 17 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
18 #include "chrome/browser/extensions/event_names.h" 18 #include "chrome/browser/extensions/event_names.h"
19 #include "chrome/browser/extensions/extension_apitest.h" 19 #include "chrome/browser/extensions/extension_apitest.h"
20 #include "chrome/browser/extensions/extension_function_test_utils.h" 20 #include "chrome/browser/extensions/extension_function_test_utils.h"
21 #include "chrome/browser/history/download_row.h" 21 #include "chrome/browser/history/download_row.h"
22 #include "chrome/browser/net/url_request_mock_util.h" 22 #include "chrome/browser/net/url_request_mock_util.h"
23 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_tabstrip.h" 26 #include "chrome/browser/ui/browser_tabstrip.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 BrowserThread::IO, FROM_HERE, 265 BrowserThread::IO, FROM_HERE,
266 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 266 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
267 InProcessBrowserTest::SetUpOnMainThread(); 267 InProcessBrowserTest::SetUpOnMainThread();
268 GoOnTheRecord(); 268 GoOnTheRecord();
269 CreateAndSetDownloadsDirectory(); 269 CreateAndSetDownloadsDirectory();
270 current_browser()->profile()->GetPrefs()->SetBoolean( 270 current_browser()->profile()->GetPrefs()->SetBoolean(
271 prefs::kPromptForDownload, false); 271 prefs::kPromptForDownload, false);
272 GetOnRecordManager()->RemoveAllDownloads(); 272 GetOnRecordManager()->RemoveAllDownloads();
273 events_listener_.reset(new DownloadsEventsListener()); 273 events_listener_.reset(new DownloadsEventsListener());
274 // Disable file chooser for current profile. 274 // Disable file chooser for current profile.
275 DownloadTestFileChooserObserver observer(current_browser()->profile()); 275 DownloadTestFileActivityObserver observer(current_browser()->profile());
276 observer.EnableFileChooser(false); 276 observer.EnableFileChooser(false);
277 } 277 }
278 278
279 void GoOnTheRecord() { current_browser_ = browser(); } 279 void GoOnTheRecord() { current_browser_ = browser(); }
280 280
281 void GoOffTheRecord() { 281 void GoOffTheRecord() {
282 if (!incognito_browser_) { 282 if (!incognito_browser_) {
283 incognito_browser_ = CreateIncognitoBrowser(); 283 incognito_browser_ = CreateIncognitoBrowser();
284 GetOffRecordManager()->RemoveAllDownloads(); 284 GetOffRecordManager()->RemoveAllDownloads();
285 // Disable file chooser for incognito profile. 285 // Disable file chooser for incognito profile.
286 DownloadTestFileChooserObserver observer(incognito_browser_->profile()); 286 DownloadTestFileActivityObserver observer(incognito_browser_->profile());
287 observer.EnableFileChooser(false); 287 observer.EnableFileChooser(false);
288 } 288 }
289 current_browser_ = incognito_browser_; 289 current_browser_ = incognito_browser_;
290 } 290 }
291 291
292 bool WaitFor(const std::string& event_name, const std::string& json_args) { 292 bool WaitFor(const std::string& event_name, const std::string& json_args) {
293 return events_listener_->WaitFor( 293 return events_listener_->WaitFor(
294 current_browser()->profile(), event_name, json_args); 294 current_browser()->profile(), event_name, json_args);
295 } 295 }
296 296
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 814
815 } // namespace 815 } // namespace
816 816
817 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 817 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
818 DownloadExtensionTest_Open) { 818 DownloadExtensionTest_Open) {
819 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 819 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
820 RunFunctionAndReturnError( 820 RunFunctionAndReturnError(
821 new DownloadsOpenFunction(), 821 new DownloadsOpenFunction(),
822 "[-42]").c_str()); 822 "[-42]").c_str());
823 823
824 GetCurrentManager()->MockDownloadOpenForTesting();
825 DownloadItem* download_item = CreateSlowTestDownload(); 824 DownloadItem* download_item = CreateSlowTestDownload();
826 ASSERT_TRUE(download_item); 825 ASSERT_TRUE(download_item);
827 EXPECT_FALSE(download_item->GetOpened()); 826 EXPECT_FALSE(download_item->GetOpened());
828 EXPECT_FALSE(download_item->GetOpenWhenComplete()); 827 EXPECT_FALSE(download_item->GetOpenWhenComplete());
829 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, 828 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
830 base::StringPrintf("[{\"danger\": \"safe\"," 829 base::StringPrintf("[{\"danger\": \"safe\","
831 " \"incognito\": false," 830 " \"incognito\": false,"
832 " \"mime\": \"application/octet-stream\"," 831 " \"mime\": \"application/octet-stream\","
833 " \"paused\": false," 832 " \"paused\": false,"
834 " \"url\": \"%s\"}]", 833 " \"url\": \"%s\"}]",
(...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2124 " \"state\": {" 2123 " \"state\": {"
2125 " \"previous\": \"in_progress\"," 2124 " \"previous\": \"in_progress\","
2126 " \"current\": \"complete\"}}]", 2125 " \"current\": \"complete\"}}]",
2127 result_id, 2126 result_id,
2128 GetFilename("on_record.txt.crdownload").c_str(), 2127 GetFilename("on_record.txt.crdownload").c_str(),
2129 GetFilename("on_record.txt").c_str()))); 2128 GetFilename("on_record.txt").c_str())));
2130 std::string disk_data; 2129 std::string disk_data;
2131 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2130 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2132 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2131 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2133 } 2132 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_test_file_chooser_observer.cc ('k') | chrome/browser/ui/browser_close_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698