diff options
4 files changed, 83 insertions, 24 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(); + } +} diff --git a/chrome/test/data/extensions/api_test/omnibox/manifest.json b/chrome/test/data/extensions/api_test/omnibox/manifest.json index c391c1f..17b0ed4 100644 --- a/chrome/test/data/extensions/api_test/omnibox/manifest.json +++ b/chrome/test/data/extensions/api_test/omnibox/manifest.json @@ -3,5 +3,6 @@ "version": "0.1", "description": "end-to-end browser test for chrome.omnibox API", "background_page": "test.html", + "incognito": "split", "omnibox": { "keyword": "keyword" } } diff --git a/chrome/test/data/extensions/api_test/omnibox/test.html b/chrome/test/data/extensions/api_test/omnibox/test.html index fb46489..765139d 100644 --- a/chrome/test/data/extensions/api_test/omnibox/test.html +++ b/chrome/test/data/extensions/api_test/omnibox/test.html @@ -1,4 +1,7 @@ <script> +var incognito = chrome.extension.inIncognitoContext; +var incognitoSuffix = incognito ? " incognito" : ""; + chrome.omnibox.onInputChanged.addListener( function(text, suggest) { chrome.test.log("onInputChanged: " + text); @@ -9,7 +12,7 @@ chrome.omnibox.onInputChanged.addListener( suggest([ {content: text + "n1", description: desc}, {content: text + "n2", description: "description2"}, - {content: text + "n3", description: "description3"}, + {content: text + "n3" + incognitoSuffix, description: "description3"}, ]); } else { // Other tests, just provide a simple suggestion. @@ -19,7 +22,7 @@ chrome.omnibox.onInputChanged.addListener( chrome.omnibox.onInputEntered.addListener( function(text) { - chrome.test.assertEq("command", text); + chrome.test.assertEq("command" + incognitoSuffix, text); chrome.test.notifyPass(); }); |