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

Side by Side Diff: chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc

Issue 9968016: Move the URL string from TemplateURLRef onto the owning TemplateURL. This will make it easier to m… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
1 // Copyright (c) 2011 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.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_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 // Verify the TableModel has the new data. 135 // Verify the TableModel has the new data.
136 ASSERT_EQ(1, table_model()->RowCount()); 136 ASSERT_EQ(1, table_model()->RowCount());
137 137
138 // Verify the TemplateURLService has the new entry. 138 // Verify the TemplateURLService has the new entry.
139 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); 139 ASSERT_EQ(1U, model_->GetTemplateURLs().size());
140 140
141 // Verify the entry is what we added. 141 // Verify the entry is what we added.
142 const TemplateURL* turl = model_->GetTemplateURLs()[0]; 142 const TemplateURL* turl = model_->GetTemplateURLs()[0];
143 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); 143 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name());
144 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); 144 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword());
145 ASSERT_TRUE(turl->url() != NULL); 145 EXPECT_EQ("http://c", turl->url());
146 EXPECT_EQ("http://c", turl->url()->url());
147 } 146 }
148 147
149 // Tests modifying a TemplateURL. 148 // Tests modifying a TemplateURL.
150 TEST_F(KeywordEditorControllerTest, Modify) { 149 TEST_F(KeywordEditorControllerTest, Modify) {
151 controller_->AddTemplateURL(kA, kB, "http://c"); 150 controller_->AddTemplateURL(kA, kB, "http://c");
152 ClearChangeCount(); 151 ClearChangeCount();
153 152
154 // Modify the entry. 153 // Modify the entry.
155 const TemplateURL* turl = model_->GetTemplateURLs()[0]; 154 const TemplateURL* turl = model_->GetTemplateURLs()[0];
156 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); 155 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1");
157 156
158 // Make sure it was updated appropriately. 157 // Make sure it was updated appropriately.
159 VerifyChangeCount(0, 1, 0, 0); 158 VerifyChangeCount(0, 1, 0, 0);
160 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); 159 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name());
161 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); 160 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword());
162 ASSERT_TRUE(turl->url() != NULL); 161 EXPECT_EQ("http://c1", turl->url());
163 EXPECT_EQ("http://c1", turl->url()->url());
164 } 162 }
165 163
166 // Tests making a TemplateURL the default search provider. 164 // Tests making a TemplateURL the default search provider.
167 TEST_F(KeywordEditorControllerTest, MakeDefault) { 165 TEST_F(KeywordEditorControllerTest, MakeDefault) {
168 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); 166 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
169 ClearChangeCount(); 167 ClearChangeCount();
170 168
171 const TemplateURL* turl = model_->GetTemplateURLs()[0]; 169 const TemplateURL* turl = model_->GetTemplateURLs()[0];
172 int new_default = controller_->MakeDefaultTemplateURL(0); 170 int new_default = controller_->MakeDefaultTemplateURL(0);
173 EXPECT_EQ(0, new_default); 171 EXPECT_EQ(0, new_default);
(...skipping 18 matching lines...) Expand all
192 const TemplateURL* turl1 = 190 const TemplateURL* turl1 =
193 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); 191 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
194 ASSERT_TRUE(turl1 != NULL); 192 ASSERT_TRUE(turl1 != NULL);
195 const TemplateURL* turl2 = 193 const TemplateURL* turl2 =
196 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); 194 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
197 ASSERT_TRUE(turl2 != NULL); 195 ASSERT_TRUE(turl2 != NULL);
198 196
199 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); 197 EXPECT_TRUE(controller_->CanMakeDefault(turl1));
200 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); 198 EXPECT_TRUE(controller_->CanMakeDefault(turl2));
201 199
202 SimulateDefaultSearchIsManaged(turl2->url()->url()); 200 SimulateDefaultSearchIsManaged(turl2->url());
203 EXPECT_TRUE(model_->is_default_search_managed()); 201 EXPECT_TRUE(model_->is_default_search_managed());
204 202
205 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); 203 EXPECT_FALSE(controller_->CanMakeDefault(turl1));
206 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); 204 EXPECT_FALSE(controller_->CanMakeDefault(turl2));
207 } 205 }
208 206
209 // Tests that a TemplateURL can't be edited if it is the managed default search 207 // Tests that a TemplateURL can't be edited if it is the managed default search
210 // provider. 208 // provider.
211 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { 209 TEST_F(KeywordEditorControllerTest, EditManagedDefault) {
212 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); 210 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}");
213 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); 211 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}");
214 ClearChangeCount(); 212 ClearChangeCount();
215 213
216 const TemplateURL* turl1 = 214 const TemplateURL* turl1 =
217 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); 215 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b"));
218 ASSERT_TRUE(turl1 != NULL); 216 ASSERT_TRUE(turl1 != NULL);
219 const TemplateURL* turl2 = 217 const TemplateURL* turl2 =
220 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); 218 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1"));
221 ASSERT_TRUE(turl2 != NULL); 219 ASSERT_TRUE(turl2 != NULL);
222 220
223 EXPECT_TRUE(controller_->CanEdit(turl1)); 221 EXPECT_TRUE(controller_->CanEdit(turl1));
224 EXPECT_TRUE(controller_->CanEdit(turl2)); 222 EXPECT_TRUE(controller_->CanEdit(turl2));
225 223
226 // Simulate setting a managed default. This will add another template URL to 224 // Simulate setting a managed default. This will add another template URL to
227 // the model. 225 // the model.
228 SimulateDefaultSearchIsManaged(turl2->url()->url()); 226 SimulateDefaultSearchIsManaged(turl2->url());
229 EXPECT_TRUE(model_->is_default_search_managed()); 227 EXPECT_TRUE(model_->is_default_search_managed());
230 EXPECT_TRUE(controller_->CanEdit(turl1)); 228 EXPECT_TRUE(controller_->CanEdit(turl1));
231 EXPECT_TRUE(controller_->CanEdit(turl2)); 229 EXPECT_TRUE(controller_->CanEdit(turl2));
232 EXPECT_FALSE(controller_->CanEdit(model_->GetDefaultSearchProvider())); 230 EXPECT_FALSE(controller_->CanEdit(model_->GetDefaultSearchProvider()));
233 } 231 }
234 232
235 TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) { 233 TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) {
236 // Simulate a failure to load Web Data. 234 // Simulate a failure to load Web Data.
237 Init(true); 235 Init(true);
238 236
(...skipping 13 matching lines...) Expand all
252 turl->set_short_name(ASCIIToUTF16("b")); 250 turl->set_short_name(ASCIIToUTF16("b"));
253 model_->Add(turl); 251 model_->Add(turl);
254 252
255 // Table model should have updated. 253 // Table model should have updated.
256 VerifyChangeCount(1, 0, 0, 0); 254 VerifyChangeCount(1, 0, 0, 0);
257 255
258 // And should contain the newly added TemplateURL. 256 // And should contain the newly added TemplateURL.
259 ASSERT_EQ(1, table_model()->RowCount()); 257 ASSERT_EQ(1, table_model()->RowCount());
260 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); 258 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl));
261 } 259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698