summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/gtk/options/cookies_view.cc69
-rw-r--r--chrome/browser/gtk/options/cookies_view.h27
-rw-r--r--chrome/browser/gtk/options/cookies_view_unittest.cc393
-rw-r--r--chrome/chrome.gyp1
-rw-r--r--chrome/test/data/valgrind/unit_tests.gtest_linux.txt1
5 files changed, 458 insertions, 33 deletions
diff --git a/chrome/browser/gtk/options/cookies_view.cc b/chrome/browser/gtk/options/cookies_view.cc
index 4821e4e..19cb8d0 100644
--- a/chrome/browser/gtk/options/cookies_view.cc
+++ b/chrome/browser/gtk/options/cookies_view.cc
@@ -30,17 +30,25 @@ enum {
RESPONSE_REMOVE_ALL
};
-// Column ids for |list_store_|.
-enum {
- COL_ICON,
- COL_SITE,
- COL_COOKIE_NAME,
- COL_COUNT,
-};
-
// The currently open cookie manager, if any.
CookiesView* instance_ = NULL;
+void InitCookieDetailStyle(GtkWidget* entry, GtkStyle* label_style,
+ GtkStyle* dialog_style) {
+ gtk_widget_modify_fg(entry, GTK_STATE_NORMAL,
+ &label_style->fg[GTK_STATE_NORMAL]);
+ gtk_widget_modify_fg(entry, GTK_STATE_INSENSITIVE,
+ &label_style->fg[GTK_STATE_INSENSITIVE]);
+ // GTK_NO_WINDOW widgets like GtkLabel don't draw their own background, so we
+ // combine the normal or insensitive fg of the label style with the normal
+ // background of the window style to achieve the "normal label" and
+ // "insensitive label" colors.
+ gtk_widget_modify_base(entry, GTK_STATE_NORMAL,
+ &dialog_style->bg[GTK_STATE_NORMAL]);
+ gtk_widget_modify_base(entry, GTK_STATE_INSENSITIVE,
+ &dialog_style->bg[GTK_STATE_NORMAL]);
+}
+
} // namespace
CookiesView::~CookiesView() {
@@ -55,6 +63,7 @@ void CookiesView::Show(Profile* profile) {
gtk_window_present(GTK_WINDOW(instance_->dialog_));
} else {
instance_ = new CookiesView(profile);
+ instance_->InitStylesAndShow();
}
}
@@ -129,10 +138,10 @@ void CookiesView::Init() {
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), cookie_list_vbox,
TRUE, TRUE, 0);
- GtkWidget* description_label = gtk_label_new(
+ description_label_ = gtk_label_new(
l10n_util::GetStringUTF8(IDS_COOKIES_INFO_LABEL).c_str());
- gtk_misc_set_alignment(GTK_MISC(description_label), 0, 0.5);
- gtk_box_pack_start(GTK_BOX(cookie_list_vbox), description_label,
+ gtk_misc_set_alignment(GTK_MISC(description_label_), 0, 0.5);
+ gtk_box_pack_start(GTK_BOX(cookie_list_vbox), description_label_,
FALSE, FALSE, 0);
GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL);
@@ -196,12 +205,6 @@ void CookiesView::Init() {
gtk_table_set_col_spacing(GTK_TABLE(cookie_details_table_), 0,
GtkUtil::kLabelSpacing);
- // Realize a label so that its style gets initialized.
- gtk_widget_realize(description_label);
- gtk_widget_realize(dialog_);
- label_style_ = gtk_widget_get_style(description_label);
- dialog_style_ = gtk_widget_get_style(dialog_);
-
InitCookieDetailRow(0, IDS_COOKIES_COOKIE_NAME_LABEL, &cookie_name_entry_);
InitCookieDetailRow(1, IDS_COOKIES_COOKIE_CONTENT_LABEL,
&cookie_content_entry_);
@@ -219,9 +222,23 @@ void CookiesView::Init() {
cookies_table_model_.reset(new CookiesTableModel(profile_));
cookies_table_model_->SetObserver(this);
OnModelChanged();
+}
+
+void CookiesView::InitStylesAndShow() {
+ // Realize a label so that its style gets initialized.
+ gtk_widget_realize(description_label_);
+ gtk_widget_realize(dialog_);
+ GtkStyle* label_style = gtk_widget_get_style(description_label_);
+ GtkStyle* dialog_style = gtk_widget_get_style(dialog_);
+
+ InitCookieDetailStyle(cookie_name_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_content_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_domain_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_path_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_send_for_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_created_entry_, label_style, dialog_style);
+ InitCookieDetailStyle(cookie_expires_entry_, label_style, dialog_style);
- // Show dialog.
- EnableControls();
gtk_widget_show_all(dialog_);
}
@@ -234,18 +251,6 @@ void CookiesView::InitCookieDetailRow(int row, int label_id,
0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
*entry = gtk_entry_new();
- gtk_widget_modify_fg(*entry, GTK_STATE_NORMAL,
- &label_style_->fg[GTK_STATE_NORMAL]);
- gtk_widget_modify_fg(*entry, GTK_STATE_INSENSITIVE,
- &label_style_->fg[GTK_STATE_INSENSITIVE]);
- // GTK_NO_WINDOW widgets like GtkLabel don't draw their own background, so we
- // combine the normal or insensitive fg of the label style with the normal
- // background of the window style to achieve the "normal label" and
- // "insensitive label" colors.
- gtk_widget_modify_base(*entry, GTK_STATE_NORMAL,
- &dialog_style_->bg[GTK_STATE_NORMAL]);
- gtk_widget_modify_base(*entry, GTK_STATE_INSENSITIVE,
- &dialog_style_->bg[GTK_STATE_NORMAL]);
gtk_entry_set_editable(GTK_ENTRY(*entry), FALSE);
gtk_entry_set_has_frame(GTK_ENTRY(*entry), FALSE);
@@ -381,6 +386,7 @@ void CookiesView::OnModelChanged() {
gtk_list_store_clear(list_store_);
for (int i = 0; i < cookies_table_model_->RowCount(); ++i)
AddNodeToList(i);
+ EnableControls();
}
void CookiesView::OnItemsChanged(int start, int length) {
@@ -411,6 +417,7 @@ void CookiesView::OnItemsRemoved(int start, int length) {
}
gtk_list_store_remove(list_store_, &iter);
}
+ EnableControls();
}
// static
diff --git a/chrome/browser/gtk/options/cookies_view.h b/chrome/browser/gtk/options/cookies_view.h
index 3401e4a..770904f 100644
--- a/chrome/browser/gtk/options/cookies_view.h
+++ b/chrome/browser/gtk/options/cookies_view.h
@@ -11,8 +11,10 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
class CookiesTableModel;
+class CookiesViewTest;
class Profile;
class CookiesView : public TableModelObserver {
@@ -23,11 +25,22 @@ class CookiesView : public TableModelObserver {
static void Show(Profile* profile);
private:
+ // Column ids for |list_store_|.
+ enum {
+ COL_ICON,
+ COL_SITE,
+ COL_COOKIE_NAME,
+ COL_COUNT,
+ };
+
explicit CookiesView(Profile* profile);
// Initialize the dialog contents and layout.
void Init();
+ // Initialize the widget styles and display the dialog.
+ void InitStylesAndShow();
+
// Helper for initializing cookie details table.
void InitCookieDetailRow(int row, int label_id, GtkWidget** display_label);
@@ -87,6 +100,7 @@ class CookiesView : public TableModelObserver {
// Widgets of the dialog.
GtkWidget* dialog_;
+ GtkWidget* description_label_;
GtkWidget* filter_entry_;
GtkWidget* filter_clear_button_;
GtkWidget* remove_button_;
@@ -99,8 +113,6 @@ class CookiesView : public TableModelObserver {
GtkTreeSelection* selection_;
// The cookie details widgets.
- GtkStyle* label_style_;
- GtkStyle* dialog_style_;
GtkWidget* cookie_details_table_;
GtkWidget* cookie_name_entry_;
GtkWidget* cookie_content_entry_;
@@ -120,6 +132,17 @@ class CookiesView : public TableModelObserver {
// re-evaluate the model after the search query string changes.
ScopedRunnableMethodFactory<CookiesView> filter_update_factory_;
+ friend class CookiesViewTest;
+ FRIEND_TEST(CookiesViewTest, TestEmpty);
+ FRIEND_TEST(CookiesViewTest, TestRemoveAll);
+ FRIEND_TEST(CookiesViewTest, TestRemove);
+ FRIEND_TEST(CookiesViewTest, TestFilter);
+ FRIEND_TEST(CookiesViewTest, TestFilterRemoveAll);
+ FRIEND_TEST(CookiesViewTest, TestFilterRemove);
+ FRIEND_TEST(CookiesViewTest, TestSort);
+ FRIEND_TEST(CookiesViewTest, TestSortRemove);
+ FRIEND_TEST(CookiesViewTest, TestSortFilterRemove);
+
DISALLOW_COPY_AND_ASSIGN(CookiesView);
};
diff --git a/chrome/browser/gtk/options/cookies_view_unittest.cc b/chrome/browser/gtk/options/cookies_view_unittest.cc
new file mode 100644
index 0000000..d5b65bc
--- /dev/null
+++ b/chrome/browser/gtk/options/cookies_view_unittest.cc
@@ -0,0 +1,393 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/options/cookies_view.h"
+
+#include <cstdarg>
+#include <gtk/gtk.h>
+
+#include "chrome/browser/cookies_table_model.h"
+#include "chrome/test/testing_profile.h"
+#include "net/url_request/url_request_context.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class TestURLRequestContext : public URLRequestContext {
+ public:
+ TestURLRequestContext() {
+ cookie_store_ = new net::CookieMonster();
+ }
+ virtual ~TestURLRequestContext() {
+ delete cookie_store_;
+ }
+};
+
+class CookieTestingProfile : public TestingProfile {
+ public:
+ virtual URLRequestContext* GetRequestContext() {
+ if (!url_request_context_.get())
+ url_request_context_ = new TestURLRequestContext;
+ return url_request_context_.get();
+ }
+ virtual ~CookieTestingProfile() {}
+
+ private:
+ scoped_refptr<TestURLRequestContext> url_request_context_;
+};
+
+} // namespace
+
+class CookiesViewTest : public testing::Test {
+ public:
+ CookiesViewTest() {
+ }
+
+ virtual void SetUp() {
+ profile_.reset(new CookieTestingProfile());
+ }
+
+ virtual void TearDown() {
+ }
+
+ void CheckDetailsSensitivity(gboolean expected,
+ const CookiesView& cookies_view) {
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_name_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_content_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_domain_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_path_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_send_for_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_created_entry_));
+ EXPECT_EQ(expected,
+ GTK_WIDGET_SENSITIVE(cookies_view.cookie_expires_entry_));
+ }
+
+ // Check if the cookie names in the cookie list match the given ones.
+ // (Note that the CookieMonster cookie list is sorted by domain.)
+ // Ex:
+ // monster->SetCookie(GURL("http://b"), "X=1")
+ // monster->SetCookie(GURL("http://a"), "Y=1")
+ // CheckCookieList(monster, "Y", "X", NULL);
+ void CheckCookieList(net::CookieMonster* monster, ...) {
+ va_list ap;
+ va_start(ap, monster);
+ net::CookieMonster::CookieList cookie_list = monster->GetAllCookies();
+ size_t i = 0;
+ while (const char* text = va_arg(ap, const char*)) {
+ ASSERT_LT(i, cookie_list.size());
+ EXPECT_EQ(text, cookie_list[i].second.Name());
+ ++i;
+ }
+ va_end(ap);
+ EXPECT_EQ(i, cookie_list.size());
+ }
+
+ // Check if the cookie names shown in the cookie manager match the given ones.
+ // Ex: CheckGtkTree(cookies_view, "X", "Y", NULL);
+ void CheckGtkTree(const CookiesView& cookies_view, ...) {
+ va_list ap;
+ va_start(ap, cookies_view);
+ GtkTreeIter iter;
+ int i = 0;
+ while (const char* text = va_arg(ap, const char*)) {
+ ASSERT_TRUE(gtk_tree_model_iter_nth_child(
+ cookies_view.list_sort_, &iter, NULL, i));
+ gchar* name;
+ gtk_tree_model_get(cookies_view.list_sort_, &iter,
+ CookiesView::COL_COOKIE_NAME, &name, -1);
+ EXPECT_STREQ(text, name);
+ g_free(name);
+ ++i;
+ }
+ va_end(ap);
+ EXPECT_EQ(i, gtk_tree_model_iter_n_children(
+ GTK_TREE_MODEL(cookies_view.list_store_), NULL));
+ }
+
+ protected:
+ MessageLoopForUI message_loop_;
+ scoped_ptr<CookieTestingProfile> profile_;
+};
+
+TEST_F(CookiesViewTest, TestEmpty) {
+ CookiesView cookies_view(profile_.get());
+ 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));
+}
+
+TEST_F(CookiesViewTest, TestRemoveAll) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->GetCookieMonster();
+ monster->SetCookie(GURL("http://foo"), "A=1");
+ monster->SetCookie(GURL("http://foo2"), "B=1");
+ CookiesView cookies_view(profile_.get());
+
+ 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));
+
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_));
+ 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_));
+ CheckDetailsSensitivity(FALSE, cookies_view);
+ EXPECT_EQ(0, gtk_tree_model_iter_n_children(
+ GTK_TREE_MODEL(cookies_view.list_store_), NULL));
+}
+
+TEST_F(CookiesViewTest, TestRemove) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->GetCookieMonster();
+ monster->SetCookie(GURL("http://foo1"), "A=1");
+ monster->SetCookie(GURL("http://foo2"), "B=1");
+ monster->SetCookie(GURL("http://foo3"), "C=1");
+ CookiesView cookies_view(profile_.get());
+ 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_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));
+
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
+
+ CheckCookieList(monster, "A", "C", NULL);
+ CheckGtkTree(cookies_view, "A", "C", NULL);
+ 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);
+
+ 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_));
+
+ CheckCookieList(monster, "A", NULL);
+ CheckGtkTree(cookies_view, "A", NULL);
+ 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(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);
+ EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
+
+ 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_));
+ CheckDetailsSensitivity(FALSE, cookies_view);
+ EXPECT_EQ(0, gtk_tree_model_iter_n_children(
+ GTK_TREE_MODEL(cookies_view.list_store_), NULL));
+}
+
+TEST_F(CookiesViewTest, TestFilter) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
+
+ // Results are filtered immediately if you activate (hit enter in the entry.)
+ gtk_widget_activate(cookies_view.filter_entry_);
+ CheckGtkTree(cookies_view, "B", "D", NULL);
+ EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
+
+ gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "bar2");
+ gtk_widget_activate(cookies_view.filter_entry_);
+ CheckGtkTree(cookies_view, "D", NULL);
+ 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_));
+}
+
+TEST_F(CookiesViewTest, TestFilterRemoveAll) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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_);
+ CheckCookieList(monster, "B", "D", "A", "C", NULL);
+ CheckGtkTree(cookies_view, "B", "D", NULL);
+ EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
+
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_));
+ CheckCookieList(monster, "A", "C", NULL);
+ CheckGtkTree(cookies_view, NULL);
+ EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
+
+ gtk_entry_set_text(GTK_ENTRY(cookies_view.filter_entry_), "");
+ gtk_widget_activate(cookies_view.filter_entry_);
+ CheckCookieList(monster, "A", "C", NULL);
+ CheckGtkTree(cookies_view, "A", "C", NULL);
+ EXPECT_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
+}
+
+TEST_F(CookiesViewTest, TestFilterRemove) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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_);
+ CheckCookieList(monster, "B", "D", "A", "C", NULL);
+ CheckGtkTree(cookies_view, "B", "D", NULL);
+ EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(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_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
+
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
+
+ CheckCookieList(monster, "D", "A", "C", NULL);
+ CheckGtkTree(cookies_view, "D", NULL);
+ 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_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
+
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
+
+ CheckCookieList(monster, "A", "C", NULL);
+ CheckGtkTree(cookies_view, NULL);
+ EXPECT_EQ(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
+}
+
+TEST_F(CookiesViewTest, TestSort) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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());
+ CheckCookieList(monster, "Z", "D", "X", "C", NULL);
+ CheckGtkTree(cookies_view, "Z", "D", "X", "C", NULL);
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE(cookies_view.list_sort_),
+ CookiesView::COL_SITE,
+ GTK_SORT_ASCENDING);
+ CheckGtkTree(cookies_view, "Z", "D", "X", "C", NULL);
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE(cookies_view.list_sort_),
+ CookiesView::COL_SITE,
+ GTK_SORT_DESCENDING);
+ CheckGtkTree(cookies_view, "C", "X", "D", "Z", NULL);
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE(cookies_view.list_sort_),
+ CookiesView::COL_COOKIE_NAME,
+ GTK_SORT_ASCENDING);
+ CheckGtkTree(cookies_view, "C", "D", "X", "Z", NULL);
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE(cookies_view.list_sort_),
+ CookiesView::COL_COOKIE_NAME,
+ GTK_SORT_DESCENDING);
+ CheckGtkTree(cookies_view, "Z", "X", "D", "C", NULL);
+}
+
+TEST_F(CookiesViewTest, TestSortRemove) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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());
+ CheckCookieList(monster, "Z", "A", "B", "C", NULL);
+ CheckGtkTree(cookies_view, "Z", "A", "B", "C", NULL);
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE(cookies_view.list_sort_),
+ CookiesView::COL_COOKIE_NAME,
+ GTK_SORT_DESCENDING);
+ CheckGtkTree(cookies_view, "Z", "C", "B", "A", NULL);
+
+ 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_button_));
+ gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
+ CheckCookieList(monster, "Z", "B", "C", NULL);
+ CheckGtkTree(cookies_view, "Z", "C", "B", NULL);
+}
+
+TEST_F(CookiesViewTest, TestSortFilterRemove) {
+ net::CookieMonster* monster =
+ profile_->GetRequestContext()->cookie_store()->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());
+ CheckCookieList(monster, "Z", "A", "B", "C", NULL);
+ CheckGtkTree(cookies_view, "Z", "A", "B", "C", NULL);
+
+ 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);
+ CheckGtkTree(cookies_view, "A", "Z", NULL);
+
+ 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_));
+ CheckCookieList(monster, "A", "B", "C", NULL);
+ CheckGtkTree(cookies_view, "A", NULL);
+
+ 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_));
+ CheckCookieList(monster, "B", "C", NULL);
+ CheckGtkTree(cookies_view, NULL);
+}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index ca67819..e4dd55f 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -3807,6 +3807,7 @@
'browser/google_update_settings_mac_unittest.mm',
'browser/gtk/bookmark_editor_gtk_unittest.cc',
'browser/gtk/go_button_gtk_unittest.cc',
+ 'browser/gtk/options/cookies_view_unittest.cc',
'browser/gtk/tabs/tab_renderer_gtk_unittest.cc',
'browser/history/expire_history_backend_unittest.cc',
'browser/history/history_backend_unittest.cc',
diff --git a/chrome/test/data/valgrind/unit_tests.gtest_linux.txt b/chrome/test/data/valgrind/unit_tests.gtest_linux.txt
index b78da34..58220ef 100644
--- a/chrome/test/data/valgrind/unit_tests.gtest_linux.txt
+++ b/chrome/test/data/valgrind/unit_tests.gtest_linux.txt
@@ -1,3 +1,4 @@
# See http://crbug.com/15445
# Only fails on the bots?
BookmarkEditorGtkTest.*
+CookiesViewTest.*