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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
10 #include "chrome/browser/instant/instant_controller.h" | 10 #include "chrome/browser/instant/instant_controller.h" |
11 #include "chrome/browser/instant/instant_loader.h" | 11 #include "chrome/browser/instant/instant_loader.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
15 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
17 #include "chrome/browser/task_manager/task_manager.h" | 17 #include "chrome/browser/task_manager/task_manager.h" |
18 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 18 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
19 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/omnibox/location_bar.h" | 22 #include "chrome/browser/ui/omnibox/location_bar.h" |
22 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 23 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
23 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 24 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 314 |
314 WebContents* preview_tab = preview()->web_contents(); | 315 WebContents* preview_tab = preview()->web_contents(); |
315 EXPECT_TRUE(preview_tab); | 316 EXPECT_TRUE(preview_tab); |
316 | 317 |
317 ASSERT_TRUE(PressEnter()); | 318 ASSERT_TRUE(PressEnter()); |
318 | 319 |
319 // Check that the preview has been committed. | 320 // Check that the preview has been committed. |
320 EXPECT_FALSE(preview()); | 321 EXPECT_FALSE(preview()); |
321 EXPECT_FALSE(instant()->is_displayable()); | 322 EXPECT_FALSE(instant()->is_displayable()); |
322 EXPECT_FALSE(instant()->IsCurrent()); | 323 EXPECT_FALSE(instant()->IsCurrent()); |
323 EXPECT_EQ(preview_tab, browser()->GetActiveWebContents()); | 324 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
324 | 325 |
325 // We should have two entries. One corresponding to the page the user was | 326 // We should have two entries. One corresponding to the page the user was |
326 // first on, and one for the search page. | 327 // first on, and one for the search page. |
327 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); | 328 EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); |
328 | 329 |
329 // Check that the value is reflected and onsubmit is called. | 330 // Check that the value is reflected and onsubmit is called. |
330 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", | 331 EXPECT_EQ("true 1 0 1 true d false defghi true 3 3", |
331 GetSearchStateAsString(preview_tab, true)); | 332 GetSearchStateAsString(preview_tab, true)); |
332 | 333 |
333 // Make sure the searchbox values were reset. | 334 // Make sure the searchbox values were reset. |
(...skipping 17 matching lines...) Expand all Loading... |
351 WebContents* preview_tab = preview()->web_contents(); | 352 WebContents* preview_tab = preview()->web_contents(); |
352 EXPECT_TRUE(preview_tab); | 353 EXPECT_TRUE(preview_tab); |
353 | 354 |
354 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 355 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
355 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 356 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
356 | 357 |
357 // Check that the preview has been committed. | 358 // Check that the preview has been committed. |
358 EXPECT_FALSE(preview()); | 359 EXPECT_FALSE(preview()); |
359 EXPECT_FALSE(instant()->is_displayable()); | 360 EXPECT_FALSE(instant()->is_displayable()); |
360 EXPECT_FALSE(instant()->IsCurrent()); | 361 EXPECT_FALSE(instant()->IsCurrent()); |
361 EXPECT_EQ(preview_tab, browser()->GetActiveWebContents()); | 362 EXPECT_EQ(preview_tab, chrome::GetActiveWebContents(browser())); |
362 | 363 |
363 // Check that the value is reflected and oncancel is called. | 364 // Check that the value is reflected and oncancel is called. |
364 EXPECT_EQ("true 0 1 1 true d false def false 3 3", | 365 EXPECT_EQ("true 0 1 1 true d false def false 3 3", |
365 GetSearchStateAsString(preview_tab, true)); | 366 GetSearchStateAsString(preview_tab, true)); |
366 | 367 |
367 // Make sure the searchbox values were reset. | 368 // Make sure the searchbox values were reset. |
368 EXPECT_EQ("true 0 1 1 true d false false 0 0", | 369 EXPECT_EQ("true 0 1 1 true d false false 0 0", |
369 GetSearchStateAsString(preview_tab, false)); | 370 GetSearchStateAsString(preview_tab, false)); |
370 } | 371 } |
371 | 372 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 std::string value; | 715 std::string value; |
715 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), | 716 ASSERT_TRUE(GetStringFromJavascript(preview()->web_contents(), |
716 "window.chrome.searchBox.value", &value)); | 717 "window.chrome.searchBox.value", &value)); |
717 EXPECT_EQ("def", value); | 718 EXPECT_EQ("def", value); |
718 | 719 |
719 // Commit the preview. | 720 // Commit the preview. |
720 ASSERT_TRUE(PressEnter()); | 721 ASSERT_TRUE(PressEnter()); |
721 EXPECT_FALSE(preview()); | 722 EXPECT_FALSE(preview()); |
722 | 723 |
723 // The searchBox actually gets cleared on commit. | 724 // The searchBox actually gets cleared on commit. |
724 ASSERT_TRUE(GetStringFromJavascript(browser()->GetActiveWebContents(), | 725 ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), |
725 "window.chrome.searchBox.value", &value)); | 726 "window.chrome.searchBox.value", &value)); |
726 EXPECT_EQ("", value); | 727 EXPECT_EQ("", value); |
727 | 728 |
728 // Navigate to a new URL. The searchBox values should stay cleared. | 729 // Navigate to a new URL. The searchBox values should stay cleared. |
729 ui_test_utils::NavigateToURL( | 730 ui_test_utils::NavigateToURL( |
730 browser(), test_server()->GetURL("files/empty.html")); | 731 browser(), test_server()->GetURL("files/empty.html")); |
731 | 732 |
732 ASSERT_TRUE(GetStringFromJavascript(browser()->GetActiveWebContents(), | 733 ASSERT_TRUE(GetStringFromJavascript(chrome::GetActiveWebContents(browser()), |
733 "window.chrome.searchBox.value", &value)); | 734 "window.chrome.searchBox.value", &value)); |
734 EXPECT_EQ("", value); | 735 EXPECT_EQ("", value); |
735 } | 736 } |
736 | 737 |
737 // Tests that instant search is preloaded whenever the omnibox gets focus. | 738 // Tests that instant search is preloaded whenever the omnibox gets focus. |
738 // PreloadsInstant fails on linux_chromeos trybots all the time, possibly | 739 // PreloadsInstant fails on linux_chromeos trybots all the time, possibly |
739 // because of http://crbug.com/80118. | 740 // because of http://crbug.com/80118. |
740 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | 741 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
741 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { | 742 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_PreloadsInstant) { |
742 #else | 743 #else |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 } | 786 } |
786 | 787 |
787 // Tests that the instant search page's visibility is set correctly. | 788 // Tests that the instant search page's visibility is set correctly. |
788 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { | 789 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(PageVisibilityTest)) { |
789 ASSERT_TRUE(test_server()->Start()); | 790 ASSERT_TRUE(test_server()->Start()); |
790 EnableInstant(); | 791 EnableInstant(); |
791 SetupInstantProvider("instant.html"); | 792 SetupInstantProvider("instant.html"); |
792 | 793 |
793 // Initially navigate to the empty page which should be visible. | 794 // Initially navigate to the empty page which should be visible. |
794 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); | 795 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("")); |
795 WebContents* initial_contents = browser()->GetActiveWebContents(); | 796 WebContents* initial_contents = chrome::GetActiveWebContents(browser()); |
796 | 797 |
797 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 798 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
798 | 799 |
799 // Type a search term and wait for the preview to appear. | 800 // Type a search term and wait for the preview to appear. |
800 browser()->window()->GetLocationBar()->FocusLocation(false); | 801 browser()->window()->GetLocationBar()->FocusLocation(false); |
801 DetermineInstantSupport(); | 802 DetermineInstantSupport(); |
802 SearchAndWaitForPreviewToShow(); | 803 SearchAndWaitForPreviewToShow(); |
803 WebContents* preview_contents = preview()->web_contents(); | 804 WebContents* preview_contents = preview()->web_contents(); |
804 | 805 |
805 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 806 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
806 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 807 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
807 | 808 |
808 // Deleting the user text should hide the preview. | 809 // Deleting the user text should hide the preview. |
809 omnibox()->SetUserText(string16()); | 810 omnibox()->SetUserText(string16()); |
810 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); | 811 ASSERT_TRUE(CheckVisibilityIs(preview_contents, false)); |
811 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); | 812 ASSERT_TRUE(CheckVisibilityIs(initial_contents, true)); |
812 | 813 |
813 // Set the user text back and we should see the preview again. | 814 // Set the user text back and we should see the preview again. |
814 omnibox()->SetUserText(ASCIIToUTF16("def")); | 815 omnibox()->SetUserText(ASCIIToUTF16("def")); |
815 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 816 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
816 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); | 817 ASSERT_TRUE(CheckVisibilityIs(initial_contents, false)); |
817 | 818 |
818 // Commit the preview. | 819 // Commit the preview. |
819 ASSERT_TRUE(PressEnter()); | 820 ASSERT_TRUE(PressEnter()); |
820 EXPECT_EQ(preview_contents, browser()->GetActiveWebContents()); | 821 EXPECT_EQ(preview_contents, chrome::GetActiveWebContents(browser())); |
821 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); | 822 ASSERT_TRUE(CheckVisibilityIs(preview_contents, true)); |
822 } | 823 } |
823 | 824 |
824 // Tests that the task manager identifies instant's preview tab correctly. | 825 // Tests that the task manager identifies instant's preview tab correctly. |
825 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { | 826 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(TaskManagerPrefix)) { |
826 // The browser starts with one new tab, so the task manager should have two | 827 // The browser starts with one new tab, so the task manager should have two |
827 // rows initially, one for the browser process and one for tab's renderer. | 828 // rows initially, one for the browser process and one for tab's renderer. |
828 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); | 829 TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); |
829 task_manager->StartUpdating(); | 830 task_manager->StartUpdating(); |
830 TaskManagerBrowserTestUtil::WaitForResourceChange(2); | 831 TaskManagerBrowserTestUtil::WaitForResourceChange(2); |
831 | 832 |
832 ASSERT_TRUE(test_server()->Start()); | 833 ASSERT_TRUE(test_server()->Start()); |
833 EnableInstant(); | 834 EnableInstant(); |
834 SetupInstantProvider("instant.html"); | 835 SetupInstantProvider("instant.html"); |
835 DetermineInstantSupport(); | 836 DetermineInstantSupport(); |
836 SearchAndWaitForPreviewToShow(); | 837 SearchAndWaitForPreviewToShow(); |
837 | 838 |
838 // Now there should be three rows, the third being the instant preview. | 839 // Now there should be three rows, the third being the instant preview. |
839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 840 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
840 string16 prefix = l10n_util::GetStringFUTF16( | 841 string16 prefix = l10n_util::GetStringFUTF16( |
841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 842 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
842 string16 title = task_manager->GetResourceTitle(2); | 843 string16 title = task_manager->GetResourceTitle(2); |
843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 844 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
844 } | 845 } |
OLD | NEW |