| OLD | NEW |
| 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" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 std::string text("user input"); | 324 std::string text("user input"); |
| 325 const AutocompleteInput input( | 325 const AutocompleteInput input( |
| 326 base::UTF8ToUTF16(text), text.length(), std::string(), GURL(), | 326 base::UTF8ToUTF16(text), text.length(), std::string(), GURL(), |
| 327 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 327 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 328 true, false, true, true, false, TestSchemeClassifier()); | 328 true, false, true, true, false, TestSchemeClassifier()); |
| 329 provider_->Start(input, false); | 329 provider_->Start(input, false); |
| 330 | 330 |
| 331 EXPECT_TRUE(provider_->matches().empty()); | 331 EXPECT_TRUE(provider_->matches().empty()); |
| 332 } | 332 } |
| 333 | 333 |
| 334 TEST_F(PhysicalWebProviderTest, TestEmptyInputAfterTyping) { |
| 335 FakePhysicalWebDataSource* data_source = |
| 336 client_->GetFakePhysicalWebDataSource(); |
| 337 EXPECT_TRUE(data_source); |
| 338 |
| 339 data_source->SetMetadataList(CreateMetadata(1)); |
| 340 |
| 341 // Construct an AutocompleteInput to simulate a blank input field, as if the |
| 342 // user typed a query and then deleted it. The provider should generate |
| 343 // suggestions for the zero-suggest case. No default match should be created. |
| 344 const AutocompleteInput input( |
| 345 base::string16(), 0, std::string(), GURL(), |
| 346 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 347 true, false, true, true, false, TestSchemeClassifier()); |
| 348 provider_->Start(input, false); |
| 349 |
| 350 size_t metadata_match_count = 0; |
| 351 size_t default_match_count = 0; |
| 352 for (const auto& match : provider_->matches()) { |
| 353 if (match.type == AutocompleteMatchType::PHYSICAL_WEB) { |
| 354 ++metadata_match_count; |
| 355 } else { |
| 356 EXPECT_TRUE(match.allowed_to_be_default_match); |
| 357 ++default_match_count; |
| 358 } |
| 359 } |
| 360 EXPECT_EQ(1U, provider_->matches().size()); |
| 361 EXPECT_EQ(1U, metadata_match_count); |
| 362 EXPECT_EQ(0U, default_match_count); |
| 363 } |
| 364 |
| 334 TEST_F(PhysicalWebProviderTest, TestManyMetadataItemsCreatesOverflowItem) { | 365 TEST_F(PhysicalWebProviderTest, TestManyMetadataItemsCreatesOverflowItem) { |
| 335 // Create enough metadata to guarantee an overflow item will be created. | 366 // Create enough metadata to guarantee an overflow item will be created. |
| 336 const size_t metadata_count = AutocompleteProvider::kMaxMatches + 1; | 367 const size_t metadata_count = AutocompleteProvider::kMaxMatches + 1; |
| 337 | 368 |
| 338 // Run the test with no text in the omnibox input to simulate NTP. | 369 // Run the test with no text in the omnibox input to simulate NTP. |
| 339 OverflowItemTestCase( | 370 OverflowItemTestCase( |
| 340 CreateInputForNTP(), CreateMetadata(metadata_count), "Example title 0", | 371 CreateInputForNTP(), CreateMetadata(metadata_count), "Example title 0", |
| 341 PhysicalWebProvider::kPhysicalWebMaxMatches, false, true); | 372 PhysicalWebProvider::kPhysicalWebMaxMatches, false, true); |
| 342 | 373 |
| 343 // Run the test again with a URL in the omnibox input. An additional match | 374 // Run the test again with a URL in the omnibox input. An additional match |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 421 |
| 391 FakePhysicalWebDataSource* data_source = | 422 FakePhysicalWebDataSource* data_source = |
| 392 client_->GetFakePhysicalWebDataSource(); | 423 client_->GetFakePhysicalWebDataSource(); |
| 393 EXPECT_TRUE(data_source); | 424 EXPECT_TRUE(data_source); |
| 394 | 425 |
| 395 data_source->SetMetadataList(CreateMetadata(1)); | 426 data_source->SetMetadataList(CreateMetadata(1)); |
| 396 provider_->Start(CreateInputForNTP(), false); | 427 provider_->Start(CreateInputForNTP(), false); |
| 397 | 428 |
| 398 EXPECT_TRUE(provider_->matches().empty()); | 429 EXPECT_TRUE(provider_->matches().empty()); |
| 399 } | 430 } |
| OLD | NEW |