diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 21:59:59 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-21 21:59:59 +0000 |
commit | 34b95db86d19643b6a40981572df1206572d5ae1 (patch) | |
tree | e58324a811a82483e4923e5416aad3c20552e84f /chrome/browser/extensions | |
parent | d1029c57273282ad53b0291e43d63c40ee5ec841 (diff) | |
download | chromium_src-34b95db86d19643b6a40981572df1206572d5ae1.zip chromium_src-34b95db86d19643b6a40981572df1206572d5ae1.tar.gz chromium_src-34b95db86d19643b6a40981572df1206572d5ae1.tar.bz2 |
Fixed a bug where the extension omnibox API wouldn't work from an incognito
split mode context.
Also unmarked OmniboxApiTest.Basic as flaky, since it has no failures on the
flakiness dashboard.
BUG=52929,100927
TEST=no
Review URL: http://codereview.chromium.org/8342057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r-- | chrome/browser/extensions/extension_omnibox_api.cc | 4 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_omnibox_apitest.cc | 95 |
2 files changed, 77 insertions, 22 deletions
diff --git a/chrome/browser/extensions/extension_omnibox_api.cc b/chrome/browser/extensions/extension_omnibox_api.cc index 25e1bbd..524f65b 100644 --- a/chrome/browser/extensions/extension_omnibox_api.cc +++ b/chrome/browser/extensions/extension_omnibox_api.cc @@ -143,7 +143,7 @@ bool OmniboxSendSuggestionsFunction::RunImpl() { content::NotificationService::current()->Notify( chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, - content::Source<Profile>(profile_), + content::Source<Profile>(profile_->GetOriginalProfile()), content::Details<ExtensionOmniboxSuggestions>(&suggestions)); return true; @@ -174,7 +174,7 @@ bool OmniboxSetDefaultSuggestionFunction::RunImpl() { content::NotificationService::current()->Notify( chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, - content::Source<Profile>(profile_), + content::Source<Profile>(profile_->GetOriginalProfile()), content::NotificationService::NoDetails()); return true; diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc index 2e96c73c..2c92eac 100644 --- a/chrome/browser/extensions/extension_omnibox_apitest.cc +++ b/chrome/browser/extensions/extension_omnibox_apitest.cc @@ -29,14 +29,6 @@ #include "chrome/browser/ui/gtk/browser_window_gtk.h" #endif -// Basic test is flaky on ChromeOS and Linux. -// http://crbug.com/52929 -#if defined(OS_CHROMEOS) || defined(OS_LINUX) -#define MAYBE_Basic FLAKY_Basic -#else -#define MAYBE_Basic Basic -#endif - namespace { string16 AutocompleteResultAsString(const AutocompleteResult& result) { @@ -55,12 +47,12 @@ string16 AutocompleteResultAsString(const AutocompleteResult& result) { class OmniboxApiTest : public ExtensionApiTest { protected: - LocationBar* GetLocationBar() const { - return browser()->window()->GetLocationBar(); + LocationBar* GetLocationBar(Browser* browser) const { + return browser->window()->GetLocationBar(); } - AutocompleteController* GetAutocompleteController() const { - return GetLocationBar()->location_entry()->model()->popup_model()-> + AutocompleteController* GetAutocompleteController(Browser* browser) const { + return GetLocationBar(browser)->location_entry()->model()->popup_model()-> autocomplete_controller(); } @@ -86,7 +78,7 @@ class OmniboxApiTest : public ExtensionApiTest { } }; -IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { +IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { #if defined(TOOLKIT_GTK) // Disable the timer because, on Lucid at least, it triggers resize/move // behavior in the browser window, which dismisses the autocomplete popup @@ -95,15 +87,15 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, MAYBE_Basic) { browser()->window())->DisableDebounceTimerForTests(true); #endif - ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; // The results depend on the TemplateURLService being loaded. Make sure it is // loaded so that the autocomplete results are consistent. WaitForTemplateURLServiceToLoad(); - LocationBar* location_bar = GetLocationBar(); - AutocompleteController* autocomplete_controller = GetAutocompleteController(); + LocationBar* location_bar = GetLocationBar(browser()); + AutocompleteController* autocomplete_controller = + GetAutocompleteController(browser()); // Test that our extension's keyword is suggested to us when we partially type // it. @@ -219,17 +211,17 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) { browser()->window())->DisableDebounceTimerForTests(true); #endif - ASSERT_TRUE(test_server()->Start()); ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; // The results depend on the TemplateURLService being loaded. Make sure it is // loaded so that the autocomplete results are consistent. WaitForTemplateURLServiceToLoad(); - LocationBar* location_bar = GetLocationBar(); - AutocompleteController* autocomplete_controller = GetAutocompleteController(); + LocationBar* location_bar = GetLocationBar(browser()); + AutocompleteController* autocomplete_controller = + GetAutocompleteController(browser()); AutocompletePopupModel* popup_model = - GetLocationBar()->location_entry()->model()->popup_model(); + GetLocationBar(browser())->location_entry()->model()->popup_model(); // Input a keyword query and wait for suggestions from the extension. autocomplete_controller->Start( @@ -252,3 +244,66 @@ IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) { EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); EXPECT_FALSE(popup_model->IsOpen()); } + +// Tests that we get suggestions from and send input to the incognito context +// of an incognito split mode extension. +// http://crbug.com/100927 +IN_PROC_BROWSER_TEST_F(OmniboxApiTest, IncognitoSplitMode) { +#if defined(TOOLKIT_GTK) + // Disable the timer because, on Lucid at least, it triggers resize/move + // behavior in the browser window, which dismisses the autocomplete popup + // before the results can be read. + static_cast<BrowserWindowGtk*>( + browser()->window())->DisableDebounceTimerForTests(true); +#endif + + ResultCatcher catcher_incognito; + catcher_incognito.RestrictToProfile( + browser()->profile()->GetOffTheRecordProfile()); + + ASSERT_TRUE(RunExtensionTestIncognito("omnibox")) << message_; + + // Open an incognito window and wait for the incognito extension process to + // respond. + Browser* incognito_browser = CreateIncognitoBrowser(); + ASSERT_TRUE(catcher_incognito.GetNextResult()) << catcher_incognito.message(); + + // The results depend on the TemplateURLService being loaded. Make sure it is + // loaded so that the autocomplete results are consistent. + WaitForTemplateURLServiceToLoad(); + + LocationBar* location_bar = GetLocationBar(incognito_browser); + AutocompleteController* autocomplete_controller = + GetAutocompleteController(incognito_browser); + + // Test that we get the incognito-specific suggestions. + { + autocomplete_controller->Start( + ASCIIToUTF16("keyword suggestio"), string16(), true, false, true, + AutocompleteInput::ALL_MATCHES); + + WaitForAutocompleteDone(autocomplete_controller); + EXPECT_TRUE(autocomplete_controller->done()); + + // First result should be to invoke the keyword with what we typed, 2-4 + // should be to invoke with suggestions from the extension, and the last + // should be to search for what we typed. + const AutocompleteResult& result = autocomplete_controller->result(); + ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); + ASSERT_TRUE(result.match_at(0).template_url); + EXPECT_EQ(ASCIIToUTF16("keyword suggestion3 incognito"), + result.match_at(3).fill_into_edit); + } + + // Test that our input is sent to the incognito context. The test will do a + // text comparison and succeed only if "command incognito" is sent to the + // incognito context. + { + ResultCatcher catcher; + autocomplete_controller->Start( + ASCIIToUTF16("keyword command incognito"), string16(), + true, false, true, AutocompleteInput::ALL_MATCHES); + location_bar->AcceptInput(); + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); + } +} |