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

Side by Side Diff: components/omnibox/browser/shortcuts_provider_unittest.cc

Issue 1877833002: Optimize shortcuts provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes after review, round 1 Created 4 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
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 "components/omnibox/browser/shortcuts_provider.h" 5 #include "components/omnibox/browser/shortcuts_provider.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 13 matching lines...) Expand all
24 #include "components/history/core/browser/history_service.h" 24 #include "components/history/core/browser/history_service.h"
25 #include "components/history/core/browser/url_database.h" 25 #include "components/history/core/browser/url_database.h"
26 #include "components/history/core/test/history_service_test_util.h" 26 #include "components/history/core/test/history_service_test_util.h"
27 #include "components/metrics/proto/omnibox_event.pb.h" 27 #include "components/metrics/proto/omnibox_event.pb.h"
28 #include "components/omnibox/browser/autocomplete_input.h" 28 #include "components/omnibox/browser/autocomplete_input.h"
29 #include "components/omnibox/browser/autocomplete_match.h" 29 #include "components/omnibox/browser/autocomplete_match.h"
30 #include "components/omnibox/browser/autocomplete_provider.h" 30 #include "components/omnibox/browser/autocomplete_provider.h"
31 #include "components/omnibox/browser/autocomplete_result.h" 31 #include "components/omnibox/browser/autocomplete_result.h"
32 #include "components/omnibox/browser/in_memory_url_index.h" 32 #include "components/omnibox/browser/in_memory_url_index.h"
33 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" 33 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
34 #include "components/omnibox/browser/shortcut_match.h"
34 #include "components/omnibox/browser/shortcuts_backend.h" 35 #include "components/omnibox/browser/shortcuts_backend.h"
35 #include "components/omnibox/browser/shortcuts_provider_test_util.h" 36 #include "components/omnibox/browser/shortcuts_provider_test_util.h"
36 #include "components/omnibox/browser/test_scheme_classifier.h" 37 #include "components/omnibox/browser/test_scheme_classifier.h"
37 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
38 39
39 using base::ASCIIToUTF16; 40 using base::ASCIIToUTF16;
40 using ExpectedURLs = std::vector<ExpectedURLAndAllowedToBeDefault>; 41 using ExpectedURLs = std::vector<ExpectedURLAndAllowedToBeDefault>;
41 42
42 namespace { 43 namespace {
43 44
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 private: 215 private:
215 base::Thread db_thread_; 216 base::Thread db_thread_;
216 base::SequencedWorkerPoolOwner pool_owner_; 217 base::SequencedWorkerPoolOwner pool_owner_;
217 base::ScopedTempDir history_dir_; 218 base::ScopedTempDir history_dir_;
218 scoped_ptr<history::HistoryService> history_service_; 219 scoped_ptr<history::HistoryService> history_service_;
219 scoped_refptr<ShortcutsBackend> shortcuts_backend_; 220 scoped_refptr<ShortcutsBackend> shortcuts_backend_;
220 221
221 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient); 222 DISALLOW_COPY_AND_ASSIGN(FakeAutocompleteProviderClient);
222 }; 223 };
223 224
225 ShortcutMatch CreateShortcutMatch(int relevance,
226 const GURL& stripped_destination_url,
227 const std::string& contents) {
228 // Create fake ShortcutsDatabase::Shortcut object and intialize its contents
229 // and type field only.
230 ShortcutsDatabase::Shortcut::MatchCore fake_match_core(
231 base::string16(), GURL(), base::UTF8ToUTF16(contents), std::string(),
232 base::string16(), std::string(), 0, 0, base::string16());
233 // Object used only for ShortcutMatch initialization.
Peter Kasting 2016/04/12 23:29:50 Nit: Wrong indenting
Alexander Yashkin 2016/04/13 09:29:36 Done.
234 ShortcutsDatabase::Shortcut fake_shortcut("", base::string16(),
Peter Kasting 2016/04/12 23:29:50 Nit: "" -> std::string
Alexander Yashkin 2016/04/13 09:29:36 Done.
235 fake_match_core, base::Time(), 0);
236 return ShortcutMatch(relevance, stripped_destination_url, &fake_shortcut);
Peter Kasting 2016/04/12 23:29:51 This leaves a pointer-to-garbage in the ShortcutMa
Alexander Yashkin 2016/04/13 09:29:36 Done.
237 }
238
224 } // namespace 239 } // namespace
225 240
226 // ClassifyTest --------------------------------------------------------------- 241 // ClassifyTest ---------------------------------------------------------------
227 242
228 // Helper class to make running tests of ClassifyAllMatchesInString() more 243 // Helper class to make running tests of ClassifyAllMatchesInString() more
229 // convenient. 244 // convenient.
230 class ClassifyTest { 245 class ClassifyTest {
231 public: 246 public:
232 ClassifyTest(const base::string16& text, ACMatchClassifications matches); 247 ClassifyTest(const base::string16& text, ACMatchClassifications matches);
233 ~ClassifyTest(); 248 ~ClassifyTest();
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 758 }
744 759
745 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) { 760 TEST_F(ShortcutsProviderTest, DoesNotProvideOnFocus) {
746 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos, 761 AutocompleteInput input(ASCIIToUTF16("about:o"), base::string16::npos,
747 std::string(), GURL(), 762 std::string(), GURL(),
748 metrics::OmniboxEventProto::INVALID_SPEC, false, 763 metrics::OmniboxEventProto::INVALID_SPEC, false,
749 false, true, true, true, TestSchemeClassifier()); 764 false, true, true, true, TestSchemeClassifier());
750 provider_->Start(input, false); 765 provider_->Start(input, false);
751 EXPECT_TRUE(provider_->matches().empty()); 766 EXPECT_TRUE(provider_->matches().empty());
752 } 767 }
768
769 TEST_F(ShortcutsProviderTest, DedupShortcutMatchesByDestination) {
770 ShortcutMatches matches;
771 matches.push_back(
772 CreateShortcutMatch(42, GURL("http://www.abc.com"), "123"));
773 matches.push_back(
774 CreateShortcutMatch(43, GURL("http://www.abcd.com"), "123"));
775 matches.push_back(
776 CreateShortcutMatch(42, GURL("http://www.abcde.com"), "123"));
777 matches.push_back(
778 CreateShortcutMatch(41, GURL("http://www.abcd.com"), "DEADBEEF"));
779 matches.push_back(
780 CreateShortcutMatch(42, GURL("http://www.abcde.com"), "234"));
781 matches.push_back(
782 CreateShortcutMatch(42, GURL("http://www.abc.com"), "123"));
783
784 ShortcutsProvider::DedupShortcutMatchesByDestination(
785 metrics::OmniboxEventProto::INVALID_SPEC, &matches);
786 // Expect deduplicated matches to be sorted by destination.
787 // The remaining match out of each set of duplicates should be the one with
788 // the highest relevance.
789 EXPECT_EQ(matches.size(), 3U);
Peter Kasting 2016/04/12 23:29:50 Nit: (expected, actual) (all lines)
Alexander Yashkin 2016/04/13 09:29:36 Done.
790 EXPECT_EQ(matches[0].stripped_destination_url, GURL("http://www.abc.com"));
791 EXPECT_EQ(matches[0].relevance, 42);
792 EXPECT_EQ(matches[0].contents, base::ASCIIToUTF16("123"));
793 EXPECT_EQ(matches[1].stripped_destination_url, GURL("http://www.abcd.com"));
794 EXPECT_EQ(matches[1].relevance, 43);
795 EXPECT_EQ(matches[1].contents, base::ASCIIToUTF16("123"));
796 EXPECT_EQ(matches[2].stripped_destination_url, GURL("http://www.abcde.com"));
797 EXPECT_EQ(matches[2].relevance, 42);
798 EXPECT_EQ(matches[2].contents, base::ASCIIToUTF16("123"));
799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698