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