OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/mac/scoped_nsautorelease_pool.h" | 5 #include "base/mac/scoped_nsautorelease_pool.h" |
6 #include "base/scoped_nsobject.h" | 6 #include "base/scoped_nsobject.h" |
| 7 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/search_engines/template_url.h" | 8 #include "chrome/browser/search_engines/template_url.h" |
8 #include "chrome/browser/search_engines/template_url_model.h" | 9 #include "chrome/browser/search_engines/template_url_model.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/cocoa/browser_test_helper.h" | 11 #include "chrome/browser/ui/cocoa/browser_test_helper.h" |
11 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #import "chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.h" | 13 #import "chrome/browser/ui/cocoa/keyword_editor_cocoa_controller.h" |
13 #include "chrome/test/testing_profile.h" | 14 #include "chrome/test/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 [newSharedInstance close]; | 145 [newSharedInstance close]; |
145 } | 146 } |
146 | 147 |
147 TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForRowMixed) { | 148 TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForRowMixed) { |
148 [controller_ window]; // Force |-awakeFromNib|. | 149 [controller_ window]; // Force |-awakeFromNib|. |
149 TemplateURLModel* template_model = [controller_ controller]->url_model(); | 150 TemplateURLModel* template_model = [controller_ controller]->url_model(); |
150 | 151 |
151 // Add a default engine. | 152 // Add a default engine. |
152 TemplateURL* t_url = new TemplateURL(); | 153 TemplateURL* t_url = new TemplateURL(); |
153 t_url->SetURL("http://test1/{searchTerms}", 0, 0); | 154 t_url->SetURL("http://test1/{searchTerms}", 0, 0); |
154 t_url->set_keyword(L"test1"); | 155 t_url->set_keyword(ASCIIToUTF16("test1")); |
155 t_url->set_short_name(L"Test1"); | 156 t_url->set_short_name(ASCIIToUTF16("Test1")); |
156 t_url->set_show_in_default_list(true); | 157 t_url->set_show_in_default_list(true); |
157 template_model->Add(t_url); | 158 template_model->Add(t_url); |
158 | 159 |
159 // Add a non-default engine. | 160 // Add a non-default engine. |
160 t_url = new TemplateURL(); | 161 t_url = new TemplateURL(); |
161 t_url->SetURL("http://test2/{searchTerms}", 0, 0); | 162 t_url->SetURL("http://test2/{searchTerms}", 0, 0); |
162 t_url->set_keyword(L"test2"); | 163 t_url->set_keyword(ASCIIToUTF16("test2")); |
163 t_url->set_short_name(L"Test2"); | 164 t_url->set_short_name(ASCIIToUTF16("Test2")); |
164 t_url->set_show_in_default_list(false); | 165 t_url->set_show_in_default_list(false); |
165 template_model->Add(t_url); | 166 template_model->Add(t_url); |
166 | 167 |
167 // Two headers with a single row underneath each. | 168 // Two headers with a single row underneath each. |
168 NSTableView* table = [controller_ tableView]; | 169 NSTableView* table = [controller_ tableView]; |
169 [table reloadData]; | 170 [table reloadData]; |
170 ASSERT_EQ(4, [[controller_ tableView] numberOfRows]); | 171 ASSERT_EQ(4, [[controller_ tableView] numberOfRows]); |
171 | 172 |
172 // Index 0 is the group header, index 1 should be the first engine. | 173 // Index 0 is the group header, index 1 should be the first engine. |
173 ASSERT_EQ(0, [controller_ indexInModelForRow:1]); | 174 ASSERT_EQ(0, [controller_ indexInModelForRow:1]); |
(...skipping 13 matching lines...) Expand all Loading... |
187 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:3]); | 188 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:3]); |
188 } | 189 } |
189 | 190 |
190 TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForDefault) { | 191 TEST_F(KeywordEditorCocoaControllerTest, IndexInModelForDefault) { |
191 [controller_ window]; // Force |-awakeFromNib|. | 192 [controller_ window]; // Force |-awakeFromNib|. |
192 TemplateURLModel* template_model = [controller_ controller]->url_model(); | 193 TemplateURLModel* template_model = [controller_ controller]->url_model(); |
193 | 194 |
194 // Add 2 default engines. | 195 // Add 2 default engines. |
195 TemplateURL* t_url = new TemplateURL(); | 196 TemplateURL* t_url = new TemplateURL(); |
196 t_url->SetURL("http://test1/{searchTerms}", 0, 0); | 197 t_url->SetURL("http://test1/{searchTerms}", 0, 0); |
197 t_url->set_keyword(L"test1"); | 198 t_url->set_keyword(ASCIIToUTF16("test1")); |
198 t_url->set_short_name(L"Test1"); | 199 t_url->set_short_name(ASCIIToUTF16("Test1")); |
199 t_url->set_show_in_default_list(true); | 200 t_url->set_show_in_default_list(true); |
200 template_model->Add(t_url); | 201 template_model->Add(t_url); |
201 | 202 |
202 t_url = new TemplateURL(); | 203 t_url = new TemplateURL(); |
203 t_url->SetURL("http://test2/{searchTerms}", 0, 0); | 204 t_url->SetURL("http://test2/{searchTerms}", 0, 0); |
204 t_url->set_keyword(L"test2"); | 205 t_url->set_keyword(ASCIIToUTF16("test2")); |
205 t_url->set_short_name(L"Test2"); | 206 t_url->set_short_name(ASCIIToUTF16("Test2")); |
206 t_url->set_show_in_default_list(true); | 207 t_url->set_show_in_default_list(true); |
207 template_model->Add(t_url); | 208 template_model->Add(t_url); |
208 | 209 |
209 // One header and two rows. | 210 // One header and two rows. |
210 NSTableView* table = [controller_ tableView]; | 211 NSTableView* table = [controller_ tableView]; |
211 [table reloadData]; | 212 [table reloadData]; |
212 ASSERT_EQ(3, [[controller_ tableView] numberOfRows]); | 213 ASSERT_EQ(3, [[controller_ tableView] numberOfRows]); |
213 | 214 |
214 // Index 0 is the group header, index 1 should be the first engine. | 215 // Index 0 is the group header, index 1 should be the first engine. |
215 ASSERT_EQ(0, [controller_ indexInModelForRow:1]); | 216 ASSERT_EQ(0, [controller_ indexInModelForRow:1]); |
216 ASSERT_EQ(1, [controller_ indexInModelForRow:2]); | 217 ASSERT_EQ(1, [controller_ indexInModelForRow:2]); |
217 | 218 |
218 ASSERT_TRUE([controller_ tableView:table isGroupRow:0]); | 219 ASSERT_TRUE([controller_ tableView:table isGroupRow:0]); |
219 ASSERT_FALSE([controller_ tableView:table isGroupRow:1]); | 220 ASSERT_FALSE([controller_ tableView:table isGroupRow:1]); |
220 ASSERT_FALSE([controller_ tableView:table isGroupRow:2]); | 221 ASSERT_FALSE([controller_ tableView:table isGroupRow:2]); |
221 | 222 |
222 ASSERT_FALSE([controller_ tableView:table shouldSelectRow:0]); | 223 ASSERT_FALSE([controller_ tableView:table shouldSelectRow:0]); |
223 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:1]); | 224 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:1]); |
224 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:2]); | 225 ASSERT_TRUE([controller_ tableView:table shouldSelectRow:2]); |
225 } | 226 } |
226 | 227 |
227 } // namespace | 228 } // namespace |
OLD | NEW |