| OLD | NEW |
| 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 "base/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "base/test/test_file_util.h" | 9 #include "base/test/test_file_util.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/chrome_constants.h" | 13 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/platform_util.h" | 14 #include "chrome/common/platform_util.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/automation/browser_proxy.h" | 16 #include "chrome/test/automation/browser_proxy.h" |
| 17 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
| 18 #include "chrome/test/automation/window_proxy.h" | 18 #include "chrome/test/automation/window_proxy.h" |
| 19 #include "chrome/test/ui/ui_test.h" | 19 #include "chrome/test/ui/ui_test.h" |
| 20 #include "gfx/native_widget_types.h" | 20 #include "gfx/native_widget_types.h" |
| 21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 24 #include "net/url_request/url_request_unittest.h" | 24 #include "net/url_request/url_request_unittest.h" |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Delay to let the browser shut down before trying more brutal methods. | |
| 29 static const int kWaitForTerminateMsec = 30000; | |
| 30 | |
| 31 class BrowserTest : public UITest { | 28 class BrowserTest : public UITest { |
| 32 | |
| 33 protected: | |
| 34 void TerminateBrowser() { | |
| 35 #if defined(OS_WIN) | |
| 36 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
| 37 ASSERT_TRUE(browser.get()); | |
| 38 ASSERT_TRUE(browser->TerminateSession()); | |
| 39 #elif defined(OS_POSIX) | |
| 40 // There's nothing to do here if the browser is not running. | |
| 41 if (IsBrowserRunning()) { | |
| 42 EXPECT_TRUE(automation()->SetFilteredInet(false)); | |
| 43 | |
| 44 int window_count = 0; | |
| 45 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); | |
| 46 | |
| 47 // Now, drop the automation IPC channel so that the automation provider in | |
| 48 // the browser notices and drops its reference to the browser process. | |
| 49 automation()->Disconnect(); | |
| 50 | |
| 51 EXPECT_EQ(kill(process_, SIGTERM), 0); | |
| 52 | |
| 53 // Wait for the browser process to quit. It should have quit when it got | |
| 54 // SIGTERM. | |
| 55 int timeout = kWaitForTerminateMsec; | |
| 56 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN | |
| 57 timeout = 500000; | |
| 58 #endif | |
| 59 if (!base::WaitForSingleProcess(process_, timeout)) { | |
| 60 // We need to force the browser to quit because it didn't quit fast | |
| 61 // enough. Take no chance and kill every chrome processes. | |
| 62 CleanupAppProcesses(); | |
| 63 } | |
| 64 | |
| 65 // Don't forget to close the handle | |
| 66 base::CloseProcessHandle(process_); | |
| 67 process_ = NULL; | |
| 68 } | |
| 69 #endif // OS_POSIX | |
| 70 } | |
| 71 }; | 29 }; |
| 72 | 30 |
| 73 class VisibleBrowserTest : public UITest { | 31 class VisibleBrowserTest : public UITest { |
| 74 protected: | 32 protected: |
| 75 VisibleBrowserTest() : UITest() { | 33 VisibleBrowserTest() : UITest() { |
| 76 show_window_ = true; | 34 show_window_ = true; |
| 77 } | 35 } |
| 78 }; | 36 }; |
| 79 | 37 |
| 80 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 81 // The browser should quit quickly if it receives a WM_ENDSESSION message. | 39 // The browser should quit quickly if it receives a WM_ENDSESSION message. |
| 82 TEST_F(BrowserTest, WindowsSessionEnd) { | 40 TEST_F(BrowserTest, WindowsSessionEnd) { |
| 83 #elif defined(OS_POSIX) | 41 #elif defined(OS_POSIX) |
| 84 // The browser should quit gracefully and quickly if it receives a SIGTERM. | 42 // The browser should quit gracefully and quickly if it receives a SIGTERM. |
| 85 TEST_F(BrowserTest, PosixSessionEnd) { | 43 TEST_F(BrowserTest, PosixSessionEnd) { |
| 86 #endif | 44 #endif |
| 87 #if defined(OS_WIN) || defined(OS_POSIX) | |
| 88 FilePath test_file(test_data_directory_); | 45 FilePath test_file(test_data_directory_); |
| 89 test_file = test_file.AppendASCII("title1.html"); | 46 test_file = test_file.AppendASCII("title1.html"); |
| 90 | 47 |
| 91 NavigateToURL(net::FilePathToFileURL(test_file)); | 48 NavigateToURL(net::FilePathToFileURL(test_file)); |
| 92 PlatformThread::Sleep(action_timeout_ms()); | |
| 93 | |
| 94 TerminateBrowser(); | 49 TerminateBrowser(); |
| 95 | |
| 96 PlatformThread::Sleep(action_timeout_ms()); | |
| 97 ASSERT_FALSE(IsBrowserRunning()); | 50 ASSERT_FALSE(IsBrowserRunning()); |
| 98 | 51 |
| 99 // Make sure the UMA metrics say we didn't crash. | 52 // Make sure the UMA metrics say we didn't crash. |
| 100 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); | 53 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); |
| 101 bool exited_cleanly; | 54 bool exited_cleanly; |
| 102 ASSERT_TRUE(local_prefs.get()); | 55 ASSERT_TRUE(local_prefs.get()); |
| 103 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, | 56 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, |
| 104 &exited_cleanly)); | 57 &exited_cleanly)); |
| 105 ASSERT_TRUE(exited_cleanly); | 58 ASSERT_TRUE(exited_cleanly); |
| 106 | 59 |
| 107 // And that session end was successful. | 60 // And that session end was successful. |
| 108 bool session_end_completed; | 61 bool session_end_completed; |
| 109 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted, | 62 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted, |
| 110 &session_end_completed)); | 63 &session_end_completed)); |
| 111 ASSERT_TRUE(session_end_completed); | 64 ASSERT_TRUE(session_end_completed); |
| 112 | 65 |
| 113 // Make sure session restore says we didn't crash. | 66 // Make sure session restore says we didn't crash. |
| 114 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); | 67 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); |
| 115 ASSERT_TRUE(profile_prefs.get()); | 68 ASSERT_TRUE(profile_prefs.get()); |
| 116 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, | 69 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, |
| 117 &exited_cleanly)); | 70 &exited_cleanly)); |
| 118 ASSERT_TRUE(exited_cleanly); | 71 ASSERT_TRUE(exited_cleanly); |
| 119 } | 72 } |
| 120 #endif // OS_WIN || OS_POSIX | |
| 121 | 73 |
| 122 // Test that scripts can fork a new renderer process for a tab in a particular | 74 // Test that scripts can fork a new renderer process for a tab in a particular |
| 123 // case (which matches following a link in Gmail). The script must open a new | 75 // case (which matches following a link in Gmail). The script must open a new |
| 124 // tab, set its window.opener to null, and redirect it to a cross-site URL. | 76 // tab, set its window.opener to null, and redirect it to a cross-site URL. |
| 125 // (Bug 1115708) | 77 // (Bug 1115708) |
| 126 // This test can only run if V8 is in use, and not KJS, because KJS will not | 78 // This test can only run if V8 is in use, and not KJS, because KJS will not |
| 127 // set window.opener to null properly. | 79 // set window.opener to null properly. |
| 128 #ifdef CHROME_V8 | 80 #ifdef CHROME_V8 |
| 129 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { | 81 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { |
| 130 // This test only works in multi-process mode | 82 // This test only works in multi-process mode |
| (...skipping 26 matching lines...) Expand all Loading... |
| 157 | 109 |
| 158 // Make sure that a new tab has been created and that we have a new renderer | 110 // Make sure that a new tab has been created and that we have a new renderer |
| 159 // process for it. | 111 // process for it. |
| 160 ASSERT_TRUE(tab->NavigateToURLAsync(fork_url)); | 112 ASSERT_TRUE(tab->NavigateToURLAsync(fork_url)); |
| 161 PlatformThread::Sleep(action_timeout_ms()); | 113 PlatformThread::Sleep(action_timeout_ms()); |
| 162 ASSERT_EQ(orig_process_count + 1, GetBrowserProcessCount()); | 114 ASSERT_EQ(orig_process_count + 1, GetBrowserProcessCount()); |
| 163 int new_tab_count = -1; | 115 int new_tab_count = -1; |
| 164 ASSERT_TRUE(window->GetTabCount(&new_tab_count)); | 116 ASSERT_TRUE(window->GetTabCount(&new_tab_count)); |
| 165 ASSERT_EQ(orig_tab_count + 1, new_tab_count); | 117 ASSERT_EQ(orig_tab_count + 1, new_tab_count); |
| 166 } | 118 } |
| 167 #endif | 119 #endif // CHROME_V8 |
| 168 | 120 |
| 169 // This test fails on ChromeOS (it has never been known to work on it). | 121 // This test fails on ChromeOS (it has never been known to work on it). |
| 170 // http://crbug.com/32799 | 122 // http://crbug.com/32799 |
| 171 #if defined(OS_CHROMEOS) | 123 #if defined(OS_CHROMEOS) |
| 172 #define MAYBE_OtherRedirectsDontForkProcess DISABLED_OtherRedirectsDontForkProce
ss | 124 #define MAYBE_OtherRedirectsDontForkProcess DISABLED_OtherRedirectsDontForkProce
ss |
| 173 #else | 125 #else |
| 174 #define MAYBE_OtherRedirectsDontForkProcess OtherRedirectsDontForkProcess | 126 #define MAYBE_OtherRedirectsDontForkProcess OtherRedirectsDontForkProcess |
| 175 #endif | 127 #endif |
| 176 | 128 |
| 177 // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or | 129 // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); | 210 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); |
| 259 ASSERT_TRUE(browser.get()); | 211 ASSERT_TRUE(browser.get()); |
| 260 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); | 212 scoped_refptr<TabProxy> tab = browser->GetActiveTab(); |
| 261 ASSERT_TRUE(tab.get()); | 213 ASSERT_TRUE(tab.get()); |
| 262 std::wstring title; | 214 std::wstring title; |
| 263 ASSERT_TRUE(tab->GetTabTitle(&title)); | 215 ASSERT_TRUE(tab->GetTabTitle(&title)); |
| 264 ASSERT_EQ(L"SUCCESS", title); | 216 ASSERT_EQ(L"SUCCESS", title); |
| 265 } | 217 } |
| 266 | 218 |
| 267 class SecurityTest : public UITest { | 219 class SecurityTest : public UITest { |
| 268 protected: | |
| 269 static const int kTestIntervalMs = 250; | |
| 270 static const int kTestWaitTimeoutMs = 60 * 1000; | |
| 271 }; | 220 }; |
| 272 | 221 |
| 273 TEST_F(SecurityTest, DisallowFileUrlUniversalAccessTest) { | 222 TEST_F(SecurityTest, DisallowFileUrlUniversalAccessTest) { |
| 274 scoped_refptr<TabProxy> tab(GetActiveTab()); | 223 scoped_refptr<TabProxy> tab(GetActiveTab()); |
| 275 ASSERT_TRUE(tab.get()); | 224 ASSERT_TRUE(tab.get()); |
| 276 | 225 |
| 277 FilePath test_file(test_data_directory_); | 226 FilePath test_file(test_data_directory_); |
| 278 test_file = test_file.AppendASCII("fileurl_universalaccess.html"); | 227 test_file = test_file.AppendASCII("fileurl_universalaccess.html"); |
| 279 | 228 |
| 280 GURL url = net::FilePathToFileURL(test_file); | 229 GURL url = net::FilePathToFileURL(test_file); |
| 281 ASSERT_TRUE(tab->NavigateToURL(url)); | 230 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 282 | 231 |
| 283 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 232 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 284 "status", kTestIntervalMs, kTestWaitTimeoutMs); | 233 "status", sleep_timeout_ms(), action_max_timeout_ms()); |
| 285 ASSERT_STREQ("Disallowed", value.c_str()); | 234 ASSERT_STREQ("Disallowed", value.c_str()); |
| 286 } | 235 } |
| 287 | 236 |
| 288 #if !defined(OS_MACOSX) | 237 #if !defined(OS_MACOSX) |
| 289 class KioskModeTest : public UITest { | 238 class KioskModeTest : public UITest { |
| 290 public: | 239 public: |
| 291 KioskModeTest() { | 240 KioskModeTest() { |
| 292 launch_arguments_.AppendSwitch(switches::kKioskMode); | 241 launch_arguments_.AppendSwitch(switches::kKioskMode); |
| 293 } | 242 } |
| 294 }; | 243 }; |
| 295 | 244 |
| 296 TEST_F(KioskModeTest, EnableKioskModeTest) { | 245 TEST_F(KioskModeTest, EnableKioskModeTest) { |
| 297 // Load a dummy url. | 246 // Load a dummy url. |
| 298 FilePath test_file(test_data_directory_); | 247 FilePath test_file(test_data_directory_); |
| 299 test_file = test_file.AppendASCII("title1.html"); | 248 test_file = test_file.AppendASCII("title1.html"); |
| 300 | 249 |
| 301 // Verify that the window is present. | 250 // Verify that the window is present. |
| 302 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 251 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 303 ASSERT_TRUE(browser.get()); | 252 ASSERT_TRUE(browser.get()); |
| 304 | 253 |
| 305 // Check if browser is in fullscreen mode. | 254 // Check if browser is in fullscreen mode. |
| 306 bool is_visible; | 255 bool is_visible; |
| 307 ASSERT_TRUE(browser->IsFullscreen(&is_visible)); | 256 ASSERT_TRUE(browser->IsFullscreen(&is_visible)); |
| 308 EXPECT_TRUE(is_visible); | 257 EXPECT_TRUE(is_visible); |
| 309 ASSERT_TRUE(browser->IsFullscreenBubbleVisible(&is_visible)); | 258 ASSERT_TRUE(browser->IsFullscreenBubbleVisible(&is_visible)); |
| 310 EXPECT_FALSE(is_visible); | 259 EXPECT_FALSE(is_visible); |
| 311 } | 260 } |
| 312 #endif | 261 #endif // !defined(OS_MACOSX) |
| 313 | 262 |
| 314 #if defined(OS_WIN) | 263 #if defined(OS_WIN) |
| 315 // This test verifies that Chrome can be launched with a user-data-dir path | 264 // This test verifies that Chrome can be launched with a user-data-dir path |
| 316 // which contains non ASCII characters. | 265 // which contains non ASCII characters. |
| 317 class LaunchBrowserWithNonAsciiUserDatadir : public UITest { | 266 class LaunchBrowserWithNonAsciiUserDatadir : public UITest { |
| 318 public: | 267 public: |
| 319 void SetUp() { | 268 void SetUp() { |
| 320 PathService::Get(base::DIR_TEMP, &tmp_profile_); | 269 PathService::Get(base::DIR_TEMP, &tmp_profile_); |
| 321 tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile"); | 270 tmp_profile_ = tmp_profile_.AppendASCII("tmp_profile"); |
| 322 tmp_profile_ = tmp_profile_.Append(L"Test Chrome Géraldine"); | 271 tmp_profile_ = tmp_profile_.Append(L"Test Chrome Géraldine"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 342 public: | 291 public: |
| 343 FilePath tmp_profile_; | 292 FilePath tmp_profile_; |
| 344 }; | 293 }; |
| 345 | 294 |
| 346 TEST_F(LaunchBrowserWithNonAsciiUserDatadir, TestNonAsciiUserDataDir) { | 295 TEST_F(LaunchBrowserWithNonAsciiUserDatadir, TestNonAsciiUserDataDir) { |
| 347 ASSERT_TRUE(LaunchAppWithProfile()); | 296 ASSERT_TRUE(LaunchAppWithProfile()); |
| 348 // Verify that the window is present. | 297 // Verify that the window is present. |
| 349 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 350 ASSERT_TRUE(browser.get()); | 299 ASSERT_TRUE(browser.get()); |
| 351 } | 300 } |
| 352 #endif | 301 #endif // defined(OS_WIN) |
| 353 | 302 |
| 354 } // namespace | 303 } // namespace |
| OLD | NEW |