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

Side by Side Diff: chrome/browser/gtk/options/content_exceptions_window_gtk_unittest.cc

Issue 6251001: Move chrome/browser/gtk/ to chrome/browser/ui/gtk/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/gtk/options/content_exceptions_window_gtk.h"
6
7 #include "chrome/test/testing_profile.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 using ::testing::ElementsAre;
12
13 class ContentExceptionsWindowGtkUnittest : public testing::Test {
14 public:
15 ContentExceptionsWindowGtkUnittest()
16 : ui_thread_(BrowserThread::UI, &message_loop_),
17 host_content_settings_map_(profile_.GetHostContentSettingsMap()),
18 window_(NULL) {
19 }
20
21 ~ContentExceptionsWindowGtkUnittest() {
22 // This will delete window_ too.
23 gtk_widget_destroy(window_->dialog_);
24 message_loop_.RunAllPending();
25 }
26
27 void AddException(const std::string& pattern, ContentSetting value) {
28 host_content_settings_map_->SetContentSetting(
29 ContentSettingsPattern(pattern),
30 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
31 "",
32 value);
33 }
34
35 void BuildWindow() {
36 window_ = new ContentExceptionsWindowGtk(
37 NULL,
38 host_content_settings_map_,
39 NULL,
40 CONTENT_SETTINGS_TYPE_JAVASCRIPT);
41 }
42
43 // Actions:
44 void SelectRows(const std::vector<int>& rows) {
45 gtk_tree_selection_unselect_all(window_->treeview_selection_);
46
47 for (std::vector<int>::const_iterator it = rows.begin(); it != rows.end();
48 ++it) {
49 GtkTreeIter iter;
50 if (!gtk_tree_model_iter_nth_child(window_->sort_list_store_,
51 &iter, NULL, *it)) {
52 NOTREACHED();
53 return;
54 }
55
56 gtk_tree_selection_select_iter(window_->treeview_selection_, &iter);
57 }
58 }
59
60 void Remove() {
61 window_->Remove(window_->remove_button_);
62 }
63
64 // Getters:
65
66 void GetSelectedRows(std::set<std::pair<int, int> >* selected) {
67 window_->GetSelectedModelIndices(selected);
68 }
69
70 int StoreListStoreCount() {
71 return gtk_tree_model_iter_n_children(
72 GTK_TREE_MODEL(window_->sort_list_store_), NULL);
73 }
74
75 int ListStoreCount() {
76 return gtk_tree_model_iter_n_children(
77 GTK_TREE_MODEL(window_->list_store_), NULL);
78 }
79
80 std::set<std::string> Paths() {
81 std::set<std::string> paths;
82 GtkTreeIter iter;
83 bool valid = gtk_tree_model_get_iter_first(
84 GTK_TREE_MODEL(window_->sort_list_store_), &iter);
85
86 while (valid) {
87 gchar* str = NULL;
88 gtk_tree_model_get(GTK_TREE_MODEL(window_->sort_list_store_), &iter,
89 0, &str, -1);
90 paths.insert(str);
91 g_free(str);
92
93 valid = gtk_tree_model_iter_next(
94 GTK_TREE_MODEL(window_->sort_list_store_), &iter);
95 }
96
97 return paths;
98 }
99
100 // Whether certain widgets are enabled:
101 bool EditButtonSensitive() {
102 return GTK_WIDGET_SENSITIVE(window_->edit_button_);
103 }
104
105 bool RemoveButtonSensitive() {
106 return GTK_WIDGET_SENSITIVE(window_->remove_button_);
107 }
108
109 bool RemoveAllSensitive() {
110 return GTK_WIDGET_SENSITIVE(window_->remove_all_button_);
111 }
112
113 private:
114 MessageLoop message_loop_;
115 BrowserThread ui_thread_;
116
117 TestingProfile profile_;
118 HostContentSettingsMap* host_content_settings_map_;
119
120 ContentExceptionsWindowGtk* window_;
121 };
122
123 TEST_F(ContentExceptionsWindowGtkUnittest, TestEmptyDisplay) {
124 BuildWindow();
125
126 EXPECT_EQ(0, StoreListStoreCount());
127 EXPECT_EQ(0, ListStoreCount());
128
129 EXPECT_FALSE(RemoveAllSensitive());
130 }
131
132 TEST_F(ContentExceptionsWindowGtkUnittest, TestDisplay) {
133 AddException("a", CONTENT_SETTING_BLOCK);
134 AddException("b", CONTENT_SETTING_ALLOW);
135
136 BuildWindow();
137
138 EXPECT_EQ(2, StoreListStoreCount());
139 EXPECT_EQ(2, ListStoreCount());
140
141 EXPECT_TRUE(RemoveAllSensitive());
142 }
143
144 TEST_F(ContentExceptionsWindowGtkUnittest, TestSelection) {
145 AddException("a", CONTENT_SETTING_BLOCK);
146
147 BuildWindow();
148
149 EXPECT_FALSE(EditButtonSensitive());
150 EXPECT_FALSE(RemoveButtonSensitive());
151
152 std::vector<int> rows;
153 rows.push_back(0);
154 SelectRows(rows);
155
156 EXPECT_TRUE(EditButtonSensitive());
157 EXPECT_TRUE(RemoveButtonSensitive());
158 }
159
160 TEST_F(ContentExceptionsWindowGtkUnittest, TestSimpleRemoval) {
161 AddException("a", CONTENT_SETTING_BLOCK);
162 AddException("b", CONTENT_SETTING_ALLOW);
163 AddException("c", CONTENT_SETTING_BLOCK);
164 AddException("d", CONTENT_SETTING_ALLOW);
165
166 BuildWindow();
167
168 std::vector<int> rows;
169 rows.push_back(1);
170 SelectRows(rows);
171
172 Remove();
173
174 EXPECT_EQ(3, StoreListStoreCount());
175 EXPECT_EQ(3, ListStoreCount());
176 EXPECT_TRUE(EditButtonSensitive());
177 EXPECT_TRUE(RemoveButtonSensitive());
178
179 std::set<std::pair<int, int> > selected;
180 GetSelectedRows(&selected);
181
182 ASSERT_EQ(1u, selected.size());
183 EXPECT_EQ(1, selected.begin()->first);
184 EXPECT_EQ(1, selected.begin()->second);
185 EXPECT_THAT(Paths(), ElementsAre("a", "c", "d"));
186 }
187
188 TEST_F(ContentExceptionsWindowGtkUnittest, TestComplexRemoval) {
189 AddException("a", CONTENT_SETTING_BLOCK);
190 AddException("b", CONTENT_SETTING_ALLOW);
191 AddException("c", CONTENT_SETTING_BLOCK);
192 AddException("d", CONTENT_SETTING_ALLOW);
193 AddException("e", CONTENT_SETTING_BLOCK);
194
195 BuildWindow();
196
197 std::vector<int> rows;
198 rows.push_back(1);
199 rows.push_back(3);
200 SelectRows(rows);
201
202 Remove();
203
204 std::set<std::pair<int, int> > selected;
205 GetSelectedRows(&selected);
206
207 ASSERT_EQ(1u, selected.size());
208 EXPECT_EQ(1, selected.begin()->first);
209 EXPECT_EQ(1, selected.begin()->second);
210 EXPECT_THAT(Paths(), ElementsAre("a", "c", "e"));
211 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/content_exceptions_window_gtk.cc ('k') | chrome/browser/gtk/options/content_filter_page_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698