Commit 2421393b authored by achuith@chromium.org's avatar achuith@chromium.org

UI test for browser termination with beforeunload handler and some cleanup.

This test will pass only after http://codereview.chromium.org/8262009 lands.
* Rename CloseAllBrowsersAndExitPosted to ExitPosted.
* Add VerifyCleanExit to UITest, code which existed in BrowserTest.SessionEnd.
* Move ui tests in browser_uitest.cc to non-anonymous namespace; the test names need to be unique.
* Create UnloadTest.BrowserTerminateBeforeUnload which sets up onbeforeunload handler and sends a SIGTERM.

BUG=chromium-os:21961
TEST=UnloadTest.BrowserTerminateBeforeUnload passes.
Review URL: http://codereview.chromium.org/8376001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107163 0039d316-1c4b-4281-b951-d872f2087c98
parent 06a76685
......@@ -105,7 +105,7 @@ NOINLINE void ShutdownFDClosedError() {
sleep(UINT_MAX);
}
NOINLINE void CloseAllBrowsersAndExitPosted() {
NOINLINE void ExitPosted() {
// Ensure function isn't optimized away.
asm("");
sleep(UINT_MAX);
......@@ -161,7 +161,7 @@ void ShutdownDetector::ThreadMain() {
RAW_LOG(WARNING, "Still here, exiting really ungracefully.");
_exit(signal | (1 << 7));
}
CloseAllBrowsersAndExitPosted();
ExitPosted();
}
// Sets the file descriptor soft limit to |max_descriptors| or the OS hard
......
......@@ -15,7 +15,6 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
......@@ -39,39 +38,17 @@ class VisibleBrowserTest : public UITest {
}
};
#if defined(OS_WIN)
// The browser should quit quickly if it receives a WM_ENDSESSION message.
TEST_F(BrowserTest, WindowsSessionEnd) {
#elif defined(OS_POSIX)
// The browser should quit gracefully and quickly if it receives a SIGTERM.
TEST_F(BrowserTest, PosixSessionEnd) {
#endif
} // namespace
// The browser should quit quickly if it receives a WM_ENDSESSION message
// on Windows, or SIGTERM on posix.
TEST_F(BrowserTest, SessionEnd) {
FilePath test_file(test_data_directory_);
test_file = test_file.AppendASCII("title1.html");
NavigateToURL(net::FilePathToFileURL(test_file));
TerminateBrowser();
// Make sure the UMA metrics say we didn't crash.
scoped_ptr<DictionaryValue> local_prefs(GetLocalState());
bool exited_cleanly;
ASSERT_TRUE(local_prefs.get());
ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly,
&exited_cleanly));
ASSERT_TRUE(exited_cleanly);
// And that session end was successful.
bool session_end_completed;
ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted,
&session_end_completed));
ASSERT_TRUE(session_end_completed);
// Make sure session restore says we didn't crash.
scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences());
ASSERT_TRUE(profile_prefs.get());
ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly,
&exited_cleanly));
ASSERT_TRUE(exited_cleanly);
VerifyCleanExit();
}
// WindowOpenClose is flaky on ChromeOS and fails consistently on linux views.
......@@ -248,8 +225,6 @@ TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) {
EXPECT_EQ(1, window_count);
}
} // namespace
// This test needs to be placed outside the anonymouse namespace because we
// need to access private type of Browser.
class AppModeTest : public UITest {
......
......@@ -315,6 +315,18 @@ TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
}
// Tests terminating the browser with a beforeunload handler.
// Currently only ChromeOS shuts down gracefully.
#if defined(OS_CHROMEOS)
TEST_F(UnloadTest, BrowserTerminateBeforeUnload) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
TerminateBrowser();
VerifyCleanExit();
}
#endif
#if defined(OS_LINUX)
// Fails sometimes on Linux valgrind. http://crbug.com/45675
#define MAYBE_BrowserCloseWithInnerFocusedFrame \
......
......@@ -37,6 +37,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
......@@ -801,3 +802,28 @@ bool UITest::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser,
ADD_FAILURE() << "Timeout reached in " << __FUNCTION__;
return false;
}
// TODO(achuith): Call VerifyCleanExit from TerminateBrowser.
// http://crbug.com/101390
void UITest::VerifyCleanExit() {
// Make sure the UMA metrics say we didn't crash.
scoped_ptr<DictionaryValue> local_prefs(GetLocalState());
bool exited_cleanly;
ASSERT_TRUE(local_prefs.get());
ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly,
&exited_cleanly));
ASSERT_TRUE(exited_cleanly);
// And that session end was successful.
bool session_end_completed;
ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilitySessionEndCompleted,
&session_end_completed));
ASSERT_TRUE(session_end_completed);
// Make sure session restore says we didn't crash.
scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences());
ASSERT_TRUE(profile_prefs.get());
ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly,
&exited_cleanly));
ASSERT_TRUE(exited_cleanly);
}
......@@ -470,6 +470,9 @@ class UITest : public UITestBase, public PlatformTest {
// Terminates the browser, simulates end of session.
void TerminateBrowser();
// Verify that the browser exited cleanly.
void VerifyCleanExit();
// Tells the browser to navigate to the given URL in the active tab
// of the first app window.
// Does not wait for the navigation to complete to return.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment