OLD | NEW |
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/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/test/thread_test_helper.h" | 8 #include "base/test/thread_test_helper.h" |
9 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 9 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // 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 |
36 // 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 |
37 // |has_cookie| to false if the |cookie| wasn't found. | 37 // |has_cookie| to false if the |cookie| wasn't found. |
38 void GetCookie(const net::CookieMonster::CanonicalCookie& cookie, | 38 void GetCookie(const net::CookieMonster::CanonicalCookie& cookie, |
39 bool* has_cookie, std::string* cookie_value) { | 39 bool* has_cookie, std::string* cookie_value) { |
40 scoped_refptr<SQLitePersistentCookieStore> cookie_store( | 40 scoped_refptr<SQLitePersistentCookieStore> cookie_store( |
41 new SQLitePersistentCookieStore( | 41 new SQLitePersistentCookieStore( |
42 user_data_dir_.AppendASCII(chrome::kInitialProfile) | 42 user_data_dir_.AppendASCII(chrome::kInitialProfile) |
43 .Append(chrome::kCookieFilename))); | 43 .Append(chrome::kCookieFilename))); |
44 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 44 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
45 cookie_store->Load( | 45 ASSERT_TRUE(cookie_store->Load( |
46 base::Bind(&FastShutdown::LoadCookiesCallback, | 46 base::Bind(&FastShutdown::LoadCookiesCallback, |
47 base::Unretained(this), | 47 base::Unretained(this), |
48 MessageLoop::current(), | 48 MessageLoop::current(), |
49 base::Unretained(&cookies))); | 49 base::Unretained(&cookies)))); |
50 // Will receive a QuitTask when LoadCookiesCallback is invoked. | 50 // Will receive a QuitTask when LoadCookiesCallback is invoked. |
51 MessageLoop::current()->Run(); | 51 MessageLoop::current()->Run(); |
52 *has_cookie = false; | 52 *has_cookie = false; |
53 for (size_t i = 0; i < cookies.size(); ++i) { | 53 for (size_t i = 0; i < cookies.size(); ++i) { |
54 if (cookies[i]->IsEquivalent(cookie)) { | 54 if (cookies[i]->IsEquivalent(cookie)) { |
55 *has_cookie = true; | 55 *has_cookie = true; |
56 *cookie_value = cookies[i]->Value(); | 56 *cookie_value = cookies[i]->Value(); |
57 } | 57 } |
58 } | 58 } |
59 cookie_store = NULL; | 59 cookie_store = NULL; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // cookie that's stored to disk. | 121 // cookie that's stored to disk. |
122 QuitBrowser(); | 122 QuitBrowser(); |
123 | 123 |
124 bool has_cookie = false; | 124 bool has_cookie = false; |
125 std::string cookie_value; | 125 std::string cookie_value; |
126 // Read the cookie and check that it has the expected value. | 126 // Read the cookie and check that it has the expected value. |
127 GetCookie(cookie, &has_cookie, &cookie_value); | 127 GetCookie(cookie, &has_cookie, &cookie_value); |
128 EXPECT_TRUE(has_cookie); | 128 EXPECT_TRUE(has_cookie); |
129 EXPECT_EQ("ohyeah", cookie_value); | 129 EXPECT_EQ("ohyeah", cookie_value); |
130 } | 130 } |
OLD | NEW |