OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/mock_browsing_data_appcache_helper.h" |
10 #include "chrome/browser/mock_browsing_data_database_helper.h" | 11 #include "chrome/browser/mock_browsing_data_database_helper.h" |
11 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" | 12 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" |
12 #include "chrome/browser/net/url_request_context_getter.h" | 13 #include "chrome/browser/net/url_request_context_getter.h" |
13 #include "chrome/test/testing_profile.h" | 14 #include "chrome/test/testing_profile.h" |
14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 class CookiesTreeModelTest : public testing::Test { | 21 class CookiesTreeModelTest : public testing::Test { |
21 public: | 22 public: |
22 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { | 23 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { |
23 } | 24 } |
24 | 25 |
25 virtual ~CookiesTreeModelTest() { | 26 virtual ~CookiesTreeModelTest() { |
26 } | 27 } |
27 | 28 |
28 virtual void SetUp() { | 29 virtual void SetUp() { |
29 profile_.reset(new TestingProfile()); | 30 profile_.reset(new TestingProfile()); |
30 profile_->CreateRequestContext(); | 31 profile_->CreateRequestContext(); |
31 mock_browsing_data_database_helper_ = | 32 mock_browsing_data_database_helper_ = |
32 new MockBrowsingDataDatabaseHelper(profile_.get()); | 33 new MockBrowsingDataDatabaseHelper(profile_.get()); |
33 mock_browsing_data_local_storage_helper_ = | 34 mock_browsing_data_local_storage_helper_ = |
34 new MockBrowsingDataLocalStorageHelper(profile_.get()); | 35 new MockBrowsingDataLocalStorageHelper(profile_.get()); |
| 36 mock_browsing_data_appcache_helper_ = |
| 37 new MockBrowsingDataAppCacheHelper(profile_.get()); |
35 } | 38 } |
36 | 39 |
37 CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() { | 40 CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() { |
38 net::CookieMonster* monster = profile_->GetCookieMonster(); | 41 net::CookieMonster* monster = profile_->GetCookieMonster(); |
39 monster->SetCookie(GURL("http://foo1"), "A=1"); | 42 monster->SetCookie(GURL("http://foo1"), "A=1"); |
40 monster->SetCookie(GURL("http://foo2"), "B=1"); | 43 monster->SetCookie(GURL("http://foo2"), "B=1"); |
41 monster->SetCookie(GURL("http://foo3"), "C=1"); | 44 monster->SetCookie(GURL("http://foo3"), "C=1"); |
42 CookiesTreeModel* cookies_model = new CookiesTreeModel( | 45 CookiesTreeModel* cookies_model = new CookiesTreeModel( |
43 profile_.get(), mock_browsing_data_database_helper_, | 46 profile_.get(), mock_browsing_data_database_helper_, |
44 mock_browsing_data_local_storage_helper_); | 47 mock_browsing_data_local_storage_helper_, |
| 48 mock_browsing_data_appcache_helper_); |
45 mock_browsing_data_database_helper_->AddDatabaseSamples(); | 49 mock_browsing_data_database_helper_->AddDatabaseSamples(); |
46 mock_browsing_data_database_helper_->Notify(); | 50 mock_browsing_data_database_helper_->Notify(); |
47 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); | 51 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); |
48 mock_browsing_data_local_storage_helper_->Notify(); | 52 mock_browsing_data_local_storage_helper_->Notify(); |
49 { | 53 { |
50 SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages"); | 54 SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages"); |
51 // 22 because there's the root, then foo1 -> cookies -> a, | 55 // 22 because there's the root, then foo1 -> cookies -> a, |
52 // foo2 -> cookies -> b, foo3 -> cookies -> c, | 56 // foo2 -> cookies -> b, foo3 -> cookies -> c, |
53 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, | 57 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, |
54 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. | 58 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
(...skipping 29 matching lines...) Expand all Loading... |
84 return retval; | 88 return retval; |
85 } else { | 89 } else { |
86 if (node->GetDetailedInfo().node_type == node_type) { | 90 if (node->GetDetailedInfo().node_type == node_type) { |
87 switch (node_type) { | 91 switch (node_type) { |
88 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: | 92 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: |
89 return node->GetDetailedInfo().local_storage_info->origin + ","; | 93 return node->GetDetailedInfo().local_storage_info->origin + ","; |
90 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: | 94 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: |
91 return node->GetDetailedInfo().database_info->database_name + ","; | 95 return node->GetDetailedInfo().database_info->database_name + ","; |
92 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: | 96 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: |
93 return node->GetDetailedInfo().cookie->second.Name() + ","; | 97 return node->GetDetailedInfo().cookie->second.Name() + ","; |
| 98 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: |
| 99 return node->GetDetailedInfo().appcache_info->manifest_url.spec() + |
| 100 ","; |
94 default: | 101 default: |
95 return ""; | 102 return ""; |
96 } | 103 } |
97 } else { | 104 } else { |
98 return ""; | 105 return ""; |
99 } | 106 } |
100 } | 107 } |
101 } | 108 } |
102 | 109 |
103 std::string GetCookiesOfChildren(const CookieTreeNode* node) { | 110 std::string GetCookiesOfChildren(const CookieTreeNode* node) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 std::string GetDisplayedDatabases(CookiesTreeModel* cookies_model) { | 142 std::string GetDisplayedDatabases(CookiesTreeModel* cookies_model) { |
136 return GetDisplayedNodes(cookies_model, | 143 return GetDisplayedNodes(cookies_model, |
137 CookieTreeNode::DetailedInfo::TYPE_DATABASE); | 144 CookieTreeNode::DetailedInfo::TYPE_DATABASE); |
138 } | 145 } |
139 | 146 |
140 std::string GetDisplayedLocalStorages(CookiesTreeModel* cookies_model) { | 147 std::string GetDisplayedLocalStorages(CookiesTreeModel* cookies_model) { |
141 return GetDisplayedNodes(cookies_model, | 148 return GetDisplayedNodes(cookies_model, |
142 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); | 149 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); |
143 } | 150 } |
144 | 151 |
| 152 std::string GetDisplayedAppCaches(CookiesTreeModel* cookies_model) { |
| 153 return GetDisplayedNodes(cookies_model, |
| 154 CookieTreeNode::DetailedInfo::TYPE_APPCACHE); |
| 155 } |
| 156 |
145 // do not call on the root | 157 // do not call on the root |
146 void DeleteStoredObjects(CookieTreeNode* node) { | 158 void DeleteStoredObjects(CookieTreeNode* node) { |
147 node->DeleteStoredObjects(); | 159 node->DeleteStoredObjects(); |
148 // find the parent and index | 160 // find the parent and index |
149 CookieTreeNode* parent_node = node->GetParent(); | 161 CookieTreeNode* parent_node = node->GetParent(); |
150 DCHECK(parent_node); | 162 DCHECK(parent_node); |
151 int ct_node_index = parent_node->IndexOfChild(node); | 163 int ct_node_index = parent_node->IndexOfChild(node); |
152 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); | 164 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); |
153 } | 165 } |
154 protected: | 166 protected: |
155 MessageLoop message_loop_; | 167 MessageLoop message_loop_; |
156 ChromeThread io_thread_; | 168 ChromeThread io_thread_; |
157 | 169 |
158 scoped_ptr<TestingProfile> profile_; | 170 scoped_ptr<TestingProfile> profile_; |
159 scoped_refptr<MockBrowsingDataDatabaseHelper> | 171 scoped_refptr<MockBrowsingDataDatabaseHelper> |
160 mock_browsing_data_database_helper_; | 172 mock_browsing_data_database_helper_; |
161 scoped_refptr<MockBrowsingDataLocalStorageHelper> | 173 scoped_refptr<MockBrowsingDataLocalStorageHelper> |
162 mock_browsing_data_local_storage_helper_; | 174 mock_browsing_data_local_storage_helper_; |
| 175 scoped_refptr<MockBrowsingDataAppCacheHelper> |
| 176 mock_browsing_data_appcache_helper_; |
163 }; | 177 }; |
164 | 178 |
165 TEST_F(CookiesTreeModelTest, RemoveAll) { | 179 TEST_F(CookiesTreeModelTest, RemoveAll) { |
166 scoped_ptr<CookiesTreeModel> cookies_model( | 180 scoped_ptr<CookiesTreeModel> cookies_model( |
167 CreateCookiesTreeModelWithInitialSample()); | 181 CreateCookiesTreeModelWithInitialSample()); |
168 net::CookieMonster* monster = profile_->GetCookieMonster(); | 182 net::CookieMonster* monster = profile_->GetCookieMonster(); |
169 | 183 |
170 // Reset the selection of the first row. | 184 // Reset the selection of the first row. |
171 { | 185 { |
172 SCOPED_TRACE("Before removing"); | 186 SCOPED_TRACE("Before removing"); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 } | 334 } |
321 | 335 |
322 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { | 336 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { |
323 net::CookieMonster* monster = profile_->GetCookieMonster(); | 337 net::CookieMonster* monster = profile_->GetCookieMonster(); |
324 monster->SetCookie(GURL("http://foo1"), "A=1"); | 338 monster->SetCookie(GURL("http://foo1"), "A=1"); |
325 monster->SetCookie(GURL("http://foo2"), "B=1"); | 339 monster->SetCookie(GURL("http://foo2"), "B=1"); |
326 monster->SetCookie(GURL("http://foo3"), "C=1"); | 340 monster->SetCookie(GURL("http://foo3"), "C=1"); |
327 monster->SetCookie(GURL("http://foo3"), "D=1"); | 341 monster->SetCookie(GURL("http://foo3"), "D=1"); |
328 CookiesTreeModel cookies_model(profile_.get(), | 342 CookiesTreeModel cookies_model(profile_.get(), |
329 mock_browsing_data_database_helper_, | 343 mock_browsing_data_database_helper_, |
330 mock_browsing_data_local_storage_helper_); | 344 mock_browsing_data_local_storage_helper_, |
| 345 mock_browsing_data_appcache_helper_); |
331 mock_browsing_data_database_helper_->AddDatabaseSamples(); | 346 mock_browsing_data_database_helper_->AddDatabaseSamples(); |
332 mock_browsing_data_database_helper_->Notify(); | 347 mock_browsing_data_database_helper_->Notify(); |
333 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); | 348 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); |
334 mock_browsing_data_local_storage_helper_->Notify(); | 349 mock_browsing_data_local_storage_helper_->Notify(); |
335 | 350 |
336 { | 351 { |
337 SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages"); | 352 SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages"); |
338 // 23 because there's the root, then foo1 -> cookies -> a, | 353 // 23 because there's the root, then foo1 -> cookies -> a, |
339 // foo2 -> cookies -> b, foo3 -> cookies -> c,d | 354 // foo2 -> cookies -> b, foo3 -> cookies -> c,d |
340 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, | 355 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, |
(...skipping 17 matching lines...) Expand all Loading... |
358 | 373 |
359 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { | 374 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { |
360 net::CookieMonster* monster = profile_->GetCookieMonster(); | 375 net::CookieMonster* monster = profile_->GetCookieMonster(); |
361 monster->SetCookie(GURL("http://foo1"), "A=1"); | 376 monster->SetCookie(GURL("http://foo1"), "A=1"); |
362 monster->SetCookie(GURL("http://foo2"), "B=1"); | 377 monster->SetCookie(GURL("http://foo2"), "B=1"); |
363 monster->SetCookie(GURL("http://foo3"), "C=1"); | 378 monster->SetCookie(GURL("http://foo3"), "C=1"); |
364 monster->SetCookie(GURL("http://foo3"), "D=1"); | 379 monster->SetCookie(GURL("http://foo3"), "D=1"); |
365 monster->SetCookie(GURL("http://foo3"), "E=1"); | 380 monster->SetCookie(GURL("http://foo3"), "E=1"); |
366 CookiesTreeModel cookies_model(profile_.get(), | 381 CookiesTreeModel cookies_model(profile_.get(), |
367 mock_browsing_data_database_helper_, | 382 mock_browsing_data_database_helper_, |
368 mock_browsing_data_local_storage_helper_); | 383 mock_browsing_data_local_storage_helper_, |
| 384 mock_browsing_data_appcache_helper_); |
369 mock_browsing_data_database_helper_->AddDatabaseSamples(); | 385 mock_browsing_data_database_helper_->AddDatabaseSamples(); |
370 mock_browsing_data_database_helper_->Notify(); | 386 mock_browsing_data_database_helper_->Notify(); |
371 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); | 387 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); |
372 mock_browsing_data_local_storage_helper_->Notify(); | 388 mock_browsing_data_local_storage_helper_->Notify(); |
373 | 389 |
374 { | 390 { |
375 SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages"); | 391 SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages"); |
376 // 24 because there's the root, then foo1 -> cookies -> a, | 392 // 24 because there's the root, then foo1 -> cookies -> a, |
377 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e | 393 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
378 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, | 394 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, |
(...skipping 17 matching lines...) Expand all Loading... |
396 } | 412 } |
397 | 413 |
398 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { | 414 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { |
399 net::CookieMonster* monster = profile_->GetCookieMonster(); | 415 net::CookieMonster* monster = profile_->GetCookieMonster(); |
400 monster->SetCookie(GURL("http://foo1"), "A=1"); | 416 monster->SetCookie(GURL("http://foo1"), "A=1"); |
401 monster->SetCookie(GURL("http://foo2"), "B=1"); | 417 monster->SetCookie(GURL("http://foo2"), "B=1"); |
402 monster->SetCookie(GURL("http://foo3"), "C=1"); | 418 monster->SetCookie(GURL("http://foo3"), "C=1"); |
403 monster->SetCookie(GURL("http://foo3"), "D=1"); | 419 monster->SetCookie(GURL("http://foo3"), "D=1"); |
404 monster->SetCookie(GURL("http://foo3"), "E=1"); | 420 monster->SetCookie(GURL("http://foo3"), "E=1"); |
405 CookiesTreeModel cookies_model(profile_.get(), | 421 CookiesTreeModel cookies_model(profile_.get(), |
406 mock_browsing_data_database_helper_, | 422 mock_browsing_data_database_helper_, |
407 mock_browsing_data_local_storage_helper_); | 423 mock_browsing_data_local_storage_helper_, |
| 424 mock_browsing_data_appcache_helper_); |
408 { | 425 { |
409 SCOPED_TRACE("Initial State 5 cookies"); | 426 SCOPED_TRACE("Initial State 5 cookies"); |
410 // 11 because there's the root, then foo1 -> cookies -> a, | 427 // 11 because there's the root, then foo1 -> cookies -> a, |
411 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e | 428 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
412 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); | 429 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); |
413 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); | 430 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); |
414 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); | 431 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
415 } | 432 } |
416 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); | 433 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); |
417 { | 434 { |
(...skipping 12 matching lines...) Expand all Loading... |
430 monster->SetCookie(GURL("http://b.foo1.com"), "C=1"); | 447 monster->SetCookie(GURL("http://b.foo1.com"), "C=1"); |
431 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;" | 448 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;" |
432 " path=/;"); // Leading dot on the foo4 | 449 " path=/;"); // Leading dot on the foo4 |
433 monster->SetCookie(GURL("http://a.foo1.com"), "E=1"); | 450 monster->SetCookie(GURL("http://a.foo1.com"), "E=1"); |
434 monster->SetCookie(GURL("http://foo1.com"), "F=1"); | 451 monster->SetCookie(GURL("http://foo1.com"), "F=1"); |
435 monster->SetCookie(GURL("http://foo3.com"), "G=1"); | 452 monster->SetCookie(GURL("http://foo3.com"), "G=1"); |
436 monster->SetCookie(GURL("http://foo4.com"), "H=1"); | 453 monster->SetCookie(GURL("http://foo4.com"), "H=1"); |
437 | 454 |
438 CookiesTreeModel cookies_model(profile_.get(), | 455 CookiesTreeModel cookies_model(profile_.get(), |
439 new MockBrowsingDataDatabaseHelper(profile_.get()), | 456 new MockBrowsingDataDatabaseHelper(profile_.get()), |
440 new MockBrowsingDataLocalStorageHelper(profile_.get())); | 457 new MockBrowsingDataLocalStorageHelper(profile_.get()), |
| 458 new MockBrowsingDataAppCacheHelper(profile_.get())); |
441 | 459 |
442 { | 460 { |
443 SCOPED_TRACE("Initial State 8 cookies"); | 461 SCOPED_TRACE("Initial State 8 cookies"); |
444 // D starts with a ., CookieMonster orders that lexicographically first | 462 // D starts with a ., CookieMonster orders that lexicographically first |
445 EXPECT_STREQ("D,E,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); | 463 EXPECT_STREQ("D,E,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); |
446 EXPECT_STREQ("F,E,C,B,A,G,D,H", | 464 EXPECT_STREQ("F,E,C,B,A,G,D,H", |
447 GetDisplayedCookies(&cookies_model).c_str()); | 465 GetDisplayedCookies(&cookies_model).c_str()); |
448 } | 466 } |
449 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" | 467 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" |
450 { | 468 { |
451 SCOPED_TRACE("Second origin removed"); | 469 SCOPED_TRACE("Second origin removed"); |
452 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); | 470 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); |
453 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); | 471 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); |
454 } | 472 } |
455 } | 473 } |
456 | 474 |
457 | |
458 | |
459 } // namespace | 475 } // namespace |
OLD | NEW |