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

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

Issue 7833042: Finalize a CL originally by departed intern ycxiao@ that detaches the loading of cookies from the... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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/file_path.h" 6 #include "base/file_path.h"
6 #include "base/stl_util.h" 7 #include "base/stl_util.h"
7 #include "base/test/thread_test_helper.h" 8 #include "base/test/thread_test_helper.h"
8 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" 9 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
9 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
10 #include "chrome/test/automation/automation_proxy.h" 11 #include "chrome/test/automation/automation_proxy.h"
11 #include "chrome/test/automation/browser_proxy.h" 12 #include "chrome/test/automation/browser_proxy.h"
12 #include "chrome/test/automation/tab_proxy.h" 13 #include "chrome/test/automation/tab_proxy.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
14 #include "chrome/test/ui/ui_test.h" 15 #include "chrome/test/ui/ui_test.h"
15 #include "content/browser/browser_thread.h" 16 #include "content/browser/browser_thread.h"
16 17
17 class FastShutdown : public UITest { 18 class FastShutdown : public UITest {
18 protected: 19 protected:
19 FastShutdown() 20 FastShutdown()
20 : db_thread_(BrowserThread::DB), 21 : db_thread_(BrowserThread::DB),
22 io_thread_(BrowserThread::IO),
21 thread_helper_(new base::ThreadTestHelper( 23 thread_helper_(new base::ThreadTestHelper(
22 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))) { 24 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))) {
23 dom_automation_enabled_ = true; 25 dom_automation_enabled_ = true;
24 } 26 }
25 27
26 void Init() { 28 void Init() {
27 ASSERT_TRUE(db_thread_.Start()); 29 ASSERT_TRUE(db_thread_.Start());
28 30 ASSERT_TRUE(io_thread_.Start());
29 // Cache this, so that we can still access it after the browser exits. 31 // Cache this, so that we can still access it after the browser exits.
30 user_data_dir_ = user_data_dir(); 32 user_data_dir_ = user_data_dir();
31 } 33 }
32 34
33 // Looks for the given |cookie| in the cookie store. If it exists, puts the 35 // Looks for the given |cookie| in the cookie store. If it exists, puts the
34 // cookie's value in |cookie_value| and sets |has_cookie| to true. Sets 36 // cookie's value in |cookie_value| and sets |has_cookie| to true. Sets
35 // |has_cookie| to false if the |cookie| wasn't found. 37 // |has_cookie| to false if the |cookie| wasn't found.
36 void GetCookie(const net::CookieMonster::CanonicalCookie& cookie, 38 void GetCookie(const net::CookieMonster::CanonicalCookie& cookie,
37 bool* has_cookie, std::string* cookie_value) { 39 bool* has_cookie, std::string* cookie_value) {
38 scoped_refptr<SQLitePersistentCookieStore> cookie_store( 40 scoped_refptr<SQLitePersistentCookieStore> cookie_store(
39 new SQLitePersistentCookieStore( 41 new SQLitePersistentCookieStore(
40 user_data_dir_.AppendASCII(chrome::kInitialProfile) 42 user_data_dir_.AppendASCII(chrome::kInitialProfile)
41 .Append(chrome::kCookieFilename))); 43 .Append(chrome::kCookieFilename)));
42 std::vector<net::CookieMonster::CanonicalCookie*> cookies; 44 std::vector<net::CookieMonster::CanonicalCookie*> cookies;
43 ASSERT_TRUE(cookie_store->Load(&cookies)); 45 ASSERT_TRUE(cookie_store->Load(
46 base::Bind(&FastShutdown::LoadCookiesCallback,
47 base::Unretained(this),
48 MessageLoop::current(),
49 base::Unretained(&cookies))));
50 // Will receive a QuitTask when LoadCookiesCallback is invoked.
51 MessageLoop::current()->Run();
44 *has_cookie = false; 52 *has_cookie = false;
45 for (size_t i = 0; i < cookies.size(); ++i) { 53 for (size_t i = 0; i < cookies.size(); ++i) {
46 if (cookies[i]->IsEquivalent(cookie)) { 54 if (cookies[i]->IsEquivalent(cookie)) {
47 *has_cookie = true; 55 *has_cookie = true;
48 *cookie_value = cookies[i]->Value(); 56 *cookie_value = cookies[i]->Value();
49 } 57 }
50 } 58 }
51 cookie_store = NULL; 59 cookie_store = NULL;
52 ASSERT_TRUE(thread_helper_->Run()); 60 ASSERT_TRUE(thread_helper_->Run());
53 STLDeleteElements(&cookies); 61 STLDeleteElements(&cookies);
54 } 62 }
55 63
56 private: 64 private:
57 BrowserThread db_thread_; // Used by the cookie store during its clean up. 65 void LoadCookiesCallback(
66 MessageLoop* to_notify,
67 std::vector<net::CookieMonster::CanonicalCookie*>* cookies,
68 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies_get) {
69 *cookies = cookies_get;
70 to_notify->PostTask(FROM_HERE, new MessageLoop::QuitTask());
71 }
72
73 BrowserThread db_thread_;
74 BrowserThread io_thread_;
58 scoped_refptr<base::ThreadTestHelper> thread_helper_; 75 scoped_refptr<base::ThreadTestHelper> thread_helper_;
59 FilePath user_data_dir_; 76 FilePath user_data_dir_;
60 77
61 DISALLOW_COPY_AND_ASSIGN(FastShutdown); 78 DISALLOW_COPY_AND_ASSIGN(FastShutdown);
62 }; 79 };
63 80
64 // This tests for a previous error where uninstalling an onbeforeunload handler 81 // This tests for a previous error where uninstalling an onbeforeunload handler
65 // would enable fast shutdown even if an onunload handler still existed. 82 // would enable fast shutdown even if an onunload handler still existed.
66 TEST_F(FastShutdown, SlowTermination) { 83 TEST_F(FastShutdown, SlowTermination) {
67 Init(); 84 Init();
68 85
69 // Only the name, domain and path are used in IsEquivalent(), so we don't care 86 // Only the name, domain and path are used in IsEquivalent(), so we don't care
70 // what the other fields have. 87 // what the other fields have.
71 net::CookieMonster::CanonicalCookie cookie( 88 net::CookieMonster::CanonicalCookie cookie(
72 GURL(), // url 89 GURL(), // url
73 "unloaded", // name 90 "unloaded", // name
74 "", // value 91 "", // value
75 "", // domain 92 "", // domain
76 "/", // path 93 "/", // path
77 "", // mac_key 94 "", // mac_key
78 "", // mac_algorithm 95 "", // mac_algorithm
79 base::Time(), // creation 96 base::Time(), // creation
80 base::Time(), // expiration 97 base::Time(), // expiration
81 base::Time(), // last_access 98 base::Time(), // last_access
82 false, // secure 99 false, // secure
83 false, // httponly 100 false, // httponly
84 false); // has_expires 101 false); // has_expires
85 102
86 bool has_cookie = false;
87 std::string cookie_value;
88
89 // Check that the cookie (to be set during unload) doesn't exist already.
90 GetCookie(cookie, &has_cookie, &cookie_value);
91 EXPECT_FALSE(has_cookie);
92 EXPECT_EQ("", cookie_value);
93
94 // This page has an unload handler. 103 // This page has an unload handler.
95 const FilePath dir(FILE_PATH_LITERAL("fast_shutdown")); 104 const FilePath dir(FILE_PATH_LITERAL("fast_shutdown"));
96 const FilePath file(FILE_PATH_LITERAL("on_unloader.html")); 105 const FilePath file(FILE_PATH_LITERAL("on_unloader.html"));
97 106
98 NavigateToURL(ui_test_utils::GetTestUrl(dir, file)); 107 NavigateToURL(ui_test_utils::GetTestUrl(dir, file));
99 108
100 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 109 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
101 110
102 // This page has a beforeunload handler. 111 // This page has a beforeunload handler.
103 ASSERT_TRUE(browser->GetTab(0)->ExecuteJavaScript( 112 ASSERT_TRUE(browser->GetTab(0)->ExecuteJavaScript(
104 "open('on_before_unloader.html')")); 113 "open('on_before_unloader.html')"));
105 WaitUntilTabCount(2); 114 WaitUntilTabCount(2);
106 115
107 // Close the tab, removing the one and only beforeunload handler. 116 // Close the tab, removing the one and only beforeunload handler.
108 ASSERT_TRUE(browser->GetTab(1)->Close(true)); 117 ASSERT_TRUE(browser->GetTab(1)->Close(true));
109 118
110 // Close the browser. This should launch the unload handler, which sets a 119 // Close the browser. This should launch the unload handler, which sets a
111 // cookie that's stored to disk. 120 // cookie that's stored to disk.
112 QuitBrowser(); 121 QuitBrowser();
113 122
123 bool has_cookie = false;
124 std::string cookie_value;
114 // Read the cookie and check that it has the expected value. 125 // Read the cookie and check that it has the expected value.
115 GetCookie(cookie, &has_cookie, &cookie_value); 126 GetCookie(cookie, &has_cookie, &cookie_value);
116 EXPECT_TRUE(has_cookie); 127 EXPECT_TRUE(has_cookie);
117 EXPECT_EQ("ohyeah", cookie_value); 128 EXPECT_EQ("ohyeah", cookie_value);
118 } 129 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | chrome/browser/net/cookie_policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698