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

Side by Side Diff: chrome/browser/autocomplete/history_url_provider_unittest.cc

Issue 672773003: Include a URL what-you-typed option when the default search provider is not available and the input… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests, make suggested style and comment changes Created 6 years, 2 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
OLDNEW
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 "chrome/browser/autocomplete/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "components/history/core/browser/url_database.h" 24 #include "components/history/core/browser/url_database.h"
25 #include "components/metrics/proto/omnibox_event.pb.h" 25 #include "components/metrics/proto/omnibox_event.pb.h"
26 #include "components/metrics/proto/omnibox_input_type.pb.h" 26 #include "components/metrics/proto/omnibox_input_type.pb.h"
27 #include "components/omnibox/autocomplete_match.h" 27 #include "components/omnibox/autocomplete_match.h"
28 #include "components/omnibox/autocomplete_provider.h" 28 #include "components/omnibox/autocomplete_provider.h"
29 #include "components/omnibox/autocomplete_provider_listener.h" 29 #include "components/omnibox/autocomplete_provider_listener.h"
30 #include "components/omnibox/autocomplete_result.h" 30 #include "components/omnibox/autocomplete_result.h"
31 #include "components/search_engines/default_search_manager.h"
31 #include "components/search_engines/search_terms_data.h" 32 #include "components/search_engines/search_terms_data.h"
32 #include "components/search_engines/template_url.h" 33 #include "components/search_engines/template_url.h"
33 #include "components/search_engines/template_url_service.h" 34 #include "components/search_engines/template_url_service.h"
34 #include "components/url_fixer/url_fixer.h" 35 #include "components/url_fixer/url_fixer.h"
35 #include "content/public/test/test_browser_thread_bundle.h" 36 #include "content/public/test/test_browser_thread_bundle.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 using base::ASCIIToUTF16; 39 using base::ASCIIToUTF16;
39 using base::Time; 40 using base::Time;
40 using base::TimeDelta; 41 using base::TimeDelta;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 bool sort_matches_; 225 bool sort_matches_;
225 }; 226 };
226 227
227 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { 228 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest {
228 protected: 229 protected:
229 virtual void SetUp() { 230 virtual void SetUp() {
230 ASSERT_TRUE(SetUpImpl(true)); 231 ASSERT_TRUE(SetUpImpl(true));
231 } 232 }
232 }; 233 };
233 234
235 class HistoryURLProviderTestNoSearchProvider : public HistoryURLProviderTest {
236 protected:
237 virtual void SetUp() {
Peter Kasting 2014/10/24 22:02:13 Nit: virtual -> override (2 places) I realize the
238 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(true);
239 HistoryURLProviderTest::SetUp();
240 }
241
242 virtual void TearDown() {
243 HistoryURLProviderTest::TearDown();
244 DefaultSearchManager::SetFallbackSearchEnginesDisabledForTesting(false);
245 }
246 };
247
234 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 248 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
235 if (autocomplete_->done()) 249 if (autocomplete_->done())
236 base::MessageLoop::current()->Quit(); 250 base::MessageLoop::current()->Quit();
237 } 251 }
238 252
239 bool HistoryURLProviderTest::SetUpImpl(bool no_db) { 253 bool HistoryURLProviderTest::SetUpImpl(bool no_db) {
240 profile_.reset(new TestingProfile()); 254 profile_.reset(new TestingProfile());
241 if (!(profile_->CreateHistoryService(true, no_db))) 255 if (!(profile_->CreateHistoryService(true, no_db)))
242 return false; 256 return false;
243 if (!no_db) { 257 if (!no_db) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // "what you typed" result, plus this one. 487 // "what you typed" result, plus this one.
474 const base::string16 typing(ASCIIToUTF16("http://redirects/")); 488 const base::string16 typing(ASCIIToUTF16("http://redirects/"));
475 const UrlAndLegalDefault expected_results[] = { 489 const UrlAndLegalDefault expected_results[] = {
476 { base::UTF16ToUTF8(typing), true }, 490 { base::UTF16ToUTF8(typing), true },
477 { test_cases[0].url, false } 491 { test_cases[0].url, false }
478 }; 492 };
479 RunTest(typing, std::string(), true, expected_results, 493 RunTest(typing, std::string(), true, expected_results,
480 arraysize(expected_results)); 494 arraysize(expected_results));
481 } 495 }
482 496
497 TEST_F(HistoryURLProviderTestNoSearchProvider, WhatYouTypedNoSearchProvider) {
498 // When no search provider is available, make sure we provide WYT matches
499 // for text that could be a URL
Peter Kasting 2014/10/24 22:02:13 Nit: Trailing period.
500
501 const UrlAndLegalDefault results_1[] = {
502 { "http://wytmatch/", true }
503 };
504 RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, results_1,
505 arraysize(results_1));
506
507 RunTest(ASCIIToUTF16("wytmatch foo bar"), std::string(), false, NULL, 0);
508 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), std::string(), false, NULL, 0);
509
510 const UrlAndLegalDefault results_2[] = {
511 { "http://wytmatch+foo+bar.com/", true }
512 };
513 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), std::string(), false,
514 results_2, arraysize(results_2));
515 }
516
483 TEST_F(HistoryURLProviderTest, WhatYouTyped) { 517 TEST_F(HistoryURLProviderTest, WhatYouTyped) {
484 // Make sure we suggest a What You Typed match at the right times. 518 // Make sure we suggest a What You Typed match at the right times.
485 RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, NULL, 0); 519 RunTest(ASCIIToUTF16("wytmatch"), std::string(), false, NULL, 0);
486 RunTest(ASCIIToUTF16("wytmatch foo bar"), std::string(), false, NULL, 0); 520 RunTest(ASCIIToUTF16("wytmatch foo bar"), std::string(), false, NULL, 0);
487 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), std::string(), false, NULL, 0); 521 RunTest(ASCIIToUTF16("wytmatch+foo+bar"), std::string(), false, NULL, 0);
488 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), std::string(), false, NULL, 0); 522 RunTest(ASCIIToUTF16("wytmatch+foo+bar.com"), std::string(), false, NULL, 0);
489 523
490 const UrlAndLegalDefault results_1[] = { 524 const UrlAndLegalDefault results_1[] = {
491 { "http://www.wytmatch.com/", true } 525 { "http://www.wytmatch.com/", true }
492 }; 526 };
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 // Test the experiment (scoring enabled). 1023 // Test the experiment (scoring enabled).
990 autocomplete_->scoring_params_.experimental_scoring_enabled = true; 1024 autocomplete_->scoring_params_.experimental_scoring_enabled = true;
991 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input), 1025 ASSERT_NO_FATAL_FAILURE(RunTest(ASCIIToUTF16(test_cases[i].input),
992 std::string(), false, output, max_matches)); 1026 std::string(), false, output, max_matches));
993 for (int j = 0; j < max_matches; ++j) { 1027 for (int j = 0; j < max_matches; ++j) {
994 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance, 1028 EXPECT_EQ(test_cases[i].matches[j].experiment_relevance,
995 matches_[j].relevance); 1029 matches_[j].relevance);
996 } 1030 }
997 } 1031 }
998 } 1032 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698