| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/cookies_tree_model.h" | 5 #include "chrome/browser/cookies_tree_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "chrome/browser/net/url_request_context_getter.h" | 10 #include "chrome/browser/net/url_request_context_getter.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 virtual ~CookieTestingProfile() {} | 43 virtual ~CookieTestingProfile() {} |
| 44 | 44 |
| 45 net::CookieMonster* GetCookieMonster() { | 45 net::CookieMonster* GetCookieMonster() { |
| 46 return GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 46 return GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 scoped_refptr<URLRequestContextGetter> url_request_context_getter_; | 50 scoped_refptr<URLRequestContextGetter> url_request_context_getter_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 | |
| 54 | |
| 55 class CookiesTreeModelTest : public testing::Test { | 53 class CookiesTreeModelTest : public testing::Test { |
| 56 public: | 54 public: |
| 55 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { |
| 56 } |
| 57 |
| 58 virtual ~CookiesTreeModelTest() { |
| 59 } |
| 60 |
| 57 virtual void SetUp() { | 61 virtual void SetUp() { |
| 58 profile_.reset(new CookieTestingProfile()); | 62 profile_.reset(new CookieTestingProfile()); |
| 59 } | 63 } |
| 60 | 64 |
| 61 // Get the cookie names in the cookie list, as a comma seperated string. | 65 // Get the cookie names in the cookie list, as a comma seperated string. |
| 62 // (Note that the CookieMonster cookie list is sorted by domain.) | 66 // (Note that the CookieMonster cookie list is sorted by domain.) |
| 63 // Ex: | 67 // Ex: |
| 64 // monster->SetCookie(GURL("http://b"), "X=1") | 68 // monster->SetCookie(GURL("http://b"), "X=1") |
| 65 // monster->SetCookie(GURL("http://a"), "Y=1") | 69 // monster->SetCookie(GURL("http://a"), "Y=1") |
| 66 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); | 70 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // do not call on the root | 106 // do not call on the root |
| 103 void DeleteCookie(CookieTreeNode* node) { | 107 void DeleteCookie(CookieTreeNode* node) { |
| 104 node->DeleteStoredObjects(); | 108 node->DeleteStoredObjects(); |
| 105 // find the parent and index | 109 // find the parent and index |
| 106 CookieTreeNode* parent_node = node->GetParent(); | 110 CookieTreeNode* parent_node = node->GetParent(); |
| 107 DCHECK(parent_node); | 111 DCHECK(parent_node); |
| 108 int ct_node_index = parent_node->IndexOfChild(node); | 112 int ct_node_index = parent_node->IndexOfChild(node); |
| 109 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); | 113 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); |
| 110 } | 114 } |
| 111 protected: | 115 protected: |
| 112 MessageLoopForUI message_loop_; | 116 MessageLoop message_loop_; |
| 117 ChromeThread io_thread_; |
| 118 |
| 113 scoped_ptr<CookieTestingProfile> profile_; | 119 scoped_ptr<CookieTestingProfile> profile_; |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 | |
| 117 TEST_F(CookiesTreeModelTest, RemoveAll) { | 122 TEST_F(CookiesTreeModelTest, RemoveAll) { |
| 118 net::CookieMonster* monster = profile_->GetCookieMonster(); | 123 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 119 monster->SetCookie(GURL("http://foo"), "A=1"); | 124 monster->SetCookie(GURL("http://foo"), "A=1"); |
| 120 monster->SetCookie(GURL("http://foo2"), "B=1"); | 125 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 121 CookiesTreeModel cookies_model(profile_.get()); | 126 CookiesTreeModel cookies_model(profile_.get()); |
| 122 | 127 |
| 123 // Reset the selection of the first row. | 128 // Reset the selection of the first row. |
| 124 { | 129 { |
| 125 SCOPED_TRACE("Before removing"); | 130 SCOPED_TRACE("Before removing"); |
| 126 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); | 131 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 { | 286 { |
| 282 SCOPED_TRACE("Second origin removed"); | 287 SCOPED_TRACE("Second origin removed"); |
| 283 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); | 288 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); |
| 284 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); | 289 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 285 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e | 290 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e |
| 286 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); | 291 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 287 } | 292 } |
| 288 } | 293 } |
| 289 | 294 |
| 290 } // namespace | 295 } // namespace |
| OLD | NEW |