OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 6 #include "base/stringprintf.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit.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/instant/instant_loader_manager.h" | 12 #include "chrome/browser/instant/instant_loader_manager.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/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/browser/ui/omnibox/location_bar.h" | 20 #include "chrome/browser/ui/omnibox/location_bar.h" |
21 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 21 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 23 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/in_process_browser_test.h" | 25 #include "chrome/test/in_process_browser_test.h" |
25 #include "chrome/test/ui_test_utils.h" | 26 #include "chrome/test/ui_test_utils.h" |
26 #include "content/browser/renderer_host/render_view_host.h" | 27 #include "content/browser/renderer_host/render_view_host.h" |
27 #include "content/browser/renderer_host/render_widget_host_view.h" | 28 #include "content/browser/renderer_host/render_widget_host_view.h" |
28 #include "content/browser/tab_contents/tab_contents.h" | 29 #include "content/browser/tab_contents/tab_contents.h" |
29 | 30 |
30 #define EXPECT_STR_EQ(ascii, utf16) \ | 31 #define EXPECT_STR_EQ(ascii, utf16) \ |
31 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) | 32 EXPECT_EQ(ASCIIToWide(ascii), UTF16ToWide(utf16)) |
32 | 33 |
(...skipping 11 matching lines...) Expand all Loading... |
44 } | 45 } |
45 | 46 |
46 void SetupInstantProvider(const std::string& page) { | 47 void SetupInstantProvider(const std::string& page) { |
47 TemplateURLService* model = | 48 TemplateURLService* model = |
48 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 49 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
49 ASSERT_TRUE(model); | 50 ASSERT_TRUE(model); |
50 | 51 |
51 if (!model->loaded()) { | 52 if (!model->loaded()) { |
52 model->Load(); | 53 model->Load(); |
53 ui_test_utils::WaitForNotification( | 54 ui_test_utils::WaitForNotification( |
54 NotificationType::TEMPLATE_URL_SERVICE_LOADED); | 55 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED); |
55 } | 56 } |
56 | 57 |
57 ASSERT_TRUE(model->loaded()); | 58 ASSERT_TRUE(model->loaded()); |
58 | 59 |
59 // TemplateURLService takes ownership of this. | 60 // TemplateURLService takes ownership of this. |
60 TemplateURL* template_url = new TemplateURL(); | 61 TemplateURL* template_url = new TemplateURL(); |
61 | 62 |
62 std::string url = StringPrintf( | 63 std::string url = StringPrintf( |
63 "http://%s:%d/files/instant/%s?q={searchTerms}", | 64 "http://%s:%d/files/instant/%s?q={searchTerms}", |
64 test_server()->host_port_pair().host().c_str(), | 65 test_server()->host_port_pair().host().c_str(), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // When the page loads, the initial searchBox values are set and only a | 117 // When the page loads, the initial searchBox values are set and only a |
117 // resize will have been sent. | 118 // resize will have been sent. |
118 ASSERT_EQ("true 0 0 0 1 d false d false 1 1", | 119 ASSERT_EQ("true 0 0 0 1 d false d false 1 1", |
119 GetSearchStateAsString(preview_, false)); | 120 GetSearchStateAsString(preview_, false)); |
120 } | 121 } |
121 | 122 |
122 void SetLocationBarText(const std::string& text) { | 123 void SetLocationBarText(const std::string& text) { |
123 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 124 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
124 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text)); | 125 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(text)); |
125 ui_test_utils::WaitForNotification( | 126 ui_test_utils::WaitForNotification( |
126 NotificationType::INSTANT_CONTROLLER_SHOWN); | 127 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN); |
127 } | 128 } |
128 | 129 |
129 const string16& GetSuggestion() const { | 130 const string16& GetSuggestion() const { |
130 return browser()->instant()->loader_manager_-> | 131 return browser()->instant()->loader_manager_-> |
131 current_loader()->complete_suggested_text_; | 132 current_loader()->complete_suggested_text_; |
132 } | 133 } |
133 | 134 |
134 void SendKey(ui::KeyboardCode key) { | 135 void SendKey(ui::KeyboardCode key) { |
135 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 136 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
136 browser(), key, false, false, false, false)); | 137 browser(), key, false, false, false, false)); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 // results. | 593 // results. |
593 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); | 594 EXPECT_TRUE(browser()->instant()->IsShowingInstant()); |
594 // But because we're waiting to determine if the page really supports instant | 595 // But because we're waiting to determine if the page really supports instant |
595 // we shouldn't be showing the preview. | 596 // we shouldn't be showing the preview. |
596 EXPECT_FALSE(browser()->instant()->is_displayable()); | 597 EXPECT_FALSE(browser()->instant()->is_displayable()); |
597 // But instant should still be active. | 598 // But instant should still be active. |
598 EXPECT_TRUE(browser()->instant()->is_active()); | 599 EXPECT_TRUE(browser()->instant()->is_active()); |
599 | 600 |
600 // When the response comes back that the page doesn't support instant the tab | 601 // When the response comes back that the page doesn't support instant the tab |
601 // should be closed. | 602 // should be closed. |
602 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 603 ui_test_utils::WaitForNotification(content::NOTIFICATION_TAB_CLOSED); |
603 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); | 604 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); |
604 EXPECT_FALSE(browser()->instant()->is_displayable()); | 605 EXPECT_FALSE(browser()->instant()->is_displayable()); |
605 EXPECT_TRUE(browser()->instant()->is_active()); | 606 EXPECT_TRUE(browser()->instant()->is_active()); |
606 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 607 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
607 } | 608 } |
608 | 609 |
609 // Verifies transitioning from loading a non-search string to a search string | 610 // Verifies transitioning from loading a non-search string to a search string |
610 // with the provider not supporting instant works (meaning we don't display | 611 // with the provider not supporting instant works (meaning we don't display |
611 // anything). | 612 // anything). |
612 #if defined(OS_MACOSX) || defined(OS_LINUX) | 613 #if defined(OS_MACOSX) || defined(OS_LINUX) |
(...skipping 29 matching lines...) Expand all Loading... |
642 ASSERT_TRUE(browser()->instant()->is_displayable()); | 643 ASSERT_TRUE(browser()->instant()->is_displayable()); |
643 ASSERT_TRUE(browser()->instant()->is_active()); | 644 ASSERT_TRUE(browser()->instant()->is_active()); |
644 // Because we typed in a search string we should think we're showing instant | 645 // Because we typed in a search string we should think we're showing instant |
645 // results. | 646 // results. |
646 EXPECT_TRUE(browser()->instant()->MightSupportInstant()); | 647 EXPECT_TRUE(browser()->instant()->MightSupportInstant()); |
647 // Instant should not be current (it's still loading). | 648 // Instant should not be current (it's still loading). |
648 EXPECT_FALSE(browser()->instant()->IsCurrent()); | 649 EXPECT_FALSE(browser()->instant()->IsCurrent()); |
649 | 650 |
650 // When the response comes back that the page doesn't support instant the tab | 651 // When the response comes back that the page doesn't support instant the tab |
651 // should be closed. | 652 // should be closed. |
652 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 653 ui_test_utils::WaitForNotification(content::NOTIFICATION_TAB_CLOSED); |
653 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); | 654 EXPECT_FALSE(browser()->instant()->IsShowingInstant()); |
654 EXPECT_FALSE(browser()->instant()->is_displayable()); | 655 EXPECT_FALSE(browser()->instant()->is_displayable()); |
655 // But because the omnibox is still open, instant should be active. | 656 // But because the omnibox is still open, instant should be active. |
656 ASSERT_TRUE(browser()->instant()->is_active()); | 657 ASSERT_TRUE(browser()->instant()->is_active()); |
657 } | 658 } |
658 | 659 |
659 // Verifies the page was told a non-zero height. | 660 // Verifies the page was told a non-zero height. |
660 // DISABLED http://crbug.com/80118 | 661 // DISABLED http://crbug.com/80118 |
661 #if defined(OS_LINUX) | 662 #if defined(OS_LINUX) |
662 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_ValidHeight) { | 663 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_ValidHeight) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 EnableInstant(); | 699 EnableInstant(); |
699 GURL url(test_server()->GetURL("files/instant/403.html")); | 700 GURL url(test_server()->GetURL("files/instant/403.html")); |
700 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 701 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
701 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 702 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
702 // The preview shouldn't be showing, but it should be loading. | 703 // The preview shouldn't be showing, but it should be loading. |
703 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); | 704 ASSERT_TRUE(browser()->instant()->GetPreviewContents()); |
704 ASSERT_TRUE(browser()->instant()->is_active()); | 705 ASSERT_TRUE(browser()->instant()->is_active()); |
705 ASSERT_FALSE(browser()->instant()->is_displayable()); | 706 ASSERT_FALSE(browser()->instant()->is_displayable()); |
706 | 707 |
707 // When instant sees the 403, it should close the tab. | 708 // When instant sees the 403, it should close the tab. |
708 ui_test_utils::WaitForNotification(NotificationType::TAB_CLOSED); | 709 ui_test_utils::WaitForNotification(content::NOTIFICATION_TAB_CLOSED); |
709 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 710 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
710 ASSERT_TRUE(browser()->instant()->is_active()); | 711 ASSERT_TRUE(browser()->instant()->is_active()); |
711 ASSERT_FALSE(browser()->instant()->is_displayable()); | 712 ASSERT_FALSE(browser()->instant()->is_displayable()); |
712 | 713 |
713 // Try loading another url on the server. Instant shouldn't create a new tab | 714 // Try loading another url on the server. Instant shouldn't create a new tab |
714 // as the server returned 403. | 715 // as the server returned 403. |
715 GURL url2(test_server()->GetURL("files/instant/empty.html")); | 716 GURL url2(test_server()->GetURL("files/instant/empty.html")); |
716 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); | 717 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url2.spec())); |
717 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); | 718 ASSERT_FALSE(browser()->instant()->GetPreviewContents()); |
718 ASSERT_TRUE(browser()->instant()->is_active()); | 719 ASSERT_TRUE(browser()->instant()->is_active()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 IN_PROC_BROWSER_TEST_F(InstantTest, DontCrashOnBlockedJS) { | 863 IN_PROC_BROWSER_TEST_F(InstantTest, DontCrashOnBlockedJS) { |
863 #endif // OS_LINUX | 864 #endif // OS_LINUX |
864 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 865 browser()->profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
865 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 866 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
866 ASSERT_TRUE(test_server()->Start()); | 867 ASSERT_TRUE(test_server()->Start()); |
867 EnableInstant(); | 868 EnableInstant(); |
868 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 869 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
869 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); | 870 ASSERT_NO_FATAL_FAILURE(SetupLocationBar()); |
870 // Wait for notification that the instant API has been determined. | 871 // Wait for notification that the instant API has been determined. |
871 ui_test_utils::WaitForNotification( | 872 ui_test_utils::WaitForNotification( |
872 NotificationType::INSTANT_SUPPORT_DETERMINED); | 873 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED); |
873 // As long as we get the notification we're good (the renderer didn't crash). | 874 // As long as we get the notification we're good (the renderer didn't crash). |
874 } | 875 } |
875 | 876 |
876 // DISABLED http://crbug.com/80118 | 877 // DISABLED http://crbug.com/80118 |
877 #if defined(OS_LINUX) | 878 #if defined(OS_LINUX) |
878 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_DownloadOnEnter) { | 879 IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_DownloadOnEnter) { |
879 #else | 880 #else |
880 IN_PROC_BROWSER_TEST_F(InstantTest, DownloadOnEnter) { | 881 IN_PROC_BROWSER_TEST_F(InstantTest, DownloadOnEnter) { |
881 #endif // OS_LINUX | 882 #endif // OS_LINUX |
882 ASSERT_TRUE(test_server()->Start()); | 883 ASSERT_TRUE(test_server()->Start()); |
883 EnableInstant(); | 884 EnableInstant(); |
884 // Make sure the browser window is the front most window. | 885 // Make sure the browser window is the front most window. |
885 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 886 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
886 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); | 887 ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html")); |
887 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); | 888 ASSERT_NO_FATAL_FAILURE(FindLocationBar()); |
888 GURL url(test_server()->GetURL("files/instant/empty.html")); | 889 GURL url(test_server()->GetURL("files/instant/empty.html")); |
889 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 890 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
890 printf("0\n"); | 891 printf("0\n"); |
891 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(true)); | 892 ASSERT_NO_FATAL_FAILURE(WaitForPreviewToNavigate(true)); |
892 url = test_server()->GetURL("files/instant/download.zip"); | 893 url = test_server()->GetURL("files/instant/download.zip"); |
893 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); | 894 location_bar_->location_entry()->SetUserText(UTF8ToUTF16(url.spec())); |
894 // Wait for the load to fail (because instant disables downloads). | 895 // Wait for the load to fail (because instant disables downloads). |
895 printf("1\n"); | 896 printf("1\n"); |
896 ui_test_utils::WaitForNotification( | 897 ui_test_utils::WaitForNotification( |
897 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR); | 898 content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR); |
898 | 899 |
899 printf("2\n"); | 900 printf("2\n"); |
900 ui_test_utils::WindowedNotificationObserver download_observer( | 901 ui_test_utils::WindowedNotificationObserver download_observer( |
901 NotificationType::DOWNLOAD_INITIATED, | 902 chrome::NOTIFICATION_DOWNLOAD_INITIATED, |
902 NotificationService::AllSources()); | 903 NotificationService::AllSources()); |
903 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); | 904 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RETURN)); |
904 printf("3\n"); | 905 printf("3\n"); |
905 download_observer.Wait(); | 906 download_observer.Wait(); |
906 printf("4\n"); | 907 printf("4\n"); |
907 | 908 |
908 // And we should end up at about:blank. | 909 // And we should end up at about:blank. |
909 TabContents* contents = browser()->GetSelectedTabContents(); | 910 TabContents* contents = browser()->GetSelectedTabContents(); |
910 ASSERT_TRUE(contents); | 911 ASSERT_TRUE(contents); |
911 EXPECT_EQ("about:blank", | 912 EXPECT_EQ("about:blank", |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 ui_test_utils::NavigateToURL( | 947 ui_test_utils::NavigateToURL( |
947 browser(), | 948 browser(), |
948 GURL(test_server()->GetURL("files/instant/empty.html"))); | 949 GURL(test_server()->GetURL("files/instant/empty.html"))); |
949 bool result; | 950 bool result; |
950 ASSERT_TRUE(GetBoolFromJavascript( | 951 ASSERT_TRUE(GetBoolFromJavascript( |
951 browser()->GetSelectedTabContents(), | 952 browser()->GetSelectedTabContents(), |
952 "window.chrome.searchBox.value.length == 0", | 953 "window.chrome.searchBox.value.length == 0", |
953 &result)); | 954 &result)); |
954 EXPECT_TRUE(result); | 955 EXPECT_TRUE(result); |
955 } | 956 } |
OLD | NEW |