| OLD | NEW |
| 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/autocomplete_provider.h" | 5 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 TestProvider* provider2 = new TestProvider( | 248 TestProvider* provider2 = new TestProvider( |
| 249 kResultsPerProvider * 2, | 249 kResultsPerProvider * 2, |
| 250 same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b"), | 250 same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b"), |
| 251 &profile_, | 251 &profile_, |
| 252 string16()); | 252 string16()); |
| 253 provider2->AddRef(); | 253 provider2->AddRef(); |
| 254 providers.push_back(provider2); | 254 providers.push_back(provider2); |
| 255 | 255 |
| 256 // Reset the controller to contain our new providers. | 256 // Reset the controller to contain our new providers. |
| 257 controller_.reset( | 257 controller_.reset(new AutocompleteController(&profile_, NULL, 0)); |
| 258 new AutocompleteController(&profile_, NULL, | 258 // We're going to swap the providers vector, but the old vector should be |
| 259 AutocompleteProvider::TYPE_SEARCH)); | 259 // empty so no elements need to be freed at this point. |
| 260 EXPECT_TRUE(controller_->providers_.empty()); |
| 260 controller_->providers_.swap(providers); | 261 controller_->providers_.swap(providers); |
| 261 provider1->set_listener(controller_.get()); | 262 provider1->set_listener(controller_.get()); |
| 262 provider2->set_listener(controller_.get()); | 263 provider2->set_listener(controller_.get()); |
| 263 | 264 |
| 264 // The providers don't complete synchronously, so listen for "result updated" | 265 // The providers don't complete synchronously, so listen for "result updated" |
| 265 // notifications. | 266 // notifications. |
| 266 registrar_.Add(this, | 267 registrar_.Add(this, |
| 267 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 268 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 268 content::Source<AutocompleteController>(controller_.get())); | 269 content::Source<AutocompleteController>(controller_.get())); |
| 269 | 270 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.5.57j58j5l2j0l3j59" }, | 553 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.5.57j58j5l2j0l3j59" }, |
| 553 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.6.57j58j5l2j0l3j59" }, | 554 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.6.57j58j5l2j0l3j59" }, |
| 554 { AutocompleteMatch::SEARCH_HISTORY, "chrome.7.57j58j5l2j0l3j59" }, | 555 { AutocompleteMatch::SEARCH_HISTORY, "chrome.7.57j58j5l2j0l3j59" }, |
| 555 }; | 556 }; |
| 556 SCOPED_TRACE("Multiple matches"); | 557 SCOPED_TRACE("Multiple matches"); |
| 557 RunAssistedQueryStatsTest(test_data, ARRAYSIZE_UNSAFE(test_data)); | 558 RunAssistedQueryStatsTest(test_data, ARRAYSIZE_UNSAFE(test_data)); |
| 558 } | 559 } |
| 559 } | 560 } |
| 560 | 561 |
| 561 TEST_F(AutocompleteProviderTest, GetDestinationURL) { | 562 TEST_F(AutocompleteProviderTest, GetDestinationURL) { |
| 562 ResetControllerWithTestProviders(false, NULL, NULL); | 563 ResetControllerWithKeywordAndSearchProviders(); |
| 563 | 564 |
| 564 // For the destination URL to have aqs parameters for query formulation time | 565 // For the destination URL to have aqs parameters for query formulation time |
| 565 // and the field trial triggered bit, many conditions need to be satisfied. | 566 // and the field trial triggered bit, many conditions need to be satisfied. |
| 566 AutocompleteMatch match(NULL, 1100, false, | 567 AutocompleteMatch match(NULL, 1100, false, |
| 567 AutocompleteMatch::SEARCH_SUGGEST); | 568 AutocompleteMatch::SEARCH_SUGGEST); |
| 568 GURL url = controller_-> | 569 GURL url = controller_-> |
| 569 GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 570 GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 570 EXPECT_TRUE(url.path().empty()); | 571 EXPECT_TRUE(url.path().empty()); |
| 571 | 572 |
| 572 // The protocol needs to be https. | 573 // The protocol needs to be https. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 590 EXPECT_TRUE(url.path().empty()); | 591 EXPECT_TRUE(url.path().empty()); |
| 591 | 592 |
| 592 // assisted_query_stats needs to have been previously set. | 593 // assisted_query_stats needs to have been previously set. |
| 593 match.search_terms_args->assisted_query_stats = "chrome.0.57j58j5l2j0l3j59"; | 594 match.search_terms_args->assisted_query_stats = "chrome.0.57j58j5l2j0l3j59"; |
| 594 url = controller_->GetDestinationURL(match, | 595 url = controller_->GetDestinationURL(match, |
| 595 base::TimeDelta::FromMilliseconds(2456)); | 596 base::TimeDelta::FromMilliseconds(2456)); |
| 596 EXPECT_EQ("//aqs=chrome.0.57j58j5l2j0l3j59.2456j0&", url.path()); | 597 EXPECT_EQ("//aqs=chrome.0.57j58j5l2j0l3j59.2456j0&", url.path()); |
| 597 | 598 |
| 598 // Test field trial triggered bit set. | 599 // Test field trial triggered bit set. |
| 599 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 600 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
| 601 EXPECT_TRUE( |
| 602 controller_->search_provider_->field_trial_triggered_in_session()); |
| 600 url = controller_->GetDestinationURL(match, | 603 url = controller_->GetDestinationURL(match, |
| 601 base::TimeDelta::FromMilliseconds(2456)); | 604 base::TimeDelta::FromMilliseconds(2456)); |
| 602 EXPECT_EQ("//aqs=chrome.0.57j58j5l2j0l3j59.2456j1&", url.path()); | 605 EXPECT_EQ("//aqs=chrome.0.57j58j5l2j0l3j59.2456j1&", url.path()); |
| 603 } | 606 } |
| OLD | NEW |