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

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/memory/scoped_temp_dir.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "chrome/browser/prefs/browser_prefs.h" 11 #include "chrome/browser/prefs/browser_prefs.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/common/chrome_constants.h" 14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/testing_browser_process.h" 17 #include "chrome/test/testing_browser_process.h"
18 #include "chrome/test/testing_pref_service.h" 18 #include "chrome/test/testing_pref_service.h"
19 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
20 #include "content/common/notification_service.h" 20 #include "content/common/notification_service.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/system_monitor/system_monitor.h" 22 #include "ui/base/system_monitor/system_monitor.h"
23 23
24 class ProfileManagerTest : public testing::Test { 24 class ProfileManagerTest : public testing::Test {
25 protected: 25 protected:
26 ProfileManagerTest() 26 ProfileManagerTest()
27 : ui_thread_(BrowserThread::UI, &message_loop_), 27 : ui_thread_(BrowserThread::UI, &message_loop_),
28 file_thread_(BrowserThread::FILE, &message_loop_) { 28 file_thread_(BrowserThread::FILE, &message_loop_) {
29 } 29 }
30 30
31 virtual void SetUp() { 31 virtual void SetUp() {
32 // Name a subdirectory of the temp directory. 32 // Create a new temporary directory, and store the path
33 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); 33 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
34 test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("ProfileManagerTest")); 34 test_dir_ = temp_dir_.path();
Paweł Hajdan Jr. 2011/04/04 08:08:54 How about removing the member variable and using t
Mike West 2011/04/04 08:39:33 Two reasons: 1. This was the minimal changeset, a
Paweł Hajdan Jr. 2011/04/04 09:05:31 Makes sense, but on the other hand it may be worth
Mike West 2011/04/04 09:16:07 Fair enough, you've convinced me. :) I'll change i
35
36 // Create a fresh, empty copy of this directory.
37 file_util::Delete(test_dir_, true);
38 file_util::CreateDirectory(test_dir_);
39 35
40 // Create a local_state PrefService. 36 // Create a local_state PrefService.
41 browser::RegisterLocalState(&test_local_state_); 37 browser::RegisterLocalState(&test_local_state_);
42 TestingBrowserProcess* testing_browser_process = 38 TestingBrowserProcess* testing_browser_process =
43 static_cast<TestingBrowserProcess*>(g_browser_process); 39 static_cast<TestingBrowserProcess*>(g_browser_process);
44 testing_browser_process->SetPrefService(&test_local_state_); 40 testing_browser_process->SetPrefService(&test_local_state_);
45 } 41 }
46 42
47 virtual void TearDown() { 43 virtual void TearDown() {
48 // Clean up test directory 44 // Clean up test directory
49 ASSERT_TRUE(file_util::Delete(test_dir_, true)); 45 ASSERT_TRUE(temp_dir_.Delete());
Paweł Hajdan Jr. 2011/04/04 08:08:54 This shouldn't be necessary. That's the entire poi
Mike West 2011/04/04 08:39:33 Maybe I'm misunderstanding the mechanics here, but
Paweł Hajdan Jr. 2011/04/04 09:05:31 Yes, it does. Feel free to check with a debugger a
Mike West 2011/04/04 09:16:07 Me, for instance. :)
50 ASSERT_FALSE(file_util::PathExists(test_dir_));
51 46
52 TestingBrowserProcess* testing_browser_process = 47 TestingBrowserProcess* testing_browser_process =
53 static_cast<TestingBrowserProcess*>(g_browser_process); 48 static_cast<TestingBrowserProcess*>(g_browser_process);
54 testing_browser_process->SetPrefService(NULL); 49 testing_browser_process->SetPrefService(NULL);
55 } 50 }
56 51
57 MessageLoopForUI message_loop_; 52 MessageLoopForUI message_loop_;
58 BrowserThread ui_thread_; 53 BrowserThread ui_thread_;
59 BrowserThread file_thread_; 54 BrowserThread file_thread_;
60 55
61 // the path to temporary directory used to contain the test operations 56 // the path to temporary directory used to contain the test operations
57 ScopedTempDir temp_dir_;
Paweł Hajdan Jr. 2011/04/04 08:08:54 Please make ScopedTempDir the first member variabl
Mike West 2011/04/04 08:39:33 Done.
62 FilePath test_dir_; 58 FilePath test_dir_;
63 59
64 TestingPrefService test_local_state_; 60 TestingPrefService test_local_state_;
65 }; 61 };
66 62
67 TEST_F(ProfileManagerTest, CreateProfile) { 63 TEST_F(ProfileManagerTest, CreateProfile) {
68 FilePath source_path; 64 FilePath source_path;
69 PathService::Get(chrome::DIR_TEST_DATA, &source_path); 65 PathService::Get(chrome::DIR_TEST_DATA, &source_path);
70 source_path = source_path.Append(FILE_PATH_LITERAL("profiles")); 66 source_path = source_path.Append(FILE_PATH_LITERAL("profiles"));
71 source_path = source_path.Append(FILE_PATH_LITERAL("sample")); 67 source_path = source_path.Append(FILE_PATH_LITERAL("sample"));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 158
163 // Make sure any pending tasks run before we destroy the profiles. 159 // Make sure any pending tasks run before we destroy the profiles.
164 message_loop_.RunAllPending(); 160 message_loop_.RunAllPending();
165 161
166 profile1.reset(); 162 profile1.reset();
167 profile2.reset(); 163 profile2.reset();
168 164
169 // Make sure history cleans up correctly. 165 // Make sure history cleans up correctly.
170 message_loop_.RunAllPending(); 166 message_loop_.RunAllPending();
171 } 167 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698