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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_unittest.cc

Issue 24733003: Update defaults for InstantExtended. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused. Created 7 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
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 "chrome/browser/ui/toolbar/toolbar_model.h" 5 #include "chrome/browser/ui/toolbar/toolbar_model.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 }, 59 },
60 { 60 {
61 GURL("chrome-extension://monkey/balls.html"), 61 GURL("chrome-extension://monkey/balls.html"),
62 ASCIIToUTF16("chrome-extension://monkey/balls.html"), 62 ASCIIToUTF16("chrome-extension://monkey/balls.html"),
63 ASCIIToUTF16("chrome-extension://monkey/balls.html"), 63 ASCIIToUTF16("chrome-extension://monkey/balls.html"),
64 ASCIIToUTF16("chrome-extension://monkey/balls.html"), 64 ASCIIToUTF16("chrome-extension://monkey/balls.html"),
65 false, 65 false,
66 true 66 true
67 }, 67 },
68 { 68 {
69 GURL("chrome://newtab/"), 69 GURL("chrome-internal://newtab/"),
70 string16(), 70 string16(),
71 string16(), 71 string16(),
72 string16(), 72 string16(),
73 false, 73 false,
74 false 74 false
75 }, 75 },
76 { 76 {
77 GURL(content::kAboutBlankURL), 77 GURL(content::kAboutBlankURL),
78 ASCIIToUTF16(content::kAboutBlankURL), 78 ASCIIToUTF16(content::kAboutBlankURL),
79 ASCIIToUTF16(content::kAboutBlankURL), 79 ASCIIToUTF16(content::kAboutBlankURL),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 class ToolbarModelTest : public BrowserWithTestWindowTest { 147 class ToolbarModelTest : public BrowserWithTestWindowTest {
148 public: 148 public:
149 ToolbarModelTest(); 149 ToolbarModelTest();
150 virtual ~ToolbarModelTest(); 150 virtual ~ToolbarModelTest();
151 151
152 // BrowserWithTestWindowTest: 152 // BrowserWithTestWindowTest:
153 virtual void SetUp() OVERRIDE; 153 virtual void SetUp() OVERRIDE;
154 154
155 protected: 155 protected:
156 void ResetDefaultTemplateURL();
157 void NavigateAndCheckText(const GURL& url, 156 void NavigateAndCheckText(const GURL& url,
158 const string16& expected_text, 157 const string16& expected_text,
159 const string16& expected_replace_text, 158 const string16& expected_replace_text,
160 bool would_perform_search_term_replacement, 159 bool would_perform_search_term_replacement,
161 bool should_display_url); 160 bool should_display_url);
162 161
163 private: 162 private:
164 void ResetTemplateURLForInstant(const GURL& instant_url);
165 void NavigateAndCheckTextImpl(const GURL& url, 163 void NavigateAndCheckTextImpl(const GURL& url,
166 bool allow_search_term_replacement, 164 bool allow_search_term_replacement,
167 const string16 expected_text, 165 const string16 expected_text,
168 bool would_perform_search_term_replacement, 166 bool would_perform_search_term_replacement,
169 bool should_display); 167 bool should_display);
170 168
171 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest); 169 DISALLOW_COPY_AND_ASSIGN(ToolbarModelTest);
172 }; 170 };
173 171
174 ToolbarModelTest::ToolbarModelTest() { 172 ToolbarModelTest::ToolbarModelTest() {
175 } 173 }
176 174
177 ToolbarModelTest::~ToolbarModelTest() { 175 ToolbarModelTest::~ToolbarModelTest() {
178 } 176 }
179 177
180 void ToolbarModelTest::SetUp() { 178 void ToolbarModelTest::SetUp() {
181 BrowserWithTestWindowTest::SetUp(); 179 BrowserWithTestWindowTest::SetUp();
182 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 180 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
183 profile(), &TemplateURLServiceFactory::BuildInstanceFor); 181 profile(), &TemplateURLServiceFactory::BuildInstanceFor);
184 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( 182 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
185 profile(), &AutocompleteClassifierFactory::BuildInstanceFor); 183 profile(), &AutocompleteClassifierFactory::BuildInstanceFor);
186 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/"); 184 UIThreadSearchTermsData::SetGoogleBaseURL("http://google.com/");
187 } 185 }
188 186
189 void ToolbarModelTest::ResetDefaultTemplateURL() {
190 ResetTemplateURLForInstant(GURL("http://does/not/exist"));
191 }
192
193 void ToolbarModelTest::NavigateAndCheckText( 187 void ToolbarModelTest::NavigateAndCheckText(
194 const GURL& url, 188 const GURL& url,
195 const string16& expected_text, 189 const string16& expected_text,
196 const string16& expected_replace_text, 190 const string16& expected_replace_text,
197 bool would_perform_search_term_replacement, 191 bool would_perform_search_term_replacement,
198 bool should_display_url) { 192 bool should_display_url) {
199 NavigateAndCheckTextImpl(url, false, expected_text, 193 NavigateAndCheckTextImpl(url, false, expected_text,
200 would_perform_search_term_replacement, 194 would_perform_search_term_replacement,
201 should_display_url); 195 should_display_url);
202 NavigateAndCheckTextImpl(url, true, expected_replace_text, 196 NavigateAndCheckTextImpl(url, true,
197 expected_replace_text,
203 would_perform_search_term_replacement, 198 would_perform_search_term_replacement,
204 should_display_url); 199 should_display_url);
205 } 200 }
206 201
207 void ToolbarModelTest::ResetTemplateURLForInstant(const GURL& instant_url) {
208 TemplateURLData data;
209 data.short_name = ASCIIToUTF16("Google");
210 data.SetURL("{google:baseURL}search?q={searchTerms}");
211 data.instant_url = instant_url.spec();
212 data.search_terms_replacement_key = "{google:instantExtendedEnabledKey}";
213 TemplateURL* search_template_url = new TemplateURL(profile(), data);
214 TemplateURLService* template_url_service =
215 TemplateURLServiceFactory::GetForProfile(profile());
216 template_url_service->Add(search_template_url);
217 template_url_service->SetDefaultSearchProvider(search_template_url);
218 ASSERT_NE(0, search_template_url->id());
219 template_url_service->Load();
220 }
221
222 void ToolbarModelTest::NavigateAndCheckTextImpl( 202 void ToolbarModelTest::NavigateAndCheckTextImpl(
223 const GURL& url, 203 const GURL& url,
224 bool allow_search_term_replacement, 204 bool allow_search_term_replacement,
225 const string16 expected_text, 205 const string16 expected_text,
226 bool would_perform_search_term_replacement, 206 bool would_perform_search_term_replacement,
227 bool should_display_url) { 207 bool should_display_url) {
228 // The URL being navigated to should be treated as the Instant URL. Else
229 // there will be no search term extraction.
230 ResetTemplateURLForInstant(url);
231
232 // Check while loading. 208 // Check while loading.
233 content::NavigationController* controller = 209 content::NavigationController* controller =
234 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 210 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
235 controller->LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_LINK, 211 controller->LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_LINK,
236 std::string()); 212 std::string());
237 ToolbarModel* toolbar_model = browser()->toolbar_model(); 213 ToolbarModel* toolbar_model = browser()->toolbar_model();
238 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); 214 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL());
239 EXPECT_EQ(expected_text, 215 EXPECT_EQ(expected_text,
240 toolbar_model->GetText(allow_search_term_replacement)); 216 toolbar_model->GetText(allow_search_term_replacement));
241 EXPECT_EQ(would_perform_search_term_replacement, 217 EXPECT_EQ(would_perform_search_term_replacement,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 EXPECT_FALSE(chrome::IsQueryExtractionEnabled()) 252 EXPECT_FALSE(chrome::IsQueryExtractionEnabled())
277 << "This test expects query extraction to be disabled."; 253 << "This test expects query extraction to be disabled.";
278 AddTab(browser(), GURL(content::kAboutBlankURL)); 254 AddTab(browser(), GURL(content::kAboutBlankURL));
279 for (size_t i = 0; i < arraysize(test_items); ++i) { 255 for (size_t i = 0; i < arraysize(test_items); ++i) {
280 const TestItem& test_item = test_items[i]; 256 const TestItem& test_item = test_items[i];
281 NavigateAndCheckText(test_item.url, test_item.expected_text, 257 NavigateAndCheckText(test_item.url, test_item.expected_text,
282 test_item.expected_replace_text_inactive, false, 258 test_item.expected_replace_text_inactive, false,
283 test_item.should_display_url); 259 test_item.should_display_url);
284 } 260 }
285 261
286 // Once we enable it, query extraction and search term replacement are 262 chrome::EnableQueryExtractionForTesting();
287 // enabled by default.
288 chrome::EnableInstantExtendedAPIForTesting();
289 EXPECT_TRUE(chrome::IsQueryExtractionEnabled()); 263 EXPECT_TRUE(chrome::IsQueryExtractionEnabled());
290 EXPECT_TRUE(browser()->toolbar_model()->search_term_replacement_enabled()); 264 EXPECT_TRUE(browser()->toolbar_model()->search_term_replacement_enabled());
291 for (size_t i = 0; i < arraysize(test_items); ++i) { 265 for (size_t i = 0; i < arraysize(test_items); ++i) {
292 const TestItem& test_item = test_items[i]; 266 const TestItem& test_item = test_items[i];
293 NavigateAndCheckText(test_item.url, test_item.expected_text, 267 NavigateAndCheckText(test_item.url, test_item.expected_text,
294 test_item.expected_replace_text_active, 268 test_item.expected_replace_text_active,
295 test_item.would_perform_search_term_replacement, 269 test_item.would_perform_search_term_replacement,
296 test_item.should_display_url); 270 test_item.should_display_url);
297 } 271 }
298 272
299 // Disabling search term replacement should reset to only showing URLs. 273 // Disabling search term replacement should reset to only showing URLs.
300 browser()->toolbar_model()->set_search_term_replacement_enabled(false); 274 browser()->toolbar_model()->set_search_term_replacement_enabled(false);
301 for (size_t i = 0; i < arraysize(test_items); ++i) { 275 for (size_t i = 0; i < arraysize(test_items); ++i) {
302 const TestItem& test_item = test_items[i]; 276 const TestItem& test_item = test_items[i];
303 NavigateAndCheckText(test_item.url, test_item.expected_text, 277 NavigateAndCheckText(test_item.url,
278 test_item.expected_text,
304 test_item.expected_replace_text_inactive, false, 279 test_item.expected_replace_text_inactive, false,
305 test_item.should_display_url); 280 test_item.should_display_url);
306 } 281 }
307 } 282 }
308 283
309 // Verify that search terms are extracted while the page is loading. 284 // Verify that search terms are extracted while the page is loading.
310 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) { 285 TEST_F(ToolbarModelTest, SearchTermsWhileLoading) {
311 chrome::EnableInstantExtendedAPIForTesting(); 286 chrome::EnableQueryExtractionForTesting();
312 ResetDefaultTemplateURL();
313 AddTab(browser(), GURL(content::kAboutBlankURL)); 287 AddTab(browser(), GURL(content::kAboutBlankURL));
314 288
315 // While loading, we should be willing to extract search terms. 289 // While loading, we should be willing to extract search terms.
316 content::NavigationController* controller = 290 content::NavigationController* controller =
317 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 291 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
318 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 292 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"),
319 content::Referrer(), content::PAGE_TRANSITION_LINK, 293 content::Referrer(), content::PAGE_TRANSITION_LINK,
320 std::string()); 294 std::string());
321 ToolbarModel* toolbar_model = browser()->toolbar_model(); 295 ToolbarModel* toolbar_model = browser()->toolbar_model();
322 controller->GetVisibleEntry()->GetSSL().security_style = 296 controller->GetVisibleEntry()->GetSSL().security_style =
323 content::SECURITY_STYLE_UNKNOWN; 297 content::SECURITY_STYLE_UNKNOWN;
324 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); 298 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false));
325 299
326 // When done loading, we shouldn't extract search terms if we didn't get an 300 // When done loading, we shouldn't extract search terms if we didn't get an
327 // authenticated connection. 301 // authenticated connection.
328 CommitPendingLoad(controller); 302 CommitPendingLoad(controller);
329 controller->GetVisibleEntry()->GetSSL().security_style = 303 controller->GetVisibleEntry()->GetSSL().security_style =
330 content::SECURITY_STYLE_UNKNOWN; 304 content::SECURITY_STYLE_UNKNOWN;
331 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 305 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false));
332 } 306 }
333 307
334 // When the Google base URL is overridden on the command line, we should extract 308 // When the Google base URL is overridden on the command line, we should extract
335 // search terms from URLs that start with that base URL even when they're not 309 // search terms from URLs that start with that base URL even when they're not
336 // secure. 310 // secure.
337 TEST_F(ToolbarModelTest, GoogleBaseURL) { 311 TEST_F(ToolbarModelTest, GoogleBaseURL) {
338 chrome::EnableInstantExtendedAPIForTesting(); 312 chrome::EnableQueryExtractionForTesting();
339 AddTab(browser(), GURL(content::kAboutBlankURL)); 313 AddTab(browser(), GURL(content::kAboutBlankURL));
340 314
341 // If the Google base URL wasn't specified on the command line, then if it's 315 // If the Google base URL wasn't specified on the command line, then if it's
342 // HTTP, we should not extract search terms. 316 // HTTP, we should not extract search terms.
343 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); 317 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/");
344 NavigateAndCheckText( 318 NavigateAndCheckText(
345 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 319 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
346 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), 320 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"),
347 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false, 321 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), false,
348 true); 322 true);
349 323
350 // The same URL, when specified on the command line, should allow search term 324 // The same URL, when specified on the command line, should allow search term
351 // extraction. 325 // extraction.
352 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); 326 UIThreadSearchTermsData::SetGoogleBaseURL(std::string());
353 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, 327 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL,
354 "http://www.foo.com/"); 328 "http://www.foo.com/");
355 NavigateAndCheckText( 329 NavigateAndCheckText(
356 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"), 330 GURL("http://www.foo.com/search?q=tractor+supply&espv=1"),
357 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"), 331 ASCIIToUTF16("www.foo.com/search?q=tractor+supply&espv=1"),
358 ASCIIToUTF16("tractor supply"), true, true); 332 ASCIIToUTF16("tractor supply"), true, true);
359 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698