diff options
author | ojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 01:18:56 +0000 |
---|---|---|
committer | ojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-06 01:18:56 +0000 |
commit | d878bab389753cb876231717217a7e470b5a261f (patch) | |
tree | 1f806e2126df04174e396755994ad9f2eec87c7c /chrome/browser/unload_uitest.cc | |
parent | dcc8f1c678af98247adc7a056ace7e6c145ed189 (diff) | |
download | chromium_src-d878bab389753cb876231717217a7e470b5a261f.zip chromium_src-d878bab389753cb876231717217a7e470b5a261f.tar.gz chromium_src-d878bab389753cb876231717217a7e470b5a261f.tar.bz2 |
Bandaid patch so that we continue with crosssite navigations instead of closing the tab if the beforeunload /unload handler hangs. This patch does the right user-visible behavior, but I'm not a huge fan of the plumbing necessary to make it work. Totally open to cleanup suggestions.
There's also currently one bug that I haven't been able to pinpoint in the UI test. It only treats the first UI test of the four that I run as a cross-site navigation. No matter which test I run first. I wonder if there is some state I should be setting/clearing before/after each test run?
Also there's a DHECK that we hit that the UI test exposed. I 'm not sure it's a case that a user could actually hit though and it's not new with this code, so I added a TODO.
Can I get help from a mac person on adding the UI test to the xcode project?
BUG=3198
Review URL: http://codereview.chromium.org/8920
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4855 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/unload_uitest.cc')
-rw-r--r-- | chrome/browser/unload_uitest.cc | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/chrome/browser/unload_uitest.cc b/chrome/browser/unload_uitest.cc new file mode 100644 index 0000000..61f9024 --- /dev/null +++ b/chrome/browser/unload_uitest.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2006-2008 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 "base/file_util.h" + +#include "chrome/browser/automation/url_request_mock_http_job.h" +#include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/ui/ui_test.h" +#include "net/url_request/url_request_unittest.h" + +class UnloadTest : public UITest { + public: + void CheckTitle(const std::wstring& expected_title) { + const int kCheckDelayMs = 100; + int max_wait_time = 5000; + while (max_wait_time > 0) { + max_wait_time -= kCheckDelayMs; + Sleep(kCheckDelayMs); + if (expected_title == GetActiveTabTitle()) + break; + } + + EXPECT_EQ(expected_title, GetActiveTabTitle()); + } + + void NavigateToUnloadFileUsingTestServer(const std::wstring& test_filename, + const std::wstring& expected_title) { + const wchar_t kDocRoot[] = L"chrome/test/data"; + TestServer server(kDocRoot); + + std::wstring test_file = L"files/unload/"; + file_util::AppendToPath(&test_file, test_filename); + + GURL url(server.TestServerPageW(test_file)); + NavigateToURL(url); + + CheckTitle(expected_title); + } + + void NavigateToNolistenersFileTwice() { + NavigateToURL( + URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html")); + CheckTitle(L"nolisteners"); + NavigateToURL( + URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html")); + CheckTitle(L"nolisteners"); + } + + void NavigateToNolistenersFileTwiceAsync() { + // TODO(ojan): We hit a DCHECK in RenderViewHost::OnMsgShouldCloseACK + // if we don't sleep here. + Sleep(400); + NavigateToURLAsync( + URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html")); + Sleep(400); + NavigateToURLAsync( + URLRequestMockHTTPJob::GetMockUrl(L"unload/nolisteners.html")); + + Sleep(2000); + + CheckTitle(L"nolisteners"); + } +}; + +// Navigate to a page with an infinite unload handler. +// Then two two async crosssite requests to ensure +// we don't get confused and think we're closing the tab. +TEST_F(UnloadTest, CrossSiteInfiniteUnloadAsync) { + NavigateToUnloadFileUsingTestServer(L"unloadlooping.html", L"unloadlooping"); + NavigateToNolistenersFileTwiceAsync(); + ASSERT_TRUE(IsBrowserRunning()); +} + +// Navigate to a page with an infinite unload handler. +// Then two two sync crosssite requests to ensure +// we correctly nav to each one. +TEST_F(UnloadTest, CrossSiteInfiniteUnloadSync) { + NavigateToUnloadFileUsingTestServer(L"unloadlooping.html", L"unloadlooping"); + NavigateToNolistenersFileTwice(); + ASSERT_TRUE(IsBrowserRunning()); +} + +// Navigate to a page with an infinite beforeunload handler. +// Then two two async crosssite requests to ensure +// we don't get confused and think we're closing the tab. +TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadAsync) { + NavigateToUnloadFileUsingTestServer(L"beforeunloadlooping.html", + L"beforeunloadlooping"); + NavigateToNolistenersFileTwiceAsync(); + ASSERT_TRUE(IsBrowserRunning()); +} + +// Navigate to a page with an infinite beforeunload handler. +// Then two two sync crosssite requests to ensure +// we correctly nav to each one. +TEST_F(UnloadTest, CrossSiteInfiniteBeforeUnloadSync) { + NavigateToUnloadFileUsingTestServer(L"beforeunloadlooping.html", + L"beforeunloadlooping"); + NavigateToNolistenersFileTwice(); + ASSERT_TRUE(IsBrowserRunning()); +} |