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. 4 5#include "chrome/browser/browsing_data/cookies_tree_model.h" 6 7#include <string> 8 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_channel_id_helper.h" 14#include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h" 15#include "chrome/browser/browsing_data/mock_browsing_data_database_helper.h" 16#include "chrome/browser/browsing_data/mock_browsing_data_file_system_helper.h" 17#include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h" 18#include "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h" 19#include "chrome/browser/browsing_data/mock_browsing_data_local_storage_helper.h" 20#include "chrome/browser/browsing_data/mock_browsing_data_quota_helper.h" 21#include "chrome/browser/browsing_data/mock_browsing_data_service_worker_helper.h" 22#include "chrome/browser/content_settings/cookie_settings.h" 23#include "chrome/browser/content_settings/host_content_settings_map.h" 24#include "chrome/browser/content_settings/mock_settings_observer.h" 25#include "chrome/test/base/testing_profile.h" 26#include "content/public/browser/notification_details.h" 27#include "content/public/browser/notification_types.h" 28#include "content/public/test/test_browser_thread_bundle.h" 29#include "net/url_request/url_request_context.h" 30#include "net/url_request/url_request_context_getter.h" 31#include "testing/gtest/include/gtest/gtest.h" 32 33#if defined(ENABLE_EXTENSIONS) 34#include "chrome/browser/extensions/extension_special_storage_policy.h" 35#endif 36 37using ::testing::_; 38using content::BrowserThread; 39 40namespace { 41 42class CookiesTreeModelTest : public testing::Test { 43 public: 44 virtual ~CookiesTreeModelTest() { 45 // Avoid memory leaks. 46#if defined(ENABLE_EXTENSIONS) 47 special_storage_policy_ = NULL; 48#endif 49 profile_.reset(); 50 base::MessageLoop::current()->RunUntilIdle(); 51 } 52 53 virtual void SetUp() OVERRIDE { 54 profile_.reset(new TestingProfile()); 55 mock_browsing_data_cookie_helper_ = 56 new MockBrowsingDataCookieHelper(profile_->GetRequestContext()); 57 mock_browsing_data_database_helper_ = 58 new MockBrowsingDataDatabaseHelper(profile_.get()); 59 mock_browsing_data_local_storage_helper_ = 60 new MockBrowsingDataLocalStorageHelper(profile_.get()); 61 mock_browsing_data_session_storage_helper_ = 62 new MockBrowsingDataLocalStorageHelper(profile_.get()); 63 mock_browsing_data_appcache_helper_ = 64 new MockBrowsingDataAppCacheHelper(profile_.get()); 65 mock_browsing_data_indexed_db_helper_ = 66 new MockBrowsingDataIndexedDBHelper(profile_.get()); 67 mock_browsing_data_file_system_helper_ = 68 new MockBrowsingDataFileSystemHelper(profile_.get()); 69 mock_browsing_data_quota_helper_ = 70 new MockBrowsingDataQuotaHelper(profile_.get()); 71 mock_browsing_data_channel_id_helper_ = 72 new MockBrowsingDataChannelIDHelper(); 73 mock_browsing_data_service_worker_helper_ = 74 new MockBrowsingDataServiceWorkerHelper(profile_.get()); 75 mock_browsing_data_flash_lso_helper_ = 76 new MockBrowsingDataFlashLSOHelper(profile_.get()); 77 78 scoped_refptr<CookieSettings> cookie_settings = 79 new CookieSettings(profile_->GetHostContentSettingsMap(), 80 profile_->GetPrefs()); 81#if defined(ENABLE_EXTENSIONS) 82 special_storage_policy_ = 83 new ExtensionSpecialStoragePolicy(cookie_settings.get()); 84#endif 85 } 86 87 virtual void TearDown() OVERRIDE { 88 mock_browsing_data_service_worker_helper_ = NULL; 89 mock_browsing_data_channel_id_helper_ = NULL; 90 mock_browsing_data_quota_helper_ = NULL; 91 mock_browsing_data_file_system_helper_ = NULL; 92 mock_browsing_data_indexed_db_helper_ = NULL; 93 mock_browsing_data_appcache_helper_ = NULL; 94 mock_browsing_data_session_storage_helper_ = NULL; 95 mock_browsing_data_local_storage_helper_ = NULL; 96 mock_browsing_data_database_helper_ = NULL; 97 mock_browsing_data_flash_lso_helper_ = NULL; 98 base::MessageLoop::current()->RunUntilIdle(); 99 } 100 101 scoped_ptr<CookiesTreeModel> CreateCookiesTreeModelWithInitialSample() { 102 LocalDataContainer* container = new LocalDataContainer( 103 mock_browsing_data_cookie_helper_.get(), 104 mock_browsing_data_database_helper_.get(), 105 mock_browsing_data_local_storage_helper_.get(), 106 mock_browsing_data_session_storage_helper_.get(), 107 mock_browsing_data_appcache_helper_.get(), 108 mock_browsing_data_indexed_db_helper_.get(), 109 mock_browsing_data_file_system_helper_.get(), 110 mock_browsing_data_quota_helper_.get(), 111 mock_browsing_data_channel_id_helper_.get(), 112 mock_browsing_data_service_worker_helper_.get(), 113 mock_browsing_data_flash_lso_helper_.get()); 114 115 CookiesTreeModel* cookies_model = 116 new CookiesTreeModel(container, special_storage_policy(), false); 117 mock_browsing_data_cookie_helper_-> 118 AddCookieSamples(GURL("http://foo1"), "A=1"); 119 mock_browsing_data_cookie_helper_-> 120 AddCookieSamples(GURL("http://foo2"), "B=1"); 121 mock_browsing_data_cookie_helper_-> 122 AddCookieSamples(GURL("http://foo3"), "C=1"); 123 mock_browsing_data_cookie_helper_->Notify(); 124 mock_browsing_data_database_helper_->AddDatabaseSamples(); 125 mock_browsing_data_database_helper_->Notify(); 126 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 127 mock_browsing_data_local_storage_helper_->Notify(); 128 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 129 mock_browsing_data_session_storage_helper_->Notify(); 130 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 131 mock_browsing_data_indexed_db_helper_->Notify(); 132 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 133 mock_browsing_data_file_system_helper_->Notify(); 134 mock_browsing_data_quota_helper_->AddQuotaSamples(); 135 mock_browsing_data_quota_helper_->Notify(); 136 mock_browsing_data_channel_id_helper_->AddChannelIDSample( 137 "sbc1"); 138 mock_browsing_data_channel_id_helper_->AddChannelIDSample( 139 "sbc2"); 140 mock_browsing_data_channel_id_helper_->Notify(); 141 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples(); 142 mock_browsing_data_service_worker_helper_->Notify(); 143 mock_browsing_data_flash_lso_helper_->AddFlashLSODomain("xyz.com"); 144 mock_browsing_data_flash_lso_helper_->Notify(); 145 146 { 147 SCOPED_TRACE("Initial State 3 cookies, 2 databases, 2 local storages, " 148 "2 session storages, 2 indexed DBs, 3 filesystems, " 149 "2 quotas, 2 server bound certs, 2 service workers, " 150 "1 Flash LSO"); 151 // 59 because there's the root, then 152 // foo1 -> cookies -> a, 153 // foo2 -> cookies -> b, 154 // foo3 -> cookies -> c, 155 // dbhost1 -> database -> db1, 156 // dbhost2 -> database -> db2, 157 // host1 -> localstorage -> http://host1:1/, 158 // -> sessionstorage -> http://host1:1/, 159 // host2 -> localstorage -> http://host2:2/. 160 // -> sessionstorage -> http://host2:2/, 161 // idbhost1 -> indexeddb -> http://idbhost1:1/, 162 // idbhost2 -> indexeddb -> http://idbhost2:2/, 163 // fshost1 -> filesystem -> http://fshost1:1/, 164 // fshost2 -> filesystem -> http://fshost2:1/, 165 // fshost3 -> filesystem -> http://fshost3:1/, 166 // quotahost1 -> quotahost1, 167 // quotahost2 -> quotahost2, 168 // sbc1 -> sbcerts -> sbc1, 169 // sbc2 -> sbcerts -> sbc2. 170 // swhost1 -> service worker -> https://swhost1:1 171 // swhost2 -> service worker -> https://swhost1:2 172 // xyz.com -> flash_lsos 173 EXPECT_EQ(59, cookies_model->GetRoot()->GetTotalNodeCount()); 174 EXPECT_EQ("A,B,C", GetDisplayedCookies(cookies_model)); 175 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model)); 176 EXPECT_EQ("http://host1:1/,http://host2:2/", 177 GetDisplayedLocalStorages(cookies_model)); 178 EXPECT_EQ("http://host1:1/,http://host2:2/", 179 GetDisplayedSessionStorages(cookies_model)); 180 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 181 GetDisplayedIndexedDBs(cookies_model)); 182 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 183 GetDisplayedFileSystems(cookies_model)); 184 EXPECT_EQ("quotahost1,quotahost2", 185 GetDisplayedQuotas(cookies_model)); 186 EXPECT_EQ("sbc1,sbc2", 187 GetDisplayedChannelIDs(cookies_model)); 188 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 189 GetDisplayedServiceWorkers(cookies_model)); 190 EXPECT_EQ("xyz.com", 191 GetDisplayedFlashLSOs(cookies_model)); 192 } 193 return make_scoped_ptr(cookies_model); 194 } 195 196 std::string GetNodesOfChildren( 197 const CookieTreeNode* node, 198 CookieTreeNode::DetailedInfo::NodeType node_type) { 199 if (!node->empty()) { 200 std::string retval; 201 for (int i = 0; i < node->child_count(); ++i) { 202 retval += GetNodesOfChildren(node->GetChild(i), node_type); 203 } 204 return retval; 205 } 206 207 if (node->GetDetailedInfo().node_type != node_type) 208 return std::string(); 209 210 switch (node_type) { 211 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: 212 return node->GetDetailedInfo().session_storage_info->origin_url.spec() + 213 ","; 214 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: 215 return node->GetDetailedInfo().local_storage_info->origin_url.spec() + 216 ","; 217 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: 218 return node->GetDetailedInfo().database_info->database_name + ","; 219 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: 220 return node->GetDetailedInfo().cookie->Name() + ","; 221 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: 222 return node->GetDetailedInfo().appcache_info->manifest_url.spec() + 223 ","; 224 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: 225 return node->GetDetailedInfo().indexed_db_info->origin_.spec() + 226 ","; 227 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: 228 return node->GetDetailedInfo().file_system_info->origin.spec() + 229 ","; 230 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: 231 return node->GetDetailedInfo().quota_info->host + ","; 232 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: 233 return node->GetDetailedInfo().channel_id->server_identifier() + ","; 234 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: 235 return node->GetDetailedInfo().service_worker_info->origin.spec() + ","; 236 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: 237 return node->GetDetailedInfo().flash_lso_domain + ","; 238 default: 239 return std::string(); 240 } 241 } 242 243 std::string GetCookiesOfChildren(const CookieTreeNode* node) { 244 return GetNodesOfChildren(node, CookieTreeNode::DetailedInfo::TYPE_COOKIE); 245 } 246 247 std::string GetDatabasesOfChildren(const CookieTreeNode* node) { 248 return GetNodesOfChildren(node, 249 CookieTreeNode::DetailedInfo::TYPE_DATABASE); 250 } 251 252 std::string GetLocalStoragesOfChildren(const CookieTreeNode* node) { 253 return GetNodesOfChildren(node, 254 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); 255 } 256 257 std::string GetSessionStoragesOfChildren(const CookieTreeNode* node) { 258 return GetNodesOfChildren( 259 node, CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE); 260 } 261 262 std::string GetIndexedDBsOfChildren(const CookieTreeNode* node) { 263 return GetNodesOfChildren( 264 node, CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB); 265 } 266 267 std::string GetFileSystemsOfChildren(const CookieTreeNode* node) { 268 return GetNodesOfChildren( 269 node, CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM); 270 } 271 272 std::string GetFileQuotaOfChildren(const CookieTreeNode* node) { 273 return GetNodesOfChildren( 274 node, CookieTreeNode::DetailedInfo::TYPE_QUOTA); 275 } 276 277 std::string GetServiceWorkersOfChildren(const CookieTreeNode* node) { 278 return GetNodesOfChildren( 279 node, CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER); 280 } 281 282 std::string GetFlashLSOsOfChildren(const CookieTreeNode* node) { 283 return GetNodesOfChildren( 284 node, CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO); 285 } 286 287 // Get the nodes names displayed in the view (if we had one) in the order 288 // they are displayed, as a comma seperated string. 289 // Ex: EXPECT_STREQ("X,Y", GetDisplayedNodes(cookies_view, type).c_str()); 290 std::string GetDisplayedNodes(CookiesTreeModel* cookies_model, 291 CookieTreeNode::DetailedInfo::NodeType type) { 292 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>( 293 cookies_model->GetRoot()); 294 std::string retval = GetNodesOfChildren(root, type); 295 if (retval.length() && retval[retval.length() - 1] == ',') 296 retval.erase(retval.length() - 1); 297 return retval; 298 } 299 300 std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) { 301 return GetDisplayedNodes(cookies_model, 302 CookieTreeNode::DetailedInfo::TYPE_COOKIE); 303 } 304 305 std::string GetDisplayedDatabases(CookiesTreeModel* cookies_model) { 306 return GetDisplayedNodes(cookies_model, 307 CookieTreeNode::DetailedInfo::TYPE_DATABASE); 308 } 309 310 std::string GetDisplayedLocalStorages(CookiesTreeModel* cookies_model) { 311 return GetDisplayedNodes(cookies_model, 312 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); 313 } 314 315 std::string GetDisplayedSessionStorages(CookiesTreeModel* cookies_model) { 316 return GetDisplayedNodes( 317 cookies_model, CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE); 318 } 319 320 std::string GetDisplayedAppCaches(CookiesTreeModel* cookies_model) { 321 return GetDisplayedNodes(cookies_model, 322 CookieTreeNode::DetailedInfo::TYPE_APPCACHE); 323 } 324 325 std::string GetDisplayedIndexedDBs(CookiesTreeModel* cookies_model) { 326 return GetDisplayedNodes(cookies_model, 327 CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB); 328 } 329 330 std::string GetDisplayedFileSystems(CookiesTreeModel* cookies_model) { 331 return GetDisplayedNodes(cookies_model, 332 CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM); 333 } 334 335 std::string GetDisplayedQuotas(CookiesTreeModel* cookies_model) { 336 return GetDisplayedNodes(cookies_model, 337 CookieTreeNode::DetailedInfo::TYPE_QUOTA); 338 } 339 340 std::string GetDisplayedChannelIDs(CookiesTreeModel* cookies_model) { 341 return GetDisplayedNodes( 342 cookies_model, CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID); 343 } 344 345 std::string GetDisplayedServiceWorkers(CookiesTreeModel* cookies_model) { 346 return GetDisplayedNodes(cookies_model, 347 CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER); 348 } 349 350 std::string GetDisplayedFlashLSOs(CookiesTreeModel* cookies_model) { 351 return GetDisplayedNodes( 352 cookies_model, CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO); 353 } 354 355 // Do not call on the root. 356 void DeleteStoredObjects(CookieTreeNode* node) { 357 node->DeleteStoredObjects(); 358 CookieTreeNode* parent_node = node->parent(); 359 DCHECK(parent_node); 360 delete parent_node->GetModel()->Remove(parent_node, node); 361 } 362 363 protected: 364 ExtensionSpecialStoragePolicy* special_storage_policy() { 365#if defined(ENABLE_EXTENSIONS) 366 return special_storage_policy_.get(); 367#else 368 return NULL; 369#endif 370 } 371 372 content::TestBrowserThreadBundle thread_bundle_; 373 scoped_ptr<TestingProfile> profile_; 374 scoped_refptr<MockBrowsingDataCookieHelper> 375 mock_browsing_data_cookie_helper_; 376 scoped_refptr<MockBrowsingDataDatabaseHelper> 377 mock_browsing_data_database_helper_; 378 scoped_refptr<MockBrowsingDataLocalStorageHelper> 379 mock_browsing_data_local_storage_helper_; 380 scoped_refptr<MockBrowsingDataLocalStorageHelper> 381 mock_browsing_data_session_storage_helper_; 382 scoped_refptr<MockBrowsingDataAppCacheHelper> 383 mock_browsing_data_appcache_helper_; 384 scoped_refptr<MockBrowsingDataIndexedDBHelper> 385 mock_browsing_data_indexed_db_helper_; 386 scoped_refptr<MockBrowsingDataFileSystemHelper> 387 mock_browsing_data_file_system_helper_; 388 scoped_refptr<MockBrowsingDataQuotaHelper> 389 mock_browsing_data_quota_helper_; 390 scoped_refptr<MockBrowsingDataChannelIDHelper> 391 mock_browsing_data_channel_id_helper_; 392 scoped_refptr<MockBrowsingDataServiceWorkerHelper> 393 mock_browsing_data_service_worker_helper_; 394 scoped_refptr<MockBrowsingDataFlashLSOHelper> 395 mock_browsing_data_flash_lso_helper_; 396 397#if defined(ENABLE_EXTENSIONS) 398 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_; 399#endif 400}; 401 402TEST_F(CookiesTreeModelTest, RemoveAll) { 403 scoped_ptr<CookiesTreeModel> cookies_model( 404 CreateCookiesTreeModelWithInitialSample()); 405 406 // Reset the selection of the first row. 407 { 408 SCOPED_TRACE("Before removing"); 409 EXPECT_EQ("A,B,C", 410 GetDisplayedCookies(cookies_model.get())); 411 EXPECT_EQ("db1,db2", 412 GetDisplayedDatabases(cookies_model.get())); 413 EXPECT_EQ("http://host1:1/,http://host2:2/", 414 GetDisplayedLocalStorages(cookies_model.get())); 415 EXPECT_EQ("http://host1:1/,http://host2:2/", 416 GetDisplayedSessionStorages(cookies_model.get())); 417 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 418 GetDisplayedIndexedDBs(cookies_model.get())); 419 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 420 GetDisplayedFileSystems(cookies_model.get())); 421 EXPECT_EQ("quotahost1,quotahost2", 422 GetDisplayedQuotas(cookies_model.get())); 423 EXPECT_EQ("sbc1,sbc2", 424 GetDisplayedChannelIDs(cookies_model.get())); 425 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 426 GetDisplayedServiceWorkers(cookies_model.get())); 427 EXPECT_EQ("xyz.com", 428 GetDisplayedFlashLSOs(cookies_model.get())); 429 } 430 431 mock_browsing_data_cookie_helper_->Reset(); 432 mock_browsing_data_database_helper_->Reset(); 433 mock_browsing_data_local_storage_helper_->Reset(); 434 mock_browsing_data_session_storage_helper_->Reset(); 435 mock_browsing_data_indexed_db_helper_->Reset(); 436 mock_browsing_data_service_worker_helper_->Reset(); 437 mock_browsing_data_file_system_helper_->Reset(); 438 439 cookies_model->DeleteAllStoredObjects(); 440 441 // Make sure the nodes are also deleted from the model's cache. 442 // http://crbug.com/43249 443 cookies_model->UpdateSearchResults(base::string16()); 444 445 { 446 // 2 nodes - root and app 447 SCOPED_TRACE("After removing"); 448 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount()); 449 EXPECT_EQ(0, cookies_model->GetRoot()->child_count()); 450 EXPECT_EQ(std::string(), GetDisplayedCookies(cookies_model.get())); 451 EXPECT_TRUE(mock_browsing_data_cookie_helper_->AllDeleted()); 452 EXPECT_TRUE(mock_browsing_data_database_helper_->AllDeleted()); 453 EXPECT_TRUE(mock_browsing_data_local_storage_helper_->AllDeleted()); 454 EXPECT_FALSE(mock_browsing_data_session_storage_helper_->AllDeleted()); 455 EXPECT_TRUE(mock_browsing_data_indexed_db_helper_->AllDeleted()); 456 EXPECT_TRUE(mock_browsing_data_file_system_helper_->AllDeleted()); 457 EXPECT_TRUE(mock_browsing_data_channel_id_helper_->AllDeleted()); 458 EXPECT_TRUE(mock_browsing_data_service_worker_helper_->AllDeleted()); 459 EXPECT_TRUE(mock_browsing_data_flash_lso_helper_->AllDeleted()); 460 } 461} 462 463TEST_F(CookiesTreeModelTest, Remove) { 464 scoped_ptr<CookiesTreeModel> cookies_model( 465 CreateCookiesTreeModelWithInitialSample()); 466 467 // Children start out arranged as follows: 468 // 469 // 0. `foo1` 470 // 1. `foo2` 471 // 2. `foo3` 472 // 3. `fshost1` 473 // 4. `fshost2` 474 // 5. `fshost3` 475 // 6. `gdbhost1` 476 // 7. `gdbhost2` 477 // 8. `host1` 478 // 9. `host2` 479 // 10. `idbhost1` 480 // 11. `idbhost2` 481 // 12. `quotahost1` 482 // 13. `quotahost2` 483 // 14. `sbc1` 484 // 15. `sbc2` 485 // 16. 'swhost1' 486 // 17. 'swhost2' 487 // 18. `xyz.com` 488 // 489 // Here, we'll remove them one by one, starting from the end, and 490 // check that the state makes sense. 491 492 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(18)); 493 { 494 SCOPED_TRACE("`xyz.com` removed."); 495 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 496 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 497 EXPECT_EQ("http://host1:1/,http://host2:2/", 498 GetDisplayedLocalStorages(cookies_model.get())); 499 EXPECT_EQ("http://host1:1/,http://host2:2/", 500 GetDisplayedSessionStorages(cookies_model.get())); 501 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 502 GetDisplayedFileSystems(cookies_model.get())); 503 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 504 GetDisplayedIndexedDBs(cookies_model.get())); 505 EXPECT_EQ("quotahost1,quotahost2", 506 GetDisplayedQuotas(cookies_model.get())); 507 EXPECT_EQ("sbc1,sbc2", 508 GetDisplayedChannelIDs(cookies_model.get())); 509 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 510 GetDisplayedServiceWorkers(cookies_model.get())); 511 EXPECT_EQ(57, cookies_model->GetRoot()->GetTotalNodeCount()); 512 } 513 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(17)); 514 { 515 SCOPED_TRACE("`swhost2` removed."); 516 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 517 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 518 EXPECT_EQ("http://host1:1/,http://host2:2/", 519 GetDisplayedLocalStorages(cookies_model.get())); 520 EXPECT_EQ("http://host1:1/,http://host2:2/", 521 GetDisplayedSessionStorages(cookies_model.get())); 522 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 523 GetDisplayedFileSystems(cookies_model.get())); 524 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 525 GetDisplayedIndexedDBs(cookies_model.get())); 526 EXPECT_EQ("quotahost1,quotahost2", 527 GetDisplayedQuotas(cookies_model.get())); 528 EXPECT_EQ("sbc1,sbc2", 529 GetDisplayedChannelIDs(cookies_model.get())); 530 EXPECT_EQ("https://swhost1:1/", 531 GetDisplayedServiceWorkers(cookies_model.get())); 532 EXPECT_EQ(54, cookies_model->GetRoot()->GetTotalNodeCount()); 533 } 534 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(16)); 535 { 536 SCOPED_TRACE("`swhost1` removed."); 537 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 538 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 539 EXPECT_EQ("http://host1:1/,http://host2:2/", 540 GetDisplayedLocalStorages(cookies_model.get())); 541 EXPECT_EQ("http://host1:1/,http://host2:2/", 542 GetDisplayedSessionStorages(cookies_model.get())); 543 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 544 GetDisplayedFileSystems(cookies_model.get())); 545 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 546 GetDisplayedIndexedDBs(cookies_model.get())); 547 EXPECT_EQ("quotahost1,quotahost2", 548 GetDisplayedQuotas(cookies_model.get())); 549 EXPECT_EQ("sbc1,sbc2", 550 GetDisplayedChannelIDs(cookies_model.get())); 551 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 552 EXPECT_EQ(51, cookies_model->GetRoot()->GetTotalNodeCount()); 553 } 554 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(15)); 555 { 556 SCOPED_TRACE("`sbc2` removed."); 557 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 558 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 559 EXPECT_EQ("http://host1:1/,http://host2:2/", 560 GetDisplayedLocalStorages(cookies_model.get())); 561 EXPECT_EQ("http://host1:1/,http://host2:2/", 562 GetDisplayedSessionStorages(cookies_model.get())); 563 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 564 GetDisplayedFileSystems(cookies_model.get())); 565 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 566 GetDisplayedIndexedDBs(cookies_model.get())); 567 EXPECT_EQ("quotahost1,quotahost2", 568 GetDisplayedQuotas(cookies_model.get())); 569 EXPECT_EQ("sbc1", 570 GetDisplayedChannelIDs(cookies_model.get())); 571 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 572 EXPECT_EQ(48, cookies_model->GetRoot()->GetTotalNodeCount()); 573 } 574 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(14)); 575 { 576 SCOPED_TRACE("`sbc1` removed."); 577 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 578 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 579 EXPECT_EQ("http://host1:1/,http://host2:2/", 580 GetDisplayedLocalStorages(cookies_model.get())); 581 EXPECT_EQ("http://host1:1/,http://host2:2/", 582 GetDisplayedSessionStorages(cookies_model.get())); 583 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 584 GetDisplayedFileSystems(cookies_model.get())); 585 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 586 GetDisplayedIndexedDBs(cookies_model.get())); 587 EXPECT_EQ("quotahost1,quotahost2", 588 GetDisplayedQuotas(cookies_model.get())); 589 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 590 EXPECT_EQ(45, cookies_model->GetRoot()->GetTotalNodeCount()); 591 } 592 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(13)); 593 { 594 SCOPED_TRACE("`quotahost2` removed."); 595 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 596 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 597 EXPECT_EQ("http://host1:1/,http://host2:2/", 598 GetDisplayedLocalStorages(cookies_model.get())); 599 EXPECT_EQ("http://host1:1/,http://host2:2/", 600 GetDisplayedSessionStorages(cookies_model.get())); 601 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 602 GetDisplayedFileSystems(cookies_model.get())); 603 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 604 GetDisplayedIndexedDBs(cookies_model.get())); 605 EXPECT_EQ("quotahost1", 606 GetDisplayedQuotas(cookies_model.get())); 607 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 608 EXPECT_EQ(43, cookies_model->GetRoot()->GetTotalNodeCount()); 609 } 610 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(12)); 611 { 612 SCOPED_TRACE("`quotahost1` 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("", GetDisplayedServiceWorkers(cookies_model.get())); 624 EXPECT_EQ(41, cookies_model->GetRoot()->GetTotalNodeCount()); 625 } 626 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(11)); 627 { 628 SCOPED_TRACE("`idbhost2` removed."); 629 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 630 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 631 EXPECT_EQ("http://host1:1/,http://host2:2/", 632 GetDisplayedLocalStorages(cookies_model.get())); 633 EXPECT_EQ("http://host1:1/,http://host2:2/", 634 GetDisplayedSessionStorages(cookies_model.get())); 635 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 636 GetDisplayedFileSystems(cookies_model.get())); 637 EXPECT_EQ("http://idbhost1:1/", 638 GetDisplayedIndexedDBs(cookies_model.get())); 639 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 640 EXPECT_EQ(38, cookies_model->GetRoot()->GetTotalNodeCount()); 641 } 642 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(10)); 643 { 644 SCOPED_TRACE("`idbhost1` removed."); 645 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 646 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 647 EXPECT_EQ("http://host1:1/,http://host2:2/", 648 GetDisplayedLocalStorages(cookies_model.get())); 649 EXPECT_EQ("http://host1:1/,http://host2:2/", 650 GetDisplayedSessionStorages(cookies_model.get())); 651 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 652 GetDisplayedFileSystems(cookies_model.get())); 653 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 654 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 655 EXPECT_EQ(35, cookies_model->GetRoot()->GetTotalNodeCount()); 656 } 657 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(9)); 658 { 659 SCOPED_TRACE("`host2` removed."); 660 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 661 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 662 EXPECT_EQ("http://host1:1/", 663 GetDisplayedLocalStorages(cookies_model.get())); 664 EXPECT_EQ("http://host1:1/", 665 GetDisplayedSessionStorages(cookies_model.get())); 666 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 667 GetDisplayedFileSystems(cookies_model.get())); 668 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 669 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 670 EXPECT_EQ(30, cookies_model->GetRoot()->GetTotalNodeCount()); 671 } 672 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(8)); 673 { 674 SCOPED_TRACE("`host1` removed."); 675 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 676 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 677 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 678 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 679 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 680 GetDisplayedFileSystems(cookies_model.get())); 681 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 682 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 683 EXPECT_EQ(25, cookies_model->GetRoot()->GetTotalNodeCount()); 684 } 685 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(7)); 686 { 687 SCOPED_TRACE("`gdbhost2` removed."); 688 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 689 EXPECT_EQ("db1", GetDisplayedDatabases(cookies_model.get())); 690 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 691 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 692 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 693 GetDisplayedFileSystems(cookies_model.get())); 694 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 695 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 696 EXPECT_EQ(22, cookies_model->GetRoot()->GetTotalNodeCount()); 697 } 698 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(6)); 699 { 700 SCOPED_TRACE("`gdbhost1` removed."); 701 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 702 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 703 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 704 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 705 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 706 GetDisplayedFileSystems(cookies_model.get())); 707 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 708 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 709 EXPECT_EQ(19, cookies_model->GetRoot()->GetTotalNodeCount()); 710 } 711 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(5)); 712 { 713 SCOPED_TRACE("`fshost3` removed."); 714 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 715 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 716 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 717 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 718 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/", 719 GetDisplayedFileSystems(cookies_model.get())); 720 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 721 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 722 EXPECT_EQ(16, cookies_model->GetRoot()->GetTotalNodeCount()); 723 } 724 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(4)); 725 { 726 SCOPED_TRACE("`fshost2` removed."); 727 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 728 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 729 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 730 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 731 EXPECT_EQ("http://fshost1:1/", 732 GetDisplayedFileSystems(cookies_model.get())); 733 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 734 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 735 EXPECT_EQ(13, cookies_model->GetRoot()->GetTotalNodeCount()); 736 } 737 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3)); 738 { 739 SCOPED_TRACE("`fshost1` removed."); 740 EXPECT_STREQ("A,B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 741 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 742 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 743 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 744 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 745 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 746 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 747 EXPECT_EQ(10, cookies_model->GetRoot()->GetTotalNodeCount()); 748 } 749 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2)); 750 { 751 SCOPED_TRACE("`foo3` removed."); 752 EXPECT_STREQ("A,B", GetDisplayedCookies(cookies_model.get()).c_str()); 753 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 754 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 755 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 756 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 757 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 758 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 759 EXPECT_EQ(7, cookies_model->GetRoot()->GetTotalNodeCount()); 760 } 761 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)); 762 { 763 SCOPED_TRACE("`foo2` removed."); 764 EXPECT_STREQ("A", GetDisplayedCookies(cookies_model.get()).c_str()); 765 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 766 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 767 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 768 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 769 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 770 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 771 EXPECT_EQ(4, cookies_model->GetRoot()->GetTotalNodeCount()); 772 } 773 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)); 774 { 775 SCOPED_TRACE("`foo1` removed."); 776 EXPECT_STREQ("", GetDisplayedCookies(cookies_model.get()).c_str()); 777 EXPECT_EQ("", GetDisplayedDatabases(cookies_model.get())); 778 EXPECT_EQ("", GetDisplayedLocalStorages(cookies_model.get())); 779 EXPECT_EQ("", GetDisplayedSessionStorages(cookies_model.get())); 780 EXPECT_EQ("", GetDisplayedFileSystems(cookies_model.get())); 781 EXPECT_EQ("", GetDisplayedIndexedDBs(cookies_model.get())); 782 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 783 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount()); 784 } 785} 786 787TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { 788 scoped_ptr<CookiesTreeModel> cookies_model( 789 CreateCookiesTreeModelWithInitialSample()); 790 791 DeleteStoredObjects( 792 cookies_model->GetRoot()->GetChild(0)->GetChild(0)); 793 { 794 SCOPED_TRACE("First origin removed"); 795 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 796 // 57 because in this case, the origin remains, although the COOKIES 797 // node beneath it has been deleted. 798 EXPECT_EQ(57, cookies_model->GetRoot()->GetTotalNodeCount()); 799 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 800 EXPECT_EQ("http://host1:1/,http://host2:2/", 801 GetDisplayedLocalStorages(cookies_model.get())); 802 EXPECT_EQ("http://host1:1/,http://host2:2/", 803 GetDisplayedSessionStorages(cookies_model.get())); 804 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 805 GetDisplayedIndexedDBs(cookies_model.get())); 806 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 807 GetDisplayedFileSystems(cookies_model.get())); 808 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 809 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 810 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 811 GetDisplayedServiceWorkers(cookies_model.get())); 812 } 813 814 DeleteStoredObjects( 815 cookies_model->GetRoot()->GetChild(6)->GetChild(0)); 816 { 817 SCOPED_TRACE("First database removed"); 818 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 819 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 820 EXPECT_EQ("http://host1:1/,http://host2:2/", 821 GetDisplayedLocalStorages(cookies_model.get())); 822 EXPECT_EQ("http://host1:1/,http://host2:2/", 823 GetDisplayedSessionStorages(cookies_model.get())); 824 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 825 GetDisplayedIndexedDBs(cookies_model.get())); 826 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 827 GetDisplayedFileSystems(cookies_model.get())); 828 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 829 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 830 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 831 GetDisplayedServiceWorkers(cookies_model.get())); 832 EXPECT_EQ(55, cookies_model->GetRoot()->GetTotalNodeCount()); 833 } 834 835 DeleteStoredObjects( 836 cookies_model->GetRoot()->GetChild(8)->GetChild(0)); 837 { 838 SCOPED_TRACE("First origin removed"); 839 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); 840 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 841 EXPECT_EQ("http://host2:2/", 842 GetDisplayedLocalStorages(cookies_model.get())); 843 EXPECT_EQ("http://host1:1/,http://host2:2/", 844 GetDisplayedSessionStorages(cookies_model.get())); 845 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 846 GetDisplayedIndexedDBs(cookies_model.get())); 847 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 848 GetDisplayedFileSystems(cookies_model.get())); 849 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 850 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 851 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 852 GetDisplayedServiceWorkers(cookies_model.get())); 853 EXPECT_EQ(53, cookies_model->GetRoot()->GetTotalNodeCount()); 854 } 855} 856 857TEST_F(CookiesTreeModelTest, RemoveCookieNode) { 858 scoped_ptr<CookiesTreeModel> cookies_model( 859 CreateCookiesTreeModelWithInitialSample()); 860 861 DeleteStoredObjects( 862 cookies_model->GetRoot()->GetChild(1)->GetChild(0)); 863 { 864 SCOPED_TRACE("Second origin COOKIES node removed"); 865 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 866 EXPECT_EQ("db1,db2", GetDisplayedDatabases(cookies_model.get())); 867 EXPECT_EQ("http://host1:1/,http://host2:2/", 868 GetDisplayedLocalStorages(cookies_model.get())); 869 EXPECT_EQ("http://host1:1/,http://host2:2/", 870 GetDisplayedSessionStorages(cookies_model.get())); 871 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 872 GetDisplayedIndexedDBs(cookies_model.get())); 873 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 874 GetDisplayedFileSystems(cookies_model.get())); 875 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 876 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 877 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 878 GetDisplayedServiceWorkers(cookies_model.get())); 879 // 57 because in this case, the origin remains, although the COOKIES 880 // node beneath it has been deleted. 881 EXPECT_EQ(57, cookies_model->GetRoot()->GetTotalNodeCount()); 882 } 883 884 DeleteStoredObjects( 885 cookies_model->GetRoot()->GetChild(6)->GetChild(0)); 886 { 887 SCOPED_TRACE("First database removed"); 888 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 889 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 890 EXPECT_EQ("http://host1:1/,http://host2:2/", 891 GetDisplayedLocalStorages(cookies_model.get())); 892 EXPECT_EQ("http://host1:1/,http://host2:2/", 893 GetDisplayedSessionStorages(cookies_model.get())); 894 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 895 GetDisplayedIndexedDBs(cookies_model.get())); 896 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 897 GetDisplayedFileSystems(cookies_model.get())); 898 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 899 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 900 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 901 GetDisplayedServiceWorkers(cookies_model.get())); 902 EXPECT_EQ(55, cookies_model->GetRoot()->GetTotalNodeCount()); 903 } 904 905 DeleteStoredObjects( 906 cookies_model->GetRoot()->GetChild(8)->GetChild(0)); 907 { 908 SCOPED_TRACE("First origin removed"); 909 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); 910 EXPECT_EQ("db2", GetDisplayedDatabases(cookies_model.get())); 911 EXPECT_EQ("http://host2:2/", 912 GetDisplayedLocalStorages(cookies_model.get())); 913 EXPECT_EQ("http://host1:1/,http://host2:2/", 914 GetDisplayedSessionStorages(cookies_model.get())); 915 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 916 GetDisplayedIndexedDBs(cookies_model.get())); 917 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 918 GetDisplayedFileSystems(cookies_model.get())); 919 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(cookies_model.get())); 920 EXPECT_EQ("sbc1,sbc2", GetDisplayedChannelIDs(cookies_model.get())); 921 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 922 GetDisplayedServiceWorkers(cookies_model.get())); 923 EXPECT_EQ(53, cookies_model->GetRoot()->GetTotalNodeCount()); 924 } 925} 926 927TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { 928 LocalDataContainer* container = 929 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 930 mock_browsing_data_database_helper_.get(), 931 mock_browsing_data_local_storage_helper_.get(), 932 mock_browsing_data_session_storage_helper_.get(), 933 mock_browsing_data_appcache_helper_.get(), 934 mock_browsing_data_indexed_db_helper_.get(), 935 mock_browsing_data_file_system_helper_.get(), 936 mock_browsing_data_quota_helper_.get(), 937 mock_browsing_data_channel_id_helper_.get(), 938 mock_browsing_data_service_worker_helper_.get(), 939 mock_browsing_data_flash_lso_helper_.get()); 940 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 941 942 mock_browsing_data_cookie_helper_-> 943 AddCookieSamples(GURL("http://foo1"), "A=1"); 944 mock_browsing_data_cookie_helper_-> 945 AddCookieSamples(GURL("http://foo2"), "B=1"); 946 mock_browsing_data_cookie_helper_-> 947 AddCookieSamples(GURL("http://foo3"), "C=1"); 948 mock_browsing_data_cookie_helper_-> 949 AddCookieSamples(GURL("http://foo3"), "D=1"); 950 mock_browsing_data_cookie_helper_->Notify(); 951 mock_browsing_data_database_helper_->AddDatabaseSamples(); 952 mock_browsing_data_database_helper_->Notify(); 953 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 954 mock_browsing_data_local_storage_helper_->Notify(); 955 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 956 mock_browsing_data_session_storage_helper_->Notify(); 957 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 958 mock_browsing_data_indexed_db_helper_->Notify(); 959 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 960 mock_browsing_data_file_system_helper_->Notify(); 961 mock_browsing_data_quota_helper_->AddQuotaSamples(); 962 mock_browsing_data_quota_helper_->Notify(); 963 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples(); 964 mock_browsing_data_service_worker_helper_->Notify(); 965 966 { 967 SCOPED_TRACE("Initial State 4 cookies, 2 databases, 2 local storages, " 968 "2 session storages, 2 indexed DBs, 3 file systems, " 969 "2 quotas, 2 service workers."); 970 // 52 because there's the root, then 971 // foo1 -> cookies -> a, 972 // foo2 -> cookies -> b, 973 // foo3 -> cookies -> c,d 974 // dbhost1 -> database -> db1, 975 // dbhost2 -> database -> db2, 976 // host1 -> localstorage -> http://host1:1/, 977 // -> sessionstorage -> http://host1:1/, 978 // host2 -> localstorage -> http://host2:2/, 979 // -> sessionstorage -> http://host2:2/, 980 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 981 // idbhost2 -> sessionstorage -> http://idbhost2:2/, 982 // fshost1 -> filesystem -> http://fshost1:1/, 983 // fshost2 -> filesystem -> http://fshost2:1/, 984 // fshost3 -> filesystem -> http://fshost3:1/, 985 // quotahost1 -> quotahost1, 986 // quotahost2 -> quotahost2. 987 // swhost1 -> service worker -> https://swhost1:1 988 // swhost2 -> service worker -> https://swhost1:2 989 EXPECT_EQ(52, cookies_model.GetRoot()->GetTotalNodeCount()); 990 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); 991 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 992 EXPECT_EQ("http://host1:1/,http://host2:2/", 993 GetDisplayedLocalStorages(&cookies_model)); 994 EXPECT_EQ("http://host1:1/,http://host2:2/", 995 GetDisplayedSessionStorages(&cookies_model)); 996 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 997 GetDisplayedIndexedDBs(&cookies_model)); 998 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 999 GetDisplayedFileSystems(&cookies_model)); 1000 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model)); 1001 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 1002 GetDisplayedServiceWorkers(&cookies_model)); 1003 } 1004 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)); 1005 { 1006 SCOPED_TRACE("Third origin removed"); 1007 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); 1008 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 1009 EXPECT_EQ("http://host1:1/,http://host2:2/", 1010 GetDisplayedLocalStorages(&cookies_model)); 1011 EXPECT_EQ("http://host1:1/,http://host2:2/", 1012 GetDisplayedSessionStorages(&cookies_model)); 1013 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 1014 GetDisplayedIndexedDBs(&cookies_model)); 1015 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 1016 GetDisplayedFileSystems(&cookies_model)); 1017 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model)); 1018 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 1019 GetDisplayedServiceWorkers(&cookies_model)); 1020 EXPECT_EQ(48, cookies_model.GetRoot()->GetTotalNodeCount()); 1021 } 1022} 1023 1024TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { 1025 LocalDataContainer* container = 1026 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 1027 mock_browsing_data_database_helper_.get(), 1028 mock_browsing_data_local_storage_helper_.get(), 1029 mock_browsing_data_session_storage_helper_.get(), 1030 mock_browsing_data_appcache_helper_.get(), 1031 mock_browsing_data_indexed_db_helper_.get(), 1032 mock_browsing_data_file_system_helper_.get(), 1033 mock_browsing_data_quota_helper_.get(), 1034 mock_browsing_data_channel_id_helper_.get(), 1035 mock_browsing_data_service_worker_helper_.get(), 1036 mock_browsing_data_flash_lso_helper_.get()); 1037 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 1038 1039 mock_browsing_data_cookie_helper_-> 1040 AddCookieSamples(GURL("http://foo1"), "A=1"); 1041 mock_browsing_data_cookie_helper_-> 1042 AddCookieSamples(GURL("http://foo2"), "B=1"); 1043 mock_browsing_data_cookie_helper_-> 1044 AddCookieSamples(GURL("http://foo3"), "C=1"); 1045 mock_browsing_data_cookie_helper_-> 1046 AddCookieSamples(GURL("http://foo3"), "D=1"); 1047 mock_browsing_data_cookie_helper_-> 1048 AddCookieSamples(GURL("http://foo3"), "E=1"); 1049 mock_browsing_data_cookie_helper_->Notify(); 1050 mock_browsing_data_database_helper_->AddDatabaseSamples(); 1051 mock_browsing_data_database_helper_->Notify(); 1052 mock_browsing_data_local_storage_helper_->AddLocalStorageSamples(); 1053 mock_browsing_data_local_storage_helper_->Notify(); 1054 mock_browsing_data_session_storage_helper_->AddLocalStorageSamples(); 1055 mock_browsing_data_session_storage_helper_->Notify(); 1056 mock_browsing_data_indexed_db_helper_->AddIndexedDBSamples(); 1057 mock_browsing_data_indexed_db_helper_->Notify(); 1058 mock_browsing_data_file_system_helper_->AddFileSystemSamples(); 1059 mock_browsing_data_file_system_helper_->Notify(); 1060 mock_browsing_data_quota_helper_->AddQuotaSamples(); 1061 mock_browsing_data_quota_helper_->Notify(); 1062 mock_browsing_data_service_worker_helper_->AddServiceWorkerSamples(); 1063 mock_browsing_data_service_worker_helper_->Notify(); 1064 1065 { 1066 SCOPED_TRACE("Initial State 5 cookies, 2 databases, 2 local storages, " 1067 "2 session storages, 2 indexed DBs, 3 filesystems, " 1068 "2 quotas, 2 service workers."); 1069 // 53 because there's the root, then 1070 // foo1 -> cookies -> a, 1071 // foo2 -> cookies -> b, 1072 // foo3 -> cookies -> c,d,e 1073 // dbhost1 -> database -> db1, 1074 // dbhost2 -> database -> db2, 1075 // host1 -> localstorage -> http://host1:1/, 1076 // -> sessionstorage -> http://host1:1/, 1077 // host2 -> localstorage -> http://host2:2/, 1078 // -> sessionstorage -> http://host2:2/, 1079 // idbhost1 -> sessionstorage -> http://idbhost1:1/, 1080 // idbhost2 -> sessionstorage -> http://idbhost2:2/, 1081 // fshost1 -> filesystem -> http://fshost1:1/, 1082 // fshost2 -> filesystem -> http://fshost2:1/, 1083 // fshost3 -> filesystem -> http://fshost3:1/, 1084 // quotahost1 -> quotahost1, 1085 // quotahost2 -> quotahost2. 1086 // swhost1 -> service worker -> https://swhost1:1 1087 // swhost2 -> service worker -> https://swhost1:2 1088 EXPECT_EQ(53, cookies_model.GetRoot()->GetTotalNodeCount()); 1089 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 1090 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 1091 EXPECT_EQ("http://host1:1/,http://host2:2/", 1092 GetDisplayedLocalStorages(&cookies_model)); 1093 EXPECT_EQ("http://host1:1/,http://host2:2/", 1094 GetDisplayedSessionStorages(&cookies_model)); 1095 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 1096 GetDisplayedIndexedDBs(&cookies_model)); 1097 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 1098 GetDisplayedFileSystems(&cookies_model)); 1099 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model)); 1100 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 1101 GetDisplayedServiceWorkers(&cookies_model)); 1102 } 1103 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> 1104 GetChild(1)); 1105 { 1106 SCOPED_TRACE("Middle cookie in third origin removed"); 1107 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); 1108 EXPECT_EQ(52, cookies_model.GetRoot()->GetTotalNodeCount()); 1109 EXPECT_EQ("db1,db2", GetDisplayedDatabases(&cookies_model)); 1110 EXPECT_EQ("http://host1:1/,http://host2:2/", 1111 GetDisplayedLocalStorages(&cookies_model)); 1112 EXPECT_EQ("http://host1:1/,http://host2:2/", 1113 GetDisplayedSessionStorages(&cookies_model)); 1114 EXPECT_EQ("http://idbhost1:1/,http://idbhost2:2/", 1115 GetDisplayedIndexedDBs(&cookies_model)); 1116 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 1117 GetDisplayedFileSystems(&cookies_model)); 1118 EXPECT_EQ("quotahost1,quotahost2", GetDisplayedQuotas(&cookies_model)); 1119 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 1120 GetDisplayedServiceWorkers(&cookies_model)); 1121 } 1122} 1123 1124TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { 1125 LocalDataContainer* container = 1126 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 1127 mock_browsing_data_database_helper_.get(), 1128 mock_browsing_data_local_storage_helper_.get(), 1129 mock_browsing_data_session_storage_helper_.get(), 1130 mock_browsing_data_appcache_helper_.get(), 1131 mock_browsing_data_indexed_db_helper_.get(), 1132 mock_browsing_data_file_system_helper_.get(), 1133 mock_browsing_data_quota_helper_.get(), 1134 mock_browsing_data_channel_id_helper_.get(), 1135 mock_browsing_data_service_worker_helper_.get(), 1136 mock_browsing_data_flash_lso_helper_.get()); 1137 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 1138 1139 mock_browsing_data_cookie_helper_-> 1140 AddCookieSamples(GURL("http://foo1"), "A=1"); 1141 mock_browsing_data_cookie_helper_-> 1142 AddCookieSamples(GURL("http://foo2"), "B=1"); 1143 mock_browsing_data_cookie_helper_-> 1144 AddCookieSamples(GURL("http://foo3"), "C=1"); 1145 mock_browsing_data_cookie_helper_-> 1146 AddCookieSamples(GURL("http://foo3"), "D=1"); 1147 mock_browsing_data_cookie_helper_-> 1148 AddCookieSamples(GURL("http://foo3"), "E=1"); 1149 mock_browsing_data_cookie_helper_->Notify(); 1150 1151 { 1152 SCOPED_TRACE("Initial State 5 cookies"); 1153 // 12 because there's the root, then foo1 -> cookies -> a, 1154 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e 1155 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); 1156 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 1157 } 1158 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); 1159 { 1160 SCOPED_TRACE("Second origin removed"); 1161 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); 1162 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e 1163 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); 1164 } 1165} 1166 1167TEST_F(CookiesTreeModelTest, OriginOrdering) { 1168 LocalDataContainer* container = 1169 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 1170 mock_browsing_data_database_helper_.get(), 1171 mock_browsing_data_local_storage_helper_.get(), 1172 mock_browsing_data_session_storage_helper_.get(), 1173 mock_browsing_data_appcache_helper_.get(), 1174 mock_browsing_data_indexed_db_helper_.get(), 1175 mock_browsing_data_file_system_helper_.get(), 1176 mock_browsing_data_quota_helper_.get(), 1177 mock_browsing_data_channel_id_helper_.get(), 1178 mock_browsing_data_service_worker_helper_.get(), 1179 mock_browsing_data_flash_lso_helper_.get()); 1180 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 1181 1182 mock_browsing_data_cookie_helper_-> 1183 AddCookieSamples(GURL("http://a.foo2.com"), "A=1"); 1184 mock_browsing_data_cookie_helper_-> 1185 AddCookieSamples(GURL("http://foo2.com"), "B=1"); 1186 mock_browsing_data_cookie_helper_-> 1187 AddCookieSamples(GURL("http://b.foo1.com"), "C=1"); 1188 // Leading dot on the foo4 1189 mock_browsing_data_cookie_helper_->AddCookieSamples( 1190 GURL("http://foo4.com"), "D=1; domain=.foo4.com; path=/;"); 1191 mock_browsing_data_cookie_helper_-> 1192 AddCookieSamples(GURL("http://a.foo1.com"), "E=1"); 1193 mock_browsing_data_cookie_helper_-> 1194 AddCookieSamples(GURL("http://foo1.com"), "F=1"); 1195 mock_browsing_data_cookie_helper_-> 1196 AddCookieSamples(GURL("http://foo3.com"), "G=1"); 1197 mock_browsing_data_cookie_helper_-> 1198 AddCookieSamples(GURL("http://foo4.com"), "H=1"); 1199 mock_browsing_data_cookie_helper_->Notify(); 1200 1201 { 1202 SCOPED_TRACE("Initial State 8 cookies"); 1203 EXPECT_EQ(23, cookies_model.GetRoot()->GetTotalNodeCount()); 1204 EXPECT_STREQ("F,E,C,B,A,G,D,H", 1205 GetDisplayedCookies(&cookies_model).c_str()); 1206 } 1207 // Delete "E" 1208 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); 1209 { 1210 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); 1211 } 1212} 1213 1214TEST_F(CookiesTreeModelTest, ContentSettings) { 1215 GURL host("http://xyz.com/"); 1216 LocalDataContainer* container = 1217 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 1218 mock_browsing_data_database_helper_.get(), 1219 mock_browsing_data_local_storage_helper_.get(), 1220 mock_browsing_data_session_storage_helper_.get(), 1221 mock_browsing_data_appcache_helper_.get(), 1222 mock_browsing_data_indexed_db_helper_.get(), 1223 mock_browsing_data_file_system_helper_.get(), 1224 mock_browsing_data_quota_helper_.get(), 1225 mock_browsing_data_channel_id_helper_.get(), 1226 mock_browsing_data_service_worker_helper_.get(), 1227 mock_browsing_data_flash_lso_helper_.get()); 1228 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 1229 1230 mock_browsing_data_cookie_helper_->AddCookieSamples(host, "A=1"); 1231 mock_browsing_data_cookie_helper_->Notify(); 1232 1233 TestingProfile profile; 1234 HostContentSettingsMap* content_settings = 1235 profile.GetHostContentSettingsMap(); 1236 CookieSettings* cookie_settings = 1237 CookieSettings::Factory::GetForProfile(&profile).get(); 1238 MockSettingsObserver observer(content_settings); 1239 1240 CookieTreeRootNode* root = 1241 static_cast<CookieTreeRootNode*>(cookies_model.GetRoot()); 1242 CookieTreeHostNode* origin = 1243 root->GetOrCreateHostNode(host); 1244 1245 EXPECT_EQ(1, origin->child_count()); 1246 EXPECT_TRUE(origin->CanCreateContentException()); 1247 EXPECT_CALL(observer, 1248 OnContentSettingsChanged( 1249 content_settings, 1250 CONTENT_SETTINGS_TYPE_COOKIES, 1251 false, 1252 ContentSettingsPattern::FromURLNoWildcard(host), 1253 ContentSettingsPattern::Wildcard(), 1254 false)); 1255 EXPECT_CALL(observer, 1256 OnContentSettingsChanged(content_settings, 1257 CONTENT_SETTINGS_TYPE_COOKIES, 1258 false, 1259 ContentSettingsPattern::FromURL(host), 1260 ContentSettingsPattern::Wildcard(), 1261 false)); 1262 origin->CreateContentException( 1263 cookie_settings, CONTENT_SETTING_SESSION_ONLY); 1264 EXPECT_TRUE(cookie_settings->IsReadingCookieAllowed(host, host)); 1265 EXPECT_TRUE(cookie_settings->IsCookieSessionOnly(host)); 1266} 1267 1268TEST_F(CookiesTreeModelTest, FileSystemFilter) { 1269 scoped_ptr<CookiesTreeModel> cookies_model( 1270 CreateCookiesTreeModelWithInitialSample()); 1271 1272 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost1")); 1273 EXPECT_EQ("http://fshost1:1/", 1274 GetDisplayedFileSystems(cookies_model.get())); 1275 1276 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost2")); 1277 EXPECT_EQ("http://fshost2:2/", 1278 GetDisplayedFileSystems(cookies_model.get())); 1279 1280 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("fshost3")); 1281 EXPECT_EQ("http://fshost3:3/", 1282 GetDisplayedFileSystems(cookies_model.get())); 1283 1284 cookies_model->UpdateSearchResults(base::string16()); 1285 EXPECT_EQ("http://fshost1:1/,http://fshost2:2/,http://fshost3:3/", 1286 GetDisplayedFileSystems(cookies_model.get())); 1287} 1288 1289TEST_F(CookiesTreeModelTest, ServiceWorkerFilter) { 1290 scoped_ptr<CookiesTreeModel> cookies_model( 1291 CreateCookiesTreeModelWithInitialSample()); 1292 1293 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost1")); 1294 EXPECT_EQ("https://swhost1:1/", 1295 GetDisplayedServiceWorkers(cookies_model.get())); 1296 1297 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost2")); 1298 EXPECT_EQ("https://swhost2:2/", 1299 GetDisplayedServiceWorkers(cookies_model.get())); 1300 1301 cookies_model->UpdateSearchResults(base::ASCIIToUTF16("swhost3")); 1302 EXPECT_EQ("", GetDisplayedServiceWorkers(cookies_model.get())); 1303 1304 cookies_model->UpdateSearchResults(base::string16()); 1305 EXPECT_EQ("https://swhost1:1/,https://swhost2:2/", 1306 GetDisplayedServiceWorkers(cookies_model.get())); 1307} 1308 1309TEST_F(CookiesTreeModelTest, CookiesFilter) { 1310 LocalDataContainer* container = 1311 new LocalDataContainer(mock_browsing_data_cookie_helper_.get(), 1312 mock_browsing_data_database_helper_.get(), 1313 mock_browsing_data_local_storage_helper_.get(), 1314 mock_browsing_data_session_storage_helper_.get(), 1315 mock_browsing_data_appcache_helper_.get(), 1316 mock_browsing_data_indexed_db_helper_.get(), 1317 mock_browsing_data_file_system_helper_.get(), 1318 mock_browsing_data_quota_helper_.get(), 1319 mock_browsing_data_channel_id_helper_.get(), 1320 mock_browsing_data_service_worker_helper_.get(), 1321 mock_browsing_data_flash_lso_helper_.get()); 1322 CookiesTreeModel cookies_model(container, special_storage_policy(), false); 1323 1324 mock_browsing_data_cookie_helper_-> 1325 AddCookieSamples(GURL("http://123.com"), "A=1"); 1326 mock_browsing_data_cookie_helper_-> 1327 AddCookieSamples(GURL("http://foo1.com"), "B=1"); 1328 mock_browsing_data_cookie_helper_-> 1329 AddCookieSamples(GURL("http://foo2.com"), "C=1"); 1330 mock_browsing_data_cookie_helper_-> 1331 AddCookieSamples(GURL("http://foo3.com"), "D=1"); 1332 mock_browsing_data_cookie_helper_->Notify(); 1333 EXPECT_EQ("A,B,C,D", GetDisplayedCookies(&cookies_model)); 1334 1335 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("foo"))); 1336 EXPECT_EQ("B,C,D", GetDisplayedCookies(&cookies_model)); 1337 1338 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("2"))); 1339 EXPECT_EQ("A,C", GetDisplayedCookies(&cookies_model)); 1340 1341 cookies_model.UpdateSearchResults(base::string16(base::ASCIIToUTF16("foo3"))); 1342 EXPECT_EQ("D", GetDisplayedCookies(&cookies_model)); 1343 1344 cookies_model.UpdateSearchResults(base::string16()); 1345 EXPECT_EQ("A,B,C,D", GetDisplayedCookies(&cookies_model)); 1346} 1347 1348} // namespace 1349