Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / browsing_data / cookies_tree_model_unittest.cc
blobf6743c5860d910d903cd82dd30bdcc0e4712b9f8
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/cookies_tree_model.h"
7 #include <string>
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/browsing_data/mock_browsing_data_appcache_helper.h"
13 #include "chrome/browser/browsing_data/mock_browsing_data_cache_storage_helper.h"
14 #include "chrome/browser/browsing_data/mock_browsing_data_channel_id_helper.h"
15 #include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h"
16 #include "chrome/browser/browsing_data/mock_browsing_data_database_helper.h"
17 #include "chrome/browser/browsing_data/mock_browsing_data_file_system_helper.h"
18 #include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h"
19 #include "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h"
20 #include "chrome/browser/browsing_data/mock_browsing_data_local_storage_helper.h"
21 #include "chrome/browser/browsing_data/mock_browsing_data_quota_helper.h"
22 #include "chrome/browser/browsing_data/mock_browsing_data_service_worker_helper.h"
23 #include "chrome/browser/content_settings/cookie_settings_factory.h"
24 #include "chrome/browser/content_settings/mock_settings_observer.h"
25 #include "chrome/test/base/testing_profile.h"
26 #include "components/content_settings/core/browser/cookie_settings.h"
27 #include "components/content_settings/core/browser/host_content_settings_map.h"
28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_details.h"
30 #include "content/public/browser/notification_types.h"
31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "net/url_request/url_request_context.h"
33 #include "net/url_request/url_request_context_getter.h"
34 #include "testing/gtest/include/gtest/gtest.h"
36 #if defined(ENABLE_EXTENSIONS)
37 #include "chrome/browser/extensions/extension_special_storage_policy.h"
38 #endif
40 using ::testing::_;
41 using content::BrowserThread;
43 namespace {
45 class CookiesTreeModelTest : public testing::Test {
46 public:
47 ~CookiesTreeModelTest() override {
48 // Avoid memory leaks.
49 #if defined(ENABLE_EXTENSIONS)
50 special_storage_policy_ = nullptr;
51 #endif
52 profile_.reset();
53 base::MessageLoop::current()->RunUntilIdle();
56 void SetUp() override {
57 profile_.reset(new TestingProfile());
58 mock_browsing_data_cookie_helper_ =
59 new MockBrowsingDataCookieHelper(profile_->GetRequestContext());
60 mock_browsing_data_database_helper_ =
61 new MockBrowsingDataDatabaseHelper(profile_.get());
62 mock_browsing_data_local_storage_helper_ =
63 new MockBrowsingDataLocalStorageHelper(profile_.get());
64 mock_browsing_data_session_storage_helper_ =
65 new MockBrowsingDataLocalStorageHelper(profile_.get());
66 mock_browsing_data_appcache_helper_ =
67 new MockBrowsingDataAppCacheHelper(profile_.get());
68 mock_browsing_data_indexed_db_helper_ =
69 new MockBrowsingDataIndexedDBHelper(profile_.get());
70 mock_browsing_data_file_system_helper_ =
71 new MockBrowsingDataFileSystemHelper(profile_.get());
72 mock_browsing_data_quota_helper_ =
73 new MockBrowsingDataQuotaHelper(profile_.get());
74 mock_browsing_data_channel_id_helper_ =
75 new MockBrowsingDataChannelIDHelper();
76 mock_browsing_data_service_worker_helper_ =
77 new MockBrowsingDataServiceWorkerHelper(profile_.get());
78 mock_browsing_data_cache_storage_helper_ =
79 new MockBrowsingDataCacheStorageHelper(profile_.get());
80 mock_browsing_data_flash_lso_helper_ =
81 new MockBrowsingDataFlashLSOHelper(profile_.get());
83 const char kExtensionScheme[] = "extensionscheme";
84 scoped_refptr<content_settings::CookieSettings> cookie_settings =
85 new content_settings::CookieSettings(
86 profile_->GetHostContentSettingsMap(), profile_->GetPrefs(),
87 kExtensionScheme);
88 #if defined(ENABLE_EXTENSIONS)
89 special_storage_policy_ =
90 new ExtensionSpecialStoragePolicy(cookie_settings.get());
91 #endif
94 void TearDown() override {
95 mock_browsing_data_service_worker_helper_ = nullptr;
96 mock_browsing_data_cache_storage_helper_ = nullptr;
97 mock_browsing_data_channel_id_helper_ = nullptr;
98 mock_browsing_data_quota_helper_ = nullptr;
99 mock_browsing_data_file_system_helper_ = nullptr;
100 mock_browsing_data_indexed_db_helper_ = nullptr;
101 mock_browsing_data_appcache_helper_ = nullptr;
102 mock_browsing_data_session_storage_helper_ = nullptr;
103 mock_browsing_data_local_storage_helper_ = nullptr;
104 mock_browsing_data_database_helper_ = nullptr;
105 mock_browsing_data_flash_lso_helper_ = nullptr;
106 base::MessageLoop::current()->RunUntilIdle();
109 scoped_ptr<CookiesTreeModel> CreateCookiesTreeModelWithInitialSample() {
110 LocalDataContainer* container =
111 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
112 mock_browsing_data_database_helper_.get(),
113 mock_browsing_data_local_storage_helper_.get(),
114 mock_browsing_data_session_storage_helper_.get(),
115 mock_browsing_data_appcache_helper_.get(),
116 mock_browsing_data_indexed_db_helper_.get(),
117 mock_browsing_data_file_system_helper_.get(),
118 mock_browsing_data_quota_helper_.get(),
119 mock_browsing_data_channel_id_helper_.get(),
120 mock_browsing_data_service_worker_helper_.get(),
121 mock_browsing_data_cache_storage_helper_.get(),
122 mock_browsing_data_flash_lso_helper_.get());
124 CookiesTreeModel* cookies_model =
125 new CookiesTreeModel(container, special_storage_policy(), false);
126 mock_browsing_data_cookie_helper_->
127 AddCookieSamples(GURL("http://foo1"), "A=1");
128 mock_browsing_data_cookie_helper_->
129 AddCookieSamples(GURL("http://foo2"), "B=1");
130 mock_browsing_data_cookie_helper_->
131 AddCookieSamples(GURL("http://foo3"), "C=1");
132 mock_browsing_data_cookie_helper_->Notify();
133 mock_browsing_data_database_helper_->AddDatabaseSamples();
134 mock_browsing_data_database_helper_->Notify();
135 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
136 mock_browsing_data_local_storage_helper_->Notify();
137 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
138 mock_browsing_data_session_storage_helper_->Notify();
139 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
140 mock_browsing_data_indexed_db_helper_->Notify();
141 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
142 mock_browsing_data_file_system_helper_->Notify();
143 mock_browsing_data_quota_helper_->AddQuotaSamples();
144 mock_browsing_data_quota_helper_->Notify();
145 mock_browsing_data_channel_id_helper_->AddChannelIDSample(
146 "sbc1");
147 mock_browsing_data_channel_id_helper_->AddChannelIDSample(
148 "sbc2");
149 mock_browsing_data_channel_id_helper_->Notify();
150 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples();
151 mock_browsing_data_service_worker_helper_->Notify();
152 mock_browsing_data_cache_storage_helper_->AddCacheStorageSamples();
153 mock_browsing_data_cache_storage_helper_->Notify();
154 mock_browsing_data_flash_lso_helper_->AddFlashLSODomain("xyz.com");
155 mock_browsing_data_flash_lso_helper_->Notify();
158 SCOPED_TRACE(
159 "Initial State 3 cookies, 2 databases, 2 local storages, "
160 "2 session storages, 2 indexed DBs, 3 filesystems, "
161 "2 quotas, 2 server bound certs, 2 service workers, "
162 "2 cache storages, 1 Flash LSO");
163 // 65 because there's the root, then
164 // cshost1 -> cache storage -> https://cshost1:1/
165 // cshost2 -> cache storage -> https://cshost2:2/
166 // foo1 -> cookies -> a,
167 // foo2 -> cookies -> b,
168 // foo3 -> cookies -> c,
169 // dbhost1 -> database -> db1,
170 // dbhost2 -> database -> db2,
171 // host1 -> localstorage -> http://host1:1/,
172 // -> sessionstorage -> http://host1:1/,
173 // host2 -> localstorage -> http://host2:2/.
174 // -> sessionstorage -> http://host2:2/,
175 // idbhost1 -> indexeddb -> http://idbhost1:1/,
176 // idbhost2 -> indexeddb -> http://idbhost2:2/,
177 // fshost1 -> filesystem -> http://fshost1:1/,
178 // fshost2 -> filesystem -> http://fshost2:1/,
179 // fshost3 -> filesystem -> http://fshost3:1/,
180 // quotahost1 -> quotahost1,
181 // quotahost2 -> quotahost2,
182 // sbc1 -> sbcerts -> sbc1,
183 // sbc2 -> sbcerts -> sbc2.
184 // swhost1 -> service worker -> https://swhost1:1
185 // swhost2 -> service worker -> https://swhost1:2
186 // xyz.com -> flash_lsos
187 EXPECT_EQ(65, cookies_model->GetRoot()->GetTotalNodeCount());
188 EXPECT_EQ("A,B,C", GetDisplayedCookies(cookies_model));
189 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model));
190 EXPECT_EQ("http://host1:1/,http://host2:2/",
191 GetDisplayedLocalStorages(cookies_model));
192 EXPECT_EQ("http://host1:1/,http://host2:2/",
193 GetDisplayedSessionStorages(cookies_model));
194 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
195 GetDisplayedIndexedDBs(cookies_model));
196 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
197 GetDisplayedFileSystems(cookies_model));
198 EXPECT_EQ("quotahost1,quotahost2",
199 GetDisplayedQuotas(cookies_model));
200 EXPECT_EQ("sbc1,sbc2",
201 GetDisplayedChannelIDs(cookies_model));
202 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
203 GetDisplayedServiceWorkers(cookies_model));
204 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
205 GetDisplayedCacheStorages(cookies_model));
206 EXPECT_EQ("xyz.com",
207 GetDisplayedFlashLSOs(cookies_model));
209 return make_scoped_ptr(cookies_model);
212 // Checks that, when setting content settings for host nodes in the
213 // cookie tree, the content settings are applied to the expected URL.
214 void CheckContentSettingsUrlForHostNodes(
215 const CookieTreeNode* node,
216 CookieTreeNode::DetailedInfo::NodeType node_type,
217 content_settings::CookieSettings* cookie_settings,
218 const GURL& expected_url) {
219 if (!node->empty()) {
220 for (int i = 0; i < node->child_count(); ++i) {
221 const CookieTreeNode* child = node->GetChild(i);
222 CheckContentSettingsUrlForHostNodes(child,
223 child->GetDetailedInfo().node_type,
224 cookie_settings, expected_url);
228 ASSERT_EQ(node_type, node->GetDetailedInfo().node_type);
230 if (node_type == CookieTreeNode::DetailedInfo::TYPE_HOST) {
231 const CookieTreeHostNode* host =
232 static_cast<const CookieTreeHostNode*>(node);
234 if (expected_url.SchemeIsFile()) {
235 EXPECT_FALSE(host->CanCreateContentException());
236 } else {
237 cookie_settings->ResetCookieSetting(
238 ContentSettingsPattern::FromURLNoWildcard(expected_url),
239 ContentSettingsPattern::Wildcard());
240 EXPECT_FALSE(cookie_settings->IsCookieSessionOnly(expected_url));
242 host->CreateContentException(cookie_settings,
243 CONTENT_SETTING_SESSION_ONLY);
244 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(expected_url));
249 std::string GetNodesOfChildren(
250 const CookieTreeNode* node,
251 CookieTreeNode::DetailedInfo::NodeType node_type) {
252 if (!node->empty()) {
253 std::string retval;
254 for (int i = 0; i < node->child_count(); ++i) {
255 retval += GetNodesOfChildren(node->GetChild(i), node_type);
257 return retval;
260 if (node->GetDetailedInfo().node_type != node_type)
261 return std::string();
263 switch (node_type) {
264 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE:
265 return node->GetDetailedInfo().session_storage_info->origin_url.spec() +
266 ",";
267 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE:
268 return node->GetDetailedInfo().local_storage_info->origin_url.spec() +
269 ",";
270 case CookieTreeNode::DetailedInfo::TYPE_DATABASE:
271 return node->GetDetailedInfo().database_info->database_name + ",";
272 case CookieTreeNode::DetailedInfo::TYPE_COOKIE:
273 return node->GetDetailedInfo().cookie->Name() + ",";
274 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE:
275 return node->GetDetailedInfo().appcache_info->manifest_url.spec() +
276 ",";
277 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
278 return node->GetDetailedInfo().indexed_db_info->origin.spec() + ",";
279 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
280 return node->GetDetailedInfo().file_system_info->origin.spec() +
281 ",";
282 case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
283 return node->GetDetailedInfo().quota_info->host + ",";
284 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID:
285 return node->GetDetailedInfo().channel_id->server_identifier() + ",";
286 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER:
287 return node->GetDetailedInfo().service_worker_info->origin.spec() + ",";
288 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE:
289 return node->GetDetailedInfo().cache_storage_info->origin.spec() + ",";
290 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO:
291 return node->GetDetailedInfo().flash_lso_domain + ",";
292 default:
293 return std::string();
297 std::string GetCookiesOfChildren(const CookieTreeNode* node) {
298 return GetNodesOfChildren(node, CookieTreeNode::DetailedInfo::TYPE_COOKIE);
301 std::string GetDatabasesOfChildren(const CookieTreeNode* node) {
302 return GetNodesOfChildren(node,
303 CookieTreeNode::DetailedInfo::TYPE_DATABASE);
306 std::string GetLocalStoragesOfChildren(const CookieTreeNode* node) {
307 return GetNodesOfChildren(node,
308 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE);
311 std::string GetSessionStoragesOfChildren(const CookieTreeNode* node) {
312 return GetNodesOfChildren(
313 node, CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE);
316 std::string GetIndexedDBsOfChildren(const CookieTreeNode* node) {
317 return GetNodesOfChildren(
318 node, CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB);
321 std::string GetFileSystemsOfChildren(const CookieTreeNode* node) {
322 return GetNodesOfChildren(
323 node, CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM);
326 std::string GetFileQuotaOfChildren(const CookieTreeNode* node) {
327 return GetNodesOfChildren(
328 node, CookieTreeNode::DetailedInfo::TYPE_QUOTA);
331 std::string GetServiceWorkersOfChildren(const CookieTreeNode* node) {
332 return GetNodesOfChildren(
333 node, CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER);
336 std::string GetCacheStoragesOfChildren(const CookieTreeNode* node) {
337 return GetNodesOfChildren(node,
338 CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE);
341 std::string GetFlashLSOsOfChildren(const CookieTreeNode* node) {
342 return GetNodesOfChildren(
343 node, CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO);
346 // Get the nodes names displayed in the view (if we had one) in the order
347 // they are displayed, as a comma seperated string.
348 // Ex: EXPECT_STREQ("X,Y", GetDisplayedNodes(cookies_view, type).c_str());
349 std::string GetDisplayedNodes(CookiesTreeModel* cookies_model,
350 CookieTreeNode::DetailedInfo::NodeType type) {
351 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(
352 cookies_model->GetRoot());
353 std::string retval = GetNodesOfChildren(root, type);
354 if (retval.length() && retval[retval.length() - 1] == ',')
355 retval.erase(retval.length() - 1);
356 return retval;
359 std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) {
360 return GetDisplayedNodes(cookies_model,
361 CookieTreeNode::DetailedInfo::TYPE_COOKIE);
364 std::string GetDisplayedDatabases(CookiesTreeModel* cookies_model) {
365 return GetDisplayedNodes(cookies_model,
366 CookieTreeNode::DetailedInfo::TYPE_DATABASE);
369 std::string GetDisplayedLocalStorages(CookiesTreeModel* cookies_model) {
370 return GetDisplayedNodes(cookies_model,
371 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE);
374 std::string GetDisplayedSessionStorages(CookiesTreeModel* cookies_model) {
375 return GetDisplayedNodes(
376 cookies_model, CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE);
379 std::string GetDisplayedAppCaches(CookiesTreeModel* cookies_model) {
380 return GetDisplayedNodes(cookies_model,
381 CookieTreeNode::DetailedInfo::TYPE_APPCACHE);
384 std::string GetDisplayedIndexedDBs(CookiesTreeModel* cookies_model) {
385 return GetDisplayedNodes(cookies_model,
386 CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB);
389 std::string GetDisplayedFileSystems(CookiesTreeModel* cookies_model) {
390 return GetDisplayedNodes(cookies_model,
391 CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM);
394 std::string GetDisplayedQuotas(CookiesTreeModel* cookies_model) {
395 return GetDisplayedNodes(cookies_model,
396 CookieTreeNode::DetailedInfo::TYPE_QUOTA);
399 std::string GetDisplayedChannelIDs(CookiesTreeModel* cookies_model) {
400 return GetDisplayedNodes(
401 cookies_model, CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID);
404 std::string GetDisplayedServiceWorkers(CookiesTreeModel* cookies_model) {
405 return GetDisplayedNodes(cookies_model,
406 CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER);
409 std::string GetDisplayedCacheStorages(CookiesTreeModel* cookies_model) {
410 return GetDisplayedNodes(cookies_model,
411 CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE);
414 std::string GetDisplayedFlashLSOs(CookiesTreeModel* cookies_model) {
415 return GetDisplayedNodes(
416 cookies_model, CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO);
419 // Do not call on the root.
420 void DeleteStoredObjects(CookieTreeNode* node) {
421 node->DeleteStoredObjects();
422 CookieTreeNode* parent_node = node->parent();
423 DCHECK(parent_node);
424 delete parent_node->GetModel()->Remove(parent_node, node);
427 protected:
428 ExtensionSpecialStoragePolicy* special_storage_policy() {
429 #if defined(ENABLE_EXTENSIONS)
430 return special_storage_policy_.get();
431 #else
432 return nullptr;
433 #endif
436 content::TestBrowserThreadBundle thread_bundle_;
437 scoped_ptr<TestingProfile> profile_;
438 scoped_refptr<MockBrowsingDataCookieHelper>
439 mock_browsing_data_cookie_helper_;
440 scoped_refptr<MockBrowsingDataDatabaseHelper>
441 mock_browsing_data_database_helper_;
442 scoped_refptr<MockBrowsingDataLocalStorageHelper>
443 mock_browsing_data_local_storage_helper_;
444 scoped_refptr<MockBrowsingDataLocalStorageHelper>
445 mock_browsing_data_session_storage_helper_;
446 scoped_refptr<MockBrowsingDataAppCacheHelper>
447 mock_browsing_data_appcache_helper_;
448 scoped_refptr<MockBrowsingDataIndexedDBHelper>
449 mock_browsing_data_indexed_db_helper_;
450 scoped_refptr<MockBrowsingDataFileSystemHelper>
451 mock_browsing_data_file_system_helper_;
452 scoped_refptr<MockBrowsingDataQuotaHelper>
453 mock_browsing_data_quota_helper_;
454 scoped_refptr<MockBrowsingDataChannelIDHelper>
455 mock_browsing_data_channel_id_helper_;
456 scoped_refptr<MockBrowsingDataServiceWorkerHelper>
457 mock_browsing_data_service_worker_helper_;
458 scoped_refptr<MockBrowsingDataCacheStorageHelper>
459 mock_browsing_data_cache_storage_helper_;
460 scoped_refptr<MockBrowsingDataFlashLSOHelper>
461 mock_browsing_data_flash_lso_helper_;
463 #if defined(ENABLE_EXTENSIONS)
464 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
465 #endif
468 TEST_F(CookiesTreeModelTest, RemoveAll) {
469 scoped_ptr<CookiesTreeModel> cookies_model(
470 CreateCookiesTreeModelWithInitialSample());
472 // Reset the selection of the first row.
474 SCOPED_TRACE("Before removing");
475 EXPECT_EQ("A,B,C",
476 GetDisplayedCookies(cookies_model.get()));
477 EXPECT_EQ("db1,db2",
478 GetDisplayedDatabases(cookies_model.get()));
479 EXPECT_EQ("http://host1:1/,http://host2:2/",
480 GetDisplayedLocalStorages(cookies_model.get()));
481 EXPECT_EQ("http://host1:1/,http://host2:2/",
482 GetDisplayedSessionStorages(cookies_model.get()));
483 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
484 GetDisplayedIndexedDBs(cookies_model.get()));
485 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
486 GetDisplayedFileSystems(cookies_model.get()));
487 EXPECT_EQ("quotahost1,quotahost2",
488 GetDisplayedQuotas(cookies_model.get()));
489 EXPECT_EQ("sbc1,sbc2",
490 GetDisplayedChannelIDs(cookies_model.get()));
491 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
492 GetDisplayedCacheStorages(cookies_model.get()));
493 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
494 GetDisplayedServiceWorkers(cookies_model.get()));
495 EXPECT_EQ("xyz.com",
496 GetDisplayedFlashLSOs(cookies_model.get()));
499 mock_browsing_data_cookie_helper_->Reset();
500 mock_browsing_data_database_helper_->Reset();
501 mock_browsing_data_local_storage_helper_->Reset();
502 mock_browsing_data_session_storage_helper_->Reset();
503 mock_browsing_data_indexed_db_helper_->Reset();
504 mock_browsing_data_service_worker_helper_->Reset();
505 mock_browsing_data_cache_storage_helper_->Reset();
506 mock_browsing_data_file_system_helper_->Reset();
508 cookies_model->DeleteAllStoredObjects();
510 // Make sure the nodes are also deleted from the model's cache.
511 // http://crbug.com/43249
512 cookies_model->UpdateSearchResults(base::string16());
515 // 2 nodes - root and app
516 SCOPED_TRACE("After removing");
517 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount());
518 EXPECT_EQ(0, cookies_model->GetRoot()->child_count());
519 EXPECT_EQ(std::string(), GetDisplayedCookies(cookies_model.get()));
520 EXPECT_TRUE(mock_browsing_data_cookie_helper_->AllDeleted());
521 EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted());
522 EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted());
523 EXPECT_FALSE(mock_browsing_data_session_storage_helper_->AllDeleted());
524 EXPECT_TRUE(mock_browsing_data_indexed_db_helper_->AllDeleted());
525 EXPECT_TRUE(mock_browsing_data_file_system_helper_->AllDeleted());
526 EXPECT_TRUE(mock_browsing_data_channel_id_helper_->AllDeleted());
527 EXPECT_TRUE(mock_browsing_data_service_worker_helper_->AllDeleted());
528 EXPECT_TRUE(mock_browsing_data_cache_storage_helper_->AllDeleted());
529 EXPECT_TRUE(mock_browsing_data_flash_lso_helper_->AllDeleted());
533 TEST_F(CookiesTreeModelTest, Remove) {
534 scoped_ptr<CookiesTreeModel> cookies_model(
535 CreateCookiesTreeModelWithInitialSample());
537 // Children start out arranged as follows:
539 // 0. `cshost1`
540 // 1. `cshost2`
541 // 2. `foo1`
542 // 3. `foo2`
543 // 4. `foo3`
544 // 5. `fshost1`
545 // 6. `fshost2`
546 // 7. `fshost3`
547 // 8. `gdbhost1`
548 // 9. `gdbhost2`
549 // 10. `host1`
550 // 11. `host2`
551 // 12. `idbhost1`
552 // 13. `idbhost2`
553 // 14. `quotahost1`
554 // 15. `quotahost2`
555 // 16. `sbc1`
556 // 17. `sbc2`
557 // 18. `swhost1`
558 // 19. `swhost2`
559 // 20. `xyz.com`
561 // Here, we'll remove them one by one, starting from the end, and
562 // check that the state makes sense.
564 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(20));
566 SCOPED_TRACE("`xyz.com` removed.");
567 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
568 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
569 EXPECT_EQ("http://host1:1/,http://host2:2/",
570 GetDisplayedLocalStorages(cookies_model.get()));
571 EXPECT_EQ("http://host1:1/,http://host2:2/",
572 GetDisplayedSessionStorages(cookies_model.get()));
573 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
574 GetDisplayedFileSystems(cookies_model.get()));
575 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
576 GetDisplayedIndexedDBs(cookies_model.get()));
577 EXPECT_EQ("quotahost1,quotahost2",
578 GetDisplayedQuotas(cookies_model.get()));
579 EXPECT_EQ("sbc1,sbc2",
580 GetDisplayedChannelIDs(cookies_model.get()));
581 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
582 GetDisplayedServiceWorkers(cookies_model.get()));
583 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
584 GetDisplayedCacheStorages(cookies_model.get()));
585 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
586 EXPECT_EQ(63, cookies_model->GetRoot()->GetTotalNodeCount());
588 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(19));
590 SCOPED_TRACE("`swhost2` removed.");
591 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
592 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
593 EXPECT_EQ("http://host1:1/,http://host2:2/",
594 GetDisplayedLocalStorages(cookies_model.get()));
595 EXPECT_EQ("http://host1:1/,http://host2:2/",
596 GetDisplayedSessionStorages(cookies_model.get()));
597 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
598 GetDisplayedFileSystems(cookies_model.get()));
599 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
600 GetDisplayedIndexedDBs(cookies_model.get()));
601 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
602 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
603 EXPECT_EQ("https://swhost1:1/",
604 GetDisplayedServiceWorkers(cookies_model.get()));
605 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
606 GetDisplayedCacheStorages(cookies_model.get()));
607 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
608 EXPECT_EQ(60, cookies_model->GetRoot()->GetTotalNodeCount());
610 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(18));
612 SCOPED_TRACE("`swhost1` removed.");
613 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
614 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
615 EXPECT_EQ("http://host1:1/,http://host2:2/",
616 GetDisplayedLocalStorages(cookies_model.get()));
617 EXPECT_EQ("http://host1:1/,http://host2:2/",
618 GetDisplayedSessionStorages(cookies_model.get()));
619 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
620 GetDisplayedFileSystems(cookies_model.get()));
621 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
622 GetDisplayedIndexedDBs(cookies_model.get()));
623 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
624 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
625 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
626 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
627 GetDisplayedCacheStorages(cookies_model.get()));
628 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
629 EXPECT_EQ(57, cookies_model->GetRoot()->GetTotalNodeCount());
631 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(17));
633 SCOPED_TRACE("`sbc2` removed.");
634 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
635 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
636 EXPECT_EQ("http://host1:1/,http://host2:2/",
637 GetDisplayedLocalStorages(cookies_model.get()));
638 EXPECT_EQ("http://host1:1/,http://host2:2/",
639 GetDisplayedSessionStorages(cookies_model.get()));
640 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
641 GetDisplayedFileSystems(cookies_model.get()));
642 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
643 GetDisplayedIndexedDBs(cookies_model.get()));
644 EXPECT_EQ("quotahost1,quotahost2",
645 GetDisplayedQuotas(cookies_model.get()));
646 EXPECT_EQ("sbc1",
647 GetDisplayedChannelIDs(cookies_model.get()));
648 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
649 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
650 GetDisplayedCacheStorages(cookies_model.get()));
651 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
652 EXPECT_EQ(54, cookies_model->GetRoot()->GetTotalNodeCount());
654 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(16));
656 SCOPED_TRACE("`sbc1` removed.");
657 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
658 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
659 EXPECT_EQ("http://host1:1/,http://host2:2/",
660 GetDisplayedLocalStorages(cookies_model.get()));
661 EXPECT_EQ("http://host1:1/,http://host2:2/",
662 GetDisplayedSessionStorages(cookies_model.get()));
663 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
664 GetDisplayedFileSystems(cookies_model.get()));
665 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
666 GetDisplayedIndexedDBs(cookies_model.get()));
667 EXPECT_EQ("quotahost1,quotahost2",
668 GetDisplayedQuotas(cookies_model.get()));
669 EXPECT_EQ("", GetDisplayedChannelIDs(cookies_model.get()));
670 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
671 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
672 GetDisplayedCacheStorages(cookies_model.get()));
673 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
674 EXPECT_EQ(51, cookies_model->GetRoot()->GetTotalNodeCount());
676 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(15));
678 SCOPED_TRACE("`quotahost2` removed.");
679 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
680 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
681 EXPECT_EQ("http://host1:1/,http://host2:2/",
682 GetDisplayedLocalStorages(cookies_model.get()));
683 EXPECT_EQ("http://host1:1/,http://host2:2/",
684 GetDisplayedSessionStorages(cookies_model.get()));
685 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
686 GetDisplayedFileSystems(cookies_model.get()));
687 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
688 GetDisplayedIndexedDBs(cookies_model.get()));
689 EXPECT_EQ("quotahost1",
690 GetDisplayedQuotas(cookies_model.get()));
691 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
692 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
693 GetDisplayedCacheStorages(cookies_model.get()));
694 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
695 EXPECT_EQ(49, cookies_model->GetRoot()->GetTotalNodeCount());
697 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(14));
699 SCOPED_TRACE("`quotahost1` removed.");
700 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
701 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
702 EXPECT_EQ("http://host1:1/,http://host2:2/",
703 GetDisplayedLocalStorages(cookies_model.get()));
704 EXPECT_EQ("http://host1:1/,http://host2:2/",
705 GetDisplayedSessionStorages(cookies_model.get()));
706 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
707 GetDisplayedFileSystems(cookies_model.get()));
708 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
709 GetDisplayedIndexedDBs(cookies_model.get()));
710 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
711 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
712 GetDisplayedCacheStorages(cookies_model.get()));
713 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
714 EXPECT_EQ(47, cookies_model->GetRoot()->GetTotalNodeCount());
716 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(13));
718 SCOPED_TRACE("`idbhost2` removed.");
719 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
720 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
721 EXPECT_EQ("http://host1:1/,http://host2:2/",
722 GetDisplayedLocalStorages(cookies_model.get()));
723 EXPECT_EQ("http://host1:1/,http://host2:2/",
724 GetDisplayedSessionStorages(cookies_model.get()));
725 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
726 GetDisplayedFileSystems(cookies_model.get()));
727 EXPECT_EQ("http://idbhost1:1/",
728 GetDisplayedIndexedDBs(cookies_model.get()));
729 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
730 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
731 GetDisplayedCacheStorages(cookies_model.get()));
732 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
733 EXPECT_EQ(44, cookies_model->GetRoot()->GetTotalNodeCount());
735 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(12));
737 SCOPED_TRACE("`idbhost1` removed.");
738 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
739 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
740 EXPECT_EQ("http://host1:1/,http://host2:2/",
741 GetDisplayedLocalStorages(cookies_model.get()));
742 EXPECT_EQ("http://host1:1/,http://host2:2/",
743 GetDisplayedSessionStorages(cookies_model.get()));
744 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
745 GetDisplayedFileSystems(cookies_model.get()));
746 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
747 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
748 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
749 GetDisplayedCacheStorages(cookies_model.get()));
750 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
751 EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount());
753 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11));
755 SCOPED_TRACE("`host2` removed.");
756 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
757 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
758 EXPECT_EQ("http://host1:1/",
759 GetDisplayedLocalStorages(cookies_model.get()));
760 EXPECT_EQ("http://host1:1/",
761 GetDisplayedSessionStorages(cookies_model.get()));
762 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
763 GetDisplayedFileSystems(cookies_model.get()));
764 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
765 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
766 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
767 GetDisplayedCacheStorages(cookies_model.get()));
768 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
769 EXPECT_EQ(36, cookies_model->GetRoot()->GetTotalNodeCount());
771 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10));
773 SCOPED_TRACE("`host1` removed.");
774 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
775 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
776 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
777 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
778 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
779 GetDisplayedFileSystems(cookies_model.get()));
780 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
781 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
782 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
783 GetDisplayedCacheStorages(cookies_model.get()));
784 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
785 EXPECT_EQ(31, cookies_model->GetRoot()->GetTotalNodeCount());
787 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(9));
789 SCOPED_TRACE("`gdbhost2` removed.");
790 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
791 EXPECT_EQ("db1", GetDisplayedDatabases(cookies_model.get()));
792 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
793 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
794 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
795 GetDisplayedFileSystems(cookies_model.get()));
796 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
797 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
798 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
799 GetDisplayedCacheStorages(cookies_model.get()));
800 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
801 EXPECT_EQ(28, cookies_model->GetRoot()->GetTotalNodeCount());
803 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8));
805 SCOPED_TRACE("`gdbhost1` removed.");
806 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
807 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
808 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
809 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
810 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
811 GetDisplayedFileSystems(cookies_model.get()));
812 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
813 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
814 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
815 GetDisplayedCacheStorages(cookies_model.get()));
816 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
817 EXPECT_EQ(25, cookies_model->GetRoot()->GetTotalNodeCount());
819 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(7));
821 SCOPED_TRACE("`fshost3` removed.");
822 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
823 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
824 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
825 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
826 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/",
827 GetDisplayedFileSystems(cookies_model.get()));
828 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
829 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
830 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
831 GetDisplayedCacheStorages(cookies_model.get()));
832 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
833 EXPECT_EQ(22, cookies_model->GetRoot()->GetTotalNodeCount());
835 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6));
837 SCOPED_TRACE("`fshost2` removed.");
838 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
839 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
840 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
841 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
842 EXPECT_EQ("http://fshost1:1/",
843 GetDisplayedFileSystems(cookies_model.get()));
844 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
845 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
846 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
847 GetDisplayedCacheStorages(cookies_model.get()));
848 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
849 EXPECT_EQ(19, cookies_model->GetRoot()->GetTotalNodeCount());
851 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(5));
853 SCOPED_TRACE("`fshost1` removed.");
854 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str());
855 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
856 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
857 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
858 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
859 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
860 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
861 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
862 GetDisplayedCacheStorages(cookies_model.get()));
863 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
864 EXPECT_EQ(16, cookies_model->GetRoot()->GetTotalNodeCount());
866 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(4));
868 SCOPED_TRACE("`foo3` removed.");
869 EXPECT_STREQ("A,B", GetDisplayedCookies(cookies_model.get()).c_str());
870 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
871 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
872 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
873 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
874 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
875 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
876 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
877 GetDisplayedCacheStorages(cookies_model.get()));
878 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
879 EXPECT_EQ(13, cookies_model->GetRoot()->GetTotalNodeCount());
881 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3));
883 SCOPED_TRACE("`foo2` removed.");
884 EXPECT_STREQ("A", GetDisplayedCookies(cookies_model.get()).c_str());
885 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
886 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
887 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
888 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
889 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
890 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
891 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
892 GetDisplayedCacheStorages(cookies_model.get()));
893 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
894 EXPECT_EQ(10, cookies_model->GetRoot()->GetTotalNodeCount());
896 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2));
898 SCOPED_TRACE("`foo1` removed.");
899 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str());
900 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
901 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
902 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
903 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
904 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
905 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
906 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
907 GetDisplayedCacheStorages(cookies_model.get()));
908 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
909 EXPECT_EQ(7, cookies_model->GetRoot()->GetTotalNodeCount());
911 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1));
913 SCOPED_TRACE("`cshost2` removed.");
914 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str());
915 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
916 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
917 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
918 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
919 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
920 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
921 EXPECT_EQ("https://cshost1:1/",
922 GetDisplayedCacheStorages(cookies_model.get()));
923 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
924 EXPECT_EQ(4, cookies_model->GetRoot()->GetTotalNodeCount());
926 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0));
928 SCOPED_TRACE("`cshost1` removed.");
929 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str());
930 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get()));
931 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get()));
932 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get()));
933 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get()));
934 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get()));
935 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
936 EXPECT_EQ("", GetDisplayedCacheStorages(cookies_model.get()));
937 EXPECT_EQ("", GetDisplayedFlashLSOs(cookies_model.get()));
938 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount());
942 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
943 scoped_ptr<CookiesTreeModel> cookies_model(
944 CreateCookiesTreeModelWithInitialSample());
946 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2)->GetChild(0));
948 SCOPED_TRACE("First cookies origin removed");
949 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
950 // 63 because in this case, the origin remains, although the COOKIES
951 // node beneath it has been deleted.
952 EXPECT_EQ(63, cookies_model->GetRoot()->GetTotalNodeCount());
953 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
954 EXPECT_EQ("http://host1:1/,http://host2:2/",
955 GetDisplayedLocalStorages(cookies_model.get()));
956 EXPECT_EQ("http://host1:1/,http://host2:2/",
957 GetDisplayedSessionStorages(cookies_model.get()));
958 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
959 GetDisplayedIndexedDBs(cookies_model.get()));
960 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
961 GetDisplayedFileSystems(cookies_model.get()));
962 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
963 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
964 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
965 GetDisplayedServiceWorkers(cookies_model.get()));
966 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
967 GetDisplayedCacheStorages(cookies_model.get()));
970 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
972 SCOPED_TRACE("First database origin removed");
973 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
974 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
975 EXPECT_EQ("http://host1:1/,http://host2:2/",
976 GetDisplayedLocalStorages(cookies_model.get()));
977 EXPECT_EQ("http://host1:1/,http://host2:2/",
978 GetDisplayedSessionStorages(cookies_model.get()));
979 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
980 GetDisplayedIndexedDBs(cookies_model.get()));
981 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
982 GetDisplayedFileSystems(cookies_model.get()));
983 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
984 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
985 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
986 GetDisplayedServiceWorkers(cookies_model.get()));
987 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
988 GetDisplayedCacheStorages(cookies_model.get()));
989 EXPECT_EQ(61, cookies_model->GetRoot()->GetTotalNodeCount());
992 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10)->GetChild(0));
994 SCOPED_TRACE("First local storage origin removed");
995 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str());
996 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
997 EXPECT_EQ("http://host2:2/",
998 GetDisplayedLocalStorages(cookies_model.get()));
999 EXPECT_EQ("http://host1:1/,http://host2:2/",
1000 GetDisplayedSessionStorages(cookies_model.get()));
1001 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1002 GetDisplayedIndexedDBs(cookies_model.get()));
1003 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1004 GetDisplayedFileSystems(cookies_model.get()));
1005 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
1006 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
1007 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1008 GetDisplayedServiceWorkers(cookies_model.get()));
1009 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1010 GetDisplayedCacheStorages(cookies_model.get()));
1011 EXPECT_EQ(59, cookies_model->GetRoot()->GetTotalNodeCount());
1015 TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
1016 scoped_ptr<CookiesTreeModel> cookies_model(
1017 CreateCookiesTreeModelWithInitialSample());
1019 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3)->GetChild(0));
1021 SCOPED_TRACE("Second origin COOKIES node removed");
1022 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
1023 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get()));
1024 EXPECT_EQ("http://host1:1/,http://host2:2/",
1025 GetDisplayedLocalStorages(cookies_model.get()));
1026 EXPECT_EQ("http://host1:1/,http://host2:2/",
1027 GetDisplayedSessionStorages(cookies_model.get()));
1028 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1029 GetDisplayedIndexedDBs(cookies_model.get()));
1030 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1031 GetDisplayedFileSystems(cookies_model.get()));
1032 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
1033 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
1034 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1035 GetDisplayedServiceWorkers(cookies_model.get()));
1036 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1037 GetDisplayedCacheStorages(cookies_model.get()));
1038 // 63 because in this case, the origin remains, although the COOKIES
1039 // node beneath it has been deleted.
1040 EXPECT_EQ(63, cookies_model->GetRoot()->GetTotalNodeCount());
1043 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)->GetChild(0));
1045 SCOPED_TRACE("First database origin removed");
1046 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
1047 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
1048 EXPECT_EQ("http://host1:1/,http://host2:2/",
1049 GetDisplayedLocalStorages(cookies_model.get()));
1050 EXPECT_EQ("http://host1:1/,http://host2:2/",
1051 GetDisplayedSessionStorages(cookies_model.get()));
1052 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1053 GetDisplayedIndexedDBs(cookies_model.get()));
1054 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1055 GetDisplayedFileSystems(cookies_model.get()));
1056 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
1057 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
1058 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1059 GetDisplayedServiceWorkers(cookies_model.get()));
1060 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1061 GetDisplayedCacheStorages(cookies_model.get()));
1062 EXPECT_EQ(61, cookies_model->GetRoot()->GetTotalNodeCount());
1065 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10)->GetChild(0));
1067 SCOPED_TRACE("First local storage origin removed");
1068 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str());
1069 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get()));
1070 EXPECT_EQ("http://host2:2/",
1071 GetDisplayedLocalStorages(cookies_model.get()));
1072 EXPECT_EQ("http://host1:1/,http://host2:2/",
1073 GetDisplayedSessionStorages(cookies_model.get()));
1074 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1075 GetDisplayedIndexedDBs(cookies_model.get()));
1076 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1077 GetDisplayedFileSystems(cookies_model.get()));
1078 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get()));
1079 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get()));
1080 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1081 GetDisplayedServiceWorkers(cookies_model.get()));
1082 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1083 GetDisplayedCacheStorages(cookies_model.get()));
1084 EXPECT_EQ(59, cookies_model->GetRoot()->GetTotalNodeCount());
1088 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
1089 LocalDataContainer* container =
1090 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1091 mock_browsing_data_database_helper_.get(),
1092 mock_browsing_data_local_storage_helper_.get(),
1093 mock_browsing_data_session_storage_helper_.get(),
1094 mock_browsing_data_appcache_helper_.get(),
1095 mock_browsing_data_indexed_db_helper_.get(),
1096 mock_browsing_data_file_system_helper_.get(),
1097 mock_browsing_data_quota_helper_.get(),
1098 mock_browsing_data_channel_id_helper_.get(),
1099 mock_browsing_data_service_worker_helper_.get(),
1100 mock_browsing_data_cache_storage_helper_.get(),
1101 mock_browsing_data_flash_lso_helper_.get());
1102 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1104 mock_browsing_data_cookie_helper_->
1105 AddCookieSamples(GURL("http://foo1"), "A=1");
1106 mock_browsing_data_cookie_helper_->
1107 AddCookieSamples(GURL("http://foo2"), "B=1");
1108 mock_browsing_data_cookie_helper_->
1109 AddCookieSamples(GURL("http://foo3"), "C=1");
1110 mock_browsing_data_cookie_helper_->
1111 AddCookieSamples(GURL("http://foo3"), "D=1");
1112 mock_browsing_data_cookie_helper_->Notify();
1113 mock_browsing_data_database_helper_->AddDatabaseSamples();
1114 mock_browsing_data_database_helper_->Notify();
1115 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
1116 mock_browsing_data_local_storage_helper_->Notify();
1117 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
1118 mock_browsing_data_session_storage_helper_->Notify();
1119 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
1120 mock_browsing_data_indexed_db_helper_->Notify();
1121 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
1122 mock_browsing_data_file_system_helper_->Notify();
1123 mock_browsing_data_quota_helper_->AddQuotaSamples();
1124 mock_browsing_data_quota_helper_->Notify();
1125 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples();
1126 mock_browsing_data_service_worker_helper_->Notify();
1127 mock_browsing_data_cache_storage_helper_->AddCacheStorageSamples();
1128 mock_browsing_data_cache_storage_helper_->Notify();
1131 SCOPED_TRACE(
1132 "Initial State 4 cookies, 2 databases, 2 local storages, "
1133 "2 session storages, 2 indexed DBs, 3 file systems, "
1134 "2 quotas, 2 service workers, 2 caches.");
1135 // 58 because there's the root, then
1136 // cshost1 -> cache storage -> https://cshost1:1/
1137 // cshost2 -> cache storage -> https://cshost2:2/
1138 // foo1 -> cookies -> a,
1139 // foo2 -> cookies -> b,
1140 // foo3 -> cookies -> c,d
1141 // dbhost1 -> database -> db1,
1142 // dbhost2 -> database -> db2,
1143 // host1 -> localstorage -> http://host1:1/,
1144 // -> sessionstorage -> http://host1:1/,
1145 // host2 -> localstorage -> http://host2:2/,
1146 // -> sessionstorage -> http://host2:2/,
1147 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
1148 // idbhost2 -> sessionstorage -> http://idbhost2:2/,
1149 // fshost1 -> filesystem -> http://fshost1:1/,
1150 // fshost2 -> filesystem -> http://fshost2:1/,
1151 // fshost3 -> filesystem -> http://fshost3:1/,
1152 // quotahost1 -> quotahost1,
1153 // quotahost2 -> quotahost2.
1154 // swhost1 -> service worker -> https://swhost1:1
1155 // swhost2 -> service worker -> https://swhost1:2
1156 EXPECT_EQ(58, cookies_model.GetRoot()->GetTotalNodeCount());
1157 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
1158 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
1159 EXPECT_EQ("http://host1:1/,http://host2:2/",
1160 GetDisplayedLocalStorages(&cookies_model));
1161 EXPECT_EQ("http://host1:1/,http://host2:2/",
1162 GetDisplayedSessionStorages(&cookies_model));
1163 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1164 GetDisplayedIndexedDBs(&cookies_model));
1165 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1166 GetDisplayedFileSystems(&cookies_model));
1167 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
1168 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1169 GetDisplayedServiceWorkers(&cookies_model));
1170 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1171 GetDisplayedCacheStorages(&cookies_model));
1173 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(4));
1175 SCOPED_TRACE("Third cookie origin removed");
1176 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str());
1177 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
1178 EXPECT_EQ("http://host1:1/,http://host2:2/",
1179 GetDisplayedLocalStorages(&cookies_model));
1180 EXPECT_EQ("http://host1:1/,http://host2:2/",
1181 GetDisplayedSessionStorages(&cookies_model));
1182 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1183 GetDisplayedIndexedDBs(&cookies_model));
1184 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1185 GetDisplayedFileSystems(&cookies_model));
1186 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
1187 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1188 GetDisplayedServiceWorkers(&cookies_model));
1189 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1190 GetDisplayedCacheStorages(&cookies_model));
1191 EXPECT_EQ(54, cookies_model.GetRoot()->GetTotalNodeCount());
1195 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
1196 LocalDataContainer* container =
1197 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1198 mock_browsing_data_database_helper_.get(),
1199 mock_browsing_data_local_storage_helper_.get(),
1200 mock_browsing_data_session_storage_helper_.get(),
1201 mock_browsing_data_appcache_helper_.get(),
1202 mock_browsing_data_indexed_db_helper_.get(),
1203 mock_browsing_data_file_system_helper_.get(),
1204 mock_browsing_data_quota_helper_.get(),
1205 mock_browsing_data_channel_id_helper_.get(),
1206 mock_browsing_data_service_worker_helper_.get(),
1207 mock_browsing_data_cache_storage_helper_.get(),
1208 mock_browsing_data_flash_lso_helper_.get());
1209 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1211 mock_browsing_data_cookie_helper_->
1212 AddCookieSamples(GURL("http://foo1"), "A=1");
1213 mock_browsing_data_cookie_helper_->
1214 AddCookieSamples(GURL("http://foo2"), "B=1");
1215 mock_browsing_data_cookie_helper_->
1216 AddCookieSamples(GURL("http://foo3"), "C=1");
1217 mock_browsing_data_cookie_helper_->
1218 AddCookieSamples(GURL("http://foo3"), "D=1");
1219 mock_browsing_data_cookie_helper_->
1220 AddCookieSamples(GURL("http://foo3"), "E=1");
1221 mock_browsing_data_cookie_helper_->Notify();
1222 mock_browsing_data_database_helper_->AddDatabaseSamples();
1223 mock_browsing_data_database_helper_->Notify();
1224 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples();
1225 mock_browsing_data_local_storage_helper_->Notify();
1226 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples();
1227 mock_browsing_data_session_storage_helper_->Notify();
1228 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples();
1229 mock_browsing_data_indexed_db_helper_->Notify();
1230 mock_browsing_data_file_system_helper_->AddFileSystemSamples();
1231 mock_browsing_data_file_system_helper_->Notify();
1232 mock_browsing_data_quota_helper_->AddQuotaSamples();
1233 mock_browsing_data_quota_helper_->Notify();
1234 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples();
1235 mock_browsing_data_service_worker_helper_->Notify();
1236 mock_browsing_data_cache_storage_helper_->AddCacheStorageSamples();
1237 mock_browsing_data_cache_storage_helper_->Notify();
1240 SCOPED_TRACE(
1241 "Initial State 5 cookies, 2 databases, 2 local storages, "
1242 "2 session storages, 2 indexed DBs, 3 filesystems, "
1243 "2 quotas, 2 service workers, 2 caches.");
1244 // 59 because there's the root, then
1245 // cshost1 -> cache storage -> https://cshost1:1/
1246 // cshost2 -> cache storage -> https://cshost2:2/
1247 // foo1 -> cookies -> a,
1248 // foo2 -> cookies -> b,
1249 // foo3 -> cookies -> c,d,e
1250 // dbhost1 -> database -> db1,
1251 // dbhost2 -> database -> db2,
1252 // host1 -> localstorage -> http://host1:1/,
1253 // -> sessionstorage -> http://host1:1/,
1254 // host2 -> localstorage -> http://host2:2/,
1255 // -> sessionstorage -> http://host2:2/,
1256 // idbhost1 -> sessionstorage -> http://idbhost1:1/,
1257 // idbhost2 -> sessionstorage -> http://idbhost2:2/,
1258 // fshost1 -> filesystem -> http://fshost1:1/,
1259 // fshost2 -> filesystem -> http://fshost2:1/,
1260 // fshost3 -> filesystem -> http://fshost3:1/,
1261 // quotahost1 -> quotahost1,
1262 // quotahost2 -> quotahost2.
1263 // swhost1 -> service worker -> https://swhost1:1
1264 // swhost2 -> service worker -> https://swhost1:2
1265 EXPECT_EQ(59, cookies_model.GetRoot()->GetTotalNodeCount());
1266 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
1267 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
1268 EXPECT_EQ("http://host1:1/,http://host2:2/",
1269 GetDisplayedLocalStorages(&cookies_model));
1270 EXPECT_EQ("http://host1:1/,http://host2:2/",
1271 GetDisplayedSessionStorages(&cookies_model));
1272 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1273 GetDisplayedIndexedDBs(&cookies_model));
1274 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1275 GetDisplayedFileSystems(&cookies_model));
1276 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
1277 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1278 GetDisplayedServiceWorkers(&cookies_model));
1279 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1280 GetDisplayedCacheStorages(&cookies_model));
1282 DeleteStoredObjects(
1283 cookies_model.GetRoot()->GetChild(4)->GetChild(0)->GetChild(1));
1285 SCOPED_TRACE("Middle cookie in third cookie origin removed");
1286 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
1287 EXPECT_EQ(58, cookies_model.GetRoot()->GetTotalNodeCount());
1288 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model));
1289 EXPECT_EQ("http://host1:1/,http://host2:2/",
1290 GetDisplayedLocalStorages(&cookies_model));
1291 EXPECT_EQ("http://host1:1/,http://host2:2/",
1292 GetDisplayedSessionStorages(&cookies_model));
1293 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/",
1294 GetDisplayedIndexedDBs(&cookies_model));
1295 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1296 GetDisplayedFileSystems(&cookies_model));
1297 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model));
1298 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1299 GetDisplayedServiceWorkers(&cookies_model));
1300 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1301 GetDisplayedCacheStorages(&cookies_model));
1305 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
1306 LocalDataContainer* container =
1307 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1308 mock_browsing_data_database_helper_.get(),
1309 mock_browsing_data_local_storage_helper_.get(),
1310 mock_browsing_data_session_storage_helper_.get(),
1311 mock_browsing_data_appcache_helper_.get(),
1312 mock_browsing_data_indexed_db_helper_.get(),
1313 mock_browsing_data_file_system_helper_.get(),
1314 mock_browsing_data_quota_helper_.get(),
1315 mock_browsing_data_channel_id_helper_.get(),
1316 mock_browsing_data_service_worker_helper_.get(),
1317 mock_browsing_data_cache_storage_helper_.get(),
1318 mock_browsing_data_flash_lso_helper_.get());
1319 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1321 mock_browsing_data_cookie_helper_->
1322 AddCookieSamples(GURL("http://foo1"), "A=1");
1323 mock_browsing_data_cookie_helper_->
1324 AddCookieSamples(GURL("http://foo2"), "B=1");
1325 mock_browsing_data_cookie_helper_->
1326 AddCookieSamples(GURL("http://foo3"), "C=1");
1327 mock_browsing_data_cookie_helper_->
1328 AddCookieSamples(GURL("http://foo3"), "D=1");
1329 mock_browsing_data_cookie_helper_->
1330 AddCookieSamples(GURL("http://foo3"), "E=1");
1331 mock_browsing_data_cookie_helper_->Notify();
1334 SCOPED_TRACE("Initial State 5 cookies");
1335 // 12 because there's the root, then foo1 -> cookies -> a,
1336 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
1337 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
1338 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
1340 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1));
1342 SCOPED_TRACE("Second origin removed");
1343 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
1344 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e
1345 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount());
1349 TEST_F(CookiesTreeModelTest, OriginOrdering) {
1350 LocalDataContainer* container =
1351 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1352 mock_browsing_data_database_helper_.get(),
1353 mock_browsing_data_local_storage_helper_.get(),
1354 mock_browsing_data_session_storage_helper_.get(),
1355 mock_browsing_data_appcache_helper_.get(),
1356 mock_browsing_data_indexed_db_helper_.get(),
1357 mock_browsing_data_file_system_helper_.get(),
1358 mock_browsing_data_quota_helper_.get(),
1359 mock_browsing_data_channel_id_helper_.get(),
1360 mock_browsing_data_service_worker_helper_.get(),
1361 mock_browsing_data_cache_storage_helper_.get(),
1362 mock_browsing_data_flash_lso_helper_.get());
1363 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1365 mock_browsing_data_cookie_helper_->
1366 AddCookieSamples(GURL("http://a.foo2.com"), "A=1");
1367 mock_browsing_data_cookie_helper_->
1368 AddCookieSamples(GURL("http://foo2.com"), "B=1");
1369 mock_browsing_data_cookie_helper_->
1370 AddCookieSamples(GURL("http://b.foo1.com"), "C=1");
1371 // Leading dot on the foo4
1372 mock_browsing_data_cookie_helper_->AddCookieSamples(
1373 GURL("http://foo4.com"), "D=1; domain=.foo4.com; path=/;");
1374 mock_browsing_data_cookie_helper_->
1375 AddCookieSamples(GURL("http://a.foo1.com"), "E=1");
1376 mock_browsing_data_cookie_helper_->
1377 AddCookieSamples(GURL("http://foo1.com"), "F=1");
1378 mock_browsing_data_cookie_helper_->
1379 AddCookieSamples(GURL("http://foo3.com"), "G=1");
1380 mock_browsing_data_cookie_helper_->
1381 AddCookieSamples(GURL("http://foo4.com"), "H=1");
1382 mock_browsing_data_cookie_helper_->Notify();
1385 SCOPED_TRACE("Initial State 8 cookies");
1386 EXPECT_EQ(23, cookies_model.GetRoot()->GetTotalNodeCount());
1387 EXPECT_STREQ("F,E,C,B,A,G,D,H",
1388 GetDisplayedCookies(&cookies_model).c_str());
1390 // Delete "E"
1391 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1));
1393 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str());
1397 TEST_F(CookiesTreeModelTest, ContentSettings) {
1398 GURL host("http://xyz.com/");
1399 LocalDataContainer* container =
1400 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1401 mock_browsing_data_database_helper_.get(),
1402 mock_browsing_data_local_storage_helper_.get(),
1403 mock_browsing_data_session_storage_helper_.get(),
1404 mock_browsing_data_appcache_helper_.get(),
1405 mock_browsing_data_indexed_db_helper_.get(),
1406 mock_browsing_data_file_system_helper_.get(),
1407 mock_browsing_data_quota_helper_.get(),
1408 mock_browsing_data_channel_id_helper_.get(),
1409 mock_browsing_data_service_worker_helper_.get(),
1410 mock_browsing_data_cache_storage_helper_.get(),
1411 mock_browsing_data_flash_lso_helper_.get());
1412 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1414 mock_browsing_data_cookie_helper_->AddCookieSamples(host, "A=1");
1415 mock_browsing_data_cookie_helper_->Notify();
1417 TestingProfile profile;
1418 HostContentSettingsMap* content_settings =
1419 profile.GetHostContentSettingsMap();
1420 content_settings::CookieSettings* cookie_settings =
1421 CookieSettingsFactory::GetForProfile(&profile).get();
1422 MockSettingsObserver observer(content_settings);
1424 CookieTreeRootNode* root =
1425 static_cast<CookieTreeRootNode*>(cookies_model.GetRoot());
1426 CookieTreeHostNode* origin =
1427 root->GetOrCreateHostNode(host);
1429 EXPECT_EQ(1, origin->child_count());
1430 EXPECT_TRUE(origin->CanCreateContentException());
1431 EXPECT_CALL(observer,
1432 OnContentSettingsChanged(
1433 content_settings,
1434 CONTENT_SETTINGS_TYPE_COOKIES,
1435 false,
1436 ContentSettingsPattern::FromURLNoWildcard(host),
1437 ContentSettingsPattern::Wildcard(),
1438 false));
1439 EXPECT_CALL(observer,
1440 OnContentSettingsChanged(content_settings,
1441 CONTENT_SETTINGS_TYPE_COOKIES,
1442 false,
1443 ContentSettingsPattern::FromURL(host),
1444 ContentSettingsPattern::Wildcard(),
1445 false));
1446 origin->CreateContentException(
1447 cookie_settings, CONTENT_SETTING_SESSION_ONLY);
1448 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(host, host));
1449 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(host));
1452 TEST_F(CookiesTreeModelTest, FileSystemFilter) {
1453 scoped_ptr<CookiesTreeModel> cookies_model(
1454 CreateCookiesTreeModelWithInitialSample());
1456 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost1"));
1457 EXPECT_EQ("http://fshost1:1/",
1458 GetDisplayedFileSystems(cookies_model.get()));
1460 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost2"));
1461 EXPECT_EQ("http://fshost2:2/",
1462 GetDisplayedFileSystems(cookies_model.get()));
1464 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost3"));
1465 EXPECT_EQ("http://fshost3:3/",
1466 GetDisplayedFileSystems(cookies_model.get()));
1468 cookies_model->UpdateSearchResults(base::string16());
1469 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/",
1470 GetDisplayedFileSystems(cookies_model.get()));
1473 TEST_F(CookiesTreeModelTest, ServiceWorkerFilter) {
1474 scoped_ptr<CookiesTreeModel> cookies_model(
1475 CreateCookiesTreeModelWithInitialSample());
1477 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost1"));
1478 EXPECT_EQ("https://swhost1:1/",
1479 GetDisplayedServiceWorkers(cookies_model.get()));
1481 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost2"));
1482 EXPECT_EQ("https://swhost2:2/",
1483 GetDisplayedServiceWorkers(cookies_model.get()));
1485 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost3"));
1486 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get()));
1488 cookies_model->UpdateSearchResults(base::string16());
1489 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/",
1490 GetDisplayedServiceWorkers(cookies_model.get()));
1493 TEST_F(CookiesTreeModelTest, CacheStorageFilter) {
1494 scoped_ptr<CookiesTreeModel> cookies_model(
1495 CreateCookiesTreeModelWithInitialSample());
1497 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("cshost1"));
1498 EXPECT_EQ("https://cshost1:1/",
1499 GetDisplayedCacheStorages(cookies_model.get()));
1501 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("cshost2"));
1502 EXPECT_EQ("https://cshost2:2/",
1503 GetDisplayedCacheStorages(cookies_model.get()));
1505 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("cshost3"));
1506 EXPECT_EQ("", GetDisplayedCacheStorages(cookies_model.get()));
1508 cookies_model->UpdateSearchResults(base::string16());
1509 EXPECT_EQ("https://cshost1:1/,https://cshost2:2/",
1510 GetDisplayedCacheStorages(cookies_model.get()));
1513 TEST_F(CookiesTreeModelTest, CookiesFilter) {
1514 LocalDataContainer* container =
1515 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1516 mock_browsing_data_database_helper_.get(),
1517 mock_browsing_data_local_storage_helper_.get(),
1518 mock_browsing_data_session_storage_helper_.get(),
1519 mock_browsing_data_appcache_helper_.get(),
1520 mock_browsing_data_indexed_db_helper_.get(),
1521 mock_browsing_data_file_system_helper_.get(),
1522 mock_browsing_data_quota_helper_.get(),
1523 mock_browsing_data_channel_id_helper_.get(),
1524 mock_browsing_data_service_worker_helper_.get(),
1525 mock_browsing_data_cache_storage_helper_.get(),
1526 mock_browsing_data_flash_lso_helper_.get());
1527 CookiesTreeModel cookies_model(container, special_storage_policy(), false);
1529 mock_browsing_data_cookie_helper_->
1530 AddCookieSamples(GURL("http://123.com"), "A=1");
1531 mock_browsing_data_cookie_helper_->
1532 AddCookieSamples(GURL("http://foo1.com"), "B=1");
1533 mock_browsing_data_cookie_helper_->
1534 AddCookieSamples(GURL("http://foo2.com"), "C=1");
1535 mock_browsing_data_cookie_helper_->
1536 AddCookieSamples(GURL("http://foo3.com"), "D=1");
1537 mock_browsing_data_cookie_helper_->Notify();
1538 EXPECT_EQ("A,B,C,D", GetDisplayedCookies(&cookies_model));
1540 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("foo")));
1541 EXPECT_EQ("B,C,D", GetDisplayedCookies(&cookies_model));
1543 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("2")));
1544 EXPECT_EQ("A,C", GetDisplayedCookies(&cookies_model));
1546 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("foo3")));
1547 EXPECT_EQ("D", GetDisplayedCookies(&cookies_model));
1549 cookies_model.UpdateSearchResults(base::string16());
1550 EXPECT_EQ("A,B,C,D", GetDisplayedCookies(&cookies_model));
1553 // Tests that cookie source URLs are stored correctly in the cookies
1554 // tree model.
1555 TEST_F(CookiesTreeModelTest, CanonicalizeCookieSource) {
1556 LocalDataContainer* container =
1557 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(),
1558 mock_browsing_data_database_helper_.get(),
1559 mock_browsing_data_local_storage_helper_.get(),
1560 mock_browsing_data_session_storage_helper_.get(),
1561 mock_browsing_data_appcache_helper_.get(),
1562 mock_browsing_data_indexed_db_helper_.get(),
1563 mock_browsing_data_file_system_helper_.get(),
1564 mock_browsing_data_quota_helper_.get(),
1565 mock_browsing_data_channel_id_helper_.get(),
1566 mock_browsing_data_service_worker_helper_.get(),
1567 mock_browsing_data_cache_storage_helper_.get(),
1568 mock_browsing_data_flash_lso_helper_.get());
1569 CookiesTreeModel cookies_model(container, special_storage_policy(),
1570 true /* group by cookie source */);
1572 mock_browsing_data_cookie_helper_->AddCookieSamples(
1573 GURL("file:///tmp/test.html"), "A=1");
1574 mock_browsing_data_cookie_helper_->AddCookieSamples(
1575 GURL("http://example.com"), "B=1");
1576 mock_browsing_data_cookie_helper_->AddCookieSamples(
1577 GURL("http://example.com/"), "C=1");
1578 mock_browsing_data_cookie_helper_->AddCookieSamples(
1579 GURL("http://example.com/test"), "D=1");
1580 mock_browsing_data_cookie_helper_->AddCookieSamples(
1581 GURL("http://example.com:1234/"), "E=1");
1582 mock_browsing_data_cookie_helper_->AddCookieSamples(
1583 GURL("https://example.com/"), "F=1");
1584 mock_browsing_data_cookie_helper_->AddCookieSamples(
1585 GURL("http://user:pwd@example.com/"), "G=1");
1586 mock_browsing_data_cookie_helper_->AddCookieSamples(
1587 GURL("http://example.com/test?foo"), "H=1");
1588 mock_browsing_data_cookie_helper_->AddCookieSamples(
1589 GURL("http://example.com/test#foo"), "I=1");
1590 mock_browsing_data_cookie_helper_->AddCookieSamples(
1591 GURL("https://example2.com/test#foo"), "J=1");
1592 mock_browsing_data_cookie_helper_->AddCookieSamples(
1593 GURL("http://example3.com:1234/test#foo"), "K=1");
1594 mock_browsing_data_cookie_helper_->AddCookieSamples(
1595 GURL("http://user:pwd@example4.com/test?foo"), "L=1");
1596 mock_browsing_data_cookie_helper_->Notify();
1598 // Check that all the above example.com cookies go on the example.com
1599 // host node.
1600 cookies_model.UpdateSearchResults(
1601 base::string16(base::ASCIIToUTF16("example.com")));
1602 EXPECT_EQ("B,C,D,E,F,G,H,I", GetDisplayedCookies(&cookies_model));
1604 TestingProfile profile;
1605 content_settings::CookieSettings* cookie_settings =
1606 CookieSettingsFactory::GetForProfile(&profile).get();
1608 // Check that content settings for different URLs get applied to the
1609 // correct URL. That is, setting a cookie on https://example2.com
1610 // should create a host node for http://example2.com and thus content
1611 // settings set on that host node should apply to http://example2.com.
1613 cookies_model.UpdateSearchResults(
1614 base::string16(base::ASCIIToUTF16("file://")));
1615 EXPECT_EQ("A", GetDisplayedCookies(&cookies_model));
1616 CheckContentSettingsUrlForHostNodes(
1617 cookies_model.GetRoot(), CookieTreeNode::DetailedInfo::TYPE_ROOT,
1618 cookie_settings, GURL("file:///test/tmp.html"));
1620 cookies_model.UpdateSearchResults(
1621 base::string16(base::ASCIIToUTF16("example2.com")));
1622 EXPECT_EQ("J", GetDisplayedCookies(&cookies_model));
1623 CheckContentSettingsUrlForHostNodes(
1624 cookies_model.GetRoot(), CookieTreeNode::DetailedInfo::TYPE_ROOT,
1625 cookie_settings, GURL("http://example2.com"));
1627 cookies_model.UpdateSearchResults(
1628 base::string16(base::ASCIIToUTF16("example3.com")));
1629 EXPECT_EQ("K", GetDisplayedCookies(&cookies_model));
1630 CheckContentSettingsUrlForHostNodes(
1631 cookies_model.GetRoot(), CookieTreeNode::DetailedInfo::TYPE_ROOT,
1632 cookie_settings, GURL("http://example3.com"));
1634 cookies_model.UpdateSearchResults(
1635 base::string16(base::ASCIIToUTF16("example4.com")));
1636 EXPECT_EQ("L", GetDisplayedCookies(&cookies_model));
1637 CheckContentSettingsUrlForHostNodes(
1638 cookies_model.GetRoot(), CookieTreeNode::DetailedInfo::TYPE_ROOT,
1639 cookie_settings, GURL("http://example4.com"));
1642 } // namespace