diff options
author | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 23:07:58 +0000 |
---|---|---|
committer | mattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 23:07:58 +0000 |
commit | 42062e78622add4b84f872707530670d4894d5c9 (patch) | |
tree | 57555878cc6583012dbc2db4c3842282d1ec6ac5 /chrome/browser/gtk/options/cookies_view_unittest.cc | |
parent | dda7d9c65875b7650f36fa8c2a03b5813dc3ecd3 (diff) | |
download | chromium_src-42062e78622add4b84f872707530670d4894d5c9.zip chromium_src-42062e78622add4b84f872707530670d4894d5c9.tar.gz chromium_src-42062e78622add4b84f872707530670d4894d5c9.tar.bz2 |
Linux: Convert Cookies options page from a list into a tree.
Add gtk_tree::TreeAdapter class.
BUG=26713
TEST=compare behavior to windows impl
Review URL: http://codereview.chromium.org/371079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31732 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/options/cookies_view_unittest.cc')
-rw-r--r-- | chrome/browser/gtk/options/cookies_view_unittest.cc | 497 |
1 files changed, 187 insertions, 310 deletions
diff --git a/chrome/browser/gtk/options/cookies_view_unittest.cc b/chrome/browser/gtk/options/cookies_view_unittest.cc index ab6589f..63e7d42 100644 --- a/chrome/browser/gtk/options/cookies_view_unittest.cc +++ b/chrome/browser/gtk/options/cookies_view_unittest.cc @@ -98,24 +98,59 @@ class CookiesViewTest : public testing::Test { return JoinString(parts, ','); } + static gboolean GetDisplayedCookiesHelper(GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) { + gchar* title; + gtk_tree_model_get(model, iter, + gtk_tree::TreeAdapter::COL_TITLE, &title, + -1); + std::string str; + str.append(gtk_tree_path_get_depth(path) - 1, '_'); + str += title; + g_free(title); + std::vector<std::string>* parts = + reinterpret_cast<std::vector<std::string>*>(user_data); + parts->push_back(str); + return FALSE; + } + // Get the cookie names displayed in the dialog in the order they are // displayed, as a comma seperated string. // Ex: EXPECT_STREQ("X,Y", GetDisplayedCookies(cookies_view).c_str()); std::string GetDisplayedCookies(const CookiesView& cookies_view) { + GtkTreeStore* tree_store = cookies_view.cookies_tree_adapter_->tree_store(); std::vector<std::string> parts; + gtk_tree_model_foreach(GTK_TREE_MODEL(tree_store), + GetDisplayedCookiesHelper, &parts); + return JoinString(parts, ','); + } + + bool SelectByPath(const CookiesView& cookies_view, const char* path_str) { + GtkTreePath* path = gtk_tree_path_new_from_string(path_str); + if (!path) + return false; + gtk_tree_selection_select_path(cookies_view.selection_, path); + gtk_tree_path_free(path); + return true; + } + + std::string GetSelectedPath(const CookiesView& cookies_view) { + std::string result; GtkTreeIter iter; - if (!gtk_tree_model_get_iter_first(cookies_view.list_sort_, &iter)) - return std::string(); - while (true) { - gchar* name; - gtk_tree_model_get(cookies_view.list_sort_, &iter, - CookiesView::COL_COOKIE_NAME, &name, -1); - parts.push_back(name); - g_free(name); - if (!gtk_tree_model_iter_next(cookies_view.list_sort_, &iter)) - break; + bool selected = gtk_tree_selection_get_selected(cookies_view.selection_, + NULL, &iter); + if (selected) { + gchar* path_str = gtk_tree_model_get_string_from_iter( + GTK_TREE_MODEL(cookies_view.cookies_tree_adapter_->tree_store()), + &iter); + if (path_str) { + result = path_str; + g_free(path_str); + } } - return JoinString(parts, ','); + return result; } protected: @@ -128,8 +163,26 @@ TEST_F(CookiesViewTest, Empty) { EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(0, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); +} + +TEST_F(CookiesViewTest, Noop) { + net::CookieMonster* monster = profile_->GetCookieMonster(); + monster->SetCookie(GURL("http://foo0"), "C=1"); + monster->SetCookie(GURL("http://foo0"), "D=1"); + monster->SetCookie(GURL("http://foo1"), "B=1"); + monster->SetCookie(GURL("http://foo1"), "A=1"); + monster->SetCookie(GURL("http://foo1"), "E=1"); + monster->SetCookie(GURL("http://foo2"), "G=1"); + monster->SetCookie(GURL("http://foo2"), "X=1"); + CookiesView cookies_view(profile_.get()); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo1,_Cookies,__A,__B,__E," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + CheckDetailsSensitivity(FALSE, cookies_view); } TEST_F(CookiesViewTest, RemoveAll) { @@ -146,8 +199,8 @@ TEST_F(CookiesViewTest, RemoveAll) { EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(2, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("foo,_Cookies,__A,foo2,_Cookies,__B", + GetDisplayedCookies(cookies_view).c_str()); } gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); @@ -157,28 +210,25 @@ TEST_F(CookiesViewTest, RemoveAll) { EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(0, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); } } -// When removing all items, if multiple items were selected the -// OnSelectionChanged callback could get called while the gtk list view and the -// CookiesTableModel were inconsistent. Test that it doesn't crash. -TEST_F(CookiesViewTest, RemoveAllWithAllSelected) { +TEST_F(CookiesViewTest, RemoveAllWithDefaultSelected) { net::CookieMonster* monster = profile_->GetCookieMonster(); monster->SetCookie(GURL("http://foo"), "A=1"); monster->SetCookie(GURL("http://foo2"), "B=1"); CookiesView cookies_view(profile_.get()); - gtk_tree_selection_select_all(cookies_view.selection_); + EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); + EXPECT_EQ(1, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); { SCOPED_TRACE("Before removing"); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(2, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("foo,_Cookies,__A,foo2,_Cookies,__B", + GetDisplayedCookies(cookies_view).c_str()); } gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); @@ -188,8 +238,9 @@ TEST_F(CookiesViewTest, RemoveAllWithAllSelected) { EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(0, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(0, + gtk_tree_selection_count_selected_rows(cookies_view.selection_)); } } @@ -197,23 +248,18 @@ TEST_F(CookiesViewTest, Remove) { net::CookieMonster* monster = profile_->GetCookieMonster(); monster->SetCookie(GURL("http://foo1"), "A=1"); monster->SetCookie(GURL("http://foo2"), "B=1"); - monster->SetCookie(GURL("http://foo3"), "C=1"); + monster->SetCookie(GURL("http://foo2"), "C=1"); CookiesView cookies_view(profile_.get()); - // Reset the selection of the first row. - gtk_tree_selection_unselect_all(cookies_view.selection_); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + ASSERT_TRUE(SelectByPath(cookies_view, "1:0:0")); { SCOPED_TRACE("First selection"); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); CheckDetailsSensitivity(TRUE, cookies_view); - EXPECT_EQ(3, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("foo1,_Cookies,__A,foo2,_Cookies,__B,__C", + GetDisplayedCookies(cookies_view).c_str()); } gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); @@ -221,361 +267,192 @@ TEST_F(CookiesViewTest, Remove) { { SCOPED_TRACE("First selection removed"); EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_STREQ("foo1,_Cookies,__A,foo2,_Cookies,__C", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, cookies_view); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("1:0:0", GetSelectedPath(cookies_view).c_str()); + CheckDetailsSensitivity(TRUE, cookies_view); } - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); { SCOPED_TRACE("Second selection"); EXPECT_STREQ("A", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("A", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_STREQ("foo1,_Cookies,__A,foo2,_Cookies", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("1:0", GetSelectedPath(cookies_view).c_str()); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(1, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); } - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + ASSERT_TRUE(SelectByPath(cookies_view, "0:0:0")); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); { SCOPED_TRACE("Second selection removed"); EXPECT_EQ(0u, monster->GetAllCookies().size()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("0:0", GetSelectedPath(cookies_view).c_str()); CheckDetailsSensitivity(FALSE, cookies_view); - EXPECT_EQ(0, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("foo1,_Cookies,foo2,_Cookies", + GetDisplayedCookies(cookies_view).c_str()); } } -TEST_F(CookiesViewTest, RemoveMultiple) { +TEST_F(CookiesViewTest, RemoveCookiesByDomain) { net::CookieMonster* monster = profile_->GetCookieMonster(); monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo1"), "D=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - monster->SetCookie(GURL("http://foo3"), "A=1"); - monster->SetCookie(GURL("http://foo4"), "E=1"); - monster->SetCookie(GURL("http://foo5"), "G=1"); - monster->SetCookie(GURL("http://foo6"), "X=1"); + monster->SetCookie(GURL("http://foo0"), "D=1"); + monster->SetCookie(GURL("http://foo1"), "B=1"); + monster->SetCookie(GURL("http://foo1"), "A=1"); + monster->SetCookie(GURL("http://foo1"), "E=1"); + monster->SetCookie(GURL("http://foo2"), "G=1"); + monster->SetCookie(GURL("http://foo2"), "X=1"); CookiesView cookies_view(profile_.get()); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo1,_Cookies,__A,__B,__E," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); - // Reset the selection of the first row. - gtk_tree_selection_unselect_all(cookies_view.selection_); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 4); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 5); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + ASSERT_TRUE(SelectByPath(cookies_view, "1:0")); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("C,B,X", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("C,B,X", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_STREQ("C,D,G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo1," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); -} - -TEST_F(CookiesViewTest, RemoveDefaultSelection) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - monster->SetCookie(GURL("http://foo3"), "C=1"); - // Now CookiesView select the first row when it is opened. - CookiesView cookies_view(profile_.get()); - - { - SCOPED_TRACE("First selection"); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(TRUE, cookies_view); - EXPECT_EQ(3, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); - } + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("1", GetSelectedPath(cookies_view).c_str()); + ASSERT_TRUE(SelectByPath(cookies_view, "0:0")); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - { - SCOPED_TRACE("First selection removed"); - EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("B,C", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - CheckDetailsSensitivity(FALSE, cookies_view); - } -} - -TEST_F(CookiesViewTest, Filter) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://bar1"), "B=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "D=1"); - CookiesView cookies_view(profile_.get()); - EXPECT_EQ(4, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - // Entering text doesn't immediately filter the results. - EXPECT_EQ(4, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); + EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo0," + "foo1," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); - // Results are filtered immediately if you activate (hit enter in the entry.) - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + ASSERT_TRUE(SelectByPath(cookies_view, "2:0")); + gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar2"); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("D", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo0," + "foo1," + "foo2", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar22"); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_EQ(0, gtk_tree_model_iter_n_children( - GTK_TREE_MODEL(cookies_view.list_store_), NULL)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("2", GetSelectedPath(cookies_view).c_str()); } -TEST_F(CookiesViewTest, FilterRemoveAll) { +TEST_F(CookiesViewTest, RemoveByDomain) { net::CookieMonster* monster = profile_->GetCookieMonster(); + monster->SetCookie(GURL("http://foo0"), "C=1"); + monster->SetCookie(GURL("http://foo0"), "D=1"); + monster->SetCookie(GURL("http://foo1"), "B=1"); monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://bar1"), "B=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "D=1"); + monster->SetCookie(GURL("http://foo1"), "E=1"); + monster->SetCookie(GURL("http://foo2"), "G=1"); + monster->SetCookie(GURL("http://foo2"), "X=1"); CookiesView cookies_view(profile_.get()); - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("B,D,A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo1,_Cookies,__A,__B,__E," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_)); - EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + ASSERT_TRUE(SelectByPath(cookies_view, "1")); - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), ""); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("A,C", GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); -} + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); -TEST_F(CookiesViewTest, FilterRemove) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "A=1"); - monster->SetCookie(GURL("http://bar1"), "B=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "D=1"); - CookiesView cookies_view(profile_.get()); - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - gtk_widget_activate(cookies_view.filter_entry_); - EXPECT_STREQ("B,D,A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("B,D", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + EXPECT_STREQ("C,D,G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("1", GetSelectedPath(cookies_view).c_str()); + ASSERT_TRUE(SelectByPath(cookies_view, "0")); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("D,A,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("D", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_STREQ("0", GetSelectedPath(cookies_view).c_str()); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); + EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); } -TEST_F(CookiesViewTest, Sort) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "X=1"); - monster->SetCookie(GURL("http://bar1"), "Z=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "D=1"); - CookiesView cookies_view(profile_.get()); - EXPECT_STREQ("Z,D,X,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("Z,D,X,C", GetDisplayedCookies(cookies_view).c_str()); - - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_SITE, - GTK_SORT_ASCENDING); - EXPECT_STREQ("Z,D,X,C", GetDisplayedCookies(cookies_view).c_str()); - - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_SITE, - GTK_SORT_DESCENDING); - EXPECT_STREQ("C,X,D,Z", GetDisplayedCookies(cookies_view).c_str()); - - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_ASCENDING); - EXPECT_STREQ("C,D,X,Z", GetDisplayedCookies(cookies_view).c_str()); - - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_DESCENDING); - EXPECT_STREQ("Z,X,D,C", GetDisplayedCookies(cookies_view).c_str()); -} - -TEST_F(CookiesViewTest, SortRemove) { +TEST_F(CookiesViewTest, RemoveDefaultSelection) { net::CookieMonster* monster = profile_->GetCookieMonster(); + monster->SetCookie(GURL("http://foo0"), "C=1"); + monster->SetCookie(GURL("http://foo0"), "D=1"); monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://bar1"), "Z=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "A=1"); + monster->SetCookie(GURL("http://foo1"), "A=1"); + monster->SetCookie(GURL("http://foo1"), "E=1"); + monster->SetCookie(GURL("http://foo2"), "G=1"); + monster->SetCookie(GURL("http://foo2"), "X=1"); CookiesView cookies_view(profile_.get()); - EXPECT_STREQ("Z,A,B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("Z,A,B,C", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_STREQ("foo0,_Cookies,__C,__D," + "foo1,_Cookies,__A,__B,__E," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_DESCENDING); - EXPECT_STREQ("Z,C,B,A", GetDisplayedCookies(cookies_view).c_str()); - // Reset the selection of the first row. - gtk_tree_selection_unselect_all(cookies_view.selection_); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("Z,B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("Z,C,B", GetDisplayedCookies(cookies_view).c_str()); -} -TEST_F(CookiesViewTest, SortFilterRemove) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "B=1"); - monster->SetCookie(GURL("http://bar1"), "Z=1"); - monster->SetCookie(GURL("http://foo2"), "C=1"); - monster->SetCookie(GURL("http://bar2"), "A=1"); - CookiesView cookies_view(profile_.get()); - EXPECT_STREQ("Z,A,B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("Z,A,B,C", GetDisplayedCookies(cookies_view).c_str()); - - gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar"); - gtk_widget_activate(cookies_view.filter_entry_); - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_ASCENDING); - EXPECT_STREQ("A,Z", GetDisplayedCookies(cookies_view).c_str()); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("A,B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("A", GetDisplayedCookies(cookies_view).c_str()); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 0); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); -} - -TEST_F(CookiesViewTest, SortRemoveMultiple) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo0"), "C=1"); - monster->SetCookie(GURL("http://foo1"), "D=1"); - monster->SetCookie(GURL("http://foo2"), "B=1"); - monster->SetCookie(GURL("http://foo3"), "A=1"); - monster->SetCookie(GURL("http://foo4"), "E=1"); - monster->SetCookie(GURL("http://foo5"), "G=1"); - monster->SetCookie(GURL("http://foo6"), "X=1"); - CookiesView cookies_view(profile_.get()); - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_DESCENDING); - EXPECT_STREQ("X,G,E,D,C,B,A", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_STREQ("C,D,B,A,E,G,X", GetMonsterCookies(monster).c_str()); - - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 1); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 4); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 5); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + EXPECT_STREQ("B,A,E,G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo1,_Cookies,__A,__B,__E," + "foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("X,E,A", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_STREQ("A,E,X", GetMonsterCookies(monster).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); - EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - EXPECT_EQ(0, gtk_tree_selection_count_selected_rows(cookies_view.selection_)); -} + EXPECT_STREQ("G,X", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("foo2,_Cookies,__G,__X", + GetDisplayedCookies(cookies_view).c_str()); -TEST_F(CookiesViewTest, SortRemoveDefaultSelection) { - net::CookieMonster* monster = profile_->GetCookieMonster(); - monster->SetCookie(GURL("http://foo1"), "Z=1"); - monster->SetCookie(GURL("http://bar1"), "X=1"); - monster->SetCookie(GURL("http://foo2"), "W=1"); - monster->SetCookie(GURL("http://bar2"), "Y=1"); - CookiesView cookies_view(profile_.get()); - EXPECT_STREQ("X,Y,Z,W", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("X,Y,Z,W", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_tree_sortable_set_sort_column_id( - GTK_TREE_SORTABLE(cookies_view.list_sort_), - CookiesView::COL_COOKIE_NAME, - GTK_SORT_ASCENDING); - EXPECT_STREQ("W,X,Y,Z", GetDisplayedCookies(cookies_view).c_str()); + gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - GtkTreeIter iter; - gtk_tree_model_iter_nth_child(cookies_view.list_sort_, &iter, NULL, 3); - gtk_tree_selection_select_iter(cookies_view.selection_, &iter); + EXPECT_STREQ("", GetMonsterCookies(monster).c_str()); + EXPECT_STREQ("", GetDisplayedCookies(cookies_view).c_str()); - EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); - gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_)); - EXPECT_STREQ("Y,W", GetMonsterCookies(monster).c_str()); - EXPECT_STREQ("W,Y", GetDisplayedCookies(cookies_view).c_str()); + EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_)); + EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_)); } |