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

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

Issue 2591053002: Show PhysicalWebProvider suggestions with omnibox input (Closed)
Patch Set: enable experiment in unit tests Created 3 years, 11 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
« no previous file with comments | « components/omnibox/browser/physical_web_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/physical_web_provider.h" 5 #include "components/omnibox/browser/physical_web_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/metrics/field_trial.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "components/metrics/proto/omnibox_event.pb.h" 15 #include "components/metrics/proto/omnibox_event.pb.h"
15 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" 16 #include "components/omnibox/browser/mock_autocomplete_provider_client.h"
17 #include "components/omnibox/browser/omnibox_field_trial.h"
16 #include "components/omnibox/browser/test_scheme_classifier.h" 18 #include "components/omnibox/browser/test_scheme_classifier.h"
17 #include "components/physical_web/data_source/fake_physical_web_data_source.h" 19 #include "components/physical_web/data_source/fake_physical_web_data_source.h"
18 #include "components/physical_web/data_source/physical_web_data_source.h" 20 #include "components/physical_web/data_source/physical_web_data_source.h"
19 #include "components/physical_web/data_source/physical_web_listener.h" 21 #include "components/physical_web/data_source/physical_web_listener.h"
22 #include "components/variations/entropy_provider.h"
23 #include "components/variations/variations_associated_data.h"
20 #include "grit/components_strings.h" 24 #include "grit/components_strings.h"
21 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/text_elider.h" 28 #include "ui/gfx/text_elider.h"
25 #include "url/gurl.h" 29 #include "url/gurl.h"
26 30
27 using physical_web::FakePhysicalWebDataSource; 31 using physical_web::FakePhysicalWebDataSource;
28 using physical_web::PhysicalWebDataSource; 32 using physical_web::PhysicalWebDataSource;
29 using physical_web::PhysicalWebListener; 33 using physical_web::PhysicalWebListener;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 private: 69 private:
66 std::unique_ptr<FakePhysicalWebDataSource> physical_web_data_source_; 70 std::unique_ptr<FakePhysicalWebDataSource> physical_web_data_source_;
67 TestSchemeClassifier scheme_classifier_; 71 TestSchemeClassifier scheme_classifier_;
68 bool is_off_the_record_; 72 bool is_off_the_record_;
69 }; 73 };
70 74
71 } // namespace 75 } // namespace
72 76
73 class PhysicalWebProviderTest : public testing::Test { 77 class PhysicalWebProviderTest : public testing::Test {
74 protected: 78 protected:
75 PhysicalWebProviderTest() : provider_(NULL) {} 79 PhysicalWebProviderTest() : provider_(NULL) {
80 ResetFieldTrialList();
81 }
82
76 ~PhysicalWebProviderTest() override {} 83 ~PhysicalWebProviderTest() override {}
77 84
78 void SetUp() override { 85 void SetUp() override {
86 base::FieldTrial* trial = CreatePhysicalWebFieldTrial();
87 trial->group();
79 client_.reset(new FakeAutocompleteProviderClient()); 88 client_.reset(new FakeAutocompleteProviderClient());
80 provider_ = PhysicalWebProvider::Create(client_.get(), nullptr); 89 provider_ = PhysicalWebProvider::Create(client_.get(), nullptr);
81 } 90 }
82 91
83 void TearDown() override { 92 void TearDown() override {
84 provider_ = NULL; 93 provider_ = NULL;
85 } 94 }
86 95
96 void ResetFieldTrialList() {
97 // Destroy the existing FieldTrialList before creating a new one to avoid a
98 // DCHECK.
99 field_trial_list_.reset();
100 field_trial_list_.reset(new base::FieldTrialList(
101 base::MakeUnique<metrics::SHA1EntropyProvider>("foo")));
102 variations::testing::ClearAllVariationParams();
103 }
104
105 static base::FieldTrial* CreatePhysicalWebFieldTrial() {
106 std::map<std::string, std::string> params;
107 params[OmniboxFieldTrial::kPhysicalWebZeroSuggestRule] = "true";
108 params[OmniboxFieldTrial::kPhysicalWebAfterTypingRule] = "true";
109 variations::AssociateVariationParams(
110 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A", params);
111 return base::FieldTrialList::CreateFieldTrial(
112 OmniboxFieldTrial::kBundledExperimentFieldTrialName, "A");
113 }
114
87 // Create a dummy metadata list with |metadata_count| items. Each item is 115 // Create a dummy metadata list with |metadata_count| items. Each item is
88 // populated with a unique scanned URL and page metadata. 116 // populated with a unique scanned URL and page metadata.
89 static std::unique_ptr<base::ListValue> CreateMetadata( 117 static std::unique_ptr<base::ListValue> CreateMetadata(
90 size_t metadata_count) { 118 size_t metadata_count) {
91 auto metadata_list = base::MakeUnique<base::ListValue>(); 119 auto metadata_list = base::MakeUnique<base::ListValue>();
92 for (size_t i = 0; i < metadata_count; ++i) { 120 for (size_t i = 0; i < metadata_count; ++i) {
93 std::string item_id = base::SizeTToString(i); 121 std::string item_id = base::SizeTToString(i);
94 std::string url = "https://example.com/" + item_id; 122 std::string url = "https://example.com/" + item_id;
95 auto metadata_item = base::MakeUnique<base::DictionaryValue>(); 123 auto metadata_item = base::MakeUnique<base::DictionaryValue>();
96 metadata_item->SetString(physical_web::kScannedUrlKey, url); 124 metadata_item->SetString(physical_web::kScannedUrlKey, url);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } else if (match.allowed_to_be_default_match) { 242 } else if (match.allowed_to_be_default_match) {
215 ++default_match_count; 243 ++default_match_count;
216 } 244 }
217 } 245 }
218 EXPECT_EQ(should_expect_overflow_item ? 1U : 0U, overflow_match_count); 246 EXPECT_EQ(should_expect_overflow_item ? 1U : 0U, overflow_match_count);
219 EXPECT_EQ(should_expect_default_match ? 1U : 0U, default_match_count); 247 EXPECT_EQ(should_expect_default_match ? 1U : 0U, default_match_count);
220 } 248 }
221 249
222 std::unique_ptr<FakeAutocompleteProviderClient> client_; 250 std::unique_ptr<FakeAutocompleteProviderClient> client_;
223 scoped_refptr<PhysicalWebProvider> provider_; 251 scoped_refptr<PhysicalWebProvider> provider_;
252 std::unique_ptr<base::FieldTrialList> field_trial_list_;
224 253
225 private: 254 private:
226 DISALLOW_COPY_AND_ASSIGN(PhysicalWebProviderTest); 255 DISALLOW_COPY_AND_ASSIGN(PhysicalWebProviderTest);
227 }; 256 };
228 257
229 TEST_F(PhysicalWebProviderTest, TestEmptyMetadataListCreatesNoMatches) { 258 TEST_F(PhysicalWebProviderTest, TestEmptyMetadataListCreatesNoMatches) {
230 FakePhysicalWebDataSource* data_source = 259 FakePhysicalWebDataSource* data_source =
231 client_->GetFakePhysicalWebDataSource(); 260 client_->GetFakePhysicalWebDataSource();
232 EXPECT_TRUE(data_source); 261 EXPECT_TRUE(data_source);
233 262
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 400
372 FakePhysicalWebDataSource* data_source = 401 FakePhysicalWebDataSource* data_source =
373 client_->GetFakePhysicalWebDataSource(); 402 client_->GetFakePhysicalWebDataSource();
374 EXPECT_TRUE(data_source); 403 EXPECT_TRUE(data_source);
375 404
376 data_source->SetMetadata(CreateMetadata(1)); 405 data_source->SetMetadata(CreateMetadata(1));
377 provider_->Start(CreateInputForNTP(), false); 406 provider_->Start(CreateInputForNTP(), false);
378 407
379 EXPECT_TRUE(provider_->matches().empty()); 408 EXPECT_TRUE(provider_->matches().empty());
380 } 409 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/physical_web_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698