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

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

Issue 404039: Sort the origins in the cookies_tree_model by effective TLD, as opposed... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/cookies_tree_model.h" 5 #include "chrome/browser/cookies_tree_model.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "chrome/browser/net/url_request_context_getter.h" 10 #include "chrome/browser/net/url_request_context_getter.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 monster->SetCookie(GURL("http://foo2"), "B=1"); 147 monster->SetCookie(GURL("http://foo2"), "B=1");
148 monster->SetCookie(GURL("http://foo3"), "C=1"); 148 monster->SetCookie(GURL("http://foo3"), "C=1");
149 CookiesTreeModel cookies_model(profile_.get()); 149 CookiesTreeModel cookies_model(profile_.get());
150 150
151 { 151 {
152 SCOPED_TRACE("Initial State 3 cookies"); 152 SCOPED_TRACE("Initial State 3 cookies");
153 // 10 because there's the root, then foo1 -> cookies -> a, 153 // 10 because there's the root, then foo1 -> cookies -> a,
154 // foo2 -> cookies -> b, foo3 -> cookies -> c 154 // foo2 -> cookies -> b, foo3 -> cookies -> c
155 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); 155 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
156 } 156 }
157 DeleteCookie(cookies_model.GetRoot()->GetChild(0)); 157 DeleteCookie(cookies_model.GetRoot()->GetChild(0));
158 { 158 {
159 SCOPED_TRACE("First origin removed"); 159 SCOPED_TRACE("First origin removed");
160 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); 160 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
161 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); 161 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str());
162 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); 162 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount());
163 } 163 }
164 } 164 }
165 165
166 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { 166 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
167 net::CookieMonster* monster = profile_->GetCookieMonster(); 167 net::CookieMonster* monster = profile_->GetCookieMonster();
168 monster->SetCookie(GURL("http://foo1"), "A=1"); 168 monster->SetCookie(GURL("http://foo1"), "A=1");
169 monster->SetCookie(GURL("http://foo2"), "B=1"); 169 monster->SetCookie(GURL("http://foo2"), "B=1");
170 monster->SetCookie(GURL("http://foo3"), "C=1"); 170 monster->SetCookie(GURL("http://foo3"), "C=1");
171 CookiesTreeModel cookies_model(profile_.get()); 171 CookiesTreeModel cookies_model(profile_.get());
172 172
173 { 173 {
174 SCOPED_TRACE("Initial State 3 cookies"); 174 SCOPED_TRACE("Initial State 3 cookies");
175 // 10 because there's the root, then foo1 -> cookies -> a, 175 // 10 because there's the root, then foo1 -> cookies -> a,
176 // foo2 -> cookies -> b, foo3 -> cookies -> c 176 // foo2 -> cookies -> b, foo3 -> cookies -> c
177 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); 177 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
178 } 178 }
179 DeleteCookie(cookies_model.GetRoot()->GetChild(0)->GetChild(0)); 179 DeleteCookie(cookies_model.GetRoot()->GetChild(0)->GetChild(0));
180 { 180 {
181 SCOPED_TRACE("First origin removed"); 181 SCOPED_TRACE("First origin removed");
182 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); 182 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
183 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); 183 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str());
184 // 8 because in this case, the origin remains, although the COOKIES 184 // 8 because in this case, the origin remains, although the COOKIES
185 // node beneath it has been deleted. So, we have 185 // node beneath it has been deleted. So, we have
186 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c 186 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
187 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); 187 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount());
188 } 188 }
189 } 189 }
190 190
191 TEST_F(CookiesTreeModelTest, RemoveCookieNode) { 191 TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
192 net::CookieMonster* monster = profile_->GetCookieMonster(); 192 net::CookieMonster* monster = profile_->GetCookieMonster();
193 monster->SetCookie(GURL("http://foo1"), "A=1"); 193 monster->SetCookie(GURL("http://foo1"), "A=1");
194 monster->SetCookie(GURL("http://foo2"), "B=1"); 194 monster->SetCookie(GURL("http://foo2"), "B=1");
195 monster->SetCookie(GURL("http://foo3"), "C=1"); 195 monster->SetCookie(GURL("http://foo3"), "C=1");
196 CookiesTreeModel cookies_model(profile_.get()); 196 CookiesTreeModel cookies_model(profile_.get());
197 197
198 { 198 {
199 SCOPED_TRACE("Initial State 3 cookies"); 199 SCOPED_TRACE("Initial State 3 cookies");
200 // 10 because there's the root, then foo1 -> cookies -> a, 200 // 10 because there's the root, then foo1 -> cookies -> a,
201 // foo2 -> cookies -> b, foo3 -> cookies -> c 201 // foo2 -> cookies -> b, foo3 -> cookies -> c
202 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); 202 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
203 } 203 }
204 DeleteCookie(cookies_model.GetRoot()->GetChild(1)->GetChild(0)); 204 DeleteCookie(cookies_model.GetRoot()->GetChild(1)->GetChild(0));
205 { 205 {
206 SCOPED_TRACE("Second origin COOKIES node removed"); 206 SCOPED_TRACE("Second origin COOKIES node removed");
207 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); 207 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
208 EXPECT_STREQ("A,C", GetDisplayedCookies(&cookies_model).c_str()); 208 EXPECT_STREQ("A,C", GetDisplayedCookies(&cookies_model).c_str());
209 // 8 because in this case, the origin remains, although the COOKIES 209 // 8 because in this case, the origin remains, although the COOKIES
210 // node beneath it has been deleted. So, we have 210 // node beneath it has been deleted. So, we have
211 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c 211 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
212 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); 212 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount());
213 } 213 }
214 } 214 }
215 215
216 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { 216 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
217 net::CookieMonster* monster = profile_->GetCookieMonster(); 217 net::CookieMonster* monster = profile_->GetCookieMonster();
218 monster->SetCookie(GURL("http://foo1"), "A=1"); 218 monster->SetCookie(GURL("http://foo1"), "A=1");
219 monster->SetCookie(GURL("http://foo2"), "B=1"); 219 monster->SetCookie(GURL("http://foo2"), "B=1");
220 monster->SetCookie(GURL("http://foo3"), "C=1"); 220 monster->SetCookie(GURL("http://foo3"), "C=1");
221 monster->SetCookie(GURL("http://foo3"), "D=1"); 221 monster->SetCookie(GURL("http://foo3"), "D=1");
222 CookiesTreeModel cookies_model(profile_.get()); 222 CookiesTreeModel cookies_model(profile_.get());
223 223
224 { 224 {
225 SCOPED_TRACE("Initial State 4 cookies"); 225 SCOPED_TRACE("Initial State 4 cookies");
226 // 11 because there's the root, then foo1 -> cookies -> a, 226 // 11 because there's the root, then foo1 -> cookies -> a,
227 // foo2 -> cookies -> b, foo3 -> cookies -> c,d 227 // foo2 -> cookies -> b, foo3 -> cookies -> c,d
228 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); 228 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount());
229 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str()); 229 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str());
230 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); 230 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
231 } 231 }
232 DeleteCookie(cookies_model.GetRoot()->GetChild(2)); 232 DeleteCookie(cookies_model.GetRoot()->GetChild(2));
233 { 233 {
234 SCOPED_TRACE("Third origin removed"); 234 SCOPED_TRACE("Third origin removed");
235 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str()); 235 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
236 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); 236 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str());
237 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); 237 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount());
238 } 238 }
239 } 239 }
240 240
241 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { 241 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
242 net::CookieMonster* monster = profile_->GetCookieMonster(); 242 net::CookieMonster* monster = profile_->GetCookieMonster();
243 monster->SetCookie(GURL("http://foo1"), "A=1"); 243 monster->SetCookie(GURL("http://foo1"), "A=1");
244 monster->SetCookie(GURL("http://foo2"), "B=1"); 244 monster->SetCookie(GURL("http://foo2"), "B=1");
245 monster->SetCookie(GURL("http://foo3"), "C=1"); 245 monster->SetCookie(GURL("http://foo3"), "C=1");
246 monster->SetCookie(GURL("http://foo3"), "D=1"); 246 monster->SetCookie(GURL("http://foo3"), "D=1");
247 monster->SetCookie(GURL("http://foo3"), "E=1"); 247 monster->SetCookie(GURL("http://foo3"), "E=1");
248 CookiesTreeModel cookies_model(profile_.get()); 248 CookiesTreeModel cookies_model(profile_.get());
249 249
250 { 250 {
251 SCOPED_TRACE("Initial State 5 cookies"); 251 SCOPED_TRACE("Initial State 5 cookies");
252 // 11 because there's the root, then foo1 -> cookies -> a, 252 // 11 because there's the root, then foo1 -> cookies -> a,
253 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e 253 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
254 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); 254 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
255 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); 255 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
256 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 256 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
257 } 257 }
258 DeleteCookie(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> 258 DeleteCookie(cookies_model.GetRoot()->GetChild(2)->GetChild(0)->
259 GetChild(1)); 259 GetChild(1));
260 { 260 {
261 SCOPED_TRACE("Middle cookie in third origin removed"); 261 SCOPED_TRACE("Middle cookie in third origin removed");
262 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str()); 262 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str());
263 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); 263 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
264 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); 264 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount());
265 } 265 }
266 } 266 }
267 267
268 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { 268 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
269 net::CookieMonster* monster = profile_->GetCookieMonster(); 269 net::CookieMonster* monster = profile_->GetCookieMonster();
270 monster->SetCookie(GURL("http://foo1"), "A=1"); 270 monster->SetCookie(GURL("http://foo1"), "A=1");
271 monster->SetCookie(GURL("http://foo2"), "B=1"); 271 monster->SetCookie(GURL("http://foo2"), "B=1");
272 monster->SetCookie(GURL("http://foo3"), "C=1"); 272 monster->SetCookie(GURL("http://foo3"), "C=1");
273 monster->SetCookie(GURL("http://foo3"), "D=1"); 273 monster->SetCookie(GURL("http://foo3"), "D=1");
274 monster->SetCookie(GURL("http://foo3"), "E=1"); 274 monster->SetCookie(GURL("http://foo3"), "E=1");
275 CookiesTreeModel cookies_model(profile_.get()); 275 CookiesTreeModel cookies_model(profile_.get());
276 276
277 { 277 {
278 SCOPED_TRACE("Initial State 5 cookies"); 278 SCOPED_TRACE("Initial State 5 cookies");
279 // 11 because there's the root, then foo1 -> cookies -> a, 279 // 11 because there's the root, then foo1 -> cookies -> a,
280 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e 280 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
281 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); 281 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
282 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); 282 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
283 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 283 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
284 } 284 }
285 DeleteCookie(cookies_model.GetRoot()->GetChild(1)); 285 DeleteCookie(cookies_model.GetRoot()->GetChild(1));
286 { 286 {
287 SCOPED_TRACE("Second origin removed"); 287 SCOPED_TRACE("Second origin removed");
288 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); 288 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str());
289 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 289 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
290 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e 290 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e
291 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); 291 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount());
292 } 292 }
293 } 293 }
294 294
295 TEST_F(CookiesTreeModelTest, OriginOrdering) {
296 net::CookieMonster* monster = profile_->GetCookieMonster();
297 monster->SetCookie(GURL("http://a.foo2.com"), "A=1");
298 monster->SetCookie(GURL("http://foo2.com"), "B=1");
299 monster->SetCookie(GURL("http://b.foo1.com"), "C=1");
300 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;"
301 " path=/;"); // Leading dot on the foo4
302 monster->SetCookie(GURL("http://a.foo1.com"), "E=1");
303 monster->SetCookie(GURL("http://foo1.com"), "F=1");
304 monster->SetCookie(GURL("http://foo3.com"), "G=1");
305 monster->SetCookie(GURL("http://foo4.com"), "H=1");
306
307 CookiesTreeModel cookies_model(profile_.get());
308
309 {
310 SCOPED_TRACE("Initial State 8 cookies");
311 // D starts with a ., CookieMonster orders that lexicographically first
312 EXPECT_STREQ("D,E,A,C,F,B,G,H", GetMonsterCookies(monster).c_str());
313 EXPECT_STREQ("F,E,C,B,A,G,D,H",
314 GetDisplayedCookies(&cookies_model).c_str());
315 }
316 DeleteCookie(cookies_model.GetRoot()->GetChild(1)); // Delete "E"
317 {
318 SCOPED_TRACE("Second origin removed");
319 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str());
320 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str());
321 }
322 }
323
324
325
295 } // namespace 326 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698