summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 22:49:05 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-05 22:49:05 +0000
commitbc27b47681a01b377b9764fee9e21eb54cb6ae85 (patch)
treee44d3f72e1517f1f385a6bc82eae5bfdca7f6c1a
parente9c62e670a04b837595f0a622468de22d82f008e (diff)
downloadchromium_src-bc27b47681a01b377b9764fee9e21eb54cb6ae85.zip
chromium_src-bc27b47681a01b377b9764fee9e21eb54cb6ae85.tar.gz
chromium_src-bc27b47681a01b377b9764fee9e21eb54cb6ae85.tar.bz2
Convert FastShutdown to a browser_test and enable it in the process.
BUG=121574,89173 Review URL: https://chromiumcodereview.appspot.com/9949028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131034 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/fast_shutdown_browsertest.cc113
-rw-r--r--chrome/browser/fast_shutdown_uitest.cc134
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/data/fast_shutdown/on_unloader.html3
4 files changed, 116 insertions, 136 deletions
diff --git a/chrome/browser/fast_shutdown_browsertest.cc b/chrome/browser/fast_shutdown_browsertest.cc
new file mode 100644
index 0000000..e61dc1b
--- /dev/null
+++ b/chrome/browser/fast_shutdown_browsertest.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 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/bind.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/tab_proxy.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/common/content_switches.h"
+#include "net/cookies/cookie_store.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+
+using content::BrowserThread;
+
+namespace {
+
+void GetCookiesCallback(std::string* cookies_out,
+ base::WaitableEvent* event,
+ const std::string& cookies) {
+ *cookies_out = cookies;
+ event->Signal();
+}
+
+void GetCookiesOnIOThread(const GURL& url,
+ net::URLRequestContextGetter* context_getter,
+ base::WaitableEvent* event,
+ std::string* cookies) {
+ net::CookieStore* cookie_store =
+ context_getter->GetURLRequestContext()->cookie_store();
+ cookie_store->GetCookiesWithOptionsAsync(
+ url, net::CookieOptions(),
+ base::Bind(&GetCookiesCallback,
+ base::Unretained(cookies), base::Unretained(event)));
+}
+
+} // namespace
+
+class FastShutdown : public InProcessBrowserTest {
+ protected:
+ FastShutdown() {
+ }
+
+ std::string GetCookies(const GURL& url) {
+ std::string cookies;
+ base::WaitableEvent event(true, false);
+ net::URLRequestContextGetter* context_getter =
+ browser()->profile()->GetRequestContext();
+
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&GetCookiesOnIOThread, url,
+ make_scoped_refptr(context_getter), &event, &cookies));
+ event.Wait();
+ return cookies;
+ }
+
+ virtual void SetUpCommandLine(CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kDisablePopupBlocking);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FastShutdown);
+};
+
+// This tests for a previous error where uninstalling an onbeforeunload handler
+// would enable fast shutdown even if an onunload handler still existed.
+// Flaky on all platforms, http://crbug.com/89173
+IN_PROC_BROWSER_TEST_F(FastShutdown, SlowTermination) {
+ // Need to run these tests on http:// since we only allow cookies on that (and
+ // https obviously).
+ ASSERT_TRUE(test_server()->Start());
+ // This page has an unload handler.
+ GURL url = test_server()->GetURL("files/fast_shutdown/on_unloader.html");
+ EXPECT_EQ("", GetCookies(url));
+
+ ui_test_utils::WindowedNotificationObserver window_observer(
+ chrome::NOTIFICATION_BROWSER_WINDOW_READY,
+ content::NotificationService::AllSources());
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), url, NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE);
+ window_observer.Wait();
+
+ // Close the new window, removing the one and only beforeunload handler.
+ ASSERT_EQ(2u, BrowserList::size());
+ BrowserList::const_iterator i = BrowserList::begin();
+ ++i;
+ (*i)->CloseWindow();
+
+ // Need to wait for the renderer process to shutdown to ensure that we got the
+ // set cookies IPC.
+ ui_test_utils::WindowedNotificationObserver renderer_shutdown_observer(
+ content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
+ content::NotificationService::AllSources());
+ // Close the tab. This should launch the unload handler, which sets a cookie
+ // that's stored to disk.
+ browser()->CloseTab();
+ renderer_shutdown_observer.Wait();
+
+
+ EXPECT_EQ("unloaded=ohyeah", GetCookies(url));
+}
diff --git a/chrome/browser/fast_shutdown_uitest.cc b/chrome/browser/fast_shutdown_uitest.cc
deleted file mode 100644
index b13efa0f..0000000
--- a/chrome/browser/fast_shutdown_uitest.cc
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright (c) 2011 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/bind.h"
-#include "base/file_path.h"
-#include "base/stl_util.h"
-#include "base/test/thread_test_helper.h"
-#include "chrome/browser/net/sqlite_persistent_cookie_store.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/test/automation/automation_proxy.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/base/ui_test_utils.h"
-#include "chrome/test/ui/ui_test.h"
-#include "content/test/test_browser_thread.h"
-
-using content::BrowserThread;
-
-class FastShutdown : public UITest {
- protected:
- FastShutdown()
- : db_thread_(BrowserThread::DB),
- io_thread_(BrowserThread::IO),
- thread_helper_(new base::ThreadTestHelper(
- BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))) {
- dom_automation_enabled_ = true;
- }
-
- void Init() {
- ASSERT_TRUE(db_thread_.Start());
- ASSERT_TRUE(io_thread_.Start());
- // Cache this, so that we can still access it after the browser exits.
- user_data_dir_ = user_data_dir();
- }
-
- // Looks for the given |cookie| in the cookie store. If it exists, puts the
- // cookie's value in |cookie_value| and sets |has_cookie| to true. Sets
- // |has_cookie| to false if the |cookie| wasn't found.
- void GetCookie(const net::CookieMonster::CanonicalCookie& cookie,
- bool* has_cookie, std::string* cookie_value) {
- scoped_refptr<SQLitePersistentCookieStore> cookie_store(
- new SQLitePersistentCookieStore(
- user_data_dir_.AppendASCII(chrome::kInitialProfile)
- .Append(chrome::kCookieFilename),
- false));
- std::vector<net::CookieMonster::CanonicalCookie*> cookies;
- cookie_store->Load(
- base::Bind(&FastShutdown::LoadCookiesCallback,
- base::Unretained(this),
- MessageLoop::current(),
- base::Unretained(&cookies)));
- // Will receive a QuitTask when LoadCookiesCallback is invoked.
- MessageLoop::current()->Run();
- *has_cookie = false;
- for (size_t i = 0; i < cookies.size(); ++i) {
- if (cookies[i]->IsEquivalent(cookie)) {
- *has_cookie = true;
- *cookie_value = cookies[i]->Value();
- }
- }
- cookie_store = NULL;
- ASSERT_TRUE(thread_helper_->Run());
- STLDeleteElements(&cookies);
- }
-
- private:
- void LoadCookiesCallback(
- MessageLoop* to_notify,
- std::vector<net::CookieMonster::CanonicalCookie*>* cookies,
- const std::vector<net::CookieMonster::CanonicalCookie*>& cookies_get) {
- *cookies = cookies_get;
- to_notify->PostTask(FROM_HERE, MessageLoop::QuitClosure());
- }
-
- content::TestBrowserThread db_thread_;
- content::TestBrowserThread io_thread_;
- scoped_refptr<base::ThreadTestHelper> thread_helper_;
- FilePath user_data_dir_;
-
- DISALLOW_COPY_AND_ASSIGN(FastShutdown);
-};
-
-// This tests for a previous error where uninstalling an onbeforeunload handler
-// would enable fast shutdown even if an onunload handler still existed.
-// Flaky on all platforms, http://crbug.com/89173
-TEST_F(FastShutdown, DISABLED_SlowTermination) {
- Init();
-
- // Only the name, domain and path are used in IsEquivalent(), so we don't care
- // what the other fields have.
- net::CookieMonster::CanonicalCookie cookie(
- GURL(), // url
- "unloaded", // name
- "", // value
- "", // domain
- "/", // path
- "", // mac_key
- "", // mac_algorithm
- base::Time(), // creation
- base::Time(), // expiration
- base::Time(), // last_access
- false, // secure
- false, // httponly
- false, // has_expires
- false); // is_persistent
-
- // This page has an unload handler.
- const FilePath dir(FILE_PATH_LITERAL("fast_shutdown"));
- const FilePath file(FILE_PATH_LITERAL("on_unloader.html"));
-
- NavigateToURL(ui_test_utils::GetTestUrl(dir, file));
-
- scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
-
- // This page has a beforeunload handler.
- ASSERT_TRUE(browser->GetTab(0)->ExecuteJavaScript(
- "open('on_before_unloader.html')"));
- WaitUntilTabCount(2);
-
- // Close the tab, removing the one and only beforeunload handler.
- ASSERT_TRUE(browser->GetTab(1)->Close(true));
-
- // Close the browser. This should launch the unload handler, which sets a
- // cookie that's stored to disk.
- QuitBrowser();
-
- bool has_cookie = false;
- std::string cookie_value;
- // Read the cookie and check that it has the expected value.
- GetCookie(cookie, &has_cookie, &cookie_value);
- EXPECT_TRUE(has_cookie);
- EXPECT_EQ("ohyeah", cookie_value);
-}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index da7ff33..1684289 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -792,7 +792,6 @@
# NOTE: DON'T ADD NEW TESTS HERE!
# New tests should be browser_tests. browser_tests are sharded and are
# less flakier.
- 'browser/fast_shutdown_uitest.cc',
'browser/history/multipart_uitest.cc',
'browser/history/redirect_uitest.cc',
'browser/iframe_uitest.cc',
@@ -2894,6 +2893,7 @@
'browser/extensions/system/system_apitest.cc',
'browser/extensions/webstore_inline_install_browsertest.cc',
'browser/extensions/window_open_apitest.cc',
+ 'browser/fast_shutdown_browsertest.cc',
'browser/first_run/first_run_browsertest.cc',
'browser/first_run/try_chrome_dialog_view_browsertest.cc',
'browser/geolocation/access_token_store_browsertest.cc',
diff --git a/chrome/test/data/fast_shutdown/on_unloader.html b/chrome/test/data/fast_shutdown/on_unloader.html
index d4b67a3..b0901ba 100644
--- a/chrome/test/data/fast_shutdown/on_unloader.html
+++ b/chrome/test/data/fast_shutdown/on_unloader.html
@@ -4,4 +4,5 @@ addEventListener("unload", function() {
expires.setMinutes(expires.getMinutes() + 1);
document.cookie = "unloaded=ohyeah;path=/;expires=" + expires.toUTCString();
}, false);
-</script>
+open('on_before_unloader.html');
+</script> \ No newline at end of file