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

Unified Diff: ui/app_list/search/mixer_unittest.cc

Issue 906133003: app_list search results relevance scores are clamped to [0, 1] range. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@applist-mixer-knownresult-test
Patch Set: Rebase. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/search/mixer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/search/mixer_unittest.cc
diff --git a/ui/app_list/search/mixer_unittest.cc b/ui/app_list/search/mixer_unittest.cc
index 565b81bdf1e965b843b3a4211e609958b64e249b..78c233eec1ef9f367dff3062959064e9fd94dcee 100644
--- a/ui/app_list/search/mixer_unittest.cc
+++ b/ui/app_list/search/mixer_unittest.cc
@@ -57,7 +57,7 @@ int TestSearchResult::instantiation_count = 0;
class TestSearchProvider : public SearchProvider {
public:
explicit TestSearchProvider(const std::string& prefix)
- : prefix_(prefix), count_(0) {}
+ : prefix_(prefix), count_(0), bad_relevance_range_(false) {}
~TestSearchProvider() override {}
// SearchProvider overrides:
@@ -66,7 +66,11 @@ class TestSearchProvider : public SearchProvider {
for (size_t i = 0; i < count_; ++i) {
const std::string id =
base::StringPrintf("%s%d", prefix_.c_str(), static_cast<int>(i));
- const double relevance = 1.0 - i / 10.0;
+ double relevance = 1.0 - i / 10.0;
+ // If bad_relevance_range_, change the relevances to give results outside
+ // of the canonical [0.0, 1.0] range.
+ if (bad_relevance_range_)
+ relevance = 10.0 - i * 10;
TestSearchResult* result = new TestSearchResult(id, relevance);
if (voice_result_indices.find(i) != voice_result_indices.end())
result->set_voice_result(true);
@@ -78,10 +82,12 @@ class TestSearchProvider : public SearchProvider {
void set_prefix(const std::string& prefix) { prefix_ = prefix; }
void set_count(size_t count) { count_ = count; }
void set_as_voice_result(size_t index) { voice_result_indices.insert(index); }
+ void set_bad_relevance_range() { bad_relevance_range_ = true; }
private:
std::string prefix_;
size_t count_;
+ bool bad_relevance_range_;
// Indices of results that will have the |voice_result| flag set.
std::set<size_t> voice_result_indices;
@@ -264,6 +270,25 @@ TEST_F(MixerTest, VoiceQuery) {
EXPECT_EQ("omnibox1,omnibox2,omnibox0", GetResults());
}
+TEST_F(MixerTest, BadRelevanceRange) {
+ // This gives relevance scores: (10.0, 0.0). Even though providers are
+ // supposed to give scores within the range [0.0, 1.0], we cannot rely on
+ // providers to do this, since they retrieve results from disparate and
+ // unreliable sources (like the Google+ API).
+ people_provider()->set_bad_relevance_range();
+ people_provider()->set_count(2);
+
+ // Give a massive boost to the second result.
+ AddKnownResult("people1", PERFECT_PRIMARY);
+
+ RunQuery();
+
+ // If the results are correctly clamped to the range [0.0, 1.0], the boost to
+ // "people1" will push it over the first result. If not, the massive base
+ // score of "people0" will erroneously keep it on top.
+ EXPECT_EQ("people1,people0", GetResults());
+}
+
TEST_F(MixerTest, Publish) {
scoped_ptr<SearchResult> result1(new TestSearchResult("app1", 0));
scoped_ptr<SearchResult> result2(new TestSearchResult("app2", 0));
« no previous file with comments | « ui/app_list/search/mixer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698