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

Side by Side Diff: chrome/browser/download/notification/download_notification_browsertest.cc

Issue 2317993003: //chrome/browser and //components A-E: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Just rebased Created 4 years, 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 void SetUpOnMainThread() override { 279 void SetUpOnMainThread() override {
280 ASSERT_TRUE(embedded_test_server()->Start()); 280 ASSERT_TRUE(embedded_test_server()->Start());
281 281
282 content::BrowserThread::PostTask( 282 content::BrowserThread::PostTask(
283 content::BrowserThread::IO, FROM_HERE, 283 content::BrowserThread::IO, FROM_HERE,
284 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler)); 284 base::Bind(&net::URLRequestSlowDownloadJob::AddUrlHandler));
285 285
286 GetMessageCenter()->DisableTimersForTest(); 286 GetMessageCenter()->DisableTimersForTest();
287 287
288 // Set up the temporary download folder. 288 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
289 ASSERT_TRUE(CreateAndSetDownloadsDirectory(browser())); 289 ASSERT_TRUE(SetDownloadsDirectory(browser()));
290 } 290 }
291 291
292 protected: 292 protected:
293 // Must be called after browser creation. Creates a temporary 293 // Must be called after browser creation. Assumes that |downloads_directory_|
294 // directory for downloads that is auto-deleted on destruction. 294 // is created and sets its path to be used for downloads by |browser|.
295 // Returning false indicates a failure of the function, and should be asserted 295 // Returning false indicates a failure of the function, and should be
296 // in the caller. 296 // asserted in the caller.
297 bool CreateAndSetDownloadsDirectory(Browser* browser) { 297 bool SetDownloadsDirectory(Browser* browser) {
298 if (!browser) 298 if (!browser)
299 return false; 299 return false;
300 300
301 if (!downloads_directory_.path().empty())
302 return true; // already created
303
304 if (!downloads_directory_.CreateUniqueTempDir())
305 return false;
306
307 browser->profile()->GetPrefs()->SetFilePath( 301 browser->profile()->GetPrefs()->SetFilePath(
308 prefs::kDownloadDefaultDirectory, 302 prefs::kDownloadDefaultDirectory, downloads_directory_.GetPath());
309 downloads_directory_.path());
310 browser->profile()->GetPrefs()->SetFilePath( 303 browser->profile()->GetPrefs()->SetFilePath(
311 prefs::kSaveFileDefaultDirectory, 304 prefs::kSaveFileDefaultDirectory, downloads_directory_.GetPath());
312 downloads_directory_.path());
313 305
314 return true; 306 return true;
315 } 307 }
316 308
317 content::DownloadManager* GetDownloadManager(Browser* browser) { 309 content::DownloadManager* GetDownloadManager(Browser* browser) {
318 return content::BrowserContext::GetDownloadManager(browser->profile()); 310 return content::BrowserContext::GetDownloadManager(browser->profile());
319 } 311 }
320 312
321 private: 313 private:
322 // Location of the downloads directory for these tests 314 // Location of the downloads directory for these tests
(...skipping 24 matching lines...) Expand all
347 TestChromeDownloadManagerDelegate* GetDownloadManagerDelegate() const { 339 TestChromeDownloadManagerDelegate* GetDownloadManagerDelegate() const {
348 return static_cast<TestChromeDownloadManagerDelegate*>( 340 return static_cast<TestChromeDownloadManagerDelegate*>(
349 DownloadServiceFactory::GetForBrowserContext(browser()->profile()) 341 DownloadServiceFactory::GetForBrowserContext(browser()->profile())
350 ->GetDownloadManagerDelegate()); 342 ->GetDownloadManagerDelegate());
351 } 343 }
352 344
353 void PrepareIncognitoBrowser() { 345 void PrepareIncognitoBrowser() {
354 incognito_browser_ = CreateIncognitoBrowser(); 346 incognito_browser_ = CreateIncognitoBrowser();
355 Profile* incognito_profile = incognito_browser_->profile(); 347 Profile* incognito_profile = incognito_browser_->profile();
356 348
357 ASSERT_TRUE(CreateAndSetDownloadsDirectory(incognito_browser_)); 349 ASSERT_TRUE(SetDownloadsDirectory(incognito_browser_));
358 350
359 std::unique_ptr<TestChromeDownloadManagerDelegate> incognito_test_delegate; 351 std::unique_ptr<TestChromeDownloadManagerDelegate> incognito_test_delegate;
360 incognito_test_delegate.reset( 352 incognito_test_delegate.reset(
361 new TestChromeDownloadManagerDelegate(incognito_profile)); 353 new TestChromeDownloadManagerDelegate(incognito_profile));
362 DownloadServiceFactory::GetForBrowserContext(incognito_profile) 354 DownloadServiceFactory::GetForBrowserContext(incognito_profile)
363 ->SetDownloadManagerDelegateForTesting( 355 ->SetDownloadManagerDelegateForTesting(
364 std::move(incognito_test_delegate)); 356 std::move(incognito_test_delegate));
365 } 357 }
366 358
367 TestChromeDownloadManagerDelegate* GetIncognitoDownloadManagerDelegate() 359 TestChromeDownloadManagerDelegate* GetIncognitoDownloadManagerDelegate()
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 1300 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1309 GetNotification(notification_id_user1)->type()); 1301 GetNotification(notification_id_user1)->type());
1310 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 1302 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1311 GetNotification(notification_id_user2_1)->type()); 1303 GetNotification(notification_id_user2_1)->type());
1312 // Normal notifications for user2. 1304 // Normal notifications for user2.
1313 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 1305 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1314 GetNotification(notification_id_user2_1)->type()); 1306 GetNotification(notification_id_user2_1)->type());
1315 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT, 1307 EXPECT_EQ(message_center::NOTIFICATION_TYPE_BASE_FORMAT,
1316 GetNotification(notification_id_user2_2)->type()); 1308 GetNotification(notification_id_user2_2)->type());
1317 } 1309 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner_unittest.cc ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698