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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // Tests various permutations of AutocompleteModel::AdjustTextForCopy. | 273 // Tests various permutations of AutocompleteModel::AdjustTextForCopy. |
274 TEST_F(OmniboxEditTest, AdjustTextForCopy) { | 274 TEST_F(OmniboxEditTest, AdjustTextForCopy) { |
275 struct Data { | 275 struct Data { |
276 const char* perm_text; | 276 const char* perm_text; |
277 const int sel_start; | 277 const int sel_start; |
278 const bool is_all_selected; | 278 const bool is_all_selected; |
279 const char* input; | 279 const char* input; |
280 const char* expected_output; | 280 const char* expected_output; |
281 const bool write_url; | 281 const bool write_url; |
282 const char* expected_url; | 282 const char* expected_url; |
283 const bool extracted_search_terms; | |
284 } input[] = { | 283 } input[] = { |
285 // Test that http:// is inserted if all text is selected. | 284 // Test that http:// is inserted if all text is selected. |
286 { "a.de/b", 0, true, "a.de/b", "http://a.de/b", true, "http://a.de/b", | 285 { "a.de/b", 0, true, "a.de/b", "http://a.de/b", true, "http://a.de/b", }, |
287 false }, | |
288 | 286 |
289 // Test that http:// is inserted if the host is selected. | 287 // Test that http:// is inserted if the host is selected. |
290 { "a.de/b", 0, false, "a.de/", "http://a.de/", true, "http://a.de/", | 288 { "a.de/b", 0, false, "a.de/", "http://a.de/", true, "http://a.de/" }, |
291 false }, | |
292 | 289 |
293 // Tests that http:// is inserted if the path is modified. | 290 // Tests that http:// is inserted if the path is modified. |
294 { "a.de/b", 0, false, "a.de/c", "http://a.de/c", true, "http://a.de/c", | 291 { "a.de/b", 0, false, "a.de/c", "http://a.de/c", true, "http://a.de/c" }, |
295 false }, | |
296 | 292 |
297 // Tests that http:// isn't inserted if the host is modified. | 293 // Tests that http:// isn't inserted if the host is modified. |
298 { "a.de/b", 0, false, "a.com/b", "a.com/b", false, "", false }, | 294 { "a.de/b", 0, false, "a.com/b", "a.com/b", false, "" }, |
299 | 295 |
300 // Tests that http:// isn't inserted if the start of the selection is 1. | 296 // Tests that http:// isn't inserted if the start of the selection is 1. |
301 { "a.de/b", 1, false, "a.de/b", "a.de/b", false, "", false }, | 297 { "a.de/b", 1, false, "a.de/b", "a.de/b", false, "" }, |
302 | 298 |
303 // Tests that http:// isn't inserted if a portion of the host is selected. | 299 // Tests that http:// isn't inserted if a portion of the host is selected. |
304 { "a.de/", 0, false, "a.d", "a.d", false, "", false }, | 300 { "a.de/", 0, false, "a.d", "a.d", false, "" }, |
305 | 301 |
306 // Tests that http:// isn't inserted for an https url after the user nukes | 302 // Tests that http:// isn't inserted for an https url after the user nukes |
307 // https. | 303 // https. |
308 { "https://a.com/", 0, false, "a.com/", "a.com/", false, "", false }, | 304 { "https://a.com/", 0, false, "a.com/", "a.com/", false, "" }, |
309 | 305 |
310 // Tests that http:// isn't inserted if the user adds to the host. | 306 // Tests that http:// isn't inserted if the user adds to the host. |
311 { "a.de/", 0, false, "a.de.com/", "a.de.com/", false, "", false }, | 307 { "a.de/", 0, false, "a.de.com/", "a.de.com/", false, "" }, |
312 | 308 |
313 // Tests that we don't get double http if the user manually inserts http. | 309 // Tests that we don't get double http if the user manually inserts http. |
314 { "a.de/", 0, false, "http://a.de/", "http://a.de/", true, "http://a.de/", | 310 { "a.de/", 0, false, "http://a.de/", "http://a.de/", true, "http://a.de/" }, |
315 false }, | |
316 | 311 |
317 // Makes sure intranet urls get 'http://' prefixed to them. | 312 // Makes sure intranet urls get 'http://' prefixed to them. |
318 { "b/foo", 0, true, "b/foo", "http://b/foo", true, "http://b/foo", false }, | 313 { "b/foo", 0, true, "b/foo", "http://b/foo", true, "http://b/foo" }, |
319 | 314 |
320 // Verifies a search term 'foo' doesn't end up with http. | 315 // Verifies a search term 'foo' doesn't end up with http. |
321 { "www.google.com/search?", 0, false, "foo", "foo", false, "", false }, | 316 { "www.google.com/search?", 0, false, "foo", "foo", false, "" }, |
322 | |
323 // Makes sure extracted search terms are not modified. | |
324 { "www.google.com/webhp?", 0, true, "hello world", "hello world", false, | |
325 "", true }, | |
326 }; | 317 }; |
327 | 318 |
328 for (size_t i = 0; i < arraysize(input); ++i) { | 319 for (size_t i = 0; i < arraysize(input); ++i) { |
329 toolbar_model()->set_text(base::ASCIIToUTF16(input[i].perm_text)); | 320 toolbar_model()->set_text(base::ASCIIToUTF16(input[i].perm_text)); |
330 model()->UpdatePermanentText(); | 321 model()->UpdatePermanentText(); |
331 | 322 |
332 toolbar_model()->set_perform_search_term_replacement( | |
333 input[i].extracted_search_terms); | |
334 | |
335 base::string16 result = base::ASCIIToUTF16(input[i].input); | 323 base::string16 result = base::ASCIIToUTF16(input[i].input); |
336 GURL url; | 324 GURL url; |
337 bool write_url; | 325 bool write_url; |
338 model()->AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, | 326 model()->AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, |
339 &result, &url, &write_url); | 327 &result, &url, &write_url); |
340 EXPECT_EQ(base::ASCIIToUTF16(input[i].expected_output), result) << "@: " | 328 EXPECT_EQ(base::ASCIIToUTF16(input[i].expected_output), result) << "@: " |
341 << i; | 329 << i; |
342 EXPECT_EQ(input[i].write_url, write_url) << " @" << i; | 330 EXPECT_EQ(input[i].write_url, write_url) << " @" << i; |
343 if (write_url) | 331 if (write_url) |
344 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; | 332 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 0); | 387 0); |
400 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( | 388 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( |
401 client->alternate_nav_match().fill_into_edit)); | 389 client->alternate_nav_match().fill_into_edit)); |
402 | 390 |
403 model()->SetUserText(base::ASCIIToUTF16("ab cd")); | 391 model()->SetUserText(base::ASCIIToUTF16("ab cd")); |
404 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(), | 392 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(), |
405 0); | 393 0); |
406 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( | 394 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( |
407 client->alternate_nav_match().fill_into_edit)); | 395 client->alternate_nav_match().fill_into_edit)); |
408 } | 396 } |
OLD | NEW |