| Index: chrome/browser/user_data_dir_extractor_win_browsertest.cc
|
| diff --git a/chrome/browser/user_data_dir_extractor_win_browsertest.cc b/chrome/browser/user_data_dir_extractor_win_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..394d525b07b27cbb75dfaf6991f2eff0921e50e3
|
| --- /dev/null
|
| +++ b/chrome/browser/user_data_dir_extractor_win_browsertest.cc
|
| @@ -0,0 +1,76 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/test/ui/ui_test.h"
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/file_util.h"
|
| +#include "base/path_service.h"
|
| +#include "base/process_util.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/browser_commands.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "chrome/test/base/ui_test_utils.h"
|
| +
|
| +#if defined(OS_WIN)
|
| +#include "chrome/browser/user_data_dir_extractor_win.h"
|
| +#endif
|
| +
|
| +// These tests only apply to the Windows version; see chrome_browser_main.cc:
|
| +// function GetUserDataDir() for details.
|
| +#if defined(OS_WIN)
|
| +class ChromeMainUserDataDirTest : public InProcessBrowserTest {
|
| + public:
|
| + ChromeMainUserDataDirTest() : is_dialog_shown(false) {}
|
| + bool is_dialog_shown() { return is_dialog_shown_; }
|
| +
|
| + protected:
|
| + virtual void SetUp() OVERRIDE {
|
| + InProcessBrowserTest::SetUp();
|
| +
|
| + // Save the actual user data dir.
|
| + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
|
| +
|
| + // Override user data dir to a bogus value. Make sure to set |create| flag
|
| + // to false so that PathService::OverrideAndCreateIfNeeded does not create
|
| + // a folder at this path.
|
| + base::FilePath bogus_user_data_dir("/bogus/should/not/exist");
|
| + PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA,
|
| + bogus_user_data_dir,
|
| + false);
|
| +
|
| + // Install custom ShowUserDataDirDialog callback.
|
| + callback_ = base::Bind(&ChromeMainUserDataDirTest::ShowUserDataDirDialog,
|
| + this);
|
| + chrome::InstallCustomShowUserDataDirDialogCallbackForTest(&callback_);
|
| + }
|
| +
|
| + private:
|
| + base::FilePath ShowUserDataDirDialog() {
|
| + base::FilePath user_data_dir;
|
| + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
| + if (!file_util::PathExists(user_data_dir)) {
|
| + // Set dialog shown flag and restore the correct user data dir.
|
| + is_dialog_shown_ = true;
|
| + PathService::Override(chrome::DIR_USER_DATA, user_data_dir_);
|
| + user_data_dir = user_data_dir_;
|
| + }
|
| + return user_data_dir;
|
| + }
|
| +
|
| + base::FilePath user_data_dir_;
|
| + ShowUserDataDirDialogCallback callback_;
|
| + bool is_dialog_shown_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ChromeMainUserDataDirTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ChromeMainUserDataDirTest, BogusUserDataDir) {
|
| + // The user data dir should have been shown and we did not crash.
|
| + ASSERT_TRUE(is_dialog_shown());
|
| +}
|
| +#endif // OS_WIN
|
|
|