| 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" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 void EnableInstant() { | 57 void EnableInstant() { |
| 58 InstantController::Enable(browser()->profile()); | 58 InstantController::Enable(browser()->profile()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SetupInstantProvider(const std::string& page) { | 61 void SetupInstantProvider(const std::string& page) { |
| 62 Profile* profile = browser()->profile(); | 62 Profile* profile = browser()->profile(); |
| 63 TemplateURLService* model = | 63 TemplateURLService* model = |
| 64 TemplateURLServiceFactory::GetForProfile(profile); | 64 TemplateURLServiceFactory::GetForProfile(profile); |
| 65 | 65 |
| 66 ui_test_utils::WindowedNotificationObserver observer( | 66 content::WindowedNotificationObserver observer( |
| 67 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 67 chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
| 68 content::NotificationService::AllSources()); | 68 content::NotificationService::AllSources()); |
| 69 if (!model->loaded()) { | 69 if (!model->loaded()) { |
| 70 model->Load(); | 70 model->Load(); |
| 71 observer.Wait(); | 71 observer.Wait(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TemplateURLData data; | 74 TemplateURLData data; |
| 75 data.short_name = ASCIIToUTF16("foo"); | 75 data.short_name = ASCIIToUTF16("foo"); |
| 76 data.SetKeyword(ASCIIToUTF16("foo")); | 76 data.SetKeyword(ASCIIToUTF16("foo")); |
| 77 data.SetURL(base::StringPrintf("http://%s:%d/files/%s?q={searchTerms}", | 77 data.SetURL(base::StringPrintf("http://%s:%d/files/%s?q={searchTerms}", |
| 78 test_server()->host_port_pair().host().c_str(), | 78 test_server()->host_port_pair().host().c_str(), |
| 79 test_server()->host_port_pair().port(), page.c_str())); | 79 test_server()->host_port_pair().port(), page.c_str())); |
| 80 data.instant_url = data.url(); | 80 data.instant_url = data.url(); |
| 81 // TemplateURLService takes ownership of this. | 81 // TemplateURLService takes ownership of this. |
| 82 TemplateURL* template_url = new TemplateURL(profile, data); | 82 TemplateURL* template_url = new TemplateURL(profile, data); |
| 83 model->Add(template_url); | 83 model->Add(template_url); |
| 84 model->SetDefaultSearchProvider(template_url); | 84 model->SetDefaultSearchProvider(template_url); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Type a character to get instant to trigger and determine instant support. | 87 // Type a character to get instant to trigger and determine instant support. |
| 88 void DetermineInstantSupport() { | 88 void DetermineInstantSupport() { |
| 89 ui_test_utils::WindowedNotificationObserver observer( | 89 content::WindowedNotificationObserver observer( |
| 90 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 90 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 91 content::NotificationService::AllSources()); | 91 content::NotificationService::AllSources()); |
| 92 // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword. | 92 // "a" triggers the "about:" provider. "b" begins the "bing.com" keyword. |
| 93 // "c" might someday trigger a "chrome:" provider. | 93 // "c" might someday trigger a "chrome:" provider. |
| 94 omnibox()->SetUserText(ASCIIToUTF16("d")); | 94 omnibox()->SetUserText(ASCIIToUTF16("d")); |
| 95 observer.Wait(); | 95 observer.Wait(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // Types "def" into the omnibox and waits for the preview to be shown. | 98 // Types "def" into the omnibox and waits for the preview to be shown. |
| 99 void SearchAndWaitForPreviewToShow() { | 99 void SearchAndWaitForPreviewToShow() { |
| 100 ui_test_utils::WindowedNotificationObserver observer( | 100 content::WindowedNotificationObserver observer( |
| 101 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, | 101 chrome::NOTIFICATION_INSTANT_CONTROLLER_SHOWN, |
| 102 content::NotificationService::AllSources()); | 102 content::NotificationService::AllSources()); |
| 103 omnibox()->SetUserText(ASCIIToUTF16("def")); | 103 omnibox()->SetUserText(ASCIIToUTF16("def")); |
| 104 observer.Wait(); | 104 observer.Wait(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Sends a message to the renderer and waits for the response to come back to | 107 // Sends a message to the renderer and waits for the response to come back to |
| 108 // the browser. Returns true on success. | 108 // the browser. Returns true on success. |
| 109 bool WaitForMessageToBeProcessedByRenderer() { | 109 bool WaitForMessageToBeProcessedByRenderer() { |
| 110 bool result = false; | 110 bool result = false; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 EXPECT_TRUE(rwhv->IsShowing()); | 581 EXPECT_TRUE(rwhv->IsShowing()); |
| 582 } | 582 } |
| 583 | 583 |
| 584 // Transition from search to non-search and make sure instant isn't displayable. | 584 // Transition from search to non-search and make sure instant isn't displayable. |
| 585 // See bug http://crbug.com/100368 for details. | 585 // See bug http://crbug.com/100368 for details. |
| 586 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { | 586 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchToNonSearch)) { |
| 587 ASSERT_TRUE(test_server()->Start()); | 587 ASSERT_TRUE(test_server()->Start()); |
| 588 EnableInstant(); | 588 EnableInstant(); |
| 589 SetupInstantProvider("instant.html"); | 589 SetupInstantProvider("instant.html"); |
| 590 | 590 |
| 591 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 591 content::WindowedNotificationObserver instant_support_observer( |
| 592 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 592 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 593 content::NotificationService::AllSources()); | 593 content::NotificationService::AllSources()); |
| 594 | 594 |
| 595 // Type in some search text. | 595 // Type in some search text. |
| 596 omnibox()->SetUserText(ASCIIToUTF16("def")); | 596 omnibox()->SetUserText(ASCIIToUTF16("def")); |
| 597 | 597 |
| 598 // Load a non search URL. Don't wait for the preview to navigate. It'll still | 598 // Load a non search URL. Don't wait for the preview to navigate. It'll still |
| 599 // end up loading in the background. | 599 // end up loading in the background. |
| 600 GURL url(test_server()->GetURL("files/empty.html")); | 600 GURL url(test_server()->GetURL("files/empty.html")); |
| 601 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 601 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 622 EXPECT_FALSE(instant()->IsCurrent()); | 622 EXPECT_FALSE(instant()->IsCurrent()); |
| 623 } | 623 } |
| 624 | 624 |
| 625 // Makes sure that if the server doesn't support the instant API we don't show | 625 // Makes sure that if the server doesn't support the instant API we don't show |
| 626 // anything. | 626 // anything. |
| 627 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) { | 627 IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE(SearchServerDoesntSupportInstant)) { |
| 628 ASSERT_TRUE(test_server()->Start()); | 628 ASSERT_TRUE(test_server()->Start()); |
| 629 EnableInstant(); | 629 EnableInstant(); |
| 630 SetupInstantProvider("empty.html"); | 630 SetupInstantProvider("empty.html"); |
| 631 | 631 |
| 632 ui_test_utils::WindowedNotificationObserver tab_closed_observer( | 632 content::WindowedNotificationObserver tab_closed_observer( |
| 633 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 633 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 634 content::NotificationService::AllSources()); | 634 content::NotificationService::AllSources()); |
| 635 | 635 |
| 636 omnibox()->SetUserText(ASCIIToUTF16("d")); | 636 omnibox()->SetUserText(ASCIIToUTF16("d")); |
| 637 EXPECT_TRUE(preview()); | 637 EXPECT_TRUE(preview()); |
| 638 | 638 |
| 639 // When the response comes back that the page doesn't support instant the tab | 639 // When the response comes back that the page doesn't support instant the tab |
| 640 // should be closed. | 640 // should be closed. |
| 641 tab_closed_observer.Wait(); | 641 tab_closed_observer.Wait(); |
| 642 EXPECT_FALSE(preview()); | 642 EXPECT_FALSE(preview()); |
| 643 } | 643 } |
| 644 | 644 |
| 645 // Verifies transitioning from loading a non-search string to a search string | 645 // Verifies transitioning from loading a non-search string to a search string |
| 646 // with the provider not supporting instant works (meaning we don't display | 646 // with the provider not supporting instant works (meaning we don't display |
| 647 // anything). | 647 // anything). |
| 648 IN_PROC_BROWSER_TEST_F(InstantTest, | 648 IN_PROC_BROWSER_TEST_F(InstantTest, |
| 649 MAYBE(NonSearchToSearchDoesntSupportInstant)) { | 649 MAYBE(NonSearchToSearchDoesntSupportInstant)) { |
| 650 ASSERT_TRUE(test_server()->Start()); | 650 ASSERT_TRUE(test_server()->Start()); |
| 651 EnableInstant(); | 651 EnableInstant(); |
| 652 SetupInstantProvider("empty.html"); | 652 SetupInstantProvider("empty.html"); |
| 653 | 653 |
| 654 GURL url(test_server()->GetURL("files/empty.html")); | 654 GURL url(test_server()->GetURL("files/empty.html")); |
| 655 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); | 655 omnibox()->SetUserText(UTF8ToUTF16(url.spec())); |
| 656 EXPECT_FALSE(preview()); | 656 EXPECT_FALSE(preview()); |
| 657 | 657 |
| 658 ui_test_utils::WindowedNotificationObserver tab_closed_observer( | 658 content::WindowedNotificationObserver tab_closed_observer( |
| 659 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 659 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 660 content::NotificationService::AllSources()); | 660 content::NotificationService::AllSources()); |
| 661 | 661 |
| 662 // Now type in some search text. | 662 // Now type in some search text. |
| 663 omnibox()->SetUserText(ASCIIToUTF16("d")); | 663 omnibox()->SetUserText(ASCIIToUTF16("d")); |
| 664 EXPECT_TRUE(preview()); | 664 EXPECT_TRUE(preview()); |
| 665 | 665 |
| 666 // When the response comes back that the page doesn't support instant the tab | 666 // When the response comes back that the page doesn't support instant the tab |
| 667 // should be closed. | 667 // should be closed. |
| 668 tab_closed_observer.Wait(); | 668 tab_closed_observer.Wait(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 // instant controller (which was only created after EnableInstant()), so no | 750 // instant controller (which was only created after EnableInstant()), so no |
| 751 // preloading happened. Unfocus the omnibox with ClickOnView(), so that when | 751 // preloading happened. Unfocus the omnibox with ClickOnView(), so that when |
| 752 // we focus it again, the controller will preload instant search. | 752 // we focus it again, the controller will preload instant search. |
| 753 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 753 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 754 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 754 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 755 | 755 |
| 756 // Verify that there is no preview. | 756 // Verify that there is no preview. |
| 757 EXPECT_FALSE(preview()); | 757 EXPECT_FALSE(preview()); |
| 758 | 758 |
| 759 // Focusing the omnibox should cause instant to be preloaded. | 759 // Focusing the omnibox should cause instant to be preloaded. |
| 760 ui_test_utils::WindowedNotificationObserver instant_support_observer( | 760 content::WindowedNotificationObserver instant_support_observer( |
| 761 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, | 761 chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
| 762 content::NotificationService::AllSources()); | 762 content::NotificationService::AllSources()); |
| 763 browser()->window()->GetLocationBar()->FocusLocation(false); | 763 browser()->window()->GetLocationBar()->FocusLocation(false); |
| 764 instant_support_observer.Wait(); | 764 instant_support_observer.Wait(); |
| 765 | 765 |
| 766 // Instant should have a preview, but not display it. | 766 // Instant should have a preview, but not display it. |
| 767 EXPECT_TRUE(preview()); | 767 EXPECT_TRUE(preview()); |
| 768 EXPECT_FALSE(instant()->is_displayable()); | 768 EXPECT_FALSE(instant()->is_displayable()); |
| 769 EXPECT_FALSE(instant()->IsCurrent()); | 769 EXPECT_FALSE(instant()->IsCurrent()); |
| 770 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); | 770 ASSERT_TRUE(CheckVisibilityIs(preview()->web_contents(), false)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 DetermineInstantSupport(); | 835 DetermineInstantSupport(); |
| 836 SearchAndWaitForPreviewToShow(); | 836 SearchAndWaitForPreviewToShow(); |
| 837 | 837 |
| 838 // Now there should be three rows, the third being the instant preview. | 838 // Now there should be three rows, the third being the instant preview. |
| 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); | 839 TaskManagerBrowserTestUtil::WaitForResourceChange(3); |
| 840 string16 prefix = l10n_util::GetStringFUTF16( | 840 string16 prefix = l10n_util::GetStringFUTF16( |
| 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); | 841 IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); |
| 842 string16 title = task_manager->GetResourceTitle(2); | 842 string16 title = task_manager->GetResourceTitle(2); |
| 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; | 843 EXPECT_TRUE(StartsWith(title, prefix, true)) << title << " vs " << prefix; |
| 844 } | 844 } |
| OLD | NEW |