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/file_path.h" | 6 #include "base/file_path.h" |
6 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/synchronization/waitable_event.h" | |
7 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
8 #include "base/test/thread_test_helper.h" | 10 #include "base/test/thread_test_helper.h" |
9 #include "chrome/app/chrome_command_ids.h" | 11 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 12 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
11 #include "chrome/browser/ui/view_ids.h" | 13 #include "chrome/browser/ui/view_ids.h" |
12 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
13 #include "chrome/test/automation/automation_proxy.h" | 15 #include "chrome/test/automation/automation_proxy.h" |
14 #include "chrome/test/automation/browser_proxy.h" | 16 #include "chrome/test/automation/browser_proxy.h" |
15 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
16 #include "chrome/test/automation/window_proxy.h" | 18 #include "chrome/test/automation/window_proxy.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
34 #define MAYBE_SlowTermination SlowTermination | 36 #define MAYBE_SlowTermination SlowTermination |
35 #endif | 37 #endif |
36 | 38 |
37 // Enable some temporary debugging to diagnose flakiness on Chrome OS. | 39 // Enable some temporary debugging to diagnose flakiness on Chrome OS. |
38 // http://crbug.com/89173. TODO(sreeram): Delete this soon! | 40 // http://crbug.com/89173. TODO(sreeram): Delete this soon! |
39 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
40 #define HERE(x) LOG(ERROR) << "Here " << (x) | 42 #define HERE(x) LOG(ERROR) << "Here " << (x) |
41 #else | 43 #else |
42 #define HERE(x) | 44 #define HERE(x) |
43 #endif | 45 #endif |
44 | 46 |
erikwright (departed)
2011/08/19 18:13:05
This test fails in a racy way due to a failure to
Randy Smith (Not in Mondays)
2011/08/19 21:40:05
Sounds good (I presume this is the test fix you me
erikwright (departed)
2011/09/06 17:34:45
As it turns out, the test could be simplified to n
| |
47 void LoadCookiesCallback( | |
48 base::WaitableEvent* event, | |
49 std::vector<net::CookieMonster::CanonicalCookie*>* cookies, | |
50 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies_get) { | |
51 *cookies = cookies_get; | |
52 event->Signal(); | |
53 } | |
54 | |
45 // Loads the cookie store from |user_data_dir|. If the given |cookie| exists, | 55 // Loads the cookie store from |user_data_dir|. If the given |cookie| exists, |
46 // puts the cookie's value in |cookie_value| and sets |has_cookie| to true. | 56 // puts the cookie's value in |cookie_value| and sets |has_cookie| to true. |
47 // Sets |has_cookie| to false if the |cookie| wasn't found. | 57 // Sets |has_cookie| to false if the |cookie| wasn't found. |
48 static void GetCookie( | 58 static void GetCookie( |
49 const FilePath& user_data_dir, | 59 const FilePath& user_data_dir, |
50 const net::CookieMonster::CanonicalCookie& cookie, | 60 const net::CookieMonster::CanonicalCookie& cookie, |
51 bool* has_cookie, | 61 bool* has_cookie, |
52 std::string* cookie_value, | 62 std::string* cookie_value, |
53 const scoped_refptr<base::ThreadTestHelper>& thread_helper) { | 63 const scoped_refptr<base::ThreadTestHelper>& thread_helper) { |
54 scoped_refptr<SQLitePersistentCookieStore> cookie_store( | 64 scoped_refptr<SQLitePersistentCookieStore> cookie_store( |
55 new SQLitePersistentCookieStore( | 65 new SQLitePersistentCookieStore( |
56 user_data_dir.AppendASCII(chrome::kNotSignedInProfile) | 66 user_data_dir.AppendASCII(chrome::kNotSignedInProfile) |
57 .Append(chrome::kCookieFilename))); | 67 .Append(chrome::kCookieFilename))); |
58 HERE(1); | 68 HERE(1); |
59 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | 69 std::vector<net::CookieMonster::CanonicalCookie*> cookies; |
60 ASSERT_TRUE(cookie_store->Load(&cookies)); | 70 base::WaitableEvent event(false, false); |
71 ASSERT_TRUE(cookie_store->Load(base::Bind(&LoadCookiesCallback, | |
72 base::Unretained(&event), | |
73 base::Unretained(&cookies)))); | |
74 event.Wait(); | |
61 HERE(2); | 75 HERE(2); |
62 *has_cookie = false; | 76 *has_cookie = false; |
63 for (size_t i = 0; i < cookies.size(); ++i) { | 77 for (size_t i = 0; i < cookies.size(); ++i) { |
64 if (cookies[i]->IsEquivalent(cookie)) { | 78 if (cookies[i]->IsEquivalent(cookie)) { |
65 *has_cookie = true; | 79 *has_cookie = true; |
66 *cookie_value = cookies[i]->Value(); | 80 *cookie_value = cookies[i]->Value(); |
67 } | 81 } |
68 } | 82 } |
69 cookie_store = NULL; | 83 cookie_store = NULL; |
70 ASSERT_TRUE(thread_helper->Run()); | 84 ASSERT_TRUE(thread_helper->Run()); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 TestTimeouts::action_max_timeout_ms(), &exit_code)); | 165 TestTimeouts::action_max_timeout_ms(), &exit_code)); |
152 HERE(24); | 166 HERE(24); |
153 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. | 167 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. |
154 | 168 |
155 // Read the cookie and check that it has the expected value. | 169 // Read the cookie and check that it has the expected value. |
156 GetCookie(user_data_dir(), cookie, &has_cookie, &cookie_value, thread_helper); | 170 GetCookie(user_data_dir(), cookie, &has_cookie, &cookie_value, thread_helper); |
157 HERE(25); | 171 HERE(25); |
158 EXPECT_TRUE(has_cookie); | 172 EXPECT_TRUE(has_cookie); |
159 EXPECT_EQ("ohyeah", cookie_value); | 173 EXPECT_EQ("ohyeah", cookie_value); |
160 } | 174 } |
OLD | NEW |