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 "chrome/test/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 20 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | |
| 27 #include "chrome/browser/user_data_dir_extractor_win.h" | |
| 28 #endif | |
| 29 | |
| 26 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch | 30 // These tests don't apply to the Mac version; see GetCommandLineForRelaunch |
| 27 // for details. | 31 // for details. |
| 28 #if !defined(OS_MACOSX) | 32 #if !defined(OS_MACOSX) |
| 29 | 33 |
| 30 class ChromeMainTest : public InProcessBrowserTest { | 34 class ChromeMainTest : public InProcessBrowserTest { |
| 31 public: | 35 public: |
| 32 ChromeMainTest() {} | 36 ChromeMainTest() {} |
| 33 | 37 |
| 34 void Relaunch(const CommandLine& new_command_line) { | 38 void Relaunch(const CommandLine& new_command_line) { |
| 35 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); | 39 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 content::NotificationService::AllSources()); | 133 content::NotificationService::AllSources()); |
| 130 Relaunch(new_command_line); | 134 Relaunch(new_command_line); |
| 131 tab_observer.Wait(); | 135 tab_observer.Wait(); |
| 132 | 136 |
| 133 // There should be one normal and one incognito window now. | 137 // There should be one normal and one incognito window now. |
| 134 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); | 138 ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
| 135 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); | 139 ASSERT_EQ(1u, chrome::GetTabbedBrowserCount(profile, host_desktop_type)); |
| 136 } | 140 } |
| 137 | 141 |
| 138 #endif // !OS_MACOSX | 142 #endif // !OS_MACOSX |
| 143 | |
| 144 // These tests only apply to the Windows version; see chrome_browser_main.cc: | |
| 145 // function GetUserDataDir() for details. | |
| 146 #if defined(OS_WIN) | |
| 147 class ChromeMainUserDataDirTest : public InProcessBrowserTest { | |
|
sky
2013/03/25 15:43:14
Move this to user_data_dir_extractor_win_browserte
hshi1
2013/03/25 17:18:55
Done.
| |
| 148 public: | |
| 149 ChromeMainUserDataDirTest(): callback_invoked_(false) {} | |
|
sky
2013/03/25 15:43:14
nit: space between () and :
| |
| 150 | |
| 151 bool is_callback_invoked() { return callback_invoked_; } | |
|
sky
2013/03/25 15:43:14
field should either be named is_callback_invoked_
hshi1
2013/03/25 17:18:55
Done.
| |
| 152 void ShowUserDataDirDialog() { | |
|
sky
2013/03/25 15:43:14
Move to private.
hshi1
2013/03/25 17:18:55
Done.
| |
| 153 // Set callback invoked flag and restore the correct user data dir. | |
| 154 callback_invoked_ = true; | |
| 155 PathService::Override(chrome::DIR_USER_DATA, user_data_dir_); | |
| 156 } | |
| 157 | |
| 158 protected: | |
| 159 base::FilePath user_data_dir_; | |
|
sky
2013/03/25 15:43:14
fields at end of section.
hshi1
2013/03/25 17:18:55
Done.
| |
| 160 base::Closure callback_; | |
| 161 bool callback_invoked_; | |
| 162 | |
| 163 virtual void SetUp() OVERRIDE { | |
| 164 InProcessBrowserTest::SetUp(); | |
| 165 | |
| 166 // Save the actual user data dir. | |
| 167 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_); | |
| 168 | |
| 169 // Override user data dir to a bogus value. Make sure to set |create| flag | |
| 170 // to false so that PathService::OverrideAndCreateIfNeeded does not create | |
| 171 // a folder at this path. | |
| 172 base::FilePath bogus_user_data_dir("/bogus/should/not/exist"); | |
| 173 PathService::OverrideAndCreateIfNeeded(chrome::DIR_USER_DATA, | |
| 174 bogus_user_data_dir, | |
| 175 false); | |
| 176 | |
| 177 // Install custom ShowUserDataDirDialog callback. | |
| 178 callback_ = base::Bind(&ChromeMainUserDataDirTest::ShowUserDataDirDialog, | |
| 179 this); | |
| 180 chrome::InstallCustomShowUserDataDirDialogCallbackForTest(&callback_); | |
| 181 } | |
| 182 }; | |
|
sky
2013/03/25 15:43:14
private:: DISALLOW...
hshi1
2013/03/25 17:18:55
Done.
| |
| 183 | |
| 184 IN_PROC_BROWSER_TEST_F(ChromeMainUserDataDirTest, BogusUserDataDir) { | |
| 185 // The ShowUserDataDirDialog should have been invoked and we did not crash. | |
| 186 ASSERT_TRUE(is_callback_invoked()); | |
| 187 } | |
| 188 #endif // OS_WIN | |
| OLD | NEW |