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

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

Issue 7491049: Revert 95534 - Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cook... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | chrome/browser/mock_browsing_data_cookie_helper.h » ('j') | 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) 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 "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 "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/content_settings/mock_settings_observer.h" 10 #include "chrome/browser/content_settings/mock_settings_observer.h"
11 #include "chrome/browser/mock_browsing_data_appcache_helper.h" 11 #include "chrome/browser/mock_browsing_data_appcache_helper.h"
12 #include "chrome/browser/mock_browsing_data_cookie_helper.h"
13 #include "chrome/browser/mock_browsing_data_database_helper.h" 12 #include "chrome/browser/mock_browsing_data_database_helper.h"
14 #include "chrome/browser/mock_browsing_data_file_system_helper.h" 13 #include "chrome/browser/mock_browsing_data_file_system_helper.h"
15 #include "chrome/browser/mock_browsing_data_indexed_db_helper.h" 14 #include "chrome/browser/mock_browsing_data_indexed_db_helper.h"
16 #include "chrome/browser/mock_browsing_data_local_storage_helper.h" 15 #include "chrome/browser/mock_browsing_data_local_storage_helper.h"
17 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/testing_browser_process_test.h" 17 #include "chrome/test/testing_browser_process_test.h"
19 #include "content/common/content_notification_types.h" 18 #include "content/common/content_notification_types.h"
20 #include "content/common/notification_details.h" 19 #include "content/common/notification_details.h"
21 #include "net/url_request/url_request_context.h" 20 #include "net/url_request/url_request_context.h"
22 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
(...skipping 10 matching lines...) Expand all
33 CookiesTreeModelTest() : ui_thread_(BrowserThread::UI, &message_loop_), 32 CookiesTreeModelTest() : ui_thread_(BrowserThread::UI, &message_loop_),
34 io_thread_(BrowserThread::IO, &message_loop_) { 33 io_thread_(BrowserThread::IO, &message_loop_) {
35 } 34 }
36 35
37 virtual ~CookiesTreeModelTest() { 36 virtual ~CookiesTreeModelTest() {
38 } 37 }
39 38
40 virtual void SetUp() { 39 virtual void SetUp() {
41 profile_.reset(new TestingProfile()); 40 profile_.reset(new TestingProfile());
42 profile_->CreateRequestContext(); 41 profile_->CreateRequestContext();
43 mock_browsing_data_cookie_helper_ =
44 new MockBrowsingDataCookieHelper(profile_.get());
45 mock_browsing_data_database_helper_ = 42 mock_browsing_data_database_helper_ =
46 new MockBrowsingDataDatabaseHelper(profile_.get()); 43 new MockBrowsingDataDatabaseHelper(profile_.get());
47 mock_browsing_data_local_storage_helper_ = 44 mock_browsing_data_local_storage_helper_ =
48 new MockBrowsingDataLocalStorageHelper(profile_.get()); 45 new MockBrowsingDataLocalStorageHelper(profile_.get());
49 mock_browsing_data_session_storage_helper_ = 46 mock_browsing_data_session_storage_helper_ =
50 new MockBrowsingDataLocalStorageHelper(profile_.get()); 47 new MockBrowsingDataLocalStorageHelper(profile_.get());
51 mock_browsing_data_appcache_helper_ = 48 mock_browsing_data_appcache_helper_ =
52 new MockBrowsingDataAppCacheHelper(profile_.get()); 49 new MockBrowsingDataAppCacheHelper(profile_.get());
53 mock_browsing_data_indexed_db_helper_ = 50 mock_browsing_data_indexed_db_helper_ =
54 new MockBrowsingDataIndexedDBHelper(profile_.get()); 51 new MockBrowsingDataIndexedDBHelper(profile_.get());
55 mock_browsing_data_file_system_helper_ = 52 mock_browsing_data_file_system_helper_ =
56 new MockBrowsingDataFileSystemHelper(profile_.get()); 53 new MockBrowsingDataFileSystemHelper(profile_.get());
57 } 54 }
58 55
59 CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() { 56 CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() {
57 net::CookieMonster* monster = profile_->GetCookieMonster();
58 monster->SetCookie(GURL("http://foo1"), "A=1");
59 monster->SetCookie(GURL("http://foo2"), "B=1");
60 monster->SetCookie(GURL("http://foo3"), "C=1");
60 CookiesTreeModel* cookies_model = new CookiesTreeModel( 61 CookiesTreeModel* cookies_model = new CookiesTreeModel(
61 mock_browsing_data_cookie_helper_, 62 monster, mock_browsing_data_database_helper_,
62 mock_browsing_data_database_helper_,
63 mock_browsing_data_local_storage_helper_, 63 mock_browsing_data_local_storage_helper_,
64 mock_browsing_data_session_storage_helper_, 64 mock_browsing_data_session_storage_helper_,
65 mock_browsing_data_appcache_helper_, 65 mock_browsing_data_appcache_helper_,
66 mock_browsing_data_indexed_db_helper_, 66 mock_browsing_data_indexed_db_helper_,
67 mock_browsing_data_file_system_helper_, 67 mock_browsing_data_file_system_helper_,
68 false); 68 false);
69 mock_browsing_data_cookie_helper_->
70 AddCookieSamples(GURL("http://foo1"), "A=1");
71 mock_browsing_data_cookie_helper_->
72 AddCookieSamples(GURL("http://foo2"), "B=1");
73 mock_browsing_data_cookie_helper_->
74 AddCookieSamples(GURL("http://foo3"), "C=1");
75 mock_browsing_data_cookie_helper_->Notify();
76 mock_browsing_data_database_helper_->AddDatabaseSamples(); 69 mock_browsing_data_database_helper_->AddDatabaseSamples();
77 mock_browsing_data_database_helper_->Notify(); 70 mock_browsing_data_database_helper_->Notify();
78 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 71 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
79 mock_browsing_data_local_storage_helper_->Notify(); 72 mock_browsing_data_local_storage_helper_->Notify();
80 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 73 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
81 mock_browsing_data_session_storage_helper_->Notify(); 74 mock_browsing_data_session_storage_helper_->Notify();
82 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 75 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
83 mock_browsing_data_indexed_db_helper_->Notify(); 76 mock_browsing_data_indexed_db_helper_->Notify();
84 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 77 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
85 mock_browsing_data_file_system_helper_->Notify(); 78 mock_browsing_data_file_system_helper_->Notify();
86 { 79 {
87 SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages, " 80 SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages, "
88 "2 session storages, 2 indexed DBs, 3 filesystems"); 81 "2 session storages, 2 indexed DBs, 3 filesystems");
89 // 41 because there's the root, then foo1 -> cookies -> a, 82 // 41 because there's the root, then foo1 -> cookies -> a,
90 // foo2 -> cookies -> b, foo3 -> cookies -> c, 83 // foo2 -> cookies -> b, foo3 -> cookies -> c,
91 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, 84 // dbhost1 -> database -> db1, dbhost2 -> database -> db2,
92 // fshost1 -> filesystem -> http://fshost1:1/, 85 // fshost1 -> filesystem -> http://fshost1:1/,
93 // fshost2 -> filesystem -> http://fshost2:1/, 86 // fshost2 -> filesystem -> http://fshost2:1/,
94 // fshost3 -> filesystem -> http://fshost3:1/, 87 // fshost3 -> filesystem -> http://fshost3:1/,
95 // host1 -> localstorage -> http://host1:1/, 88 // host1 -> localstorage -> http://host1:1/,
96 // host2 -> localstorage -> http://host2:2/. 89 // host2 -> localstorage -> http://host2:2/.
97 // host1 -> sessionstorage -> http://host1:1/, 90 // host1 -> sessionstorage -> http://host1:1/,
98 // host2 -> sessionstorage -> http://host2:2/, 91 // host2 -> sessionstorage -> http://host2:2/,
99 // idbhost1 -> indexeddb -> http://idbhost1:1/, 92 // idbhost1 -> indexeddb -> http://idbhost1:1/,
100 // idbhost2 -> indexeddb -> http://idbhost2:2/. 93 // idbhost2 -> indexeddb -> http://idbhost2:2/.
101 EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount()); 94 EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
102 EXPECT_EQ("A,B,C", GetDisplayedCookies(cookies_model));
103 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model)); 95 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model));
104 EXPECT_EQ("http://host1:1/,http://host2:2/", 96 EXPECT_EQ("http://host1:1/,http://host2:2/",
105 GetDisplayedLocalStorages(cookies_model)); 97 GetDisplayedLocalStorages(cookies_model));
106 EXPECT_EQ("http://host1:1/,http://host2:2/", 98 EXPECT_EQ("http://host1:1/,http://host2:2/",
107 GetDisplayedSessionStorages(cookies_model)); 99 GetDisplayedSessionStorages(cookies_model));
108 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 100 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
109 GetDisplayedIndexedDBs(cookies_model)); 101 GetDisplayedIndexedDBs(cookies_model));
110 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 102 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
111 GetDisplayedFileSystems(cookies_model)); 103 GetDisplayedFileSystems(cookies_model));
112 } 104 }
113 return cookies_model; 105 return cookies_model;
114 } 106 }
115 107
108 // Get the cookie names in the cookie list, as a comma seperated string.
109 // (Note that the CookieMonster cookie list is sorted by domain.)
110 // Ex:
111 // monster->SetCookie(GURL("http://b"), "X=1")
112 // monster->SetCookie(GURL("http://a"), "Y=1")
113 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str());
114 std::string GetMonsterCookies(net::CookieMonster* monster) {
115 std::vector<std::string> parts;
116 net::CookieList cookie_list = monster->GetAllCookies();
117 for (size_t i = 0; i < cookie_list.size(); ++i)
118 parts.push_back(cookie_list[i].Name());
119 return JoinString(parts, ',');
120 }
121
116 std::string GetNodesOfChildren( 122 std::string GetNodesOfChildren(
117 const CookieTreeNode* node, 123 const CookieTreeNode* node,
118 CookieTreeNode::DetailedInfo::NodeType node_type) { 124 CookieTreeNode::DetailedInfo::NodeType node_type) {
119 if (!node->empty()) { 125 if (!node->empty()) {
120 std::string retval; 126 std::string retval;
121 for (int i = 0; i < node->child_count(); ++i) { 127 for (int i = 0; i < node->child_count(); ++i) {
122 retval += GetNodesOfChildren(node->GetChild(i), node_type); 128 retval += GetNodesOfChildren(node->GetChild(i), node_type);
123 } 129 }
124 return retval; 130 return retval;
125 } else { 131 } else {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 DCHECK(parent_node); 240 DCHECK(parent_node);
235 delete parent_node->GetModel()->Remove(parent_node, node); 241 delete parent_node->GetModel()->Remove(parent_node, node);
236 } 242 }
237 243
238 protected: 244 protected:
239 MessageLoop message_loop_; 245 MessageLoop message_loop_;
240 BrowserThread ui_thread_; 246 BrowserThread ui_thread_;
241 BrowserThread io_thread_; 247 BrowserThread io_thread_;
242 248
243 scoped_ptr<TestingProfile> profile_; 249 scoped_ptr<TestingProfile> profile_;
244 scoped_refptr<MockBrowsingDataCookieHelper>
245 mock_browsing_data_cookie_helper_;
246 scoped_refptr<MockBrowsingDataDatabaseHelper> 250 scoped_refptr<MockBrowsingDataDatabaseHelper>
247 mock_browsing_data_database_helper_; 251 mock_browsing_data_database_helper_;
248 scoped_refptr<MockBrowsingDataLocalStorageHelper> 252 scoped_refptr<MockBrowsingDataLocalStorageHelper>
249 mock_browsing_data_local_storage_helper_; 253 mock_browsing_data_local_storage_helper_;
250 scoped_refptr<MockBrowsingDataLocalStorageHelper> 254 scoped_refptr<MockBrowsingDataLocalStorageHelper>
251 mock_browsing_data_session_storage_helper_; 255 mock_browsing_data_session_storage_helper_;
252 scoped_refptr<MockBrowsingDataAppCacheHelper> 256 scoped_refptr<MockBrowsingDataAppCacheHelper>
253 mock_browsing_data_appcache_helper_; 257 mock_browsing_data_appcache_helper_;
254 scoped_refptr<MockBrowsingDataIndexedDBHelper> 258 scoped_refptr<MockBrowsingDataIndexedDBHelper>
255 mock_browsing_data_indexed_db_helper_; 259 mock_browsing_data_indexed_db_helper_;
256 scoped_refptr<MockBrowsingDataFileSystemHelper> 260 scoped_refptr<MockBrowsingDataFileSystemHelper>
257 mock_browsing_data_file_system_helper_; 261 mock_browsing_data_file_system_helper_;
258 }; 262 };
259 263
260 TEST_F(CookiesTreeModelTest, RemoveAll) { 264 TEST_F(CookiesTreeModelTest, RemoveAll) {
261 scoped_ptr<CookiesTreeModel> cookies_model( 265 scoped_ptr<CookiesTreeModel> cookies_model(
262 CreateCookiesTreeModelWithInitialSample()); 266 CreateCookiesTreeModelWithInitialSample());
267 net::CookieMonster* monster = profile_->GetCookieMonster();
263 268
264 // Reset the selection of the first row. 269 // Reset the selection of the first row.
265 { 270 {
266 SCOPED_TRACE("Before removing"); 271 SCOPED_TRACE("Before removing");
267 EXPECT_EQ("A,B,C", 272 EXPECT_EQ(GetMonsterCookies(monster),
268 GetDisplayedCookies(cookies_model.get())); 273 GetDisplayedCookies(cookies_model.get()));
269 EXPECT_EQ("db1,db2", 274 EXPECT_EQ("db1,db2",
270 GetDisplayedDatabases(cookies_model.get())); 275 GetDisplayedDatabases(cookies_model.get()));
271 EXPECT_EQ("http://host1:1/,http://host2:2/", 276 EXPECT_EQ("http://host1:1/,http://host2:2/",
272 GetDisplayedLocalStorages(cookies_model.get())); 277 GetDisplayedLocalStorages(cookies_model.get()));
273 EXPECT_EQ("http://host1:1/,http://host2:2/", 278 EXPECT_EQ("http://host1:1/,http://host2:2/",
274 GetDisplayedSessionStorages(cookies_model.get())); 279 GetDisplayedSessionStorages(cookies_model.get()));
275 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 280 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
276 GetDisplayedIndexedDBs(cookies_model.get())); 281 GetDisplayedIndexedDBs(cookies_model.get()));
277 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 282 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
278 GetDisplayedFileSystems(cookies_model.get())); 283 GetDisplayedFileSystems(cookies_model.get()));
279 } 284 }
280 285
281 mock_browsing_data_cookie_helper_->Reset();
282 mock_browsing_data_database_helper_->Reset(); 286 mock_browsing_data_database_helper_->Reset();
283 mock_browsing_data_local_storage_helper_->Reset(); 287 mock_browsing_data_local_storage_helper_->Reset();
284 mock_browsing_data_session_storage_helper_->Reset(); 288 mock_browsing_data_session_storage_helper_->Reset();
285 mock_browsing_data_indexed_db_helper_->Reset(); 289 mock_browsing_data_indexed_db_helper_->Reset();
286 mock_browsing_data_file_system_helper_->Reset(); 290 mock_browsing_data_file_system_helper_->Reset();
287 291
288 cookies_model->DeleteAllStoredObjects(); 292 cookies_model->DeleteAllStoredObjects();
289 293
290 { 294 {
291 SCOPED_TRACE("After removing"); 295 SCOPED_TRACE("After removing");
292 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount()); 296 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount());
293 EXPECT_EQ(0, cookies_model->GetRoot()->child_count()); 297 EXPECT_EQ(0, cookies_model->GetRoot()->child_count());
294 EXPECT_EQ(std::string(""), GetDisplayedCookies(cookies_model.get())); 298 EXPECT_EQ(std::string(""), GetMonsterCookies(monster));
295 EXPECT_TRUE(mock_browsing_data_cookie_helper_->AllDeleted()); 299 EXPECT_EQ(GetMonsterCookies(monster),
300 GetDisplayedCookies(cookies_model.get()));
296 EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted()); 301 EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted());
297 EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted()); 302 EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted());
298 EXPECT_FALSE(mock_browsing_data_session_storage_helper_->AllDeleted()); 303 EXPECT_FALSE(mock_browsing_data_session_storage_helper_->AllDeleted());
299 EXPECT_TRUE(mock_browsing_data_indexed_db_helper_->AllDeleted()); 304 EXPECT_TRUE(mock_browsing_data_indexed_db_helper_->AllDeleted());
300 EXPECT_TRUE(mock_browsing_data_file_system_helper_->AllDeleted()); 305 EXPECT_TRUE(mock_browsing_data_file_system_helper_->AllDeleted());
301 } 306 }
302 } 307 }
303 308
304 TEST_F(CookiesTreeModelTest, Remove) { 309 TEST_F(CookiesTreeModelTest, Remove) {
305 scoped_ptr<CookiesTreeModel> cookies_model( 310 scoped_ptr<CookiesTreeModel> cookies_model(
306 CreateCookiesTreeModelWithInitialSample()); 311 CreateCookiesTreeModelWithInitialSample());
312 net::CookieMonster* monster = profile_->GetCookieMonster();
307 313
308 // Children start out arranged as follows: 314 // Children start out arranged as follows:
309 // 315 //
310 // 0. `foo1` 316 // 0. `foo1`
311 // 1. `foo2` 317 // 1. `foo2`
312 // 2. `foo3` 318 // 2. `foo3`
313 // 3. `fshost1` 319 // 3. `fshost1`
314 // 4. `fshost2` 320 // 4. `fshost2`
315 // 5. `fshost3` 321 // 5. `fshost3`
316 // 6. `gdbhost1` 322 // 6. `gdbhost1`
317 // 7. `gdbhost2` 323 // 7. `gdbhost2`
318 // 8. `host1` 324 // 8. `host1`
319 // 9. `host2` 325 // 9. `host2`
320 // 10. `idbhost1` 326 // 10. `idbhost1`
321 // 11. `idbhost2` 327 // 11. `idbhost2`
322 // 328 //
323 // Here, we'll remove them one by one, starting from the end, and 329 // Here, we'll remove them one by one, starting from the end, and
324 // check that the state makes sense. 330 // check that the state makes sense.
325 331
326 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11)); 332 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11));
327 { 333 {
328 SCOPED_TRACE("`idbhost2` removed."); 334 SCOPED_TRACE("`idbhost2` removed.");
335 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
329 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 336 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
330 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 337 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
331 EXPECT_EQ("http://host1:1/,http://host2:2/", 338 EXPECT_EQ("http://host1:1/,http://host2:2/",
332 GetDisplayedLocalStorages(cookies_model.get())); 339 GetDisplayedLocalStorages(cookies_model.get()));
333 EXPECT_EQ("http://host1:1/,http://host2:2/", 340 EXPECT_EQ("http://host1:1/,http://host2:2/",
334 GetDisplayedSessionStorages(cookies_model.get())); 341 GetDisplayedSessionStorages(cookies_model.get()));
335 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 342 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
336 GetDisplayedFileSystems(cookies_model.get())); 343 GetDisplayedFileSystems(cookies_model.get()));
337 EXPECT_EQ("http://idbhost1:1/", 344 EXPECT_EQ("http://idbhost1:1/",
338 GetDisplayedIndexedDBs(cookies_model.get())); 345 GetDisplayedIndexedDBs(cookies_model.get()));
339 EXPECT_EQ(38, cookies_model->GetRoot()->GetTotalNodeCount()); 346 EXPECT_EQ(38, cookies_model->GetRoot()->GetTotalNodeCount());
340 } 347 }
341 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10)); 348 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10));
342 { 349 {
343 SCOPED_TRACE("`idbhost1` removed."); 350 SCOPED_TRACE("`idbhost1` removed.");
351 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
344 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 352 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
345 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 353 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
346 EXPECT_EQ("http://host1:1/,http://host2:2/", 354 EXPECT_EQ("http://host1:1/,http://host2:2/",
347 GetDisplayedLocalStorages(cookies_model.get())); 355 GetDisplayedLocalStorages(cookies_model.get()));
348 EXPECT_EQ("http://host1:1/,http://host2:2/", 356 EXPECT_EQ("http://host1:1/,http://host2:2/",
349 GetDisplayedSessionStorages(cookies_model.get())); 357 GetDisplayedSessionStorages(cookies_model.get()));
350 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 358 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
351 GetDisplayedFileSystems(cookies_model.get())); 359 GetDisplayedFileSystems(cookies_model.get()));
352 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 360 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
353 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount()); 361 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount());
354 } 362 }
355 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(9)); 363 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(9));
356 { 364 {
357 SCOPED_TRACE("`host2` removed."); 365 SCOPED_TRACE("`host2` removed.");
366 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
358 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 367 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
359 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 368 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
360 EXPECT_EQ("http://host1:1/", 369 EXPECT_EQ("http://host1:1/",
361 GetDisplayedLocalStorages(cookies_model.get())); 370 GetDisplayedLocalStorages(cookies_model.get()));
362 EXPECT_EQ("http://host1:1/", 371 EXPECT_EQ("http://host1:1/",
363 GetDisplayedSessionStorages(cookies_model.get())); 372 GetDisplayedSessionStorages(cookies_model.get()));
364 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 373 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
365 GetDisplayedFileSystems(cookies_model.get())); 374 GetDisplayedFileSystems(cookies_model.get()));
366 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 375 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
367 EXPECT_EQ(30, cookies_model->GetRoot()->GetTotalNodeCount()); 376 EXPECT_EQ(30, cookies_model->GetRoot()->GetTotalNodeCount());
368 } 377 }
369 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)); 378 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8));
370 { 379 {
371 SCOPED_TRACE("`host1` removed."); 380 SCOPED_TRACE("`host1` removed.");
381 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
372 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 382 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
373 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 383 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
374 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 384 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
375 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 385 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
376 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 386 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
377 GetDisplayedFileSystems(cookies_model.get())); 387 GetDisplayedFileSystems(cookies_model.get()));
378 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 388 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
379 EXPECT_EQ(25, cookies_model->GetRoot()->GetTotalNodeCount()); 389 EXPECT_EQ(25, cookies_model->GetRoot()->GetTotalNodeCount());
380 } 390 }
381 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(7)); 391 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(7));
382 { 392 {
383 SCOPED_TRACE("`gdbhost2` removed."); 393 SCOPED_TRACE("`gdbhost2` removed.");
394 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
384 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 395 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
385 EXPECT_EQ("db1", GetDisplayedDatabases(cookies_model.get())); 396 EXPECT_EQ("db1", GetDisplayedDatabases(cookies_model.get()));
386 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 397 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
387 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 398 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
388 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 399 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
389 GetDisplayedFileSystems(cookies_model.get())); 400 GetDisplayedFileSystems(cookies_model.get()));
390 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 401 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
391 EXPECT_EQ(22, cookies_model->GetRoot()->GetTotalNodeCount()); 402 EXPECT_EQ(22, cookies_model->GetRoot()->GetTotalNodeCount());
392 } 403 }
393 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)); 404 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6));
394 { 405 {
395 SCOPED_TRACE("`gdbhost1` removed."); 406 SCOPED_TRACE("`gdbhost1` removed.");
407 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
396 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 408 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
397 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 409 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
398 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 410 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
399 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 411 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
400 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 412 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
401 GetDisplayedFileSystems(cookies_model.get())); 413 GetDisplayedFileSystems(cookies_model.get()));
402 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 414 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
403 EXPECT_EQ(19, cookies_model->GetRoot()->GetTotalNodeCount()); 415 EXPECT_EQ(19, cookies_model->GetRoot()->GetTotalNodeCount());
404 } 416 }
405 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(5)); 417 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(5));
406 { 418 {
407 SCOPED_TRACE("`fshost3` removed."); 419 SCOPED_TRACE("`fshost3` removed.");
420 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
408 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 421 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
409 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 422 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
410 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 423 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
411 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 424 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
412 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/", 425 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/",
413 GetDisplayedFileSystems(cookies_model.get())); 426 GetDisplayedFileSystems(cookies_model.get()));
414 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 427 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
415 EXPECT_EQ(16, cookies_model->GetRoot()->GetTotalNodeCount()); 428 EXPECT_EQ(16, cookies_model->GetRoot()->GetTotalNodeCount());
416 } 429 }
417 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(4)); 430 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(4));
418 { 431 {
419 SCOPED_TRACE("`fshost2` removed."); 432 SCOPED_TRACE("`fshost2` removed.");
433 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
420 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 434 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
421 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 435 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
422 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 436 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
423 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 437 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
424 EXPECT_EQ("http://fshost1:1/", 438 EXPECT_EQ("http://fshost1:1/",
425 GetDisplayedFileSystems(cookies_model.get())); 439 GetDisplayedFileSystems(cookies_model.get()));
426 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 440 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
427 EXPECT_EQ(13, cookies_model->GetRoot()->GetTotalNodeCount()); 441 EXPECT_EQ(13, cookies_model->GetRoot()->GetTotalNodeCount());
428 } 442 }
429 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3)); 443 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3));
430 { 444 {
431 SCOPED_TRACE("`fshost1` removed."); 445 SCOPED_TRACE("`fshost1` removed.");
446 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str());
432 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 447 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
433 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 448 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
434 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 449 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
435 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 450 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
436 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 451 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
437 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 452 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
438 EXPECT_EQ(10, cookies_model->GetRoot()->GetTotalNodeCount()); 453 EXPECT_EQ(10, cookies_model->GetRoot()->GetTotalNodeCount());
439 } 454 }
440 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2)); 455 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2));
441 { 456 {
442 SCOPED_TRACE("`foo3` removed."); 457 SCOPED_TRACE("`foo3` removed.");
458 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
443 EXPECT_STREQ("A,B", GetDisplayedCookies(cookies_model.get()).c_str()); 459 EXPECT_STREQ("A,B", GetDisplayedCookies(cookies_model.get()).c_str());
444 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 460 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
445 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 461 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
446 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 462 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
447 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 463 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
448 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 464 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
449 EXPECT_EQ(7, cookies_model->GetRoot()->GetTotalNodeCount()); 465 EXPECT_EQ(7, cookies_model->GetRoot()->GetTotalNodeCount());
450 } 466 }
451 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)); 467 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1));
452 { 468 {
453 SCOPED_TRACE("`foo2` removed."); 469 SCOPED_TRACE("`foo2` removed.");
470 EXPECT_STREQ("A", GetMonsterCookies(monster).c_str());
454 EXPECT_STREQ("A", GetDisplayedCookies(cookies_model.get()).c_str()); 471 EXPECT_STREQ("A", GetDisplayedCookies(cookies_model.get()).c_str());
455 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 472 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
456 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 473 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
457 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 474 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
458 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 475 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
459 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 476 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
460 EXPECT_EQ(4, cookies_model->GetRoot()->GetTotalNodeCount()); 477 EXPECT_EQ(4, cookies_model->GetRoot()->GetTotalNodeCount());
461 } 478 }
462 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)); 479 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0));
463 { 480 {
464 SCOPED_TRACE("`foo1` removed."); 481 SCOPED_TRACE("`foo1` removed.");
482 EXPECT_STREQ("", GetMonsterCookies(monster).c_str());
465 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str()); 483 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str());
466 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 484 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
467 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 485 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
468 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 486 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
469 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 487 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
470 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 488 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
471 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount()); 489 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount());
472 } 490 }
473 } 491 }
474 492
475 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { 493 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
476 scoped_ptr<CookiesTreeModel> cookies_model( 494 scoped_ptr<CookiesTreeModel> cookies_model(
477 CreateCookiesTreeModelWithInitialSample()); 495 CreateCookiesTreeModelWithInitialSample());
496 net::CookieMonster* monster = profile_->GetCookieMonster();
478 497
479 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)->GetChild(0)); 498 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)->GetChild(0));
480 { 499 {
481 SCOPED_TRACE("First origin removed"); 500 SCOPED_TRACE("First origin removed");
501 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
482 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 502 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
483 // 39 because in this case, the origin remains, although the COOKIES 503 // 39 because in this case, the origin remains, although the COOKIES
484 // node beneath it has been deleted. So, we have 504 // node beneath it has been deleted. So, we have
485 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c 505 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
486 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, 506 // dbhost1 -> database -> db1, dbhost2 -> database -> db2,
487 // fshost1 -> filesystem -> http://fshost1:1/, 507 // fshost1 -> filesystem -> http://fshost1:1/,
488 // fshost2 -> filesystem -> http://fshost2:1/, 508 // fshost2 -> filesystem -> http://fshost2:1/,
489 // fshost3 -> filesystem -> http://fshost3:1/, 509 // fshost3 -> filesystem -> http://fshost3:1/,
490 // host1 -> localstorage -> http://host1:1/, 510 // host1 -> localstorage -> http://host1:1/,
491 // host2 -> localstorage -> http://host2:2/, 511 // host2 -> localstorage -> http://host2:2/,
492 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 512 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
493 // idbhost2 -> sessionstorage -> http://idbhost2:2/. 513 // idbhost2 -> sessionstorage -> http://idbhost2:2/.
494 EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount()); 514 EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
495 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 515 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
496 EXPECT_EQ("http://host1:1/,http://host2:2/", 516 EXPECT_EQ("http://host1:1/,http://host2:2/",
497 GetDisplayedLocalStorages(cookies_model.get())); 517 GetDisplayedLocalStorages(cookies_model.get()));
498 EXPECT_EQ("http://host1:1/,http://host2:2/", 518 EXPECT_EQ("http://host1:1/,http://host2:2/",
499 GetDisplayedSessionStorages(cookies_model.get())); 519 GetDisplayedSessionStorages(cookies_model.get()));
500 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 520 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
501 GetDisplayedIndexedDBs(cookies_model.get())); 521 GetDisplayedIndexedDBs(cookies_model.get()));
502 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 522 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
503 GetDisplayedFileSystems(cookies_model.get())); 523 GetDisplayedFileSystems(cookies_model.get()));
504 } 524 }
505 525
506 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0)); 526 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
507 { 527 {
508 SCOPED_TRACE("First database removed"); 528 SCOPED_TRACE("First database removed");
529 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
509 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 530 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
510 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 531 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
511 EXPECT_EQ("http://host1:1/,http://host2:2/", 532 EXPECT_EQ("http://host1:1/,http://host2:2/",
512 GetDisplayedLocalStorages(cookies_model.get())); 533 GetDisplayedLocalStorages(cookies_model.get()));
513 EXPECT_EQ("http://host1:1/,http://host2:2/", 534 EXPECT_EQ("http://host1:1/,http://host2:2/",
514 GetDisplayedSessionStorages(cookies_model.get())); 535 GetDisplayedSessionStorages(cookies_model.get()));
515 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 536 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
516 GetDisplayedIndexedDBs(cookies_model.get())); 537 GetDisplayedIndexedDBs(cookies_model.get()));
517 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 538 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
518 GetDisplayedFileSystems(cookies_model.get())); 539 GetDisplayedFileSystems(cookies_model.get()));
519 EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount()); 540 EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount());
520 } 541 }
521 542
522 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0)); 543 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
523 { 544 {
524 SCOPED_TRACE("First origin removed"); 545 SCOPED_TRACE("First origin removed");
546 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
525 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 547 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
526 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 548 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
527 EXPECT_EQ("http://host2:2/", 549 EXPECT_EQ("http://host2:2/",
528 GetDisplayedLocalStorages(cookies_model.get())); 550 GetDisplayedLocalStorages(cookies_model.get()));
529 EXPECT_EQ("http://host1:1/,http://host2:2/", 551 EXPECT_EQ("http://host1:1/,http://host2:2/",
530 GetDisplayedSessionStorages(cookies_model.get())); 552 GetDisplayedSessionStorages(cookies_model.get()));
531 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 553 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
532 GetDisplayedIndexedDBs(cookies_model.get())); 554 GetDisplayedIndexedDBs(cookies_model.get()));
533 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 555 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
534 GetDisplayedFileSystems(cookies_model.get())); 556 GetDisplayedFileSystems(cookies_model.get()));
535 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount()); 557 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount());
536 } 558 }
537 } 559 }
538 560
539 TEST_F(CookiesTreeModelTest, RemoveCookieNode) { 561 TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
540 scoped_ptr<CookiesTreeModel> cookies_model( 562 scoped_ptr<CookiesTreeModel> cookies_model(
541 CreateCookiesTreeModelWithInitialSample()); 563 CreateCookiesTreeModelWithInitialSample());
564 net::CookieMonster* monster = profile_->GetCookieMonster();
542 565
543 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)->GetChild(0)); 566 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)->GetChild(0));
544 { 567 {
545 SCOPED_TRACE("Second origin COOKIES node removed"); 568 SCOPED_TRACE("Second origin COOKIES node removed");
569 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
546 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 570 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
547 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 571 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
548 EXPECT_EQ("http://host1:1/,http://host2:2/", 572 EXPECT_EQ("http://host1:1/,http://host2:2/",
549 GetDisplayedLocalStorages(cookies_model.get())); 573 GetDisplayedLocalStorages(cookies_model.get()));
550 EXPECT_EQ("http://host1:1/,http://host2:2/", 574 EXPECT_EQ("http://host1:1/,http://host2:2/",
551 GetDisplayedSessionStorages(cookies_model.get())); 575 GetDisplayedSessionStorages(cookies_model.get()));
552 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 576 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
553 GetDisplayedIndexedDBs(cookies_model.get())); 577 GetDisplayedIndexedDBs(cookies_model.get()));
554 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 578 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
555 GetDisplayedFileSystems(cookies_model.get())); 579 GetDisplayedFileSystems(cookies_model.get()));
556 // 39 because in this case, the origin remains, although the COOKIES 580 // 39 because in this case, the origin remains, although the COOKIES
557 // node beneath it has been deleted. So, we have 581 // node beneath it has been deleted. So, we have
558 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c 582 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
559 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, 583 // dbhost1 -> database -> db1, dbhost2 -> database -> db2,
560 // fshost1 -> filesystem -> http://fshost1:1/, 584 // fshost1 -> filesystem -> http://fshost1:1/,
561 // fshost2 -> filesystem -> http://fshost2:1/, 585 // fshost2 -> filesystem -> http://fshost2:1/,
562 // fshost3 -> filesystem -> http://fshost3:1/, 586 // fshost3 -> filesystem -> http://fshost3:1/,
563 // host1 -> localstorage -> http://host1:1/, 587 // host1 -> localstorage -> http://host1:1/,
564 // host2 -> localstorage -> http://host2:2/, 588 // host2 -> localstorage -> http://host2:2/,
565 // host1 -> sessionstorage -> http://host1:1/, 589 // host1 -> sessionstorage -> http://host1:1/,
566 // host2 -> sessionstorage -> http://host2:2/, 590 // host2 -> sessionstorage -> http://host2:2/,
567 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 591 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
568 // idbhost2 -> sessionstorage -> http://idbhost2:2/. 592 // idbhost2 -> sessionstorage -> http://idbhost2:2/.
569 EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount()); 593 EXPECT_EQ(39, cookies_model->GetRoot()->GetTotalNodeCount());
570 } 594 }
571 595
572 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0)); 596 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)->GetChild(0));
573 { 597 {
574 SCOPED_TRACE("First database removed"); 598 SCOPED_TRACE("First database removed");
599 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
575 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 600 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
576 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 601 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
577 EXPECT_EQ("http://host1:1/,http://host2:2/", 602 EXPECT_EQ("http://host1:1/,http://host2:2/",
578 GetDisplayedLocalStorages(cookies_model.get())); 603 GetDisplayedLocalStorages(cookies_model.get()));
579 EXPECT_EQ("http://host1:1/,http://host2:2/", 604 EXPECT_EQ("http://host1:1/,http://host2:2/",
580 GetDisplayedSessionStorages(cookies_model.get())); 605 GetDisplayedSessionStorages(cookies_model.get()));
581 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 606 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
582 GetDisplayedIndexedDBs(cookies_model.get())); 607 GetDisplayedIndexedDBs(cookies_model.get()));
583 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 608 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
584 GetDisplayedFileSystems(cookies_model.get())); 609 GetDisplayedFileSystems(cookies_model.get()));
585 EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount()); 610 EXPECT_EQ(37, cookies_model->GetRoot()->GetTotalNodeCount());
586 } 611 }
587 612
588 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0)); 613 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
589 { 614 {
590 SCOPED_TRACE("First origin removed"); 615 SCOPED_TRACE("First origin removed");
616 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
591 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 617 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
592 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 618 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
593 EXPECT_EQ("http://host2:2/", 619 EXPECT_EQ("http://host2:2/",
594 GetDisplayedLocalStorages(cookies_model.get())); 620 GetDisplayedLocalStorages(cookies_model.get()));
595 EXPECT_EQ("http://host1:1/,http://host2:2/", 621 EXPECT_EQ("http://host1:1/,http://host2:2/",
596 GetDisplayedSessionStorages(cookies_model.get())); 622 GetDisplayedSessionStorages(cookies_model.get()));
597 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 623 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
598 GetDisplayedIndexedDBs(cookies_model.get())); 624 GetDisplayedIndexedDBs(cookies_model.get()));
599 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 625 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
600 GetDisplayedFileSystems(cookies_model.get())); 626 GetDisplayedFileSystems(cookies_model.get()));
601 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount()); 627 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount());
602 } 628 }
603 } 629 }
604 630
605 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { 631 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
606 CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_, 632 net::CookieMonster* monster = profile_->GetCookieMonster();
633 monster->SetCookie(GURL("http://foo1"), "A=1");
634 monster->SetCookie(GURL("http://foo2"), "B=1");
635 monster->SetCookie(GURL("http://foo3"), "C=1");
636 monster->SetCookie(GURL("http://foo3"), "D=1");
637 CookiesTreeModel cookies_model(monster,
607 mock_browsing_data_database_helper_, 638 mock_browsing_data_database_helper_,
608 mock_browsing_data_local_storage_helper_, 639 mock_browsing_data_local_storage_helper_,
609 mock_browsing_data_session_storage_helper_, 640 mock_browsing_data_session_storage_helper_,
610 mock_browsing_data_appcache_helper_, 641 mock_browsing_data_appcache_helper_,
611 mock_browsing_data_indexed_db_helper_, 642 mock_browsing_data_indexed_db_helper_,
612 mock_browsing_data_file_system_helper_, 643 mock_browsing_data_file_system_helper_,
613 false); 644 false);
614 mock_browsing_data_cookie_helper_->
615 AddCookieSamples(GURL("http://foo1"), "A=1");
616 mock_browsing_data_cookie_helper_->
617 AddCookieSamples(GURL("http://foo2"), "B=1");
618 mock_browsing_data_cookie_helper_->
619 AddCookieSamples(GURL("http://foo3"), "C=1");
620 mock_browsing_data_cookie_helper_->
621 AddCookieSamples(GURL("http://foo3"), "D=1");
622 mock_browsing_data_cookie_helper_->Notify();
623 mock_browsing_data_database_helper_->AddDatabaseSamples(); 645 mock_browsing_data_database_helper_->AddDatabaseSamples();
624 mock_browsing_data_database_helper_->Notify(); 646 mock_browsing_data_database_helper_->Notify();
625 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 647 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
626 mock_browsing_data_local_storage_helper_->Notify(); 648 mock_browsing_data_local_storage_helper_->Notify();
627 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 649 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
628 mock_browsing_data_session_storage_helper_->Notify(); 650 mock_browsing_data_session_storage_helper_->Notify();
629 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 651 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
630 mock_browsing_data_indexed_db_helper_->Notify(); 652 mock_browsing_data_indexed_db_helper_->Notify();
631 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 653 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
632 mock_browsing_data_file_system_helper_->Notify(); 654 mock_browsing_data_file_system_helper_->Notify();
633 655
634 { 656 {
635 SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages, " 657 SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages, "
636 "2 session storages, 2 indexed DBs, 3 file systems"); 658 "2 session storages, 2 indexed DBs, 3 file systems");
637 // 42 because there's the root, then foo1 -> cookies -> a, 659 // 42 because there's the root, then foo1 -> cookies -> a,
638 // foo2 -> cookies -> b, foo3 -> cookies -> c,d 660 // foo2 -> cookies -> b, foo3 -> cookies -> c,d
639 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, 661 // dbhost1 -> database -> db1, dbhost2 -> database -> db2,
640 // fshost1 -> filesystem -> http://fshost1:1/, 662 // fshost1 -> filesystem -> http://fshost1:1/,
641 // fshost2 -> filesystem -> http://fshost2:1/, 663 // fshost2 -> filesystem -> http://fshost2:1/,
642 // fshost3 -> filesystem -> http://fshost3:1/, 664 // fshost3 -> filesystem -> http://fshost3:1/,
643 // host1 -> localstorage -> http://host1:1/, 665 // host1 -> localstorage -> http://host1:1/,
644 // host1 -> sessionstorage -> http://host1:1/, 666 // host1 -> sessionstorage -> http://host1:1/,
645 // host2 -> sessionstorage -> http://host2:2/, 667 // host2 -> sessionstorage -> http://host2:2/,
646 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 668 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
647 // idbhost2 -> sessionstorage -> http://idbhost2:2/. 669 // idbhost2 -> sessionstorage -> http://idbhost2:2/.
648 EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount()); 670 EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount());
671 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str());
649 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); 672 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
650 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 673 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
651 EXPECT_EQ("http://host1:1/,http://host2:2/", 674 EXPECT_EQ("http://host1:1/,http://host2:2/",
652 GetDisplayedLocalStorages(&cookies_model)); 675 GetDisplayedLocalStorages(&cookies_model));
653 EXPECT_EQ("http://host1:1/,http://host2:2/", 676 EXPECT_EQ("http://host1:1/,http://host2:2/",
654 GetDisplayedSessionStorages(&cookies_model)); 677 GetDisplayedSessionStorages(&cookies_model));
655 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 678 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
656 GetDisplayedIndexedDBs(&cookies_model)); 679 GetDisplayedIndexedDBs(&cookies_model));
657 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 680 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
658 GetDisplayedFileSystems(&cookies_model)); 681 GetDisplayedFileSystems(&cookies_model));
659 } 682 }
660 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)); 683 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2));
661 { 684 {
662 SCOPED_TRACE("Third origin removed"); 685 SCOPED_TRACE("Third origin removed");
686 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
663 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); 687 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str());
664 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 688 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
665 EXPECT_EQ("http://host1:1/,http://host2:2/", 689 EXPECT_EQ("http://host1:1/,http://host2:2/",
666 GetDisplayedLocalStorages(&cookies_model)); 690 GetDisplayedLocalStorages(&cookies_model));
667 EXPECT_EQ("http://host1:1/,http://host2:2/", 691 EXPECT_EQ("http://host1:1/,http://host2:2/",
668 GetDisplayedSessionStorages(&cookies_model)); 692 GetDisplayedSessionStorages(&cookies_model));
669 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 693 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
670 GetDisplayedIndexedDBs(&cookies_model)); 694 GetDisplayedIndexedDBs(&cookies_model));
671 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 695 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
672 GetDisplayedFileSystems(&cookies_model)); 696 GetDisplayedFileSystems(&cookies_model));
673 EXPECT_EQ(38, cookies_model.GetRoot()->GetTotalNodeCount()); 697 EXPECT_EQ(38, cookies_model.GetRoot()->GetTotalNodeCount());
674 } 698 }
675 } 699 }
676 700
677 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { 701 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
678 CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_, 702 net::CookieMonster* monster = profile_->GetCookieMonster();
703 monster->SetCookie(GURL("http://foo1"), "A=1");
704 monster->SetCookie(GURL("http://foo2"), "B=1");
705 monster->SetCookie(GURL("http://foo3"), "C=1");
706 monster->SetCookie(GURL("http://foo3"), "D=1");
707 monster->SetCookie(GURL("http://foo3"), "E=1");
708 CookiesTreeModel cookies_model(monster,
679 mock_browsing_data_database_helper_, 709 mock_browsing_data_database_helper_,
680 mock_browsing_data_local_storage_helper_, 710 mock_browsing_data_local_storage_helper_,
681 mock_browsing_data_session_storage_helper_, 711 mock_browsing_data_session_storage_helper_,
682 mock_browsing_data_appcache_helper_, 712 mock_browsing_data_appcache_helper_,
683 mock_browsing_data_indexed_db_helper_, 713 mock_browsing_data_indexed_db_helper_,
684 mock_browsing_data_file_system_helper_, 714 mock_browsing_data_file_system_helper_,
685 false); 715 false);
686 mock_browsing_data_cookie_helper_->
687 AddCookieSamples(GURL("http://foo1"), "A=1");
688 mock_browsing_data_cookie_helper_->
689 AddCookieSamples(GURL("http://foo2"), "B=1");
690 mock_browsing_data_cookie_helper_->
691 AddCookieSamples(GURL("http://foo3"), "C=1");
692 mock_browsing_data_cookie_helper_->
693 AddCookieSamples(GURL("http://foo3"), "D=1");
694 mock_browsing_data_cookie_helper_->
695 AddCookieSamples(GURL("http://foo3"), "E=1");
696 mock_browsing_data_cookie_helper_->Notify();
697 mock_browsing_data_database_helper_->AddDatabaseSamples(); 716 mock_browsing_data_database_helper_->AddDatabaseSamples();
698 mock_browsing_data_database_helper_->Notify(); 717 mock_browsing_data_database_helper_->Notify();
699 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 718 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
700 mock_browsing_data_local_storage_helper_->Notify(); 719 mock_browsing_data_local_storage_helper_->Notify();
701 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 720 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
702 mock_browsing_data_session_storage_helper_->Notify(); 721 mock_browsing_data_session_storage_helper_->Notify();
703 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 722 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
704 mock_browsing_data_indexed_db_helper_->Notify(); 723 mock_browsing_data_indexed_db_helper_->Notify();
705 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 724 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
706 mock_browsing_data_file_system_helper_->Notify(); 725 mock_browsing_data_file_system_helper_->Notify();
707 726
708 { 727 {
709 SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages, " 728 SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages, "
710 "2 session storages, 2 indexed DBs"); 729 "2 session storages, 2 indexed DBs");
711 // 43 because there's the root, then foo1 -> cookies -> a, 730 // 43 because there's the root, then foo1 -> cookies -> a,
712 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e 731 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
713 // dbhost1 -> database -> db1, dbhost2 -> database -> db2, 732 // dbhost1 -> database -> db1, dbhost2 -> database -> db2,
714 // fshost1 -> filesystem -> http://fshost1:1/, 733 // fshost1 -> filesystem -> http://fshost1:1/,
715 // fshost2 -> filesystem -> http://fshost2:1/, 734 // fshost2 -> filesystem -> http://fshost2:1/,
716 // fshost3 -> filesystem -> http://fshost3:1/, 735 // fshost3 -> filesystem -> http://fshost3:1/,
717 // host1 -> localstorage -> http://host1:1/, 736 // host1 -> localstorage -> http://host1:1/,
718 // host2 -> localstorage -> http://host2:2/, 737 // host2 -> localstorage -> http://host2:2/,
719 // host1 -> sessionstorage -> http://host1:1/, 738 // host1 -> sessionstorage -> http://host1:1/,
720 // host2 -> sessionstorage -> http://host2:2/, 739 // host2 -> sessionstorage -> http://host2:2/,
721 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 740 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
722 // idbhost2 -> sessionstorage -> http://idbhost2:2/. 741 // idbhost2 -> sessionstorage -> http://idbhost2:2/.
723 EXPECT_EQ(43, cookies_model.GetRoot()->GetTotalNodeCount()); 742 EXPECT_EQ(43, cookies_model.GetRoot()->GetTotalNodeCount());
743 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
724 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 744 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
725 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 745 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
726 EXPECT_EQ("http://host1:1/,http://host2:2/", 746 EXPECT_EQ("http://host1:1/,http://host2:2/",
727 GetDisplayedLocalStorages(&cookies_model)); 747 GetDisplayedLocalStorages(&cookies_model));
728 EXPECT_EQ("http://host1:1/,http://host2:2/", 748 EXPECT_EQ("http://host1:1/,http://host2:2/",
729 GetDisplayedSessionStorages(&cookies_model)); 749 GetDisplayedSessionStorages(&cookies_model));
730 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 750 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
731 GetDisplayedIndexedDBs(&cookies_model)); 751 GetDisplayedIndexedDBs(&cookies_model));
732 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 752 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
733 GetDisplayedFileSystems(&cookies_model)); 753 GetDisplayedFileSystems(&cookies_model));
734 } 754 }
735 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> 755 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)->GetChild(0)->
736 GetChild(1)); 756 GetChild(1));
737 { 757 {
738 SCOPED_TRACE("Middle cookie in third origin removed"); 758 SCOPED_TRACE("Middle cookie in third origin removed");
759 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str());
739 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); 760 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
740 EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount()); 761 EXPECT_EQ(42, cookies_model.GetRoot()->GetTotalNodeCount());
741 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 762 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
742 EXPECT_EQ("http://host1:1/,http://host2:2/", 763 EXPECT_EQ("http://host1:1/,http://host2:2/",
743 GetDisplayedLocalStorages(&cookies_model)); 764 GetDisplayedLocalStorages(&cookies_model));
744 EXPECT_EQ("http://host1:1/,http://host2:2/", 765 EXPECT_EQ("http://host1:1/,http://host2:2/",
745 GetDisplayedSessionStorages(&cookies_model)); 766 GetDisplayedSessionStorages(&cookies_model));
746 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 767 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
747 GetDisplayedIndexedDBs(&cookies_model)); 768 GetDisplayedIndexedDBs(&cookies_model));
748 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 769 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
749 GetDisplayedFileSystems(&cookies_model)); 770 GetDisplayedFileSystems(&cookies_model));
750 } 771 }
751 } 772 }
752 773
753 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { 774 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
754 CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_, 775 net::CookieMonster* monster = profile_->GetCookieMonster();
776 monster->SetCookie(GURL("http://foo1"), "A=1");
777 monster->SetCookie(GURL("http://foo2"), "B=1");
778 monster->SetCookie(GURL("http://foo3"), "C=1");
779 monster->SetCookie(GURL("http://foo3"), "D=1");
780 monster->SetCookie(GURL("http://foo3"), "E=1");
781 CookiesTreeModel cookies_model(monster,
755 mock_browsing_data_database_helper_, 782 mock_browsing_data_database_helper_,
756 mock_browsing_data_local_storage_helper_, 783 mock_browsing_data_local_storage_helper_,
757 mock_browsing_data_session_storage_helper_, 784 mock_browsing_data_session_storage_helper_,
758 mock_browsing_data_appcache_helper_, 785 mock_browsing_data_appcache_helper_,
759 mock_browsing_data_indexed_db_helper_, 786 mock_browsing_data_indexed_db_helper_,
760 mock_browsing_data_file_system_helper_, 787 mock_browsing_data_file_system_helper_,
761 false); 788 false);
762 mock_browsing_data_cookie_helper_->
763 AddCookieSamples(GURL("http://foo1"), "A=1");
764 mock_browsing_data_cookie_helper_->
765 AddCookieSamples(GURL("http://foo2"), "B=1");
766 mock_browsing_data_cookie_helper_->
767 AddCookieSamples(GURL("http://foo3"), "C=1");
768 mock_browsing_data_cookie_helper_->
769 AddCookieSamples(GURL("http://foo3"), "D=1");
770 mock_browsing_data_cookie_helper_->
771 AddCookieSamples(GURL("http://foo3"), "E=1");
772 mock_browsing_data_cookie_helper_->Notify();
773
774 { 789 {
775 SCOPED_TRACE("Initial State 5 cookies"); 790 SCOPED_TRACE("Initial State 5 cookies");
776 // 11 because there's the root, then foo1 -> cookies -> a, 791 // 11 because there's the root, then foo1 -> cookies -> a,
777 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e 792 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
778 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); 793 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
794 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
779 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 795 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
780 } 796 }
781 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); 797 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1));
782 { 798 {
783 SCOPED_TRACE("Second origin removed"); 799 SCOPED_TRACE("Second origin removed");
800 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str());
784 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 801 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
785 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e 802 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e
786 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); 803 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount());
787 } 804 }
788 } 805 }
789 806
790 TEST_F(CookiesTreeModelTest, OriginOrdering) { 807 TEST_F(CookiesTreeModelTest, OriginOrdering) {
791 CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_, 808 net::CookieMonster* monster = profile_->GetCookieMonster();
792 mock_browsing_data_database_helper_, 809 monster->SetCookie(GURL("http://a.foo2.com"), "A=1");
793 mock_browsing_data_local_storage_helper_, 810 monster->SetCookie(GURL("http://foo2.com"), "B=1");
794 mock_browsing_data_session_storage_helper_, 811 monster->SetCookie(GURL("http://b.foo1.com"), "C=1");
795 mock_browsing_data_appcache_helper_, 812 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;"
796 mock_browsing_data_indexed_db_helper_, 813 " path=/;"); // Leading dot on the foo4
797 mock_browsing_data_file_system_helper_, 814 monster->SetCookie(GURL("http://a.foo1.com"), "E=1");
798 false); 815 monster->SetCookie(GURL("http://foo1.com"), "F=1");
799 mock_browsing_data_cookie_helper_-> 816 monster->SetCookie(GURL("http://foo3.com"), "G=1");
800 AddCookieSamples(GURL("http://a.foo2.com"), "A=1"); 817 monster->SetCookie(GURL("http://foo4.com"), "H=1");
801 mock_browsing_data_cookie_helper_-> 818
802 AddCookieSamples(GURL("http://foo2.com"), "B=1"); 819 CookiesTreeModel cookies_model(monster,
803 mock_browsing_data_cookie_helper_-> 820 new MockBrowsingDataDatabaseHelper(profile_.get()),
804 AddCookieSamples(GURL("http://b.foo1.com"), "C=1"); 821 new MockBrowsingDataLocalStorageHelper(profile_.get()),
805 // Leading dot on the foo4 822 new MockBrowsingDataLocalStorageHelper(profile_.get()),
806 mock_browsing_data_cookie_helper_->AddCookieSamples( 823 new MockBrowsingDataAppCacheHelper(profile_.get()),
807 GURL("http://foo4.com"), "D=1; domain=.foo4.com; path=/;"); 824 new MockBrowsingDataIndexedDBHelper(profile_.get()),
808 mock_browsing_data_cookie_helper_-> 825 new MockBrowsingDataFileSystemHelper(profile_.get()),
809 AddCookieSamples(GURL("http://a.foo1.com"), "E=1"); 826 false);
810 mock_browsing_data_cookie_helper_->
811 AddCookieSamples(GURL("http://foo1.com"), "F=1");
812 mock_browsing_data_cookie_helper_->
813 AddCookieSamples(GURL("http://foo3.com"), "G=1");
814 mock_browsing_data_cookie_helper_->
815 AddCookieSamples(GURL("http://foo4.com"), "H=1");
816 mock_browsing_data_cookie_helper_->Notify();
817 827
818 { 828 {
819 SCOPED_TRACE("Initial State 8 cookies"); 829 SCOPED_TRACE("Initial State 8 cookies");
820 EXPECT_EQ(23, cookies_model.GetRoot()->GetTotalNodeCount()); 830 // CookieMonster orders cookies by pathlength, then by creation time.
831 // All paths are length 1.
832 EXPECT_STREQ("A,B,C,D,E,F,G,H", GetMonsterCookies(monster).c_str());
821 EXPECT_STREQ("F,E,C,B,A,G,D,H", 833 EXPECT_STREQ("F,E,C,B,A,G,D,H",
822 GetDisplayedCookies(&cookies_model).c_str()); 834 GetDisplayedCookies(&cookies_model).c_str());
823 } 835 }
824 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" 836 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E"
825 { 837 {
838 EXPECT_STREQ("A,B,C,D,F,G,H", GetMonsterCookies(monster).c_str());
826 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); 839 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str());
827 } 840 }
828 } 841 }
829 842
830 TEST_F(CookiesTreeModelTest, ContentSettings) { 843 TEST_F(CookiesTreeModelTest, ContentSettings) {
831 GURL host("http://example.com/"); 844 GURL host("http://example.com/");
832 CookiesTreeModel cookies_model(mock_browsing_data_cookie_helper_, 845 net::CookieMonster* monster = profile_->GetCookieMonster();
833 mock_browsing_data_database_helper_, 846 monster->SetCookie(host, "A=1");
834 mock_browsing_data_local_storage_helper_, 847
835 mock_browsing_data_session_storage_helper_, 848 CookiesTreeModel cookies_model(monster,
836 mock_browsing_data_appcache_helper_, 849 new MockBrowsingDataDatabaseHelper(profile_.get()),
837 mock_browsing_data_indexed_db_helper_, 850 new MockBrowsingDataLocalStorageHelper(profile_.get()),
838 mock_browsing_data_file_system_helper_, 851 new MockBrowsingDataLocalStorageHelper(profile_.get()),
839 false); 852 new MockBrowsingDataAppCacheHelper(profile_.get()),
840 mock_browsing_data_cookie_helper_->AddCookieSamples(host, "A=1"); 853 new MockBrowsingDataIndexedDBHelper(profile_.get()),
841 mock_browsing_data_cookie_helper_->Notify(); 854 new MockBrowsingDataFileSystemHelper(profile_.get()),
855 false);
842 856
843 TestingProfile profile; 857 TestingProfile profile;
844 HostContentSettingsMap* content_settings = 858 HostContentSettingsMap* content_settings =
845 profile.GetHostContentSettingsMap(); 859 profile.GetHostContentSettingsMap();
846 MockSettingsObserver observer; 860 MockSettingsObserver observer;
847 861
848 CookieTreeRootNode* root = 862 CookieTreeRootNode* root =
849 static_cast<CookieTreeRootNode*>(cookies_model.GetRoot()); 863 static_cast<CookieTreeRootNode*>(cookies_model.GetRoot());
850 CookieTreeOriginNode* origin = root->GetOrCreateOriginNode(host); 864 CookieTreeOriginNode* origin = root->GetOrCreateOriginNode(host);
851 865
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 cookies_model->UpdateSearchResults(std::wstring(L"fshost3")); 901 cookies_model->UpdateSearchResults(std::wstring(L"fshost3"));
888 EXPECT_EQ("http://fshost3:3/", 902 EXPECT_EQ("http://fshost3:3/",
889 GetDisplayedFileSystems(cookies_model.get())); 903 GetDisplayedFileSystems(cookies_model.get()));
890 904
891 cookies_model->UpdateSearchResults(std::wstring()); 905 cookies_model->UpdateSearchResults(std::wstring());
892 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 906 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
893 GetDisplayedFileSystems(cookies_model.get())); 907 GetDisplayedFileSystems(cookies_model.get()));
894 } 908 }
895 909
896 } // namespace 910 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | chrome/browser/mock_browsing_data_cookie_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698