OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/string16.h" | 5 #include "base/string16.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/browser/search_engines/keyword_editor_controller.h" | 8 #include "chrome/browser/search_engines/keyword_editor_controller.h" |
9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
10 #include "chrome/browser/search_engines/template_url_model.h" | 10 #include "chrome/browser/search_engines/template_url_model.h" |
11 #include "chrome/browser/search_engines/template_url_table_model.h" | 11 #include "chrome/browser/search_engines/template_url_table_model.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 return; | 130 return; |
131 | 131 |
132 // Verify the TableModel has the new data. | 132 // Verify the TableModel has the new data. |
133 ASSERT_EQ(1, table_model()->RowCount()); | 133 ASSERT_EQ(1, table_model()->RowCount()); |
134 | 134 |
135 // Verify the TemplateURLModel has the new entry. | 135 // Verify the TemplateURLModel has the new entry. |
136 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); | 136 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); |
137 | 137 |
138 // Verify the entry is what we added. | 138 // Verify the entry is what we added. |
139 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 139 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
140 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); | 140 EXPECT_EQ(L"a", turl->short_name()); |
141 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); | 141 EXPECT_EQ(L"b", turl->keyword()); |
142 ASSERT_TRUE(turl->url() != NULL); | 142 ASSERT_TRUE(turl->url() != NULL); |
143 EXPECT_EQ("http://c", turl->url()->url()); | 143 EXPECT_EQ("http://c", turl->url()->url()); |
144 } | 144 } |
145 | 145 |
146 // Tests modifying a TemplateURL. | 146 // Tests modifying a TemplateURL. |
147 TEST_F(KeywordEditorControllerTest, Modify) { | 147 TEST_F(KeywordEditorControllerTest, Modify) { |
148 controller_->AddTemplateURL(kA, kB, "http://c"); | 148 controller_->AddTemplateURL(kA, kB, "http://c"); |
149 ClearChangeCount(); | 149 ClearChangeCount(); |
150 | 150 |
151 // Modify the entry. | 151 // Modify the entry. |
152 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 152 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
153 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); | 153 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); |
154 | 154 |
155 // Make sure it was updated appropriately. | 155 // Make sure it was updated appropriately. |
156 VerifyChangeCount(0, 1, 0, 0); | 156 VerifyChangeCount(0, 1, 0, 0); |
157 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); | 157 EXPECT_EQ(L"a1", turl->short_name()); |
158 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); | 158 EXPECT_EQ(L"b1", turl->keyword()); |
159 ASSERT_TRUE(turl->url() != NULL); | 159 ASSERT_TRUE(turl->url() != NULL); |
160 EXPECT_EQ("http://c1", turl->url()->url()); | 160 EXPECT_EQ("http://c1", turl->url()->url()); |
161 } | 161 } |
162 | 162 |
163 // Tests making a TemplateURL the default search provider. | 163 // Tests making a TemplateURL the default search provider. |
164 TEST_F(KeywordEditorControllerTest, MakeDefault) { | 164 TEST_F(KeywordEditorControllerTest, MakeDefault) { |
165 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 165 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
166 ClearChangeCount(); | 166 ClearChangeCount(); |
167 | 167 |
168 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 168 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
(...skipping 10 matching lines...) Expand all Loading... |
179 EXPECT_EQ(-1, new_default); | 179 EXPECT_EQ(-1, new_default); |
180 } | 180 } |
181 | 181 |
182 // Tests that a TemplateURL can't be made the default if the default search | 182 // Tests that a TemplateURL can't be made the default if the default search |
183 // provider is managed via policy. | 183 // provider is managed via policy. |
184 TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { | 184 TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { |
185 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 185 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
186 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); | 186 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); |
187 ClearChangeCount(); | 187 ClearChangeCount(); |
188 | 188 |
189 const TemplateURL* turl1 = | 189 const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); |
190 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | |
191 ASSERT_TRUE(turl1 != NULL); | 190 ASSERT_TRUE(turl1 != NULL); |
192 const TemplateURL* turl2 = | 191 const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); |
193 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); | |
194 ASSERT_TRUE(turl2 != NULL); | 192 ASSERT_TRUE(turl2 != NULL); |
195 | 193 |
196 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); | 194 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); |
197 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); | 195 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); |
198 | 196 |
199 SimulateDefaultSearchIsManaged(turl2->url()->url()); | 197 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
200 EXPECT_TRUE(model_->is_default_search_managed()); | 198 EXPECT_TRUE(model_->is_default_search_managed()); |
201 | 199 |
202 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); | 200 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); |
203 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); | 201 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); |
204 } | 202 } |
205 | 203 |
206 // Tests that a TemplateURL can't be edited if it is the managed default search | 204 // Tests that a TemplateURL can't be edited if it is the managed default search |
207 // provider. | 205 // provider. |
208 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { | 206 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { |
209 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 207 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
210 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); | 208 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); |
211 ClearChangeCount(); | 209 ClearChangeCount(); |
212 | 210 |
213 const TemplateURL* turl1 = | 211 const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); |
214 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); | |
215 ASSERT_TRUE(turl1 != NULL); | 212 ASSERT_TRUE(turl1 != NULL); |
216 const TemplateURL* turl2 = | 213 const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); |
217 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); | |
218 ASSERT_TRUE(turl2 != NULL); | 214 ASSERT_TRUE(turl2 != NULL); |
219 | 215 |
220 EXPECT_TRUE(controller_->CanEdit(turl1)); | 216 EXPECT_TRUE(controller_->CanEdit(turl1)); |
221 EXPECT_TRUE(controller_->CanEdit(turl2)); | 217 EXPECT_TRUE(controller_->CanEdit(turl2)); |
222 | 218 |
223 // Simulate setting a managed default. This will add another template URL to | 219 // Simulate setting a managed default. This will add another template URL to |
224 // the model. | 220 // the model. |
225 SimulateDefaultSearchIsManaged(turl2->url()->url()); | 221 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
226 EXPECT_TRUE(model_->is_default_search_managed()); | 222 EXPECT_TRUE(model_->is_default_search_managed()); |
227 EXPECT_TRUE(controller_->CanEdit(turl1)); | 223 EXPECT_TRUE(controller_->CanEdit(turl1)); |
(...skipping 10 matching lines...) Expand all Loading... |
238 | 234 |
239 // This should not result in a crash. | 235 // This should not result in a crash. |
240 int new_default = controller_->MakeDefaultTemplateURL(0); | 236 int new_default = controller_->MakeDefaultTemplateURL(0); |
241 EXPECT_EQ(0, new_default); | 237 EXPECT_EQ(0, new_default); |
242 } | 238 } |
243 | 239 |
244 // Mutates the TemplateURLModel and make sure table model is updating | 240 // Mutates the TemplateURLModel and make sure table model is updating |
245 // appropriately. | 241 // appropriately. |
246 TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { | 242 TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { |
247 TemplateURL* turl = new TemplateURL(); | 243 TemplateURL* turl = new TemplateURL(); |
248 turl->set_keyword(ASCIIToUTF16("a")); | 244 turl->set_keyword(L"a"); |
249 turl->set_short_name(ASCIIToUTF16("b")); | 245 turl->set_short_name(L"b"); |
250 model_->Add(turl); | 246 model_->Add(turl); |
251 | 247 |
252 // Table model should have updated. | 248 // Table model should have updated. |
253 VerifyChangeCount(1, 0, 0, 0); | 249 VerifyChangeCount(1, 0, 0, 0); |
254 | 250 |
255 // And should contain the newly added TemplateURL. | 251 // And should contain the newly added TemplateURL. |
256 ASSERT_EQ(1, table_model()->RowCount()); | 252 ASSERT_EQ(1, table_model()->RowCount()); |
257 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); | 253 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); |
258 } | 254 } |
OLD | NEW |