OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_base.h" | 9 #include "base/metrics/histogram_base.h" |
10 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
(...skipping 2292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2303 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, | 2303 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, |
2304 content::NotificationService::AllSources()); | 2304 content::NotificationService::AllSources()); |
2305 | 2305 |
2306 SetOmniboxText("http://www.example.com"); | 2306 SetOmniboxText("http://www.example.com"); |
2307 | 2307 |
2308 autocomplete_observer.Wait(); | 2308 autocomplete_observer.Wait(); |
2309 ASSERT_TRUE(omnibox()->model()->autocomplete_controller()-> | 2309 ASSERT_TRUE(omnibox()->model()->autocomplete_controller()-> |
2310 search_provider()->IsNonInstantSearchDone()); | 2310 search_provider()->IsNonInstantSearchDone()); |
2311 } | 2311 } |
2312 | 2312 |
| 2313 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OverlaySendsSearchWhatYouTyped) { |
| 2314 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2315 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2316 |
| 2317 // This input could be interpreted either as an URL or a query based on the |
| 2318 // relative ranking of search-what-you-typed or url-what-you-typed. |
| 2319 content::WindowedNotificationObserver autocomplete_observer( |
| 2320 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, |
| 2321 content::NotificationService::AllSources()); |
| 2322 SetOmniboxText("define:foo"); |
| 2323 autocomplete_observer.Wait(); |
| 2324 |
| 2325 // In this case, we should treat [define:foo] as a query, so |
| 2326 // search-what-you-typed should be the top suggestion. |
| 2327 EXPECT_TRUE(ExecuteScript( |
| 2328 "var sorted = chrome.embeddedSearch.searchBox.nativeSuggestions.sort(" |
| 2329 "function (a,b) {" |
| 2330 "return b.rankingData.relevance - a.rankingData.relevance;" |
| 2331 "});")); |
| 2332 std::string type; |
| 2333 EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), |
| 2334 "sorted[0].type", &type)); |
| 2335 ASSERT_EQ("search-what-you-typed", type); |
| 2336 } |
| 2337 |
| 2338 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 2339 OverlayDoesNotEchoSearchProviderNAVSUGGEST) { |
| 2340 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2341 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2342 |
| 2343 // Show the overlay so suggestions are allowed. |
| 2344 SetOmniboxTextAndWaitForOverlayToShow("www."); |
| 2345 content::WebContents* overlay = instant()->GetOverlayContents(); |
| 2346 |
| 2347 // Set a URL suggestion and wait for SearchProvider to echo it. |
| 2348 content::WindowedNotificationObserver autocomplete_observer( |
| 2349 chrome::NOTIFICATION_INSTANT_SENT_AUTOCOMPLETE_RESULTS, |
| 2350 content::NotificationService::AllSources()); |
| 2351 instant()->SetSuggestions( |
| 2352 overlay, |
| 2353 std::vector<InstantSuggestion>( |
| 2354 1, |
| 2355 InstantSuggestion(ASCIIToUTF16("http://www.example.com/"), |
| 2356 INSTANT_COMPLETE_NOW, |
| 2357 INSTANT_SUGGESTION_URL, |
| 2358 ASCIIToUTF16("www."), |
| 2359 kNoMatchIndex))); |
| 2360 autocomplete_observer.Wait(); |
| 2361 |
| 2362 // Check that SearchProvider set a NAVSUGGEST match. |
| 2363 bool have_navsuggest_match = false; |
| 2364 SearchProvider* search_provider = |
| 2365 omnibox()->model()->autocomplete_controller()->search_provider(); |
| 2366 for (ACMatches::const_iterator match = search_provider->matches().begin(); |
| 2367 match != search_provider->matches().end(); ++match) { |
| 2368 if (match->type == AutocompleteMatchType::NAVSUGGEST) { |
| 2369 have_navsuggest_match = true; |
| 2370 break; |
| 2371 } |
| 2372 } |
| 2373 ASSERT_TRUE(have_navsuggest_match); |
| 2374 |
| 2375 // Check that InstantController did not send the NAVSUGGEST match. |
| 2376 bool sent_navsuggest_match = true; |
| 2377 EXPECT_TRUE(GetBoolFromJS(overlay, |
| 2378 "chrome.embeddedSearch.searchBox.nativeSuggestions.some(" |
| 2379 "function (s) {" |
| 2380 "return s.type == 'navsuggest';" |
| 2381 "})", &sent_navsuggest_match)); |
| 2382 EXPECT_FALSE(sent_navsuggest_match); |
| 2383 } |
| 2384 |
2313 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { | 2385 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, AcceptingURLSearchDoesNotNavigate) { |
2314 // Get a committed Instant tab, which will be in the Instant process and thus | 2386 // Get a committed Instant tab, which will be in the Instant process and thus |
2315 // support chrome::GetSearchTerms(). | 2387 // support chrome::GetSearchTerms(). |
2316 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2388 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2317 FocusOmniboxAndWaitForInstantOverlaySupport(); | 2389 FocusOmniboxAndWaitForInstantOverlaySupport(); |
2318 | 2390 |
2319 // Create an observer to wait for the instant tab to support Instant. | 2391 // Create an observer to wait for the instant tab to support Instant. |
2320 content::WindowedNotificationObserver observer( | 2392 content::WindowedNotificationObserver observer( |
2321 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, | 2393 chrome::NOTIFICATION_INSTANT_TAB_SUPPORT_DETERMINED, |
2322 content::NotificationService::AllSources()); | 2394 content::NotificationService::AllSources()); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2513 | 2585 |
2514 // Test that if the LogDropdownShown() call records a histogram value. | 2586 // Test that if the LogDropdownShown() call records a histogram value. |
2515 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LogDropdownShown) { | 2587 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, LogDropdownShown) { |
2516 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 2588 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
2517 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | 2589 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
2518 int64 histogramValue = GetHistogramCount("Instant.TimeToFirstShowFromWeb"); | 2590 int64 histogramValue = GetHistogramCount("Instant.TimeToFirstShowFromWeb"); |
2519 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("a")); | 2591 ASSERT_TRUE(SetOmniboxTextAndWaitForOverlayToShow("a")); |
2520 EXPECT_EQ(histogramValue + 1, | 2592 EXPECT_EQ(histogramValue + 1, |
2521 GetHistogramCount("Instant.TimeToFirstShowFromWeb")); | 2593 GetHistogramCount("Instant.TimeToFirstShowFromWeb")); |
2522 } | 2594 } |
OLD | NEW |