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