Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: chrome/browser/fast_shutdown_browsertest.cc

Issue 10875045: Rewrite the cookies pyauto test as browser tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/test/automation/automation_proxy.h" 16 #include "chrome/test/automation/automation_proxy.h"
16 #include "chrome/test/automation/browser_proxy.h" 17 #include "chrome/test/automation/browser_proxy.h"
17 #include "chrome/test/automation/tab_proxy.h" 18 #include "chrome/test/automation/tab_proxy.h"
18 #include "chrome/test/base/in_process_browser_test.h" 19 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 #include "net/cookies/cookie_store.h" 23 #include "content/public/test/browser_test_utils.h"
23 #include "net/url_request/url_request_context.h"
24 #include "net/url_request/url_request_context_getter.h"
25 24
26 using content::BrowserThread; 25 using content::BrowserThread;
27 26
28 namespace {
29
30 void GetCookiesCallback(std::string* cookies_out,
31 base::WaitableEvent* event,
32 const std::string& cookies) {
33 *cookies_out = cookies;
34 event->Signal();
35 }
36
37 void GetCookiesOnIOThread(const GURL& url,
38 net::URLRequestContextGetter* context_getter,
39 base::WaitableEvent* event,
40 std::string* cookies) {
41 net::CookieStore* cookie_store =
42 context_getter->GetURLRequestContext()->cookie_store();
43 cookie_store->GetCookiesWithOptionsAsync(
44 url, net::CookieOptions(),
45 base::Bind(&GetCookiesCallback,
46 base::Unretained(cookies), base::Unretained(event)));
47 }
48
49 } // namespace
50
51 class FastShutdown : public InProcessBrowserTest { 27 class FastShutdown : public InProcessBrowserTest {
52 protected: 28 protected:
53 FastShutdown() { 29 FastShutdown() {
54 } 30 }
55 31
56 std::string GetCookies(const GURL& url) {
57 std::string cookies;
58 base::WaitableEvent event(true, false);
59 net::URLRequestContextGetter* context_getter =
60 browser()->profile()->GetRequestContext();
61
62 BrowserThread::PostTask(
63 BrowserThread::IO, FROM_HERE,
64 base::Bind(&GetCookiesOnIOThread, url,
65 make_scoped_refptr(context_getter), &event, &cookies));
66 event.Wait();
67 return cookies;
68 }
69
70 virtual void SetUpCommandLine(CommandLine* command_line) { 32 virtual void SetUpCommandLine(CommandLine* command_line) {
71 command_line->AppendSwitch(switches::kDisablePopupBlocking); 33 command_line->AppendSwitch(switches::kDisablePopupBlocking);
72 } 34 }
73 35
74 private: 36 private:
75 DISALLOW_COPY_AND_ASSIGN(FastShutdown); 37 DISALLOW_COPY_AND_ASSIGN(FastShutdown);
76 }; 38 };
77 39
78 // This tests for a previous error where uninstalling an onbeforeunload handler 40 // This tests for a previous error where uninstalling an onbeforeunload handler
79 // would enable fast shutdown even if an onunload handler still existed. 41 // would enable fast shutdown even if an onunload handler still existed.
80 // Flaky on all platforms, http://crbug.com/89173 42 // Flaky on all platforms, http://crbug.com/89173
81 #if !defined(OS_CHROMEOS) // ChromeOS opens tabs instead of windows for popups. 43 #if !defined(OS_CHROMEOS) // ChromeOS opens tabs instead of windows for popups.
82 IN_PROC_BROWSER_TEST_F(FastShutdown, SlowTermination) { 44 IN_PROC_BROWSER_TEST_F(FastShutdown, SlowTermination) {
83 // Need to run these tests on http:// since we only allow cookies on that (and 45 // Need to run these tests on http:// since we only allow cookies on that (and
84 // https obviously). 46 // https obviously).
85 ASSERT_TRUE(test_server()->Start()); 47 ASSERT_TRUE(test_server()->Start());
86 // This page has an unload handler. 48 // This page has an unload handler.
87 GURL url = test_server()->GetURL("files/fast_shutdown/on_unloader.html"); 49 GURL url = test_server()->GetURL("files/fast_shutdown/on_unloader.html");
88 EXPECT_EQ("", GetCookies(url)); 50 TabContents* tab = chrome::GetActiveTabContents(browser());
51 EXPECT_EQ("", content::GetCookies(tab->profile(), url));
89 52
90 content::WindowedNotificationObserver window_observer( 53 content::WindowedNotificationObserver window_observer(
91 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 54 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
92 content::NotificationService::AllSources()); 55 content::NotificationService::AllSources());
93 ui_test_utils::NavigateToURLWithDisposition( 56 ui_test_utils::NavigateToURLWithDisposition(
94 browser(), url, NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE); 57 browser(), url, NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE);
95 window_observer.Wait(); 58 window_observer.Wait();
96 59
97 // Close the new window, removing the one and only beforeunload handler. 60 // Close the new window, removing the one and only beforeunload handler.
98 ASSERT_EQ(2u, BrowserList::size()); 61 ASSERT_EQ(2u, BrowserList::size());
99 BrowserList::const_iterator i = BrowserList::begin(); 62 BrowserList::const_iterator i = BrowserList::begin();
100 ++i; 63 ++i;
101 chrome::CloseWindow(*i); 64 chrome::CloseWindow(*i);
102 65
103 // Need to wait for the renderer process to shutdown to ensure that we got the 66 // Need to wait for the renderer process to shutdown to ensure that we got the
104 // set cookies IPC. 67 // set cookies IPC.
105 content::WindowedNotificationObserver renderer_shutdown_observer( 68 content::WindowedNotificationObserver renderer_shutdown_observer(
106 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 69 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
107 content::NotificationService::AllSources()); 70 content::NotificationService::AllSources());
108 // Close the tab. This should launch the unload handler, which sets a cookie 71 // Close the tab. This should launch the unload handler, which sets a cookie
109 // that's stored to disk. 72 // that's stored to disk.
110 chrome::CloseTab(browser()); 73 chrome::CloseTab(browser());
111 renderer_shutdown_observer.Wait(); 74 renderer_shutdown_observer.Wait();
112 75
113 76 EXPECT_EQ("unloaded=ohyeah", content::GetCookies(tab->profile(), url));
114 EXPECT_EQ("unloaded=ohyeah", GetCookies(url));
115 } 77 }
116 #endif 78 #endif
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_browsertest.cc ('k') | chrome/browser/net/cookie_policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698