OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/metrics/histogram.h" | 6 #include "base/metrics/histogram.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/protector/histograms.h" | 9 #include "chrome/browser/protector/histograms.h" |
10 #include "chrome/browser/protector/mock_protector_service.h" | 10 #include "chrome/browser/protector/mock_protector_service.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // This is test-only and should not be happening in real code. | 145 // This is test-only and should not be happening in real code. |
146 | 146 |
147 // |backup_url| in further test cases is owned by DefaultSearchProviderChange | 147 // |backup_url| in further test cases is owned by DefaultSearchProviderChange |
148 // instance, while other TemplateURLs are owned by TemplateURLService. | 148 // instance, while other TemplateURLs are owned by TemplateURLService. |
149 | 149 |
150 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValid) { | 150 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValid) { |
151 // Most common case: current default search provider exists, backup is valid, | 151 // Most common case: current default search provider exists, backup is valid, |
152 // they are different. | 152 // they are different. |
153 TemplateURL* backup_url = | 153 TemplateURL* backup_url = |
154 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); | 154 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); |
| 155 int backup_histogram_id = protector::GetSearchProviderHistogramID(backup_url); |
155 TemplateURL* current_url = | 156 TemplateURL* current_url = |
156 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); | 157 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); |
| 158 int current_histogram_id = |
| 159 protector::GetSearchProviderHistogramID(current_url); |
157 | 160 |
158 AddCopy(backup_url); | 161 AddCopy(backup_url); |
159 AddAndSetDefault(current_url); | 162 AddAndSetDefault(current_url); |
160 | 163 |
161 scoped_ptr<BaseSettingChange> change( | 164 scoped_ptr<BaseSettingChange> change( |
162 CreateDefaultSearchProviderChange(current_url, backup_url)); | 165 CreateDefaultSearchProviderChange(current_url, backup_url)); |
163 ASSERT_TRUE(change.get()); | 166 ASSERT_TRUE(change.get()); |
164 ASSERT_TRUE(change->Init(browser()->profile())); | 167 ASSERT_TRUE(change->Init(browser()->profile())); |
165 | 168 |
166 // Verify that backup is active. | 169 // Verify that backup is active. |
167 EXPECT_EQ(FindTemplateURL(http_example_info), | 170 EXPECT_EQ(FindTemplateURL(http_example_info), |
168 turl_service_->GetDefaultSearchProvider()); | 171 turl_service_->GetDefaultSearchProvider()); |
169 | 172 |
170 // Verify histograms. | 173 // Verify histograms. |
171 ExpectHistogramCount(kProtectorHistogramSearchProviderHijacked, | 174 ExpectHistogramCount(kProtectorHistogramSearchProviderHijacked, |
172 SEARCH_ENGINE_OTHER, 1); | 175 current_histogram_id, 1); |
173 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 176 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
174 SEARCH_ENGINE_OTHER, 1); | 177 backup_histogram_id, 1); |
175 | 178 |
176 // Verify text messages. | 179 // Verify text messages. |
177 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); | 180 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); |
178 EXPECT_EQ(GetChangeSearchButtonText(example_com), | 181 EXPECT_EQ(GetChangeSearchButtonText(example_com), |
179 change->GetApplyButtonText()); | 182 change->GetApplyButtonText()); |
180 EXPECT_EQ(GetKeepSearchButtonText(example_info), | 183 EXPECT_EQ(GetKeepSearchButtonText(example_info), |
181 change->GetDiscardButtonText()); | 184 change->GetDiscardButtonText()); |
182 | 185 |
183 // Discard does nothing - backup was already active. | 186 // Discard does nothing - backup was already active. |
184 change->Discard(browser()); | 187 change->Discard(browser()); |
185 EXPECT_EQ(FindTemplateURL(http_example_info), | 188 EXPECT_EQ(FindTemplateURL(http_example_info), |
186 turl_service_->GetDefaultSearchProvider()); | 189 turl_service_->GetDefaultSearchProvider()); |
187 ExpectHistogramCount(kProtectorHistogramSearchProviderDiscarded, | 190 ExpectHistogramCount(kProtectorHistogramSearchProviderDiscarded, |
188 SEARCH_ENGINE_OTHER, 1); | 191 current_histogram_id, 1); |
189 | 192 |
190 // Verify that Apply switches back to |current_url|. | 193 // Verify that Apply switches back to |current_url|. |
191 change->Apply(browser()); | 194 change->Apply(browser()); |
192 EXPECT_EQ(FindTemplateURL(http_example_com), | 195 EXPECT_EQ(FindTemplateURL(http_example_com), |
193 turl_service_->GetDefaultSearchProvider()); | 196 turl_service_->GetDefaultSearchProvider()); |
194 ExpectHistogramCount(kProtectorHistogramSearchProviderApplied, | 197 ExpectHistogramCount(kProtectorHistogramSearchProviderApplied, |
195 SEARCH_ENGINE_OTHER, 1); | 198 current_histogram_id, 1); |
196 } | 199 } |
197 | 200 |
198 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValidLongNames) { | 201 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupValidLongNames) { |
199 // Verify that search provider names that are too long are not displayed. | 202 // Verify that search provider names that are too long are not displayed. |
200 TemplateURL* backup_url = | 203 TemplateURL* backup_url = |
201 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); | 204 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); |
202 TemplateURL* backup_url_long = | 205 TemplateURL* backup_url_long = |
203 MakeTemplateURL(example_info_long, ASCIIToUTF16("a"), http_example_info); | 206 MakeTemplateURL(example_info_long, ASCIIToUTF16("a"), http_example_info); |
204 TemplateURL* current_url = | 207 TemplateURL* current_url = |
205 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); | 208 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); | 240 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); |
238 EXPECT_EQ(GetChangeSearchButtonText(), change->GetApplyButtonText()); | 241 EXPECT_EQ(GetChangeSearchButtonText(), change->GetApplyButtonText()); |
239 EXPECT_EQ(GetKeepSearchButtonText(example_info), | 242 EXPECT_EQ(GetKeepSearchButtonText(example_info), |
240 change->GetDiscardButtonText()); | 243 change->GetDiscardButtonText()); |
241 } | 244 } |
242 } | 245 } |
243 | 246 |
244 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupInvalid) { | 247 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, BackupInvalid) { |
245 // Backup is invalid, current search provider exists, fallback to the | 248 // Backup is invalid, current search provider exists, fallback to the |
246 // prepopulated default search, which exists among keywords. | 249 // prepopulated default search, which exists among keywords. |
| 250 int prepopulated_histogram_id = |
| 251 protector::GetSearchProviderHistogramID(prepopulated_url_.get()); |
247 TemplateURL* current_url = | 252 TemplateURL* current_url = |
248 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); | 253 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); |
| 254 int current_histogram_id = |
| 255 protector::GetSearchProviderHistogramID(current_url); |
249 | 256 |
250 AddAndSetDefault(current_url); | 257 AddAndSetDefault(current_url); |
251 | 258 |
252 // Prepopulated default search must exist. | 259 // Prepopulated default search must exist. |
253 ASSERT_TRUE(FindTemplateURL(prepopulated_url_->url()->url())); | 260 ASSERT_TRUE(FindTemplateURL(prepopulated_url_->url()->url())); |
254 | 261 |
255 scoped_ptr<BaseSettingChange> change( | 262 scoped_ptr<BaseSettingChange> change( |
256 CreateDefaultSearchProviderChange(current_url, NULL)); | 263 CreateDefaultSearchProviderChange(current_url, NULL)); |
257 ASSERT_TRUE(change.get()); | 264 ASSERT_TRUE(change.get()); |
258 ASSERT_TRUE(change->Init(browser()->profile())); | 265 ASSERT_TRUE(change->Init(browser()->profile())); |
259 | 266 |
260 // Verify that the prepopulated default search is active. | 267 // Verify that the prepopulated default search is active. |
261 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 268 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
262 turl_service_->GetDefaultSearchProvider()); | 269 turl_service_->GetDefaultSearchProvider()); |
263 | 270 |
264 // Verify histograms. | 271 // Verify histograms. |
265 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, | 272 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, |
266 SEARCH_ENGINE_OTHER, 1); | 273 current_histogram_id, 1); |
267 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 274 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
268 prepopulated_url_->search_engine_type(), 1); | 275 prepopulated_histogram_id, 1); |
269 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, | 276 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, |
270 prepopulated_url_->search_engine_type(), 1); | 277 prepopulated_histogram_id, 1); |
271 | 278 |
272 // Verify text messages. | 279 // Verify text messages. |
273 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), | 280 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), |
274 change->GetBubbleMessage()); | 281 change->GetBubbleMessage()); |
275 EXPECT_EQ(GetChangeSearchButtonText(example_com), | 282 EXPECT_EQ(GetChangeSearchButtonText(example_com), |
276 change->GetApplyButtonText()); | 283 change->GetApplyButtonText()); |
277 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); | 284 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); |
278 | 285 |
279 // Verify that search engine settings are opened by Discard. | 286 // Verify that search engine settings are opened by Discard. |
280 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); | 287 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); |
281 change->Discard(browser()); | 288 change->Discard(browser()); |
282 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 289 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
283 turl_service_->GetDefaultSearchProvider()); | 290 turl_service_->GetDefaultSearchProvider()); |
284 | 291 |
285 // Verify that Apply switches back to |current_url|. | 292 // Verify that Apply switches back to |current_url|. |
286 change->Apply(browser()); | 293 change->Apply(browser()); |
287 EXPECT_EQ(FindTemplateURL(http_example_com), | 294 EXPECT_EQ(FindTemplateURL(http_example_com), |
288 turl_service_->GetDefaultSearchProvider()); | 295 turl_service_->GetDefaultSearchProvider()); |
289 } | 296 } |
290 | 297 |
291 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, | 298 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, |
292 BackupInvalidFallbackRemoved) { | 299 BackupInvalidFallbackRemoved) { |
293 // Backup is invalid, current search provider exists, fallback to the | 300 // Backup is invalid, current search provider exists, fallback to the |
294 // prepopulated default search, which was removed from keywords (will be | 301 // prepopulated default search, which was removed from keywords (will be |
295 // added). | 302 // added). |
| 303 int prepopulated_histogram_id = |
| 304 protector::GetSearchProviderHistogramID(prepopulated_url_.get()); |
296 TemplateURL* current_url = | 305 TemplateURL* current_url = |
297 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); | 306 MakeTemplateURL(example_com, ASCIIToUTF16("b"), http_example_com); |
| 307 int current_histogram_id = |
| 308 protector::GetSearchProviderHistogramID(current_url); |
298 | 309 |
299 AddAndSetDefault(current_url); | 310 AddAndSetDefault(current_url); |
300 | 311 |
301 const TemplateURL* prepopulated_default = | 312 const TemplateURL* prepopulated_default = |
302 FindTemplateURL(prepopulated_url_->url()->url()); | 313 FindTemplateURL(prepopulated_url_->url()->url()); |
303 // Prepopulated default search must exist, remove it. | 314 // Prepopulated default search must exist, remove it. |
304 ASSERT_TRUE(prepopulated_default); | 315 ASSERT_TRUE(prepopulated_default); |
305 turl_service_->Remove(prepopulated_default); | 316 turl_service_->Remove(prepopulated_default); |
306 | 317 |
307 scoped_ptr<BaseSettingChange> change( | 318 scoped_ptr<BaseSettingChange> change( |
308 CreateDefaultSearchProviderChange(current_url, NULL)); | 319 CreateDefaultSearchProviderChange(current_url, NULL)); |
309 ASSERT_TRUE(change.get()); | 320 ASSERT_TRUE(change.get()); |
310 ASSERT_TRUE(change->Init(browser()->profile())); | 321 ASSERT_TRUE(change->Init(browser()->profile())); |
311 | 322 |
312 // Verify that the prepopulated default search is active. | 323 // Verify that the prepopulated default search is active. |
313 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 324 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
314 turl_service_->GetDefaultSearchProvider()); | 325 turl_service_->GetDefaultSearchProvider()); |
315 | 326 |
316 // Verify histograms. | 327 // Verify histograms. |
317 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, | 328 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, |
318 SEARCH_ENGINE_OTHER, 1); | 329 current_histogram_id, 1); |
319 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 330 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
320 prepopulated_url_->search_engine_type(), 1); | 331 prepopulated_histogram_id, 1); |
321 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, | 332 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, |
322 prepopulated_url_->search_engine_type(), 1); | 333 prepopulated_histogram_id, 1); |
323 ExpectHistogramCount(kProtectorHistogramSearchProviderMissing, | 334 ExpectHistogramCount(kProtectorHistogramSearchProviderMissing, |
324 prepopulated_url_->search_engine_type(), 1); | 335 prepopulated_histogram_id, 1); |
325 | 336 |
326 // Verify text messages. | 337 // Verify text messages. |
327 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), | 338 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), |
328 change->GetBubbleMessage()); | 339 change->GetBubbleMessage()); |
329 EXPECT_EQ(GetChangeSearchButtonText(example_com), | 340 EXPECT_EQ(GetChangeSearchButtonText(example_com), |
330 change->GetApplyButtonText()); | 341 change->GetApplyButtonText()); |
331 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); | 342 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); |
332 | 343 |
333 // Verify that search engine settings are opened by Discard. | 344 // Verify that search engine settings are opened by Discard. |
334 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); | 345 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); |
335 change->Discard(browser()); | 346 change->Discard(browser()); |
336 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 347 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
337 turl_service_->GetDefaultSearchProvider()); | 348 turl_service_->GetDefaultSearchProvider()); |
338 | 349 |
339 // Verify that Apply switches back to |current_url|. | 350 // Verify that Apply switches back to |current_url|. |
340 change->Apply(browser()); | 351 change->Apply(browser()); |
341 EXPECT_EQ(FindTemplateURL(http_example_com), | 352 EXPECT_EQ(FindTemplateURL(http_example_com), |
342 turl_service_->GetDefaultSearchProvider()); | 353 turl_service_->GetDefaultSearchProvider()); |
343 } | 354 } |
344 | 355 |
345 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, | 356 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, |
346 BackupValidCurrentRemoved) { | 357 BackupValidCurrentRemoved) { |
347 // Backup is valid, no current search provider. | 358 // Backup is valid, no current search provider. |
348 TemplateURL* backup_url = | 359 TemplateURL* backup_url = |
349 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); | 360 MakeTemplateURL(example_info, ASCIIToUTF16("a"), http_example_info); |
| 361 int backup_histogram_id = protector::GetSearchProviderHistogramID(backup_url); |
350 | 362 |
351 AddCopy(backup_url); | 363 AddCopy(backup_url); |
352 turl_service_->SetDefaultSearchProvider(NULL); | 364 turl_service_->SetDefaultSearchProvider(NULL); |
353 | 365 |
354 scoped_ptr<BaseSettingChange> change( | 366 scoped_ptr<BaseSettingChange> change( |
355 CreateDefaultSearchProviderChange(NULL, backup_url)); | 367 CreateDefaultSearchProviderChange(NULL, backup_url)); |
356 ASSERT_TRUE(change.get()); | 368 ASSERT_TRUE(change.get()); |
357 ASSERT_TRUE(change->Init(browser()->profile())); | 369 ASSERT_TRUE(change->Init(browser()->profile())); |
358 | 370 |
359 // Verify that backup is active. | 371 // Verify that backup is active. |
360 EXPECT_EQ(FindTemplateURL(http_example_info), | 372 EXPECT_EQ(FindTemplateURL(http_example_info), |
361 turl_service_->GetDefaultSearchProvider()); | 373 turl_service_->GetDefaultSearchProvider()); |
362 | 374 |
363 // Verify histograms. | 375 // Verify histograms. |
364 ExpectHistogramCount(kProtectorHistogramSearchProviderHijacked, | 376 ExpectHistogramCount(kProtectorHistogramSearchProviderHijacked, |
365 SEARCH_ENGINE_NONE, 1); | 377 protector::GetSearchProviderHistogramID(NULL), 1); |
366 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 378 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
367 SEARCH_ENGINE_OTHER, 1); | 379 backup_histogram_id, 1); |
368 | 380 |
369 // Verify text messages. | 381 // Verify text messages. |
370 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); | 382 EXPECT_EQ(GetBubbleMessage(), change->GetBubbleMessage()); |
371 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetApplyButtonText()); | 383 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetApplyButtonText()); |
372 EXPECT_EQ(GetKeepSearchButtonText(example_info), | 384 EXPECT_EQ(GetKeepSearchButtonText(example_info), |
373 change->GetDiscardButtonText()); | 385 change->GetDiscardButtonText()); |
374 | 386 |
375 // Discard does nothing - backup was already active. | 387 // Discard does nothing - backup was already active. |
376 change->Discard(browser()); | 388 change->Discard(browser()); |
377 EXPECT_EQ(FindTemplateURL(http_example_info), | 389 EXPECT_EQ(FindTemplateURL(http_example_info), |
378 turl_service_->GetDefaultSearchProvider()); | 390 turl_service_->GetDefaultSearchProvider()); |
379 | 391 |
380 // Verify that search engine settings are opened by Apply (no other changes). | 392 // Verify that search engine settings are opened by Apply (no other changes). |
381 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); | 393 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); |
382 change->Apply(browser()); | 394 change->Apply(browser()); |
383 EXPECT_EQ(FindTemplateURL(http_example_info), | 395 EXPECT_EQ(FindTemplateURL(http_example_info), |
384 turl_service_->GetDefaultSearchProvider()); | 396 turl_service_->GetDefaultSearchProvider()); |
385 } | 397 } |
386 | 398 |
387 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, | 399 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, |
388 BackupInvalidCurrentRemoved) { | 400 BackupInvalidCurrentRemoved) { |
389 // Backup is invalid, no current search provider, fallback to the prepopulated | 401 // Backup is invalid, no current search provider, fallback to the prepopulated |
390 // default search. | 402 // default search. |
| 403 int prepopulated_histogram_id = |
| 404 protector::GetSearchProviderHistogramID(prepopulated_url_.get()); |
391 turl_service_->SetDefaultSearchProvider(NULL); | 405 turl_service_->SetDefaultSearchProvider(NULL); |
392 | 406 |
393 scoped_ptr<BaseSettingChange> change( | 407 scoped_ptr<BaseSettingChange> change( |
394 CreateDefaultSearchProviderChange(NULL, NULL)); | 408 CreateDefaultSearchProviderChange(NULL, NULL)); |
395 ASSERT_TRUE(change.get()); | 409 ASSERT_TRUE(change.get()); |
396 ASSERT_TRUE(change->Init(browser()->profile())); | 410 ASSERT_TRUE(change->Init(browser()->profile())); |
397 | 411 |
398 // Verify that the prepopulated default search is active. | 412 // Verify that the prepopulated default search is active. |
399 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 413 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
400 turl_service_->GetDefaultSearchProvider()); | 414 turl_service_->GetDefaultSearchProvider()); |
401 | 415 |
402 // Verify histograms. | 416 // Verify histograms. |
403 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, | 417 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, |
404 SEARCH_ENGINE_NONE, 1); | 418 protector::GetSearchProviderHistogramID(NULL), 1); |
405 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 419 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
406 prepopulated_url_->search_engine_type(), 1); | 420 prepopulated_histogram_id, 1); |
407 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, | 421 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, |
408 prepopulated_url_->search_engine_type(), 1); | 422 prepopulated_histogram_id, 1); |
409 | 423 |
410 // Verify text messages. | 424 // Verify text messages. |
411 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), | 425 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), |
412 change->GetBubbleMessage()); | 426 change->GetBubbleMessage()); |
413 EXPECT_EQ(string16(), change->GetApplyButtonText()); | 427 EXPECT_EQ(string16(), change->GetApplyButtonText()); |
414 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); | 428 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); |
415 | 429 |
416 // Verify that search engine settings are opened by Discard. | 430 // Verify that search engine settings are opened by Discard. |
417 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); | 431 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); |
418 change->Discard(browser()); | 432 change->Discard(browser()); |
419 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), | 433 EXPECT_EQ(FindTemplateURL(prepopulated_url_->url()->url()), |
420 turl_service_->GetDefaultSearchProvider()); | 434 turl_service_->GetDefaultSearchProvider()); |
421 } | 435 } |
422 | 436 |
423 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, | 437 IN_PROC_BROWSER_TEST_F(DefaultSearchProviderChangeTest, |
424 BackupInvalidFallbackSameAsCurrent) { | 438 BackupInvalidFallbackSameAsCurrent) { |
425 // Backup is invalid, fallback to the prepopulated default search which is | 439 // Backup is invalid, fallback to the prepopulated default search which is |
426 // same as the current search provider. | 440 // same as the current search provider. |
| 441 int prepopulated_histogram_id = |
| 442 protector::GetSearchProviderHistogramID(prepopulated_url_.get()); |
427 const TemplateURL* current_url = turl_service_->GetDefaultSearchProvider(); | 443 const TemplateURL* current_url = turl_service_->GetDefaultSearchProvider(); |
428 | 444 |
429 // Verify that current search provider is same as the prepopulated default. | 445 // Verify that current search provider is same as the prepopulated default. |
430 ASSERT_TRUE(current_url); | 446 ASSERT_TRUE(current_url); |
431 ASSERT_EQ(current_url, FindTemplateURL(prepopulated_url_->url()->url())); | 447 ASSERT_EQ(current_url, FindTemplateURL(prepopulated_url_->url()->url())); |
432 | 448 |
433 scoped_ptr<BaseSettingChange> change( | 449 scoped_ptr<BaseSettingChange> change( |
434 CreateDefaultSearchProviderChange(current_url, NULL)); | 450 CreateDefaultSearchProviderChange(current_url, NULL)); |
435 ASSERT_TRUE(change.get()); | 451 ASSERT_TRUE(change.get()); |
436 ASSERT_TRUE(change->Init(browser()->profile())); | 452 ASSERT_TRUE(change->Init(browser()->profile())); |
437 | 453 |
438 // Verify that the default search has not changed. | 454 // Verify that the default search has not changed. |
439 EXPECT_EQ(current_url, turl_service_->GetDefaultSearchProvider()); | 455 EXPECT_EQ(current_url, turl_service_->GetDefaultSearchProvider()); |
440 | 456 |
441 // Verify histograms. | 457 // Verify histograms. |
442 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, | 458 ExpectHistogramCount(kProtectorHistogramSearchProviderCorrupt, |
443 prepopulated_url_->search_engine_type(), 1); | 459 prepopulated_histogram_id, 1); |
444 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, | 460 ExpectHistogramCount(kProtectorHistogramSearchProviderRestored, |
445 prepopulated_url_->search_engine_type(), 1); | 461 prepopulated_histogram_id, 1); |
446 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, | 462 ExpectHistogramCount(kProtectorHistogramSearchProviderFallback, |
447 prepopulated_url_->search_engine_type(), 1); | 463 prepopulated_histogram_id, 1); |
448 | 464 |
449 // Verify text messages. | 465 // Verify text messages. |
450 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), | 466 EXPECT_EQ(GetBubbleMessage(prepopulated_url_->short_name()), |
451 change->GetBubbleMessage()); | 467 change->GetBubbleMessage()); |
452 EXPECT_EQ(string16(), change->GetApplyButtonText()); | 468 EXPECT_EQ(string16(), change->GetApplyButtonText()); |
453 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); | 469 EXPECT_EQ(GetOpenSettingsButtonText(), change->GetDiscardButtonText()); |
454 | 470 |
455 // Verify that search engine settings are opened by Discard. | 471 // Verify that search engine settings are opened by Discard. |
456 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); | 472 ExpectSettingsOpened(chrome::kSearchEnginesSubPage); |
457 change->Discard(browser()); | 473 change->Discard(browser()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 EXPECT_EQ(FindTemplateURL(http_example_info), | 538 EXPECT_EQ(FindTemplateURL(http_example_info), |
523 turl_service_->GetDefaultSearchProvider()); | 539 turl_service_->GetDefaultSearchProvider()); |
524 | 540 |
525 // Discard does nothing - backup was already active. | 541 // Discard does nothing - backup was already active. |
526 change->Discard(browser()); | 542 change->Discard(browser()); |
527 EXPECT_EQ(FindTemplateURL(http_example_info), | 543 EXPECT_EQ(FindTemplateURL(http_example_info), |
528 turl_service_->GetDefaultSearchProvider()); | 544 turl_service_->GetDefaultSearchProvider()); |
529 } | 545 } |
530 | 546 |
531 } // namespace protector | 547 } // namespace protector |
OLD | NEW |