| OLD | NEW |
| 1 // Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 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/mock_browsing_data_local_storage_helper.h" |
| 10 #include "chrome/browser/net/url_request_context_getter.h" | 11 #include "chrome/browser/net/url_request_context_getter.h" |
| 11 #include "chrome/test/testing_profile.h" | 12 #include "chrome/test/testing_profile.h" |
| 12 #include "net/url_request/url_request_context.h" | 13 #include "net/url_request/url_request_context.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class CookiesTreeModelTest : public testing::Test { | 19 class CookiesTreeModelTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { | 21 CookiesTreeModelTest() : io_thread_(ChromeThread::IO, &message_loop_) { |
| 21 } | 22 } |
| 22 | 23 |
| 23 virtual ~CookiesTreeModelTest() { | 24 virtual ~CookiesTreeModelTest() { |
| 24 } | 25 } |
| 25 | 26 |
| 26 virtual void SetUp() { | 27 virtual void SetUp() { |
| 27 profile_.reset(new TestingProfile()); | 28 profile_.reset(new TestingProfile()); |
| 28 profile_->CreateRequestContext(); | 29 profile_->CreateRequestContext(); |
| 30 mock_browsing_data_helper_ = |
| 31 new MockBrowsingDataLocalStorageHelper(profile_.get()); |
| 32 } |
| 33 |
| 34 CookiesTreeModel* CreateCookiesTreeModelWithInitialSample() { |
| 35 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 36 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 37 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 38 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 39 CookiesTreeModel* cookies_model = new CookiesTreeModel( |
| 40 profile_.get(), mock_browsing_data_helper_); |
| 41 mock_browsing_data_helper_->AddLocalStorageSamples(); |
| 42 mock_browsing_data_helper_->Notify(); |
| 43 { |
| 44 SCOPED_TRACE("Initial State 3 cookies, 2 local storages"); |
| 45 // 16 because there's the root, then foo1 -> cookies -> a, |
| 46 // foo2 -> cookies -> b, foo3 -> cookies -> c, |
| 47 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
| 48 EXPECT_EQ(16, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 49 EXPECT_EQ("origin1,origin2", GetDisplayedLocalStorages(cookies_model)); |
| 50 } |
| 51 return cookies_model; |
| 29 } | 52 } |
| 30 | 53 |
| 31 // Get the cookie names in the cookie list, as a comma seperated string. | 54 // Get the cookie names in the cookie list, as a comma seperated string. |
| 32 // (Note that the CookieMonster cookie list is sorted by domain.) | 55 // (Note that the CookieMonster cookie list is sorted by domain.) |
| 33 // Ex: | 56 // Ex: |
| 34 // monster->SetCookie(GURL("http://b"), "X=1") | 57 // monster->SetCookie(GURL("http://b"), "X=1") |
| 35 // monster->SetCookie(GURL("http://a"), "Y=1") | 58 // monster->SetCookie(GURL("http://a"), "Y=1") |
| 36 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); | 59 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); |
| 37 std::string GetMonsterCookies(net::CookieMonster* monster) { | 60 std::string GetMonsterCookies(net::CookieMonster* monster) { |
| 38 std::vector<std::string> parts; | 61 std::vector<std::string> parts; |
| 39 net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); | 62 net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); |
| 40 for (size_t i = 0; i < cookie_list.size(); ++i) | 63 for (size_t i = 0; i < cookie_list.size(); ++i) |
| 41 parts.push_back(cookie_list[i].second.Name()); | 64 parts.push_back(cookie_list[i].second.Name()); |
| 42 return JoinString(parts, ','); | 65 return JoinString(parts, ','); |
| 43 } | 66 } |
| 44 | 67 |
| 45 std::string GetCookiesOfChildren(const CookieTreeNode* node) { | 68 std::string GetNodesOfChildren( |
| 69 const CookieTreeNode* node, |
| 70 CookieTreeNode::DetailedInfo::NodeType node_type) { |
| 46 if (node->GetChildCount()) { | 71 if (node->GetChildCount()) { |
| 47 std::string retval; | 72 std::string retval; |
| 48 for (int i = 0; i < node->GetChildCount(); ++i) { | 73 for (int i = 0; i < node->GetChildCount(); ++i) { |
| 49 retval += GetCookiesOfChildren(node->GetChild(i)); | 74 retval += GetNodesOfChildren(node->GetChild(i), node_type); |
| 50 } | 75 } |
| 51 return retval; | 76 return retval; |
| 52 } else { | 77 } else { |
| 53 if (node->GetDetailedInfo().node_type == | 78 if (node->GetDetailedInfo().node_type == node_type) { |
| 54 CookieTreeNode::DetailedInfo::TYPE_COOKIE) | 79 switch (node_type) { |
| 55 return node->GetDetailedInfo().cookie->second.Name() + ","; | 80 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: |
| 56 else | 81 return node->GetDetailedInfo().local_storage_info->origin + ","; |
| 82 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: |
| 83 return node->GetDetailedInfo().cookie->second.Name() + ","; |
| 84 default: |
| 85 return ""; |
| 86 } |
| 87 } else { |
| 57 return ""; | 88 return ""; |
| 89 } |
| 58 } | 90 } |
| 59 } | 91 } |
| 60 // Get the cookie names displayed in the view (if we had one) in the order | 92 |
| 93 std::string GetCookiesOfChildren(const CookieTreeNode* node) { |
| 94 return GetNodesOfChildren(node, CookieTreeNode::DetailedInfo::TYPE_COOKIE); |
| 95 } |
| 96 |
| 97 std::string GetLocalStoragesOfChildren(const CookieTreeNode* node) { |
| 98 return GetNodesOfChildren(node, |
| 99 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); |
| 100 } |
| 101 |
| 102 // Get the nodes names displayed in the view (if we had one) in the order |
| 61 // they are displayed, as a comma seperated string. | 103 // they are displayed, as a comma seperated string. |
| 62 // Ex: EXPECT_STREQ("X,Y", GetDisplayedCookies(cookies_view).c_str()); | 104 // Ex: EXPECT_STREQ("X,Y", GetDisplayedNodes(cookies_view, type).c_str()); |
| 63 std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) { | 105 std::string GetDisplayedNodes(CookiesTreeModel* cookies_model, |
| 106 CookieTreeNode::DetailedInfo::NodeType type) { |
| 64 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>( | 107 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>( |
| 65 cookies_model->GetRoot()); | 108 cookies_model->GetRoot()); |
| 66 std::string retval = GetCookiesOfChildren(root); | 109 std::string retval = GetNodesOfChildren(root, type); |
| 67 if (retval.length() && retval[retval.length() - 1] == ',') | 110 if (retval.length() && retval[retval.length() - 1] == ',') |
| 68 retval.erase(retval.length() - 1); | 111 retval.erase(retval.length() - 1); |
| 69 return retval; | 112 return retval; |
| 70 } | 113 } |
| 71 | 114 |
| 115 std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) { |
| 116 return GetDisplayedNodes(cookies_model, |
| 117 CookieTreeNode::DetailedInfo::TYPE_COOKIE); |
| 118 } |
| 119 |
| 120 std::string GetDisplayedLocalStorages(CookiesTreeModel* cookies_model) { |
| 121 return GetDisplayedNodes(cookies_model, |
| 122 CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE); |
| 123 } |
| 124 |
| 72 // do not call on the root | 125 // do not call on the root |
| 73 void DeleteCookie(CookieTreeNode* node) { | 126 void DeleteStoredObjects(CookieTreeNode* node) { |
| 74 node->DeleteStoredObjects(); | 127 node->DeleteStoredObjects(); |
| 75 // find the parent and index | 128 // find the parent and index |
| 76 CookieTreeNode* parent_node = node->GetParent(); | 129 CookieTreeNode* parent_node = node->GetParent(); |
| 77 DCHECK(parent_node); | 130 DCHECK(parent_node); |
| 78 int ct_node_index = parent_node->IndexOfChild(node); | 131 int ct_node_index = parent_node->IndexOfChild(node); |
| 79 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); | 132 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); |
| 80 } | 133 } |
| 81 protected: | 134 protected: |
| 82 MessageLoop message_loop_; | 135 MessageLoop message_loop_; |
| 83 ChromeThread io_thread_; | 136 ChromeThread io_thread_; |
| 84 | 137 |
| 85 scoped_ptr<TestingProfile> profile_; | 138 scoped_ptr<TestingProfile> profile_; |
| 139 MockBrowsingDataLocalStorageHelper* mock_browsing_data_helper_; |
| 86 }; | 140 }; |
| 87 | 141 |
| 88 TEST_F(CookiesTreeModelTest, RemoveAll) { | 142 TEST_F(CookiesTreeModelTest, RemoveAll) { |
| 143 scoped_ptr<CookiesTreeModel> cookies_model( |
| 144 CreateCookiesTreeModelWithInitialSample()); |
| 89 net::CookieMonster* monster = profile_->GetCookieMonster(); | 145 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 90 monster->SetCookie(GURL("http://foo"), "A=1"); | |
| 91 monster->SetCookie(GURL("http://foo2"), "B=1"); | |
| 92 CookiesTreeModel cookies_model(profile_.get()); | |
| 93 | 146 |
| 94 // Reset the selection of the first row. | 147 // Reset the selection of the first row. |
| 95 { | 148 { |
| 96 SCOPED_TRACE("Before removing"); | 149 SCOPED_TRACE("Before removing"); |
| 97 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); | 150 EXPECT_EQ(GetMonsterCookies(monster), |
| 151 GetDisplayedCookies(cookies_model.get())); |
| 152 EXPECT_EQ("origin1,origin2", |
| 153 GetDisplayedLocalStorages(cookies_model.get())); |
| 98 } | 154 } |
| 99 | 155 |
| 100 cookies_model.DeleteAllCookies(); | 156 cookies_model->DeleteAllCookies(); |
| 157 cookies_model->DeleteAllLocalStorage(); |
| 158 |
| 101 { | 159 { |
| 102 SCOPED_TRACE("After removing"); | 160 SCOPED_TRACE("After removing"); |
| 103 EXPECT_EQ(1, cookies_model.GetRoot()->GetTotalNodeCount()); | 161 EXPECT_EQ(1, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 104 EXPECT_EQ(0, cookies_model.GetRoot()->GetChildCount()); | 162 EXPECT_EQ(0, cookies_model->GetRoot()->GetChildCount()); |
| 105 EXPECT_EQ(std::string(""), GetMonsterCookies(monster)); | 163 EXPECT_EQ(std::string(""), GetMonsterCookies(monster)); |
| 106 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); | 164 EXPECT_EQ(GetMonsterCookies(monster), |
| 165 GetDisplayedCookies(cookies_model.get())); |
| 166 EXPECT_TRUE(mock_browsing_data_helper_->delete_all_files_called_); |
| 107 } | 167 } |
| 108 } | 168 } |
| 109 | 169 |
| 110 TEST_F(CookiesTreeModelTest, Remove) { | 170 TEST_F(CookiesTreeModelTest, Remove) { |
| 171 scoped_ptr<CookiesTreeModel> cookies_model( |
| 172 CreateCookiesTreeModelWithInitialSample()); |
| 111 net::CookieMonster* monster = profile_->GetCookieMonster(); | 173 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 112 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 113 monster->SetCookie(GURL("http://foo2"), "B=1"); | |
| 114 monster->SetCookie(GURL("http://foo3"), "C=1"); | |
| 115 CookiesTreeModel cookies_model(profile_.get()); | |
| 116 | 174 |
| 175 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)); |
| 117 { | 176 { |
| 118 SCOPED_TRACE("Initial State 3 cookies"); | 177 SCOPED_TRACE("First cookie origin removed"); |
| 119 // 10 because there's the root, then foo1 -> cookies -> a, | 178 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 120 // foo2 -> cookies -> b, foo3 -> cookies -> c | 179 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 121 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); | 180 EXPECT_EQ("origin1,origin2", GetDisplayedLocalStorages(cookies_model.get()))
; |
| 181 EXPECT_EQ(13, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 122 } | 182 } |
| 123 DeleteCookie(cookies_model.GetRoot()->GetChild(0)); | 183 |
| 184 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(2)); |
| 124 { | 185 { |
| 125 SCOPED_TRACE("First origin removed"); | 186 SCOPED_TRACE("First local storage origin removed"); |
| 126 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); | 187 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 127 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); | 188 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 128 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); | 189 EXPECT_EQ("origin2", GetDisplayedLocalStorages(cookies_model.get())); |
| 190 EXPECT_EQ(10, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 129 } | 191 } |
| 130 } | 192 } |
| 131 | 193 |
| 132 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { | 194 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { |
| 195 scoped_ptr<CookiesTreeModel> cookies_model( |
| 196 CreateCookiesTreeModelWithInitialSample()); |
| 133 net::CookieMonster* monster = profile_->GetCookieMonster(); | 197 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 134 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 135 monster->SetCookie(GURL("http://foo2"), "B=1"); | |
| 136 monster->SetCookie(GURL("http://foo3"), "C=1"); | |
| 137 CookiesTreeModel cookies_model(profile_.get()); | |
| 138 | 198 |
| 139 { | 199 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(0)->GetChild(0)); |
| 140 SCOPED_TRACE("Initial State 3 cookies"); | |
| 141 // 10 because there's the root, then foo1 -> cookies -> a, | |
| 142 // foo2 -> cookies -> b, foo3 -> cookies -> c | |
| 143 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); | |
| 144 } | |
| 145 DeleteCookie(cookies_model.GetRoot()->GetChild(0)->GetChild(0)); | |
| 146 { | 200 { |
| 147 SCOPED_TRACE("First origin removed"); | 201 SCOPED_TRACE("First origin removed"); |
| 148 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); | 202 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 149 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); | 203 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 150 // 8 because in this case, the origin remains, although the COOKIES | 204 // 14 because in this case, the origin remains, although the COOKIES |
| 151 // node beneath it has been deleted. So, we have | 205 // node beneath it has been deleted. So, we have |
| 152 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c | 206 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c |
| 153 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); | 207 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
| 208 EXPECT_EQ(14, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 209 EXPECT_EQ("origin1,origin2", |
| 210 GetDisplayedLocalStorages(cookies_model.get())); |
| 211 } |
| 212 |
| 213 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3)->GetChild(0)); |
| 214 { |
| 215 SCOPED_TRACE("First origin removed"); |
| 216 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 217 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 218 EXPECT_EQ("origin2", GetDisplayedLocalStorages(cookies_model.get())); |
| 219 EXPECT_EQ(12, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 154 } | 220 } |
| 155 } | 221 } |
| 156 | 222 |
| 157 TEST_F(CookiesTreeModelTest, RemoveCookieNode) { | 223 TEST_F(CookiesTreeModelTest, RemoveCookieNode) { |
| 224 scoped_ptr<CookiesTreeModel> cookies_model( |
| 225 CreateCookiesTreeModelWithInitialSample()); |
| 158 net::CookieMonster* monster = profile_->GetCookieMonster(); | 226 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 159 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 160 monster->SetCookie(GURL("http://foo2"), "B=1"); | |
| 161 monster->SetCookie(GURL("http://foo3"), "C=1"); | |
| 162 CookiesTreeModel cookies_model(profile_.get()); | |
| 163 | 227 |
| 164 { | 228 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(1)->GetChild(0)); |
| 165 SCOPED_TRACE("Initial State 3 cookies"); | |
| 166 // 10 because there's the root, then foo1 -> cookies -> a, | |
| 167 // foo2 -> cookies -> b, foo3 -> cookies -> c | |
| 168 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); | |
| 169 } | |
| 170 DeleteCookie(cookies_model.GetRoot()->GetChild(1)->GetChild(0)); | |
| 171 { | 229 { |
| 172 SCOPED_TRACE("Second origin COOKIES node removed"); | 230 SCOPED_TRACE("Second origin COOKIES node removed"); |
| 173 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); | 231 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); |
| 174 EXPECT_STREQ("A,C", GetDisplayedCookies(&cookies_model).c_str()); | 232 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 175 // 8 because in this case, the origin remains, although the COOKIES | 233 // 14 because in this case, the origin remains, although the COOKIES |
| 176 // node beneath it has been deleted. So, we have | 234 // node beneath it has been deleted. So, we have |
| 177 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c | 235 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c |
| 178 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); | 236 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
| 237 EXPECT_EQ(14, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 238 } |
| 239 |
| 240 DeleteStoredObjects(cookies_model->GetRoot()->GetChild(3)->GetChild(0)); |
| 241 { |
| 242 SCOPED_TRACE("First origin removed"); |
| 243 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); |
| 244 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_model.get()).c_str()); |
| 245 EXPECT_EQ("origin2", GetDisplayedLocalStorages(cookies_model.get())); |
| 246 EXPECT_EQ(12, cookies_model->GetRoot()->GetTotalNodeCount()); |
| 179 } | 247 } |
| 180 } | 248 } |
| 181 | 249 |
| 182 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { | 250 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { |
| 183 net::CookieMonster* monster = profile_->GetCookieMonster(); | 251 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 184 monster->SetCookie(GURL("http://foo1"), "A=1"); | 252 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 185 monster->SetCookie(GURL("http://foo2"), "B=1"); | 253 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 186 monster->SetCookie(GURL("http://foo3"), "C=1"); | 254 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 187 monster->SetCookie(GURL("http://foo3"), "D=1"); | 255 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 188 CookiesTreeModel cookies_model(profile_.get()); | 256 CookiesTreeModel cookies_model( |
| 257 profile_.get(), mock_browsing_data_helper_); |
| 258 mock_browsing_data_helper_->AddLocalStorageSamples(); |
| 259 mock_browsing_data_helper_->Notify(); |
| 189 | 260 |
| 190 { | 261 { |
| 191 SCOPED_TRACE("Initial State 4 cookies"); | 262 SCOPED_TRACE("Initial State 4 cookies, 2 local storages"); |
| 192 // 11 because there's the root, then foo1 -> cookies -> a, | 263 // 17 because there's the root, then foo1 -> cookies -> a, |
| 193 // foo2 -> cookies -> b, foo3 -> cookies -> c,d | 264 // foo2 -> cookies -> b, foo3 -> cookies -> c,d |
| 194 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); | 265 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
| 266 EXPECT_EQ(17, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 195 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str()); | 267 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str()); |
| 196 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); | 268 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); |
| 269 EXPECT_EQ("origin1,origin2", GetDisplayedLocalStorages(&cookies_model)); |
| 197 } | 270 } |
| 198 DeleteCookie(cookies_model.GetRoot()->GetChild(2)); | 271 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)); |
| 199 { | 272 { |
| 200 SCOPED_TRACE("Third origin removed"); | 273 SCOPED_TRACE("Third origin removed"); |
| 201 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str()); | 274 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str()); |
| 202 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); | 275 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); |
| 203 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); | 276 EXPECT_EQ(13, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 204 } | 277 } |
| 205 } | 278 } |
| 206 | 279 |
| 207 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { | 280 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { |
| 208 net::CookieMonster* monster = profile_->GetCookieMonster(); | 281 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 209 monster->SetCookie(GURL("http://foo1"), "A=1"); | 282 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 210 monster->SetCookie(GURL("http://foo2"), "B=1"); | 283 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 211 monster->SetCookie(GURL("http://foo3"), "C=1"); | 284 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 212 monster->SetCookie(GURL("http://foo3"), "D=1"); | 285 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 213 monster->SetCookie(GURL("http://foo3"), "E=1"); | 286 monster->SetCookie(GURL("http://foo3"), "E=1"); |
| 214 CookiesTreeModel cookies_model(profile_.get()); | 287 CookiesTreeModel cookies_model(profile_.get(), mock_browsing_data_helper_); |
| 288 mock_browsing_data_helper_->AddLocalStorageSamples(); |
| 289 mock_browsing_data_helper_->Notify(); |
| 215 | 290 |
| 216 { | 291 { |
| 217 SCOPED_TRACE("Initial State 5 cookies"); | 292 SCOPED_TRACE("Initial State 5 cookies, 2 local storages"); |
| 218 // 11 because there's the root, then foo1 -> cookies -> a, | 293 // 17 because there's the root, then foo1 -> cookies -> a, |
| 219 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e | 294 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
| 220 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); | 295 // host1 -> localstorage -> origin1, host2 -> localstorage -> origin2. |
| 296 EXPECT_EQ(18, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 221 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); | 297 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); |
| 222 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); | 298 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 299 EXPECT_EQ("origin1,origin2", GetDisplayedLocalStorages(&cookies_model)); |
| 223 } | 300 } |
| 224 DeleteCookie(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> | 301 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> |
| 225 GetChild(1)); | 302 GetChild(1)); |
| 226 { | 303 { |
| 227 SCOPED_TRACE("Middle cookie in third origin removed"); | 304 SCOPED_TRACE("Middle cookie in third origin removed"); |
| 228 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str()); | 305 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str()); |
| 229 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); | 306 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 230 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); | 307 EXPECT_EQ(17, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 308 EXPECT_EQ("origin1,origin2", GetDisplayedLocalStorages(&cookies_model)); |
| 231 } | 309 } |
| 232 } | 310 } |
| 233 | 311 |
| 234 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { | 312 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { |
| 235 net::CookieMonster* monster = profile_->GetCookieMonster(); | 313 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 236 monster->SetCookie(GURL("http://foo1"), "A=1"); | 314 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 237 monster->SetCookie(GURL("http://foo2"), "B=1"); | 315 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 238 monster->SetCookie(GURL("http://foo3"), "C=1"); | 316 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 239 monster->SetCookie(GURL("http://foo3"), "D=1"); | 317 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 240 monster->SetCookie(GURL("http://foo3"), "E=1"); | 318 monster->SetCookie(GURL("http://foo3"), "E=1"); |
| 241 CookiesTreeModel cookies_model(profile_.get()); | 319 CookiesTreeModel cookies_model(profile_.get(), mock_browsing_data_helper_); |
| 242 | |
| 243 { | 320 { |
| 244 SCOPED_TRACE("Initial State 5 cookies"); | 321 SCOPED_TRACE("Initial State 5 cookies"); |
| 245 // 11 because there's the root, then foo1 -> cookies -> a, | 322 // 11 because there's the root, then foo1 -> cookies -> a, |
| 246 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e | 323 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
| 247 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); | 324 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 248 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); | 325 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); |
| 249 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); | 326 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 250 } | 327 } |
| 251 DeleteCookie(cookies_model.GetRoot()->GetChild(1)); | 328 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); |
| 252 { | 329 { |
| 253 SCOPED_TRACE("Second origin removed"); | 330 SCOPED_TRACE("Second origin removed"); |
| 254 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); | 331 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); |
| 255 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); | 332 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 256 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e | 333 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e |
| 257 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); | 334 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 258 } | 335 } |
| 259 } | 336 } |
| 260 | 337 |
| 261 TEST_F(CookiesTreeModelTest, OriginOrdering) { | 338 TEST_F(CookiesTreeModelTest, OriginOrdering) { |
| 262 net::CookieMonster* monster = profile_->GetCookieMonster(); | 339 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 263 monster->SetCookie(GURL("http://a.foo2.com"), "A=1"); | 340 monster->SetCookie(GURL("http://a.foo2.com"), "A=1"); |
| 264 monster->SetCookie(GURL("http://foo2.com"), "B=1"); | 341 monster->SetCookie(GURL("http://foo2.com"), "B=1"); |
| 265 monster->SetCookie(GURL("http://b.foo1.com"), "C=1"); | 342 monster->SetCookie(GURL("http://b.foo1.com"), "C=1"); |
| 266 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;" | 343 monster->SetCookie(GURL("http://foo4.com"), "D=1; domain=.foo4.com;" |
| 267 " path=/;"); // Leading dot on the foo4 | 344 " path=/;"); // Leading dot on the foo4 |
| 268 monster->SetCookie(GURL("http://a.foo1.com"), "E=1"); | 345 monster->SetCookie(GURL("http://a.foo1.com"), "E=1"); |
| 269 monster->SetCookie(GURL("http://foo1.com"), "F=1"); | 346 monster->SetCookie(GURL("http://foo1.com"), "F=1"); |
| 270 monster->SetCookie(GURL("http://foo3.com"), "G=1"); | 347 monster->SetCookie(GURL("http://foo3.com"), "G=1"); |
| 271 monster->SetCookie(GURL("http://foo4.com"), "H=1"); | 348 monster->SetCookie(GURL("http://foo4.com"), "H=1"); |
| 272 | 349 |
| 273 CookiesTreeModel cookies_model(profile_.get()); | 350 CookiesTreeModel cookies_model( |
| 351 profile_.get(), new MockBrowsingDataLocalStorageHelper(profile_.get())); |
| 274 | 352 |
| 275 { | 353 { |
| 276 SCOPED_TRACE("Initial State 8 cookies"); | 354 SCOPED_TRACE("Initial State 8 cookies"); |
| 277 // D starts with a ., CookieMonster orders that lexicographically first | 355 // D starts with a ., CookieMonster orders that lexicographically first |
| 278 EXPECT_STREQ("D,E,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); | 356 EXPECT_STREQ("D,E,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); |
| 279 EXPECT_STREQ("F,E,C,B,A,G,D,H", | 357 EXPECT_STREQ("F,E,C,B,A,G,D,H", |
| 280 GetDisplayedCookies(&cookies_model).c_str()); | 358 GetDisplayedCookies(&cookies_model).c_str()); |
| 281 } | 359 } |
| 282 DeleteCookie(cookies_model.GetRoot()->GetChild(1)); // Delete "E" | 360 DeleteStoredObjects(cookies_model.GetRoot()->GetChild(1)); // Delete "E" |
| 283 { | 361 { |
| 284 SCOPED_TRACE("Second origin removed"); | 362 SCOPED_TRACE("Second origin removed"); |
| 285 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); | 363 EXPECT_STREQ("D,A,C,F,B,G,H", GetMonsterCookies(monster).c_str()); |
| 286 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); | 364 EXPECT_STREQ("F,C,B,A,G,D,H", GetDisplayedCookies(&cookies_model).c_str()); |
| 287 } | 365 } |
| 288 } | 366 } |
| 289 | 367 |
| 290 | 368 |
| 291 | 369 |
| 292 } // namespace | 370 } // namespace |
| OLD | NEW |