diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 22:50:39 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 22:50:39 +0000 |
commit | 0189bbd4cc569eaec4c6664109659c32fed8e4b7 (patch) | |
tree | f792f823d15a1e806d1b25d0f6d318622db6daf4 /chrome/browser/process_singleton_linux_uitest.cc | |
parent | 079487b08bf7867eb7c078b59dec61f142a42df2 (diff) | |
download | chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.zip chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.tar.gz chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.tar.bz2 |
CommandLine: rejigger how initialization works.
I'm attempting to clean up CommandLine.
This change rearranges how initialization is done. I am trying
to eliminate redundant functions; more will come in subsequent changes.
Review URL: http://codereview.chromium.org/273018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux_uitest.cc')
-rw-r--r-- | chrome/browser/process_singleton_linux_uitest.cc | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc index d7f309a..2e775f4 100644 --- a/chrome/browser/process_singleton_linux_uitest.cc +++ b/chrome/browser/process_singleton_linux_uitest.cc @@ -25,46 +25,38 @@ #include "chrome/test/ui/ui_test.h" #include "testing/gtest/include/gtest/gtest.h" -class ProcessSingletonLinuxTest : public UITest { - public: - virtual void SetUp() { - UITest::SetUp(); - old_argv_ = CommandLine::ForCurrentProcess()->argv(); - } - - virtual void TearDown() { - if (!old_argv_.empty()) { - CommandLine::Reset(); - CommandLine::Init(old_argv_); - } - UITest::TearDown(); - } - - protected: - // A helper method to call ProcessSingleton::NotifyOtherProcess(). - // |url| will be added to CommandLine for current process, so that it can be - // sent to browser process by ProcessSingleton::NotifyOtherProcess(). - ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url) { - FilePath user_data_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); - - std::vector<std::string> argv; - argv.push_back(old_argv_[0]); - argv.push_back(url); - argv.push_back("--" + WideToASCII(switches::kNoProcessSingletonDialog)); - - CommandLine::Reset(); - CommandLine::Init(argv); - - ProcessSingleton process_singleton(user_data_dir); - - // Use a short timeout to keep tests fast. - const int kTimeoutSeconds = 3; - return process_singleton.NotifyOtherProcessWithTimeout(kTimeoutSeconds); - } - - std::vector<std::string> old_argv_; -}; + +namespace { + +typedef UITest ProcessSingletonLinuxTest; + +// A helper method to call ProcessSingleton::NotifyOtherProcess(). +// |url| will be added to CommandLine for current process, so that it can be +// sent to browser process by ProcessSingleton::NotifyOtherProcess(). +ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url) { + FilePath user_data_dir; + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + + // Hack: mutate the current process's command line so we don't show a dialog. + // Note that this only works if we have no loose values on the command line, + // but that's fine for unit tests. In a UI test we disable error dialogs + // when spawning Chrome, but this test hits the ProcessSingleton directly. + CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (!cmd_line->HasSwitch(switches::kNoProcessSingletonDialog)) + cmd_line->AppendSwitch(switches::kNoProcessSingletonDialog); + + CommandLine new_cmd_line(*cmd_line); + new_cmd_line.AppendLooseValue(ASCIIToWide(url)); + + ProcessSingleton process_singleton(user_data_dir); + + // Use a short timeout to keep tests fast. + const int kTimeoutSeconds = 3; + return process_singleton.NotifyOtherProcessWithTimeout(new_cmd_line, + kTimeoutSeconds); +} + +} // namespace // Test if the socket file and symbol link created by ProcessSingletonLinux // are valid. When running this test, the ProcessSingleton object is already |