Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_browsertest.cc

Issue 11198074: Initial implementation of dedupping search provider's URLs. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a missing include. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/format_macros.h" 5 #include "base/format_macros.h"
6 #include "base/path_service.h" 6 #include "base/path_service.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/autocomplete/autocomplete_input.h" 9 #include "chrome/browser/autocomplete/autocomplete_input.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h" 10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h" 11 #include "chrome/browser/autocomplete/autocomplete_provider.h"
12 #include "chrome/browser/extensions/extension_browsertest.h" 12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/unpacked_installer.h" 14 #include "chrome/browser/extensions/unpacked_installer.h"
15 #include "chrome/browser/history/history.h" 15 #include "chrome/browser/history/history.h"
16 #include "chrome/browser/history/history_service_factory.h" 16 #include "chrome/browser/history/history_service_factory.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_commands.h" 20 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 21 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/omnibox/location_bar.h" 23 #include "chrome/browser/ui/omnibox/location_bar.h"
23 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 24 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
24 #include "chrome/browser/ui/omnibox/omnibox_view.h" 25 #include "chrome/browser/ui/omnibox/omnibox_view.h"
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
26 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
(...skipping 13 matching lines...) Expand all
41 UTF16ToUTF8(match.contents).c_str(), 42 UTF16ToUTF8(match.contents).c_str(),
42 match.provider->GetName())); 43 match.provider->GetName()));
43 } 44 }
44 return UTF8ToUTF16(output); 45 return UTF8ToUTF16(output);
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 class AutocompleteBrowserTest : public ExtensionBrowserTest { 50 class AutocompleteBrowserTest : public ExtensionBrowserTest {
50 protected: 51 protected:
52 void WaitForTemplateURLServiceToLoad() {
53 ui_test_utils::WaitForTemplateURLServiceToLoad(
54 TemplateURLServiceFactory::GetForProfile(browser()->profile()));
55 }
56
51 LocationBar* GetLocationBar() const { 57 LocationBar* GetLocationBar() const {
52 return browser()->window()->GetLocationBar(); 58 return browser()->window()->GetLocationBar();
53 } 59 }
54 60
55 AutocompleteController* GetAutocompleteController() const { 61 AutocompleteController* GetAutocompleteController() const {
56 return GetLocationBar()->GetLocationEntry()->model()->popup_model()-> 62 return GetLocationBar()->GetLocationEntry()->model()->popup_model()->
57 autocomplete_controller(); 63 autocomplete_controller();
58 } 64 }
59 }; 65 };
60 66
61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { 67 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) {
68 WaitForTemplateURLServiceToLoad();
62 LocationBar* location_bar = GetLocationBar(); 69 LocationBar* location_bar = GetLocationBar();
63 OmniboxView* location_entry = location_bar->GetLocationEntry(); 70 OmniboxView* location_entry = location_bar->GetLocationEntry();
64 71
65 EXPECT_TRUE(location_bar->GetInputString().empty()); 72 EXPECT_TRUE(location_bar->GetInputString().empty());
66 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 73 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across 74 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across
68 // platforms. 75 // platforms.
69 76
70 location_bar->FocusLocation(true); 77 location_bar->FocusLocation(true);
71 78
(...skipping 23 matching lines...) Expand all
95 102
96 // Autocomplete test is flaky on ChromeOS. 103 // Autocomplete test is flaky on ChromeOS.
97 // http://crbug.com/52928 104 // http://crbug.com/52928
98 #if defined(OS_CHROMEOS) 105 #if defined(OS_CHROMEOS)
99 #define MAYBE_Autocomplete DISABLED_Autocomplete 106 #define MAYBE_Autocomplete DISABLED_Autocomplete
100 #else 107 #else
101 #define MAYBE_Autocomplete Autocomplete 108 #define MAYBE_Autocomplete Autocomplete
102 #endif 109 #endif
103 110
104 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { 111 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) {
112 WaitForTemplateURLServiceToLoad();
105 // The results depend on the history backend being loaded. Make sure it is 113 // The results depend on the history backend being loaded. Make sure it is
106 // loaded so that the autocomplete results are consistent. 114 // loaded so that the autocomplete results are consistent.
107 ui_test_utils::WaitForHistoryToLoad( 115 ui_test_utils::WaitForHistoryToLoad(
108 HistoryServiceFactory::GetForProfile(browser()->profile(), 116 HistoryServiceFactory::GetForProfile(browser()->profile(),
109 Profile::EXPLICIT_ACCESS)); 117 Profile::EXPLICIT_ACCESS));
110 118
111 LocationBar* location_bar = GetLocationBar(); 119 LocationBar* location_bar = GetLocationBar();
112 AutocompleteController* autocomplete_controller = GetAutocompleteController(); 120 AutocompleteController* autocomplete_controller = GetAutocompleteController();
113 121
114 { 122 {
(...skipping 23 matching lines...) Expand all
138 146
139 EXPECT_TRUE(location_bar->GetInputString().empty()); 147 EXPECT_TRUE(location_bar->GetInputString().empty());
140 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 148 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
141 EXPECT_FALSE(location_entry->IsSelectAll()); 149 EXPECT_FALSE(location_entry->IsSelectAll());
142 const AutocompleteResult& result = autocomplete_controller->result(); 150 const AutocompleteResult& result = autocomplete_controller->result();
143 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result); 151 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result);
144 } 152 }
145 } 153 }
146 154
147 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { 155 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) {
156 WaitForTemplateURLServiceToLoad();
148 // http://code.google.com/p/chromium/issues/detail?id=38385 157 // http://code.google.com/p/chromium/issues/detail?id=38385
149 // Make sure that tabbing away from an empty omnibar causes a revert 158 // Make sure that tabbing away from an empty omnibar causes a revert
150 // and select all. 159 // and select all.
151 LocationBar* location_bar = GetLocationBar(); 160 LocationBar* location_bar = GetLocationBar();
152 OmniboxView* location_entry = location_bar->GetLocationEntry(); 161 OmniboxView* location_entry = location_bar->GetLocationEntry();
153 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 162 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
154 location_entry->SetUserText(string16()); 163 location_entry->SetUserText(string16());
155 content::WindowedNotificationObserver observer( 164 content::WindowedNotificationObserver observer(
156 content::NOTIFICATION_LOAD_STOP, 165 content::NOTIFICATION_LOAD_STOP,
157 content::NotificationService::AllSources()); 166 content::NotificationService::AllSources());
158 chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL), 167 chrome::AddSelectedTabWithURL(browser(), GURL(chrome::kAboutBlankURL),
159 content::PAGE_TRANSITION_AUTO_TOPLEVEL); 168 content::PAGE_TRANSITION_AUTO_TOPLEVEL);
160 observer.Wait(); 169 observer.Wait();
161 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 170 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
162 chrome::CloseTab(browser()); 171 chrome::CloseTab(browser());
163 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 172 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
164 EXPECT_TRUE(location_entry->IsSelectAll()); 173 EXPECT_TRUE(location_entry->IsSelectAll());
165 } 174 }
166 175
167 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { 176 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
177 WaitForTemplateURLServiceToLoad();
168 LocationBar* location_bar = GetLocationBar(); 178 LocationBar* location_bar = GetLocationBar();
169 OmniboxView* location_entry = location_bar->GetLocationEntry(); 179 OmniboxView* location_entry = location_bar->GetLocationEntry();
170 180
171 // Focus search when omnibox is blank 181 // Focus search when omnibox is blank
172 { 182 {
173 EXPECT_TRUE(location_bar->GetInputString().empty()); 183 EXPECT_TRUE(location_bar->GetInputString().empty());
174 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText()); 184 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), location_entry->GetText());
175 185
176 location_bar->FocusSearch(); 186 location_bar->FocusSearch();
177 EXPECT_TRUE(location_bar->GetInputString().empty()); 187 EXPECT_TRUE(location_bar->GetInputString().empty());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 EXPECT_EQ(ASCIIToUTF16(" ?foo"), location_entry->GetText()); 254 EXPECT_EQ(ASCIIToUTF16(" ?foo"), location_entry->GetText());
245 255
246 size_t selection_start, selection_end; 256 size_t selection_start, selection_end;
247 location_entry->GetSelectionBounds(&selection_start, &selection_end); 257 location_entry->GetSelectionBounds(&selection_start, &selection_end);
248 EXPECT_EQ(4U, std::min(selection_start, selection_end)); 258 EXPECT_EQ(4U, std::min(selection_start, selection_end));
249 EXPECT_EQ(7U, std::max(selection_start, selection_end)); 259 EXPECT_EQ(7U, std::max(selection_start, selection_end));
250 } 260 }
251 } 261 }
252 262
253 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, ExtensionAppProvider) { 263 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, ExtensionAppProvider) {
264 WaitForTemplateURLServiceToLoad();
254 ExtensionService* service = browser()->profile()->GetExtensionService(); 265 ExtensionService* service = browser()->profile()->GetExtensionService();
255 size_t extension_count = service->extensions()->size(); 266 size_t extension_count = service->extensions()->size();
256 267
257 FilePath test_dir; 268 FilePath test_dir;
258 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 269 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
259 // Load a packaged app. 270 // Load a packaged app.
260 extensions::UnpackedInstaller::Create(service)->Load( 271 extensions::UnpackedInstaller::Create(service)->Load(
261 test_dir.AppendASCII("extensions").AppendASCII("packaged_app")); 272 test_dir.AppendASCII("extensions").AppendASCII("packaged_app"));
262 WaitForExtensionLoad(); 273 WaitForExtensionLoad();
263 // Load a hosted app. 274 // Load a hosted app.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 EXPECT_TRUE(autocomplete_controller->done()); 311 EXPECT_TRUE(autocomplete_controller->done());
301 const AutocompleteResult& result = autocomplete_controller->result(); 312 const AutocompleteResult& result = autocomplete_controller->result();
302 // 'App test' is also a substring of extension 'Packaged App Test'. 313 // 'App test' is also a substring of extension 'Packaged App Test'.
303 EXPECT_GT(result.size(), 2U) << AutocompleteResultAsString(result); 314 EXPECT_GT(result.size(), 2U) << AutocompleteResultAsString(result);
304 AutocompleteMatch match = result.match_at(0); 315 AutocompleteMatch match = result.match_at(0);
305 EXPECT_EQ(ASCIIToUTF16("App Test"), match.contents); 316 EXPECT_EQ(ASCIIToUTF16("App Test"), match.contents);
306 EXPECT_EQ(AutocompleteMatch::EXTENSION_APP, match.type); 317 EXPECT_EQ(AutocompleteMatch::EXTENSION_APP, match.type);
307 EXPECT_FALSE(match.deletable); 318 EXPECT_FALSE(match.deletable);
308 } 319 }
309 } 320 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698