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

Side by Side Diff: chrome/test/in_process_browser_test.cc

Issue 159658: Remove duplication of DieFileDie, and move it to proper location. (Closed)
Patch Set: Created 11 years, 4 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
« no previous file with comments | « chrome/common/pref_service_uitest.cc ('k') | chrome/test/ui/ui_test.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/test/in_process_browser_test.h" 5 #include "chrome/test/in_process_browser_test.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/test_file_util.h"
11 #include "chrome/browser/browser.h" 12 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_shutdown.h" 15 #include "chrome/browser/browser_shutdown.h"
15 #include "chrome/browser/browser_window.h" 16 #include "chrome/browser/browser_window.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/browser/profile_manager.h" 18 #include "chrome/browser/profile_manager.h"
18 #include "chrome/browser/renderer_host/render_process_host.h" 19 #include "chrome/browser/renderer_host/render_process_host.h"
19 #include "chrome/browser/tab_contents/tab_contents.h" 20 #include "chrome/browser/tab_contents/tab_contents.h"
20 #if defined(OS_WIN) 21 #if defined(OS_WIN)
(...skipping 12 matching lines...) Expand all
33 34
34 const wchar_t kUnitTestShowWindows[] = L"show-windows"; 35 const wchar_t kUnitTestShowWindows[] = L"show-windows";
35 36
36 // Default delay for the time-out at which we stop the 37 // Default delay for the time-out at which we stop the
37 // inner-message loop the first time. 38 // inner-message loop the first time.
38 const int kInitialTimeoutInMS = 30000; 39 const int kInitialTimeoutInMS = 30000;
39 40
40 // Delay for sub-sequent time-outs once the initial time-out happened. 41 // Delay for sub-sequent time-outs once the initial time-out happened.
41 const int kSubsequentTimeoutInMS = 5000; 42 const int kSubsequentTimeoutInMS = 5000;
42 43
43 namespace {
44
45 bool DieFileDie(const std::wstring& file, bool recurse) {
46 if (!file_util::PathExists(file))
47 return true;
48
49 // Sometimes Delete fails, so try a few more times.
50 for (int i = 0; i < 10; ++i) {
51 if (file_util::Delete(file, recurse))
52 return true;
53 PlatformThread::Sleep(100);
54 }
55 return false;
56 }
57
58 } // namespace
59
60 InProcessBrowserTest::InProcessBrowserTest() 44 InProcessBrowserTest::InProcessBrowserTest()
61 : browser_(NULL), 45 : browser_(NULL),
62 show_window_(false), 46 show_window_(false),
63 dom_automation_enabled_(false), 47 dom_automation_enabled_(false),
64 single_process_(false), 48 single_process_(false),
65 original_single_process_(false), 49 original_single_process_(false),
66 initial_timeout_(kInitialTimeoutInMS) { 50 initial_timeout_(kInitialTimeoutInMS) {
67 } 51 }
68 52
69 void InProcessBrowserTest::SetUp() { 53 void InProcessBrowserTest::SetUp() {
70 // Cleanup the user data dir. 54 // Cleanup the user data dir.
71 std::wstring user_data_dir; 55 FilePath user_data_dir;
72 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 56 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
73 ASSERT_LT(10, static_cast<int>(user_data_dir.size())) << 57 ASSERT_LT(10, static_cast<int>(user_data_dir.value().size())) <<
74 "The user data directory name passed into this test was too " 58 "The user data directory name passed into this test was too "
75 "short to delete safely. Please check the user-data-dir " 59 "short to delete safely. Please check the user-data-dir "
76 "argument and try again."; 60 "argument and try again.";
77 ASSERT_TRUE(DieFileDie(user_data_dir, true)); 61 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true));
78 62
79 // The unit test suite creates a testingbrowser, but we want the real thing. 63 // The unit test suite creates a testingbrowser, but we want the real thing.
80 // Delete the current one. We'll install the testing one in TearDown. 64 // Delete the current one. We'll install the testing one in TearDown.
81 delete g_browser_process; 65 delete g_browser_process;
82 66
83 // Don't delete the resources when BrowserMain returns. Many ui classes 67 // Don't delete the resources when BrowserMain returns. Many ui classes
84 // cache SkBitmaps in a static field so that if we delete the resource 68 // cache SkBitmaps in a static field so that if we delete the resource
85 // bundle we'll crash. 69 // bundle we'll crash.
86 browser_shutdown::delete_resources_on_shutdown = false; 70 browser_shutdown::delete_resources_on_shutdown = false;
87 71
(...skipping 12 matching lines...) Expand all
100 command_line->AppendSwitch(switches::kDomAutomationController); 84 command_line->AppendSwitch(switches::kDomAutomationController);
101 85
102 if (single_process_) 86 if (single_process_)
103 command_line->AppendSwitch(switches::kSingleProcess); 87 command_line->AppendSwitch(switches::kSingleProcess);
104 88
105 // TODO(arv): Reenable once kEnableWebResources is changed back to 89 // TODO(arv): Reenable once kEnableWebResources is changed back to
106 // kDisableWebResources 90 // kDisableWebResources
107 // http://crbug.com/17725 91 // http://crbug.com/17725
108 // command_line->AppendSwitch(switches::kEnableWebResources); 92 // command_line->AppendSwitch(switches::kEnableWebResources);
109 93
110 command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); 94 command_line->AppendSwitchWithValue(switches::kUserDataDir,
95 user_data_dir.ToWStringHack());
111 96
112 // For some reason the sandbox wasn't happy running in test mode. These 97 // For some reason the sandbox wasn't happy running in test mode. These
113 // tests aren't intended to test the sandbox, so we turn it off. 98 // tests aren't intended to test the sandbox, so we turn it off.
114 command_line->AppendSwitch(switches::kNoSandbox); 99 command_line->AppendSwitch(switches::kNoSandbox);
115 100
116 // Don't show the first run ui. 101 // Don't show the first run ui.
117 command_line->AppendSwitch(switches::kNoFirstRun); 102 command_line->AppendSwitch(switches::kNoFirstRun);
118 103
119 // Single-process mode is not set in BrowserMain so it needs to be processed 104 // Single-process mode is not set in BrowserMain so it needs to be processed
120 // explicitlty. 105 // explicitlty.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut), 249 NewRunnableMethod(this, &InProcessBrowserTest::TimedOut),
265 kSubsequentTimeoutInMS); 250 kSubsequentTimeoutInMS);
266 251
267 MessageLoopForUI::current()->Quit(); 252 MessageLoopForUI::current()->Quit();
268 } 253 }
269 254
270 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) { 255 void InProcessBrowserTest::SetInitialTimeoutInMS(int timeout_value) {
271 DCHECK_GT(timeout_value, 0); 256 DCHECK_GT(timeout_value, 0);
272 initial_timeout_ = timeout_value; 257 initial_timeout_ = timeout_value;
273 } 258 }
OLDNEW
« no previous file with comments | « chrome/common/pref_service_uitest.cc ('k') | chrome/test/ui/ui_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698