Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1227)

Unified Diff: chrome/browser/cookies_tree_model_unittest.cc

Issue 365005: Converting the Cookies options page from a TableView to a TreeView... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | chrome/browser/views/options/advanced_contents_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cookies_tree_model_unittest.cc
===================================================================
--- chrome/browser/cookies_tree_model_unittest.cc (revision 31033)
+++ chrome/browser/cookies_tree_model_unittest.cc (working copy)
@@ -1,21 +1,18 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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 "chrome/browser/cookies_tree_model.h"
#include <string>
-#include <vector>
-#include <gtk/gtk.h>
-
-#include "base/string_util.h"
-#include "chrome/browser/cookies_table_model.h"
+#include "app/l10n_util.h"
#include "chrome/browser/net/url_request_context_getter.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 {
@@ -30,7 +27,7 @@
virtual URLRequestContext* GetURLRequestContext() {
if (!context_)
context_ = new TestURLRequestContext();
- return context_;
+ return context_.get();
}
private:
scoped_refptr<URLRequestContext> context_;
@@ -53,32 +50,14 @@
scoped_refptr<URLRequestContextGetter> url_request_context_getter_;
};
-} // namespace
-class CookiesViewTest : public testing::Test {
+
+class CookiesTreeModelTest : public testing::Test {
public:
virtual void SetUp() {
profile_.reset(new CookieTestingProfile());
}
- 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_));
- }
-
// Get the cookie names in the cookie list, as a comma seperated string.
// (Note that the CookieMonster cookie list is sorted by domain.)
// Ex:
@@ -93,484 +72,219 @@
return JoinString(parts, ',');
}
- // 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) {
- std::vector<std::string> parts;
- 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;
+ std::string GetCookiesOfChildren(const CookieTreeNode* node) {
+ if (node->GetChildCount()) {
+ std::string retval;
+ for (int i = 0; i < node->GetChildCount(); ++i) {
+ retval += GetCookiesOfChildren(node->GetChild(i));
+ }
+ return retval;
+ } else {
+ if (node->GetDetailedInfo().node_type ==
+ CookieTreeNode::DetailedInfo::TYPE_COOKIE)
+ return node->GetDetailedInfo().cookie->second.Name() + ",";
+ else
+ return "";
}
- return JoinString(parts, ',');
}
+ // Get the cookie names displayed in the view (if we had one) in the order
+ // they are displayed, as a comma seperated string.
+ // Ex: EXPECT_STREQ("X,Y", GetDisplayedCookies(cookies_view).c_str());
+ std::string GetDisplayedCookies(CookiesTreeModel* cookies_model) {
+ CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(
+ cookies_model->GetRoot());
+ std::string retval = GetCookiesOfChildren(root);
+ if (retval.length() && retval[retval.length() - 1] == ',')
+ retval.erase(retval.length() - 1);
+ return retval;
+ }
+ // do not call on the root
+ void DeleteCookie(CookieTreeNode* node) {
+ node->DeleteStoredObjects();
+ // find the parent and index
+ CookieTreeNode* parent_node = node->GetParent();
+ DCHECK(parent_node);
+ int ct_node_index = parent_node->IndexOfChild(node);
+ delete parent_node->GetModel()->Remove(parent_node, ct_node_index);
+ }
protected:
MessageLoopForUI message_loop_;
scoped_ptr<CookieTestingProfile> profile_;
};
-TEST_F(CookiesViewTest, Empty) {
- 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, RemoveAll) {
+TEST_F(CookiesTreeModelTest, RemoveAll) {
net::CookieMonster* monster = profile_->GetCookieMonster();
monster->SetCookie(GURL("http://foo"), "A=1");
monster->SetCookie(GURL("http://foo2"), "B=1");
- CookiesView cookies_view(profile_.get());
+ CookiesTreeModel cookies_model(profile_.get());
// Reset the selection of the first row.
- gtk_tree_selection_unselect_all(cookies_view.selection_);
-
{
SCOPED_TRACE("Before removing");
- 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_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model));
}
- gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_));
+ cookies_model.DeleteAllCookies();
{
SCOPED_TRACE("After removing");
- 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));
+ EXPECT_EQ(1, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_EQ(0, cookies_model.GetRoot()->GetChildCount());
+ EXPECT_EQ(std::string(""), GetMonsterCookies(monster));
+ EXPECT_EQ(GetMonsterCookies(monster), GetDisplayedCookies(&cookies_model));
}
}
-// 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(CookiesTreeModelTest, Remove) {
net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo"), "A=1");
+ monster->SetCookie(GURL("http://foo1"), "A=1");
monster->SetCookie(GURL("http://foo2"), "B=1");
- CookiesView cookies_view(profile_.get());
+ monster->SetCookie(GURL("http://foo3"), "C=1");
+ CookiesTreeModel cookies_model(profile_.get());
- gtk_tree_selection_select_all(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));
+ SCOPED_TRACE("Initial State 3 cookies");
+ // 10 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c
+ EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
}
-
- gtk_button_clicked(GTK_BUTTON(cookies_view.remove_all_button_));
+ DeleteCookie(cookies_model.GetRoot()->GetChild(0));
{
- SCOPED_TRACE("After removing");
- 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));
+ SCOPED_TRACE("First origin removed");
+ EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str());
+ EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount());
}
}
-TEST_F(CookiesViewTest, Remove) {
+TEST_F(CookiesTreeModelTest, RemoveCookiesNode) {
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");
- CookiesView cookies_view(profile_.get());
+ CookiesTreeModel cookies_model(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);
-
{
- 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));
+ SCOPED_TRACE("Initial State 3 cookies");
+ // 10 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c
+ EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
}
-
- gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
-
+ DeleteCookie(cookies_model.GetRoot()->GetChild(0)->GetChild(0));
{
- SCOPED_TRACE("First selection removed");
- 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(FALSE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
- CheckDetailsSensitivity(FALSE, cookies_view);
+ SCOPED_TRACE("First origin removed");
+ EXPECT_STREQ("B,C", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("B,C", GetDisplayedCookies(&cookies_model).c_str());
+ // 8 because in this case, the origin remains, although the COOKIES
+ // node beneath it has been deleted. So, we have
+ // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
+ EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount());
}
+}
- 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_));
+TEST_F(CookiesTreeModelTest, RemoveCookieNode) {
+ 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");
+ CookiesTreeModel cookies_model(profile_.get());
{
- SCOPED_TRACE("Second selection");
- EXPECT_STREQ("A", GetMonsterCookies(monster).c_str());
- EXPECT_STREQ("A", 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(1, gtk_tree_model_iter_n_children(
- GTK_TREE_MODEL(cookies_view.list_store_), NULL));
+ SCOPED_TRACE("Initial State 3 cookies");
+ // 10 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c
+ EXPECT_EQ(10, cookies_model.GetRoot()->GetTotalNodeCount());
}
-
- 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_));
-
+ DeleteCookie(cookies_model.GetRoot()->GetChild(1)->GetChild(0));
{
- 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_));
- CheckDetailsSensitivity(FALSE, cookies_view);
- EXPECT_EQ(0, gtk_tree_model_iter_n_children(
- GTK_TREE_MODEL(cookies_view.list_store_), NULL));
+ SCOPED_TRACE("Second origin COOKIES node removed");
+ EXPECT_STREQ("A,C", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,C", GetDisplayedCookies(&cookies_model).c_str());
+ // 8 because in this case, the origin remains, although the COOKIES
+ // node beneath it has been deleted. So, we have
+ // root -> foo1 -> cookies -> a, foo2, foo3 -> cookies -> c
+ EXPECT_EQ(8, cookies_model.GetRoot()->GetTotalNodeCount());
}
}
-TEST_F(CookiesViewTest, RemoveMultiple) {
+TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) {
net::CookieMonster* monster = profile_->GetCookieMonster();
- monster->SetCookie(GURL("http://foo0"), "C=1");
- monster->SetCookie(GURL("http://foo1"), "D=1");
+ monster->SetCookie(GURL("http://foo1"), "A=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());
+ monster->SetCookie(GURL("http://foo3"), "C=1");
+ monster->SetCookie(GURL("http://foo3"), "D=1");
+ CookiesTreeModel cookies_model(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);
- 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_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_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_));
+ {
+ SCOPED_TRACE("Initial State 4 cookies");
+ // 11 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c,d
+ EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_STREQ("A,B,C,D", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C,D", GetDisplayedCookies(&cookies_model).c_str());
+ }
+ DeleteCookie(cookies_model.GetRoot()->GetChild(2));
+ {
+ SCOPED_TRACE("Third origin removed");
+ EXPECT_STREQ("A,B", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B", GetDisplayedCookies(&cookies_model).c_str());
+ EXPECT_EQ(7, cookies_model.GetRoot()->GetTotalNodeCount());
+ }
}
-TEST_F(CookiesViewTest, RemoveDefaultSelection) {
+TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) {
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());
+ monster->SetCookie(GURL("http://foo3"), "D=1");
+ monster->SetCookie(GURL("http://foo3"), "E=1");
+ CookiesTreeModel cookies_model(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));
+ SCOPED_TRACE("Initial State 5 cookies");
+ // 11 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
+ EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
}
-
- gtk_button_clicked(GTK_BUTTON(cookies_view.remove_button_));
-
+ DeleteCookie(cookies_model.GetRoot()->GetChild(2)->GetChild(0)->
+ GetChild(1));
{
- 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);
+ SCOPED_TRACE("Middle cookie in third origin removed");
+ EXPECT_STREQ("A,B,C,E", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C,E", GetDisplayedCookies(&cookies_model).c_str());
+ EXPECT_EQ(11, cookies_model.GetRoot()->GetTotalNodeCount());
}
}
-TEST_F(CookiesViewTest, Filter) {
+TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) {
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_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_);
- EXPECT_STREQ("B,D", 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_), "bar2");
- gtk_widget_activate(cookies_view.filter_entry_);
- EXPECT_STREQ("D", 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_));
-}
-
-TEST_F(CookiesViewTest, FilterRemoveAll) {
- 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(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_all_button_));
-
- 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_));
-
- 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_));
-}
-
-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_));
-
- 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_));
-
- 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_EQ(TRUE, GTK_WIDGET_SENSITIVE(cookies_view.remove_button_));
-
- gtk_button_clicked(GTK_BUTTON(cookies_view.remove_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_button_));
-}
-
-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) {
- 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_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_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());
+ monster->SetCookie(GURL("http://foo3"), "C=1");
+ monster->SetCookie(GURL("http://foo3"), "D=1");
+ monster->SetCookie(GURL("http://foo3"), "E=1");
+ CookiesTreeModel cookies_model(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);
- 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_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_));
+ {
+ SCOPED_TRACE("Initial State 5 cookies");
+ // 11 because there's the root, then foo1 -> cookies -> a,
+ // foo2 -> cookies -> b, foo3 -> cookies -> c,d,e
+ EXPECT_EQ(12, cookies_model.GetRoot()->GetTotalNodeCount());
+ EXPECT_STREQ("A,B,C,D,E", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,B,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
+ }
+ DeleteCookie(cookies_model.GetRoot()->GetChild(1));
+ {
+ SCOPED_TRACE("Second origin removed");
+ EXPECT_STREQ("A,C,D,E", GetMonsterCookies(monster).c_str());
+ EXPECT_STREQ("A,C,D,E", GetDisplayedCookies(&cookies_model).c_str());
+ // Left with root -> foo1 -> cookies -> a, foo3 -> cookies -> c,d,e
+ EXPECT_EQ(9, cookies_model.GetRoot()->GetTotalNodeCount());
+ }
}
-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());
-
- 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());
-
- 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_));
- EXPECT_STREQ("Y,W", GetMonsterCookies(monster).c_str());
- EXPECT_STREQ("W,Y", GetDisplayedCookies(cookies_view).c_str());
-}
+} // namespace
« no previous file with comments | « chrome/browser/cookies_tree_model.cc ('k') | chrome/browser/views/options/advanced_contents_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698