Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "content/public/test/test_launcher.h" | 5 #include "content/public/test/test_launcher.h" |
| 6 | 6 |
| 7 #include <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/scoped_temp_dir.h" | |
| 14 #include "base/test/test_file_util.h" | 13 #include "base/test/test_file_util.h" |
| 15 #include "chrome/app/chrome_main_delegate.h" | 14 #include "chrome/app/chrome_main_delegate.h" |
| 16 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 18 #include "chrome/test/base/chrome_test_suite.h" | 17 #include "chrome/test/base/chrome_test_suite.h" |
| 19 #include "content/public/app/content_main.h" | 18 #include "content/public/app/content_main.h" |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 | 20 |
| 22 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 23 #include "chrome/browser/chrome_browser_application_mac.h" | 22 #include "chrome/browser/chrome_browser_application_mac.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 #endif // defined(OS_WIN) | 70 #endif // defined(OS_WIN) |
| 72 | 71 |
| 73 return false; | 72 return false; |
| 74 } | 73 } |
| 75 | 74 |
| 76 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { | 75 virtual int RunTestSuite(int argc, char** argv) OVERRIDE { |
| 77 return ChromeTestSuite(argc, argv).Run(); | 76 return ChromeTestSuite(argc, argv).Run(); |
| 78 } | 77 } |
| 79 | 78 |
| 80 virtual bool AdjustChildProcessCommandLine( | 79 virtual bool AdjustChildProcessCommandLine( |
| 81 CommandLine* command_line) OVERRIDE { | 80 CommandLine* command_line, const FilePath& temp_data_dir) OVERRIDE { |
| 82 CommandLine new_command_line(command_line->GetProgram()); | 81 CommandLine new_command_line(command_line->GetProgram()); |
| 83 CommandLine::SwitchMap switches = command_line->GetSwitches(); | 82 CommandLine::SwitchMap switches = command_line->GetSwitches(); |
| 84 | 83 |
| 85 // Strip out user-data-dir if present. We will add it back in again later. | 84 // Strip out user-data-dir if present. We will add it back in again later. |
| 86 switches.erase(switches::kUserDataDir); | 85 switches.erase(switches::kUserDataDir); |
| 87 | 86 |
| 88 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); | 87 for (CommandLine::SwitchMap::const_iterator iter = switches.begin(); |
| 89 iter != switches.end(); ++iter) { | 88 iter != switches.end(); ++iter) { |
| 90 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); | 89 new_command_line.AppendSwitchNative((*iter).first, (*iter).second); |
| 91 } | 90 } |
| 92 | 91 |
| 93 // Clean up previous temp dir. | 92 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir); |
| 94 // We Take() the directory and delete it ourselves so that the next | |
| 95 // CreateUniqueTempDir will succeed even if deleting the directory fails. | |
|
scottmg
2012/08/17 21:00:06
does this need to happen in test_launcher now?
jam
2012/08/17 21:08:05
no, because now it's a scoped ptr around each Adju
| |
| 96 if (!temp_dir_.path().empty() && | |
| 97 !file_util::DieFileDie(temp_dir_.Take(), true)) { | |
| 98 LOG(ERROR) << "Error deleting previous temp profile directory"; | |
| 99 } | |
| 100 | |
| 101 // Create a new user data dir and pass it to the child. | |
| 102 if (!temp_dir_.CreateUniqueTempDir() || !temp_dir_.IsValid()) { | |
| 103 LOG(ERROR) << "Error creating temp profile directory"; | |
| 104 return false; | |
| 105 } | |
| 106 new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_dir_.path()); | |
| 107 | 93 |
| 108 // file:// access for ChromeOS. | 94 // file:// access for ChromeOS. |
| 109 new_command_line.AppendSwitch(switches::kAllowFileAccess); | 95 new_command_line.AppendSwitch(switches::kAllowFileAccess); |
| 110 | 96 |
| 111 *command_line = new_command_line; | 97 *command_line = new_command_line; |
| 112 return true; | 98 return true; |
| 113 } | 99 } |
| 114 | 100 |
| 115 virtual void PreRunMessageLoop(base::RunLoop* run_loop) OVERRIDE { | 101 virtual void PreRunMessageLoop(base::RunLoop* run_loop) OVERRIDE { |
| 116 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) | 102 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) |
| 117 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 103 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 118 linked_ptr<views::AcceleratorHandler> handler( | 104 linked_ptr<views::AcceleratorHandler> handler( |
| 119 new views::AcceleratorHandler); | 105 new views::AcceleratorHandler); |
| 120 handlers_.push(handler); | 106 handlers_.push(handler); |
| 121 run_loop->set_dispatcher(handler.get()); | 107 run_loop->set_dispatcher(handler.get()); |
| 122 } | 108 } |
| 123 #endif | 109 #endif |
| 124 } | 110 } |
| 125 | 111 |
| 126 virtual void PostRunMessageLoop() { | 112 virtual void PostRunMessageLoop() { |
| 127 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) | 113 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) |
| 128 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 114 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
| 129 DCHECK_EQ(handlers_.empty(), false); | 115 DCHECK_EQ(handlers_.empty(), false); |
| 130 handlers_.pop(); | 116 handlers_.pop(); |
| 131 } | 117 } |
| 132 #endif | 118 #endif |
| 133 } | 119 } |
| 134 | 120 |
| 135 private: | 121 private: |
| 136 ScopedTempDir temp_dir_; | |
| 137 | |
| 138 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) | 122 #if !defined(USE_AURA) && defined(TOOLKIT_VIEWS) |
| 139 std::stack<linked_ptr<views::AcceleratorHandler> > handlers_; | 123 std::stack<linked_ptr<views::AcceleratorHandler> > handlers_; |
| 140 #endif | 124 #endif |
| 141 | 125 |
| 142 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); | 126 DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); |
| 143 }; | 127 }; |
| 144 | 128 |
| 145 int main(int argc, char** argv) { | 129 int main(int argc, char** argv) { |
| 146 #if defined(OS_MACOSX) | 130 #if defined(OS_MACOSX) |
| 147 chrome_browser_application_mac::RegisterBrowserCrApp(); | 131 chrome_browser_application_mac::RegisterBrowserCrApp(); |
| 148 #endif | 132 #endif |
| 149 ChromeTestLauncherDelegate launcher_delegate; | 133 ChromeTestLauncherDelegate launcher_delegate; |
| 150 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); | 134 return test_launcher::LaunchTests(&launcher_delegate, argc, argv); |
| 151 } | 135 } |
| OLD | NEW |