| 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/gfx/native_widget_types.h" | 6 #include "base/gfx/native_widget_types.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/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/platform_util.h" | 13 #include "chrome/common/platform_util.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/automation/browser_proxy.h" | 15 #include "chrome/test/automation/browser_proxy.h" |
| 16 #include "chrome/test/automation/tab_proxy.h" | 16 #include "chrome/test/automation/tab_proxy.h" |
| 17 #include "chrome/test/automation/window_proxy.h" | 17 #include "chrome/test/automation/window_proxy.h" |
| 18 #include "chrome/test/ui/ui_test.h" | 18 #include "chrome/test/ui/ui_test.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 #include "net/url_request/url_request_unittest.h" | 20 #include "net/url_request/url_request_unittest.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 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Delay to let the browser shut down before trying more brutal methods. |
| 27 static const int kWaitForTerminateMsec = 30000; |
| 28 |
| 26 class BrowserTest : public UITest { | 29 class BrowserTest : public UITest { |
| 30 |
| 31 protected: |
| 32 void TerminateBrowser() { |
| 33 #if defined(OS_WIN) |
| 34 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 35 ASSERT_TRUE(browser->TerminateSession()); |
| 36 #elif defined(OS_POSIX) |
| 37 // There's nothing to do here if the browser is not running. |
| 38 if (IsBrowserRunning()) { |
| 39 automation()->SetFilteredInet(false); |
| 40 |
| 41 int window_count = 0; |
| 42 EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); |
| 43 |
| 44 // Now, drop the automation IPC channel so that the automation provider in |
| 45 // the browser notices and drops its reference to the browser process. |
| 46 automation()->Disconnect(); |
| 47 |
| 48 EXPECT_EQ(kill(process_, SIGTERM), 0); |
| 49 |
| 50 // Wait for the browser process to quit. It should have quit when it got |
| 51 // SIGTERM. |
| 52 int timeout = kWaitForTerminateMsec; |
| 53 #ifdef WAIT_FOR_DEBUGGER_ON_OPEN |
| 54 timeout = 500000; |
| 55 #endif |
| 56 if (!base::WaitForSingleProcess(process_, timeout)) { |
| 57 // We need to force the browser to quit because it didn't quit fast |
| 58 // enough. Take no chance and kill every chrome processes. |
| 59 CleanupAppProcesses(); |
| 60 } |
| 61 |
| 62 // Don't forget to close the handle |
| 63 base::CloseProcessHandle(process_); |
| 64 process_ = NULL; |
| 65 } |
| 66 #endif // OS_POSIX |
| 67 } |
| 68 |
| 27 }; | 69 }; |
| 28 | 70 |
| 29 class VisibleBrowserTest : public UITest { | 71 class VisibleBrowserTest : public UITest { |
| 30 protected: | 72 protected: |
| 31 VisibleBrowserTest() : UITest() { | 73 VisibleBrowserTest() : UITest() { |
| 32 show_window_ = true; | 74 show_window_ = true; |
| 33 } | 75 } |
| 34 }; | 76 }; |
| 35 | 77 |
| 36 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
| 37 // The browser should quit quickly if it receives a WM_ENDSESSION message. | 79 // The browser should quit quickly if it receives a WM_ENDSESSION message. |
| 38 TEST_F(BrowserTest, WindowsSessionEnd) { | 80 TEST_F(BrowserTest, WindowsSessionEnd) { |
| 81 #elif defined(OS_POSIX) |
| 82 // The browser should quit gracefully and quickly if it receives a SIGTERM. |
| 83 TEST_F(BrowserTest, PosixSessionEnd) { |
| 84 #endif |
| 85 #if defined(OS_WIN) || defined(OS_POSIX) |
| 39 FilePath test_file(test_data_directory_); | 86 FilePath test_file(test_data_directory_); |
| 40 test_file = test_file.AppendASCII("title1.html"); | 87 test_file = test_file.AppendASCII("title1.html"); |
| 41 | 88 |
| 42 NavigateToURL(net::FilePathToFileURL(test_file)); | 89 NavigateToURL(net::FilePathToFileURL(test_file)); |
| 43 PlatformThread::Sleep(action_timeout_ms()); | 90 PlatformThread::Sleep(action_timeout_ms()); |
| 44 | 91 |
| 45 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 92 TerminateBrowser(); |
| 46 ASSERT_TRUE(browser->TerminateSession()); | |
| 47 | 93 |
| 48 PlatformThread::Sleep(action_timeout_ms()); | 94 PlatformThread::Sleep(action_timeout_ms()); |
| 49 ASSERT_FALSE(IsBrowserRunning()); | 95 ASSERT_FALSE(IsBrowserRunning()); |
| 50 | 96 |
| 51 // Make sure the UMA metrics say we didn't crash. | 97 // Make sure the UMA metrics say we didn't crash. |
| 52 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); | 98 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); |
| 53 bool exited_cleanly; | 99 bool exited_cleanly; |
| 54 ASSERT_TRUE(local_prefs.get()); | 100 ASSERT_TRUE(local_prefs.get()); |
| 55 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, | 101 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, |
| 56 &exited_cleanly)); | 102 &exited_cleanly)); |
| 57 ASSERT_TRUE(exited_cleanly); | 103 ASSERT_TRUE(exited_cleanly); |
| 58 | 104 |
| 59 // And that session end was successful. | 105 // And that session end was successful. |
| 60 bool session_end_completed; | 106 bool session_end_completed; |
| 61 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted, | 107 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted, |
| 62 &session_end_completed)); | 108 &session_end_completed)); |
| 63 ASSERT_TRUE(session_end_completed); | 109 ASSERT_TRUE(session_end_completed); |
| 64 | 110 |
| 65 // Make sure session restore says we didn't crash. | 111 // Make sure session restore says we didn't crash. |
| 66 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); | 112 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); |
| 67 ASSERT_TRUE(profile_prefs.get()); | 113 ASSERT_TRUE(profile_prefs.get()); |
| 68 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, | 114 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, |
| 69 &exited_cleanly)); | 115 &exited_cleanly)); |
| 70 ASSERT_TRUE(exited_cleanly); | 116 ASSERT_TRUE(exited_cleanly); |
| 71 } | 117 } |
| 72 #endif | 118 #endif // OS_WIN || OS_POSIX |
| 73 | 119 |
| 74 // Test that scripts can fork a new renderer process for a tab in a particular | 120 // Test that scripts can fork a new renderer process for a tab in a particular |
| 75 // case (which matches following a link in Gmail). The script must open a new | 121 // case (which matches following a link in Gmail). The script must open a new |
| 76 // tab, set its window.opener to null, and redirect it to a cross-site URL. | 122 // tab, set its window.opener to null, and redirect it to a cross-site URL. |
| 77 // (Bug 1115708) | 123 // (Bug 1115708) |
| 78 // This test can only run if V8 is in use, and not KJS, because KJS will not | 124 // This test can only run if V8 is in use, and not KJS, because KJS will not |
| 79 // set window.opener to null properly. | 125 // set window.opener to null properly. |
| 80 #ifdef CHROME_V8 | 126 #ifdef CHROME_V8 |
| 81 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { | 127 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { |
| 82 // This test only works in multi-process mode | 128 // This test only works in multi-process mode |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 282 |
| 237 GURL url = net::FilePathToFileURL(test_file); | 283 GURL url = net::FilePathToFileURL(test_file); |
| 238 ASSERT_TRUE(tab->NavigateToURL(url)); | 284 ASSERT_TRUE(tab->NavigateToURL(url)); |
| 239 | 285 |
| 240 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, | 286 std::string value = WaitUntilCookieNonEmpty(tab.get(), url, |
| 241 "status", kTestIntervalMs, kTestWaitTimeoutMs); | 287 "status", kTestIntervalMs, kTestWaitTimeoutMs); |
| 242 ASSERT_STREQ("Disallowed", value.c_str()); | 288 ASSERT_STREQ("Disallowed", value.c_str()); |
| 243 } | 289 } |
| 244 | 290 |
| 245 } // namespace | 291 } // namespace |
| OLD | NEW |