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

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

Issue 7355025: Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cookies at UI thread. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 5 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "chrome/browser/browsing_data_cookie_helper.h"
7 #include "chrome/test/in_process_browser_test.h"
8 #include "chrome/test/testing_profile.h"
9 #include "chrome/test/ui_test_utils.h"
10 #include "content/browser/browser_thread.h"
11
12 namespace {
13
14 class BrowsingDataCookieHelperTest : public InProcessBrowserTest {
15 public:
16 void CreatCookiesForTest() {
erikwright (departed) 2011/07/19 14:40:33 Creat -> Create
ycxiao1 2011/07/19 22:12:48 Done.
17 testing_profile_.CreateRequestContext();
18 scoped_refptr<net::CookieMonster> cookie_monster =
19 testing_profile_.GetCookieMonster();
20 cookie_monster->SetCookieWithOptions(
21 GURL("http://www.google.com"), "A=1", net::CookieOptions());
22 cookie_monster->SetCookieWithOptions(
23 GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions());
24 }
25
26 protected:
27 TestingProfile testing_profile_;
28 };
29
30 // Called back by BrowsingDataCookieHelper on the UI thread once the cookie
31 // information has been retrieved.
32 class StopTestOnCallback {
33 public:
34 explicit StopTestOnCallback(BrowsingDataCookieHelper* cookie_helper)
35 : cookie_helper_(cookie_helper) {
36 DCHECK(cookie_helper_);
37 }
38
39 void FetchCallback(const net::CookieList& cookies) {
erikwright (departed) 2011/07/19 14:40:33 Is there any reason why these callback methods can
ycxiao1 2011/07/19 22:12:48 Done.
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41 ASSERT_EQ(2UL, cookies.size());
42 cookie_list_ = cookies;
43 net::CookieList::const_iterator it = cookies.begin();
erikwright (departed) 2011/07/19 14:40:33 Is there any guarantee that the cookies will be de
ycxiao1 2011/07/19 22:12:48 The CookieMonster::GetAllCookies will sort the coo
44
45 ASSERT_TRUE(it != cookies.end());
46 EXPECT_EQ("www.google.com", it->Domain());
47 EXPECT_EQ("A", it->Name());
48
49 ASSERT_TRUE(++it != cookies.end());
50 EXPECT_EQ("www.gmail.google.com", it->Domain());
51 EXPECT_EQ("B", it->Name());
52
53 ASSERT_TRUE(++it == cookies.end());
54 MessageLoop::current()->Quit();
55 }
56
57 void DeleteCallback(const net::CookieList& cookies) {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59 ASSERT_EQ(1UL, cookies.size());
60 net::CookieList::const_iterator it = cookies.begin();
61
62 ASSERT_TRUE(it != cookies.end());
63 EXPECT_EQ("www.gmail.google.com", it->Domain());
64 EXPECT_EQ("B", it->Name());
65
66 ASSERT_TRUE(++it == cookies.end());
67 MessageLoop::current()->Quit();
68 }
69
70 void CannedUniqueCallback(const net::CookieList& cookies) {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72 ASSERT_EQ(1UL, cookies.size());
73 net::CookieList::const_iterator it = cookies.begin();
74
75 ASSERT_TRUE(it != cookies.end());
76 EXPECT_EQ("http://www.google.com/", it->Source());
77 EXPECT_EQ("A", it->Name());
78
79 ASSERT_TRUE(++it == cookies.end());
80 }
81
82 net::CookieList cookie_list_;
83
84 private:
85 BrowsingDataCookieHelper* cookie_helper_;
86 };
87
88 IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, FetchData) {
89 CreatCookiesForTest();
90 scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
91 new BrowsingDataCookieHelper(&testing_profile_));
92 StopTestOnCallback stop_test_on_callback(cookie_helper);
93
94 cookie_helper->StartFetching(
95 base::Bind(&StopTestOnCallback::FetchCallback,
96 base::Unretained(&stop_test_on_callback)));
97
98 // Blocks until StopTestOnCallback::Callback is notified.
99 ui_test_utils::RunMessageLoop();
100 }
101
102 IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
103 CreatCookiesForTest();
104 scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
105 new BrowsingDataCookieHelper(&testing_profile_));
106 StopTestOnCallback stop_test_on_callback(cookie_helper);
107
108 cookie_helper->StartFetching(
109 base::Bind(&StopTestOnCallback::FetchCallback,
110 base::Unretained(&stop_test_on_callback)));
111
112 // Blocks until StopTestOnCallback::Callback is notified.
113 ui_test_utils::RunMessageLoop();
114
115 net::CookieMonster::CanonicalCookie cookie =
116 stop_test_on_callback.cookie_list_[0];
117 cookie_helper->DeleteCookie(cookie);
118
119 cookie_helper->StartFetching(
120 base::Bind(&StopTestOnCallback::DeleteCallback,
121 base::Unretained(&stop_test_on_callback)));
122 ui_test_utils::RunMessageLoop();
123 }
124
125 IN_PROC_BROWSER_TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
126 const GURL origin("http://www.google.com");
127 net::CookieList cookie;
128
129 scoped_refptr<CannedBrowsingDataCookieHelper> helper(
130 new CannedBrowsingDataCookieHelper(&testing_profile_));
131 StopTestOnCallback callback(helper);
132
133 ASSERT_TRUE(helper->empty());
134 helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
135 helper->AddChangeCookie(origin, "A=1", net::CookieOptions());
136 helper->StartFetching(
137 base::Bind(&StopTestOnCallback::CannedUniqueCallback,
138 base::Unretained(&callback)));
139 cookie = helper->cookie_list();
erikwright (departed) 2011/07/19 14:40:33 If I understand correctly, you are using this acce
ycxiao1 2011/07/19 22:12:48 Done.
140 helper->Reset();
141 ASSERT_TRUE(helper->empty());
142
143 helper->AddReadCookie(origin, cookie);
144 helper->AddReadCookie(origin, cookie);
145 helper->StartFetching(
146 base::Bind(&StopTestOnCallback::CannedUniqueCallback,
147 base::Unretained(&callback)));
148 }
149
150 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698