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

Side by Side Diff: chrome/browser/ui/search/search_tab_helper_unittest.cc

Issue 2152743002: Remove search::ShouldPrerenderInstantUrlOnOmniboxFocus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_prefetch_srp
Patch Set: rebase Created 4 years, 4 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 | « chrome/browser/ui/search/search_tab_helper.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 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 "chrome/browser/ui/search/search_tab_helper.h" 5 #include "chrome/browser/ui/search/search_tab_helper.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <tuple> 11 #include <tuple>
12 12
13 #include "base/command_line.h"
14 #include "base/metrics/field_trial.h"
15 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
16 #include "base/time/time.h" 14 #include "base/time/time.h"
17 #include "chrome/browser/prerender/prerender_manager.h"
18 #include "chrome/browser/prerender/prerender_manager_factory.h"
19 #include "chrome/browser/search/instant_unittest_base.h"
20 #include "chrome/browser/search/search.h"
21 #include "chrome/browser/search_engines/template_url_service_factory.h"
22 #include "chrome/browser/signin/fake_signin_manager_builder.h" 15 #include "chrome/browser/signin/fake_signin_manager_builder.h"
23 #include "chrome/browser/signin/signin_manager_factory.h" 16 #include "chrome/browser/signin/signin_manager_factory.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 17 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/browser/sync/profile_sync_test_util.h" 18 #include "chrome/browser/sync/profile_sync_test_util.h"
26 #include "chrome/browser/ui/search/search_ipc_router.h" 19 #include "chrome/browser/ui/search/search_ipc_router.h"
27 #include "chrome/browser/ui/tabs/tab_strip_model.h" 20 #include "chrome/browser/ui/tabs/tab_strip_model.h"
28 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/render_messages.h" 21 #include "chrome/common/render_messages.h"
31 #include "chrome/common/search/ntp_logging_events.h"
32 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
33 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
34 #include "chrome/test/base/browser_with_test_window_test.h" 24 #include "chrome/test/base/browser_with_test_window_test.h"
35 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
36 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
37 #include "components/browser_sync/browser/profile_sync_service.h" 27 #include "components/browser_sync/browser/profile_sync_service.h"
38 #include "components/omnibox/common/omnibox_focus_state.h" 28 #include "components/omnibox/common/omnibox_focus_state.h"
39 #include "components/search_engines/template_url_service.h"
40 #include "components/strings/grit/components_strings.h" 29 #include "components/strings/grit/components_strings.h"
41 #include "content/public/browser/navigation_controller.h" 30 #include "content/public/browser/navigation_controller.h"
42 #include "content/public/browser/navigation_entry.h" 31 #include "content/public/browser/navigation_entry.h"
43 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
44 #include "content/public/test/mock_render_process_host.h" 33 #include "content/public/test/mock_render_process_host.h"
45 #include "ipc/ipc_message.h" 34 #include "ipc/ipc_message.h"
46 #include "ipc/ipc_test_sink.h" 35 #include "ipc/ipc_test_sink.h"
47 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
48 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 }; 337 };
349 338
350 TEST_F(SearchTabHelperTest, TitleIsSetForNTP) { 339 TEST_F(SearchTabHelperTest, TitleIsSetForNTP) {
351 TabTitleObserver title_observer(web_contents()); 340 TabTitleObserver title_observer(web_contents());
352 NavigateAndCommit(GURL(chrome::kChromeUINewTabURL)); 341 NavigateAndCommit(GURL(chrome::kChromeUINewTabURL));
353 const base::string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); 342 const base::string16 title = l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE);
354 EXPECT_EQ(title, title_observer.title_on_start()); 343 EXPECT_EQ(title, title_observer.title_on_start());
355 EXPECT_EQ(title, title_observer.title_on_commit()); 344 EXPECT_EQ(title, title_observer.title_on_commit());
356 EXPECT_EQ(title, web_contents()->GetTitle()); 345 EXPECT_EQ(title, web_contents()->GetTitle());
357 } 346 }
358
359 class SearchTabHelperPrerenderTest : public InstantUnitTestBase {
360 public:
361 ~SearchTabHelperPrerenderTest() override {}
362
363 protected:
364 void SetUp() override {
365 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
366 "EmbeddedSearch",
367 "Group1 espv:89 prefetch_results:1 "
368 "prerender_instant_url_on_omnibox_focus:1"));
369 InstantUnitTestBase::SetUp();
370
371 AddTab(browser(), GURL(chrome::kChromeUINewTabURL));
372 SearchTabHelper::FromWebContents(web_contents())->set_omnibox_has_focus_fn(
373 omnibox_has_focus);
374 SearchTabHelperPrerenderTest::omnibox_has_focus_ = true;
375 }
376
377 content::WebContents* web_contents() {
378 return browser()->tab_strip_model()->GetActiveWebContents();
379 }
380
381 bool IsInstantURLMarkedForPrerendering() {
382 GURL instant_url(search::GetSearchResultPrefetchBaseURL(profile()));
383 prerender::PrerenderManager* prerender_manager =
384 prerender::PrerenderManagerFactory::GetForProfile(profile());
385 return prerender_manager->HasPrerenderedUrl(instant_url, web_contents());
386 }
387
388 static bool omnibox_has_focus(OmniboxView* omnibox) {
389 return omnibox_has_focus_;
390 }
391
392 static bool omnibox_has_focus_;
393 };
394
395 bool SearchTabHelperPrerenderTest::omnibox_has_focus_ = true;
396
397 TEST_F(SearchTabHelperPrerenderTest, OnOmniboxFocusPrerenderInstantURL) {
398 SearchTabHelper* search_tab_helper =
399 SearchTabHelper::FromWebContents(web_contents());
400 search_tab_helper->OmniboxFocusChanged(OMNIBOX_FOCUS_VISIBLE,
401 OMNIBOX_FOCUS_CHANGE_EXPLICIT);
402 ASSERT_TRUE(IsInstantURLMarkedForPrerendering());
403 search_tab_helper->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE,
404 OMNIBOX_FOCUS_CHANGE_EXPLICIT);
405 ASSERT_FALSE(IsInstantURLMarkedForPrerendering());
406 }
407
408 TEST_F(SearchTabHelperPrerenderTest, OnTabActivatedPrerenderInstantURL) {
409 SearchTabHelper* search_tab_helper =
410 SearchTabHelper::FromWebContents(web_contents());
411 search_tab_helper->OnTabActivated();
412 ASSERT_TRUE(IsInstantURLMarkedForPrerendering());
413 }
414
415 TEST_F(SearchTabHelperPrerenderTest,
416 OnTabActivatedNoPrerenderIfOmniboxBlurred) {
417 SearchTabHelperPrerenderTest::omnibox_has_focus_ = false;
418 SearchTabHelper* search_tab_helper =
419 SearchTabHelper::FromWebContents(web_contents());
420 search_tab_helper->OnTabActivated();
421 ASSERT_FALSE(IsInstantURLMarkedForPrerendering());
422 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698