| OLD | NEW |
| 1 // Copyright (c) 2006-2008 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/gtk/options/cookies_view.h" | 5 #include "chrome/browser/cookies_tree_model.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | |
| 9 | 8 |
| 10 #include <gtk/gtk.h> | 9 #include "app/l10n_util.h" |
| 11 | |
| 12 #include "base/string_util.h" | |
| 13 #include "chrome/browser/cookies_table_model.h" | |
| 14 #include "chrome/browser/net/url_request_context_getter.h" | 10 #include "chrome/browser/net/url_request_context_getter.h" |
| 15 #include "chrome/test/testing_profile.h" | 11 #include "chrome/test/testing_profile.h" |
| 16 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 14 |
| 15 |
| 19 namespace { | 16 namespace { |
| 20 | 17 |
| 21 class TestURLRequestContext : public URLRequestContext { | 18 class TestURLRequestContext : public URLRequestContext { |
| 22 public: | 19 public: |
| 23 TestURLRequestContext() { | 20 TestURLRequestContext() { |
| 24 cookie_store_ = new net::CookieMonster(); | 21 cookie_store_ = new net::CookieMonster(); |
| 25 } | 22 } |
| 26 }; | 23 }; |
| 27 | 24 |
| 28 class TestURLRequestContextGetter : public URLRequestContextGetter { | 25 class TestURLRequestContextGetter : public URLRequestContextGetter { |
| 29 public: | 26 public: |
| 30 virtual URLRequestContext* GetURLRequestContext() { | 27 virtual URLRequestContext* GetURLRequestContext() { |
| 31 if (!context_) | 28 if (!context_) |
| 32 context_ = new TestURLRequestContext(); | 29 context_ = new TestURLRequestContext(); |
| 33 return context_; | 30 return context_.get(); |
| 34 } | 31 } |
| 35 private: | 32 private: |
| 36 scoped_refptr<URLRequestContext> context_; | 33 scoped_refptr<URLRequestContext> context_; |
| 37 }; | 34 }; |
| 38 | 35 |
| 39 class CookieTestingProfile : public TestingProfile { | 36 class CookieTestingProfile : public TestingProfile { |
| 40 public: | 37 public: |
| 41 virtual URLRequestContextGetter* GetRequestContext() { | 38 virtual URLRequestContextGetter* GetRequestContext() { |
| 42 if (!url_request_context_getter_.get()) | 39 if (!url_request_context_getter_.get()) |
| 43 url_request_context_getter_ = new TestURLRequestContextGetter; | 40 url_request_context_getter_ = new TestURLRequestContextGetter; |
| 44 return url_request_context_getter_.get(); | 41 return url_request_context_getter_.get(); |
| 45 } | 42 } |
| 46 virtual ~CookieTestingProfile() {} | 43 virtual ~CookieTestingProfile() {} |
| 47 | 44 |
| 48 net::CookieMonster* GetCookieMonster() { | 45 net::CookieMonster* GetCookieMonster() { |
| 49 return GetRequestContext()->GetCookieStore()->GetCookieMonster(); | 46 return GetRequestContext()->GetCookieStore()->GetCookieMonster(); |
| 50 } | 47 } |
| 51 | 48 |
| 52 private: | 49 private: |
| 53 scoped_refptr<URLRequestContextGetter> url_request_context_getter_; | 50 scoped_refptr<URLRequestContextGetter> url_request_context_getter_; |
| 54 }; | 51 }; |
| 55 | 52 |
| 56 } // namespace | |
| 57 | 53 |
| 58 class CookiesViewTest : public testing::Test { | 54 |
| 55 class CookiesTreeModelTest : public testing::Test { |
| 59 public: | 56 public: |
| 60 virtual void SetUp() { | 57 virtual void SetUp() { |
| 61 profile_.reset(new CookieTestingProfile()); | 58 profile_.reset(new CookieTestingProfile()); |
| 62 } | 59 } |
| 63 | 60 |
| 64 void CheckDetailsSensitivity(gboolean expected, | |
| 65 const CookiesView& cookies_view) { | |
| 66 EXPECT_EQ(expected, | |
| 67 GTK_WIDGET_SENSITIVE(cookies_view.cookie_name_entry_)); | |
| 68 EXPECT_EQ(expected, | |
| 69 GTK_WIDGET_SENSITIVE(cookies_view.cookie_content_entry_)); | |
| 70 EXPECT_EQ(expected, | |
| 71 GTK_WIDGET_SENSITIVE(cookies_view.cookie_domain_entry_)); | |
| 72 EXPECT_EQ(expected, | |
| 73 GTK_WIDGET_SENSITIVE(cookies_view.cookie_path_entry_)); | |
| 74 EXPECT_EQ(expected, | |
| 75 GTK_WIDGET_SENSITIVE(cookies_view.cookie_send_for_entry_)); | |
| 76 EXPECT_EQ(expected, | |
| 77 GTK_WIDGET_SENSITIVE(cookies_view.cookie_created_entry_)); | |
| 78 EXPECT_EQ(expected, | |
| 79 GTK_WIDGET_SENSITIVE(cookies_view.cookie_expires_entry_)); | |
| 80 } | |
| 81 | |
| 82 // Get the cookie names in the cookie list, as a comma seperated string. | 61 // Get the cookie names in the cookie list, as a comma seperated string. |
| 83 // (Note that the CookieMonster cookie list is sorted by domain.) | 62 // (Note that the CookieMonster cookie list is sorted by domain.) |
| 84 // Ex: | 63 // Ex: |
| 85 // monster->SetCookie(GURL("http://b"), "X=1") | 64 // monster->SetCookie(GURL("http://b"), "X=1") |
| 86 // monster->SetCookie(GURL("http://a"), "Y=1") | 65 // monster->SetCookie(GURL("http://a"), "Y=1") |
| 87 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); | 66 // EXPECT_STREQ("Y,X", GetMonsterCookies(monster).c_str()); |
| 88 std::string GetMonsterCookies(net::CookieMonster* monster) { | 67 std::string GetMonsterCookies(net::CookieMonster* monster) { |
| 89 std::vector<std::string> parts; | 68 std::vector<std::string> parts; |
| 90 net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); | 69 net::CookieMonster::CookieList cookie_list = monster->GetAllCookies(); |
| 91 for (size_t i = 0; i < cookie_list.size(); ++i) | 70 for (size_t i = 0; i < cookie_list.size(); ++i) |
| 92 parts.push_back(cookie_list[i].second.Name()); | 71 parts.push_back(cookie_list[i].second.Name()); |
| 93 return JoinString(parts, ','); | 72 return JoinString(parts, ','); |
| 94 } | 73 } |
| 95 | 74 |
| 96 // Get the cookie names displayed in the dialog in the order they are | 75 std::string GetCookiesOfChildren(const CookieTreeNode* node) { |
| 97 // displayed, as a comma seperated string. | 76 if (node->GetChildCount()) { |
| 77 std::string retval; |
| 78 for (int i = 0; i < node->GetChildCount(); ++i) { |
| 79 retval += GetCookiesOfChildren(node->GetChild(i)); |
| 80 } |
| 81 return retval; |
| 82 } else { |
| 83 if (node->GetDetailedInfo().node_type == |
| 84 CookieTreeNode::DetailedInfo::TYPE_COOKIE) |
| 85 return node->GetDetailedInfo().cookie->second.Name() + ","; |
| 86 else |
| 87 return ""; |
| 88 } |
| 89 } |
| 90 // Get the cookie names displayed in the view (if we had one) in the order |
| 91 // they are displayed, as a comma seperated string. |
| 98 // Ex: EXPECT_STREQ("X,Y", GetDisplayedCookies(cookies_view).c_str()); | 92 // Ex: EXPECT_STREQ("X,Y", GetDisplayedCookies(cookies_view).c_str()); |
| 99 std::string GetDisplayedCookies(const CookiesView& cookies_view) { | 93 std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) { |
| 100 std::vector<std::string> parts; | 94 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>( |
| 101 GtkTreeIter iter; | 95 cookies_model->GetRoot()); |
| 102 if (!gtk_tree_model_get_iter_first(cookies_view.list_sort_, &iter)) | 96 std::string retval = GetCookiesOfChildren(root); |
| 103 return std::string(); | 97 if (retval.length() && retval[retval.length() - 1] == ',') |
| 104 while (true) { | 98 retval.erase(retval.length() - 1); |
| 105 gchar* name; | 99 return retval; |
| 106 gtk_tree_model_get(cookies_view.list_sort_, &iter, | 100 } |
| 107 CookiesView::COL_COOKIE_NAME, &name, -1); | 101 |
| 108 parts.push_back(name); | 102 // do not call on the root |
| 109 g_free(name); | 103 void DeleteCookie(CookieTreeNode* node) { |
| 110 if (!gtk_tree_model_iter_next(cookies_view.list_sort_, &iter)) | 104 node->DeleteStoredObjects(); |
| 111 break; | 105 // find the parent and index |
| 112 } | 106 CookieTreeNode* parent_node = node->GetParent(); |
| 113 return JoinString(parts, ','); | 107 DCHECK(parent_node); |
| 114 } | 108 int ct_node_index = parent_node->IndexOfChild(node); |
| 115 | 109 delete parent_node->GetModel()->Remove(parent_node, ct_node_index); |
| 110 } |
| 116 protected: | 111 protected: |
| 117 MessageLoopForUI message_loop_; | 112 MessageLoopForUI message_loop_; |
| 118 scoped_ptr<CookieTestingProfile> profile_; | 113 scoped_ptr<CookieTestingProfile> profile_; |
| 119 }; | 114 }; |
| 120 | 115 |
| 121 TEST_F(CookiesViewTest, Empty) { | 116 |
| 122 CookiesView cookies_view(profile_.get()); | 117 TEST_F(CookiesTreeModelTest, RemoveAll) { |
| 123 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 124 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 125 CheckDetailsSensitivity(FALSE, cookies_view); | |
| 126 EXPECT_EQ(0, gtk_tree_model_iter_n_children( | |
| 127 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 128 } | |
| 129 | |
| 130 TEST_F(CookiesViewTest, RemoveAll) { | |
| 131 net::CookieMonster* monster = profile_->GetCookieMonster(); | 118 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 132 monster->SetCookie(GURL("http://foo"), "A=1"); | 119 monster->SetCookie(GURL("http://foo"), "A=1"); |
| 133 monster->SetCookie(GURL("http://foo2"), "B=1"); | 120 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 134 CookiesView cookies_view(profile_.get()); | 121 CookiesTreeModel cookies_model(profile_.get()); |
| 135 | 122 |
| 136 // Reset the selection of the first row. | 123 // Reset the selection of the first row. |
| 137 gtk_tree_selection_unselect_all(cookies_view.selection_); | |
| 138 | |
| 139 { | 124 { |
| 140 SCOPED_TRACE("Before removing"); | 125 SCOPED_TRACE("Before removing"); |
| 141 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 126 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); |
| 142 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 127 } |
| 143 CheckDetailsSensitivity(FALSE, cookies_view); | 128 |
| 144 EXPECT_EQ(2, gtk_tree_model_iter_n_children( | 129 cookies_model.DeleteAllCookies(); |
| 145 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 146 } | |
| 147 | |
| 148 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); | |
| 149 { | 130 { |
| 150 SCOPED_TRACE("After removing"); | 131 SCOPED_TRACE("After removing"); |
| 151 EXPECT_EQ(0u, monster->GetAllCookies().size()); | 132 EXPECT_EQ(1, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 152 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 133 EXPECT_EQ(0, cookies_model.GetRoot()->GetChildCount()); |
| 153 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 134 EXPECT_EQ(std::string(""), GetMonsterCookies(monster)); |
| 154 CheckDetailsSensitivity(FALSE, cookies_view); | 135 EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model)); |
| 155 EXPECT_EQ(0, gtk_tree_model_iter_n_children( | 136 } |
| 156 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 137 } |
| 157 } | 138 |
| 158 } | 139 TEST_F(CookiesTreeModelTest, Remove) { |
| 159 | 140 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 160 // When removing all items, if multiple items were selected the | 141 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 161 // OnSelectionChanged callback could get called while the gtk list view and the | 142 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 162 // CookiesTableModel were inconsistent. Test that it doesn't crash. | 143 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 163 TEST_F(CookiesViewTest, RemoveAllWithAllSelected) { | 144 CookiesTreeModel cookies_model(profile_.get()); |
| 164 net::CookieMonster* monster = profile_->GetCookieMonster(); | 145 |
| 165 monster->SetCookie(GURL("http://foo"), "A=1"); | 146 { |
| 166 monster->SetCookie(GURL("http://foo2"), "B=1"); | 147 SCOPED_TRACE("Initial State 3 cookies"); |
| 167 CookiesView cookies_view(profile_.get()); | 148 // 10 because there's the root, then foo1 -> cookies -> a, |
| 168 | 149 // foo2 -> cookies -> b, foo3 -> cookies -> c |
| 169 gtk_tree_selection_select_all(cookies_view.selection_); | 150 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 170 { | 151 } |
| 171 SCOPED_TRACE("Before removing"); | 152 DeleteCookie(cookies_model.GetRoot()->GetChild(0)); |
| 172 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 153 { |
| 173 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 154 SCOPED_TRACE("First origin removed"); |
| 174 CheckDetailsSensitivity(FALSE, cookies_view); | 155 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 175 EXPECT_EQ(2, gtk_tree_model_iter_n_children( | 156 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); |
| 176 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 157 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 177 } | 158 } |
| 178 | 159 } |
| 179 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); | 160 |
| 180 { | 161 TEST_F(CookiesTreeModelTest, RemoveCookiesNode) { |
| 181 SCOPED_TRACE("After removing"); | 162 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 182 EXPECT_EQ(0u, monster->GetAllCookies().size()); | 163 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 183 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 164 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 184 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 165 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 185 CheckDetailsSensitivity(FALSE, cookies_view); | 166 CookiesTreeModel cookies_model(profile_.get()); |
| 186 EXPECT_EQ(0, gtk_tree_model_iter_n_children( | 167 |
| 187 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 168 { |
| 188 } | 169 SCOPED_TRACE("Initial State 3 cookies"); |
| 189 } | 170 // 10 because there's the root, then foo1 -> cookies -> a, |
| 190 | 171 // foo2 -> cookies -> b, foo3 -> cookies -> c |
| 191 TEST_F(CookiesViewTest, Remove) { | 172 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 192 net::CookieMonster* monster = profile_->GetCookieMonster(); | 173 } |
| 193 monster->SetCookie(GURL("http://foo1"), "A=1"); | 174 DeleteCookie(cookies_model.GetRoot()->GetChild(0)->GetChild(0)); |
| 194 monster->SetCookie(GURL("http://foo2"), "B=1"); | 175 { |
| 195 monster->SetCookie(GURL("http://foo3"), "C=1"); | 176 SCOPED_TRACE("First origin removed"); |
| 196 CookiesView cookies_view(profile_.get()); | 177 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); |
| 197 | 178 EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str()); |
| 198 // Reset the selection of the first row. | 179 // 8 because in this case, the origin remains, although the COOKIES |
| 199 gtk_tree_selection_unselect_all(cookies_view.selection_); | 180 // node beneath it has been deleted. So, we have |
| 200 | 181 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c |
| 201 GtkTreeIter iter; | 182 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 202 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); | 183 } |
| 203 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 184 } |
| 204 | 185 |
| 205 { | 186 TEST_F(CookiesTreeModelTest, RemoveCookieNode) { |
| 206 SCOPED_TRACE("First selection"); | 187 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 207 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 188 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 208 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 189 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 209 CheckDetailsSensitivity(TRUE, cookies_view); | 190 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 210 EXPECT_EQ(3, gtk_tree_model_iter_n_children( | 191 CookiesTreeModel cookies_model(profile_.get()); |
| 211 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 192 |
| 212 } | 193 { |
| 213 | 194 SCOPED_TRACE("Initial State 3 cookies"); |
| 214 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | 195 // 10 because there's the root, then foo1 -> cookies -> a, |
| 215 | 196 // foo2 -> cookies -> b, foo3 -> cookies -> c |
| 216 { | 197 EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 217 SCOPED_TRACE("First selection removed"); | 198 } |
| 199 DeleteCookie(cookies_model.GetRoot()->GetChild(1)->GetChild(0)); |
| 200 { |
| 201 SCOPED_TRACE("Second origin COOKIES node removed"); |
| 218 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); | 202 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); |
| 219 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_view).c_str()); | 203 EXPECT_STREQ("A,C", GetDisplayedCookies(&cookies_model).c_str()); |
| 220 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 204 // 8 because in this case, the origin remains, although the COOKIES |
| 221 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 205 // node beneath it has been deleted. So, we have |
| 222 CheckDetailsSensitivity(FALSE, cookies_view); | 206 // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c |
| 223 } | 207 EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 224 | 208 } |
| 225 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); | 209 } |
| 226 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 210 |
| 227 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 211 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { |
| 228 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | 212 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 229 | 213 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 230 { | 214 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 231 SCOPED_TRACE("Second selection"); | 215 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 232 EXPECT_STREQ("A", GetMonsterCookies(monster).c_str()); | 216 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 233 EXPECT_STREQ("A", GetDisplayedCookies(cookies_view).c_str()); | 217 CookiesTreeModel cookies_model(profile_.get()); |
| 234 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 218 |
| 235 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 219 { |
| 236 CheckDetailsSensitivity(FALSE, cookies_view); | 220 SCOPED_TRACE("Initial State 4 cookies"); |
| 237 EXPECT_EQ(1, gtk_tree_model_iter_n_children( | 221 // 11 because there's the root, then foo1 -> cookies -> a, |
| 238 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 222 // foo2 -> cookies -> b, foo3 -> cookies -> c,d |
| 239 } | 223 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 240 | 224 EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str()); |
| 241 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); | 225 EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str()); |
| 242 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 226 } |
| 243 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 227 DeleteCookie(cookies_model.GetRoot()->GetChild(2)); |
| 244 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | 228 { |
| 245 | 229 SCOPED_TRACE("Third origin removed"); |
| 246 { | 230 EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str()); |
| 247 SCOPED_TRACE("Second selection removed"); | 231 EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str()); |
| 248 EXPECT_EQ(0u, monster->GetAllCookies().size()); | 232 EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 249 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 233 } |
| 250 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 234 } |
| 251 CheckDetailsSensitivity(FALSE, cookies_view); | 235 |
| 252 EXPECT_EQ(0, gtk_tree_model_iter_n_children( | 236 TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { |
| 253 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | 237 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 254 } | 238 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 255 } | 239 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 256 | 240 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 257 TEST_F(CookiesViewTest, RemoveMultiple) { | 241 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 258 net::CookieMonster* monster = profile_->GetCookieMonster(); | 242 monster->SetCookie(GURL("http://foo3"), "E=1"); |
| 259 monster->SetCookie(GURL("http://foo0"), "C=1"); | 243 CookiesTreeModel cookies_model(profile_.get()); |
| 260 monster->SetCookie(GURL("http://foo1"), "D=1"); | 244 |
| 261 monster->SetCookie(GURL("http://foo2"), "B=1"); | 245 { |
| 262 monster->SetCookie(GURL("http://foo3"), "A=1"); | 246 SCOPED_TRACE("Initial State 5 cookies"); |
| 263 monster->SetCookie(GURL("http://foo4"), "E=1"); | 247 // 11 because there's the root, then foo1 -> cookies -> a, |
| 264 monster->SetCookie(GURL("http://foo5"), "G=1"); | 248 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
| 265 monster->SetCookie(GURL("http://foo6"), "X=1"); | 249 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 266 CookiesView cookies_view(profile_.get()); | 250 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); |
| 267 | 251 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 268 // Reset the selection of the first row. | 252 } |
| 269 gtk_tree_selection_unselect_all(cookies_view.selection_); | 253 DeleteCookie(cookies_model.GetRoot()->GetChild(2)->GetChild(0)-> |
| 270 | 254 GetChild(1)); |
| 271 GtkTreeIter iter; | 255 { |
| 272 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); | 256 SCOPED_TRACE("Middle cookie in third origin removed"); |
| 273 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 257 EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str()); |
| 274 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); | 258 EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 275 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 259 EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 276 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 4); | 260 } |
| 277 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 261 } |
| 278 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 5); | 262 |
| 279 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | 263 TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { |
| 280 | 264 net::CookieMonster* monster = profile_->GetCookieMonster(); |
| 281 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 265 monster->SetCookie(GURL("http://foo1"), "A=1"); |
| 282 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 266 monster->SetCookie(GURL("http://foo2"), "B=1"); |
| 283 | 267 monster->SetCookie(GURL("http://foo3"), "C=1"); |
| 284 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | 268 monster->SetCookie(GURL("http://foo3"), "D=1"); |
| 285 | 269 monster->SetCookie(GURL("http://foo3"), "E=1"); |
| 286 EXPECT_STREQ("C,B,X", GetMonsterCookies(monster).c_str()); | 270 CookiesTreeModel cookies_model(profile_.get()); |
| 287 EXPECT_STREQ("C,B,X", GetDisplayedCookies(cookies_view).c_str()); | 271 |
| 288 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 272 { |
| 289 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 273 SCOPED_TRACE("Initial State 5 cookies"); |
| 290 EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); | 274 // 11 because there's the root, then foo1 -> cookies -> a, |
| 291 } | 275 // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e |
| 292 | 276 EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 293 TEST_F(CookiesViewTest, RemoveDefaultSelection) { | 277 EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str()); |
| 294 net::CookieMonster* monster = profile_->GetCookieMonster(); | 278 EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 295 monster->SetCookie(GURL("http://foo1"), "A=1"); | 279 } |
| 296 monster->SetCookie(GURL("http://foo2"), "B=1"); | 280 DeleteCookie(cookies_model.GetRoot()->GetChild(1)); |
| 297 monster->SetCookie(GURL("http://foo3"), "C=1"); | 281 { |
| 298 // Now CookiesView select the first row when it is opened. | 282 SCOPED_TRACE("Second origin removed"); |
| 299 CookiesView cookies_view(profile_.get()); | 283 EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str()); |
| 300 | 284 EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str()); |
| 301 { | 285 // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e |
| 302 SCOPED_TRACE("First selection"); | 286 EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount()); |
| 303 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | 287 } |
| 304 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | 288 } |
| 305 CheckDetailsSensitivity(TRUE, cookies_view); | 289 |
| 306 EXPECT_EQ(3, gtk_tree_model_iter_n_children( | 290 } // namespace |
| 307 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 308 } | |
| 309 | |
| 310 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 311 | |
| 312 { | |
| 313 SCOPED_TRACE("First selection removed"); | |
| 314 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); | |
| 315 EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 316 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 317 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 318 CheckDetailsSensitivity(FALSE, cookies_view); | |
| 319 } | |
| 320 } | |
| 321 | |
| 322 TEST_F(CookiesViewTest, Filter) { | |
| 323 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 324 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 325 monster->SetCookie(GURL("http://bar1"), "B=1"); | |
| 326 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 327 monster->SetCookie(GURL("http://bar2"), "D=1"); | |
| 328 CookiesView cookies_view(profile_.get()); | |
| 329 EXPECT_EQ(4, gtk_tree_model_iter_n_children( | |
| 330 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 331 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 332 | |
| 333 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); | |
| 334 // Entering text doesn't immediately filter the results. | |
| 335 EXPECT_EQ(4, gtk_tree_model_iter_n_children( | |
| 336 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 337 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 338 | |
| 339 // Results are filtered immediately if you activate (hit enter in the entry.) | |
| 340 gtk_widget_activate(cookies_view.filter_entry_); | |
| 341 EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); | |
| 342 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 343 | |
| 344 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar2"); | |
| 345 gtk_widget_activate(cookies_view.filter_entry_); | |
| 346 EXPECT_STREQ("D", GetDisplayedCookies(cookies_view).c_str()); | |
| 347 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 348 | |
| 349 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar22"); | |
| 350 gtk_widget_activate(cookies_view.filter_entry_); | |
| 351 EXPECT_EQ(0, gtk_tree_model_iter_n_children( | |
| 352 GTK_TREE_MODEL(cookies_view.list_store_), NULL)); | |
| 353 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 354 } | |
| 355 | |
| 356 TEST_F(CookiesViewTest, FilterRemoveAll) { | |
| 357 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 358 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 359 monster->SetCookie(GURL("http://bar1"), "B=1"); | |
| 360 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 361 monster->SetCookie(GURL("http://bar2"), "D=1"); | |
| 362 CookiesView cookies_view(profile_.get()); | |
| 363 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); | |
| 364 gtk_widget_activate(cookies_view.filter_entry_); | |
| 365 EXPECT_STREQ("B,D,A,C", GetMonsterCookies(monster).c_str()); | |
| 366 EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); | |
| 367 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 368 | |
| 369 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); | |
| 370 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); | |
| 371 EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); | |
| 372 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 373 | |
| 374 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), ""); | |
| 375 gtk_widget_activate(cookies_view.filter_entry_); | |
| 376 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); | |
| 377 EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 378 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 379 } | |
| 380 | |
| 381 TEST_F(CookiesViewTest, FilterRemove) { | |
| 382 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 383 monster->SetCookie(GURL("http://foo1"), "A=1"); | |
| 384 monster->SetCookie(GURL("http://bar1"), "B=1"); | |
| 385 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 386 monster->SetCookie(GURL("http://bar2"), "D=1"); | |
| 387 CookiesView cookies_view(profile_.get()); | |
| 388 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); | |
| 389 gtk_widget_activate(cookies_view.filter_entry_); | |
| 390 EXPECT_STREQ("B,D,A,C", GetMonsterCookies(monster).c_str()); | |
| 391 EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); | |
| 392 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 393 | |
| 394 GtkTreeIter iter; | |
| 395 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); | |
| 396 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 397 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 398 | |
| 399 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 400 | |
| 401 EXPECT_STREQ("D,A,C", GetMonsterCookies(monster).c_str()); | |
| 402 EXPECT_STREQ("D", GetDisplayedCookies(cookies_view).c_str()); | |
| 403 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 404 | |
| 405 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); | |
| 406 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 407 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 408 | |
| 409 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 410 | |
| 411 EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); | |
| 412 EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); | |
| 413 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 414 } | |
| 415 | |
| 416 TEST_F(CookiesViewTest, Sort) { | |
| 417 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 418 monster->SetCookie(GURL("http://foo1"), "X=1"); | |
| 419 monster->SetCookie(GURL("http://bar1"), "Z=1"); | |
| 420 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 421 monster->SetCookie(GURL("http://bar2"), "D=1"); | |
| 422 CookiesView cookies_view(profile_.get()); | |
| 423 EXPECT_STREQ("Z,D,X,C", GetMonsterCookies(monster).c_str()); | |
| 424 EXPECT_STREQ("Z,D,X,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 425 | |
| 426 gtk_tree_sortable_set_sort_column_id( | |
| 427 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 428 CookiesView::COL_SITE, | |
| 429 GTK_SORT_ASCENDING); | |
| 430 EXPECT_STREQ("Z,D,X,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 431 | |
| 432 gtk_tree_sortable_set_sort_column_id( | |
| 433 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 434 CookiesView::COL_SITE, | |
| 435 GTK_SORT_DESCENDING); | |
| 436 EXPECT_STREQ("C,X,D,Z", GetDisplayedCookies(cookies_view).c_str()); | |
| 437 | |
| 438 gtk_tree_sortable_set_sort_column_id( | |
| 439 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 440 CookiesView::COL_COOKIE_NAME, | |
| 441 GTK_SORT_ASCENDING); | |
| 442 EXPECT_STREQ("C,D,X,Z", GetDisplayedCookies(cookies_view).c_str()); | |
| 443 | |
| 444 gtk_tree_sortable_set_sort_column_id( | |
| 445 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 446 CookiesView::COL_COOKIE_NAME, | |
| 447 GTK_SORT_DESCENDING); | |
| 448 EXPECT_STREQ("Z,X,D,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 449 } | |
| 450 | |
| 451 TEST_F(CookiesViewTest, SortRemove) { | |
| 452 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 453 monster->SetCookie(GURL("http://foo1"), "B=1"); | |
| 454 monster->SetCookie(GURL("http://bar1"), "Z=1"); | |
| 455 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 456 monster->SetCookie(GURL("http://bar2"), "A=1"); | |
| 457 CookiesView cookies_view(profile_.get()); | |
| 458 EXPECT_STREQ("Z,A,B,C", GetMonsterCookies(monster).c_str()); | |
| 459 EXPECT_STREQ("Z,A,B,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 460 | |
| 461 gtk_tree_sortable_set_sort_column_id( | |
| 462 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 463 CookiesView::COL_COOKIE_NAME, | |
| 464 GTK_SORT_DESCENDING); | |
| 465 EXPECT_STREQ("Z,C,B,A", GetDisplayedCookies(cookies_view).c_str()); | |
| 466 | |
| 467 // Reset the selection of the first row. | |
| 468 gtk_tree_selection_unselect_all(cookies_view.selection_); | |
| 469 | |
| 470 GtkTreeIter iter; | |
| 471 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); | |
| 472 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 473 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 474 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 475 EXPECT_STREQ("Z,B,C", GetMonsterCookies(monster).c_str()); | |
| 476 EXPECT_STREQ("Z,C,B", GetDisplayedCookies(cookies_view).c_str()); | |
| 477 } | |
| 478 | |
| 479 TEST_F(CookiesViewTest, SortFilterRemove) { | |
| 480 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 481 monster->SetCookie(GURL("http://foo1"), "B=1"); | |
| 482 monster->SetCookie(GURL("http://bar1"), "Z=1"); | |
| 483 monster->SetCookie(GURL("http://foo2"), "C=1"); | |
| 484 monster->SetCookie(GURL("http://bar2"), "A=1"); | |
| 485 CookiesView cookies_view(profile_.get()); | |
| 486 EXPECT_STREQ("Z,A,B,C", GetMonsterCookies(monster).c_str()); | |
| 487 EXPECT_STREQ("Z,A,B,C", GetDisplayedCookies(cookies_view).c_str()); | |
| 488 | |
| 489 gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); | |
| 490 gtk_widget_activate(cookies_view.filter_entry_); | |
| 491 gtk_tree_sortable_set_sort_column_id( | |
| 492 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 493 CookiesView::COL_COOKIE_NAME, | |
| 494 GTK_SORT_ASCENDING); | |
| 495 EXPECT_STREQ("A,Z", GetDisplayedCookies(cookies_view).c_str()); | |
| 496 | |
| 497 GtkTreeIter iter; | |
| 498 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); | |
| 499 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 500 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 501 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 502 EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str()); | |
| 503 EXPECT_STREQ("A", GetDisplayedCookies(cookies_view).c_str()); | |
| 504 | |
| 505 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); | |
| 506 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 507 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 508 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 509 EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); | |
| 510 EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); | |
| 511 } | |
| 512 | |
| 513 TEST_F(CookiesViewTest, SortRemoveMultiple) { | |
| 514 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 515 monster->SetCookie(GURL("http://foo0"), "C=1"); | |
| 516 monster->SetCookie(GURL("http://foo1"), "D=1"); | |
| 517 monster->SetCookie(GURL("http://foo2"), "B=1"); | |
| 518 monster->SetCookie(GURL("http://foo3"), "A=1"); | |
| 519 monster->SetCookie(GURL("http://foo4"), "E=1"); | |
| 520 monster->SetCookie(GURL("http://foo5"), "G=1"); | |
| 521 monster->SetCookie(GURL("http://foo6"), "X=1"); | |
| 522 CookiesView cookies_view(profile_.get()); | |
| 523 gtk_tree_sortable_set_sort_column_id( | |
| 524 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 525 CookiesView::COL_COOKIE_NAME, | |
| 526 GTK_SORT_DESCENDING); | |
| 527 EXPECT_STREQ("X,G,E,D,C,B,A", GetDisplayedCookies(cookies_view).c_str()); | |
| 528 EXPECT_STREQ("C,D,B,A,E,G,X", GetMonsterCookies(monster).c_str()); | |
| 529 | |
| 530 GtkTreeIter iter; | |
| 531 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); | |
| 532 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 533 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); | |
| 534 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 535 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 4); | |
| 536 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 537 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 5); | |
| 538 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 539 | |
| 540 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 541 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 542 | |
| 543 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 544 | |
| 545 EXPECT_STREQ("X,E,A", GetDisplayedCookies(cookies_view).c_str()); | |
| 546 EXPECT_STREQ("A,E,X", GetMonsterCookies(monster).c_str()); | |
| 547 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); | |
| 548 EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 549 EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); | |
| 550 } | |
| 551 | |
| 552 TEST_F(CookiesViewTest, SortRemoveDefaultSelection) { | |
| 553 net::CookieMonster* monster = profile_->GetCookieMonster(); | |
| 554 monster->SetCookie(GURL("http://foo1"), "Z=1"); | |
| 555 monster->SetCookie(GURL("http://bar1"), "X=1"); | |
| 556 monster->SetCookie(GURL("http://foo2"), "W=1"); | |
| 557 monster->SetCookie(GURL("http://bar2"), "Y=1"); | |
| 558 CookiesView cookies_view(profile_.get()); | |
| 559 EXPECT_STREQ("X,Y,Z,W", GetMonsterCookies(monster).c_str()); | |
| 560 EXPECT_STREQ("X,Y,Z,W", GetDisplayedCookies(cookies_view).c_str()); | |
| 561 | |
| 562 gtk_tree_sortable_set_sort_column_id( | |
| 563 GTK_TREE_SORTABLE(cookies_view.list_sort_), | |
| 564 CookiesView::COL_COOKIE_NAME, | |
| 565 GTK_SORT_ASCENDING); | |
| 566 EXPECT_STREQ("W,X,Y,Z", GetDisplayedCookies(cookies_view).c_str()); | |
| 567 | |
| 568 GtkTreeIter iter; | |
| 569 gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); | |
| 570 gtk_tree_selection_select_iter(cookies_view.selection_, &iter); | |
| 571 | |
| 572 EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); | |
| 573 gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); | |
| 574 EXPECT_STREQ("Y,W", GetMonsterCookies(monster).c_str()); | |
| 575 EXPECT_STREQ("W,Y", GetDisplayedCookies(cookies_view).c_str()); | |
| 576 } | |
| OLD | NEW |