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

Side by Side Diff: chrome/browser/search_engines/template_url_unittest.cc

Issue 343823002: Move GenerateSearchURL() and GenerateKeyword() from TemplateURLService to TemplateURL (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months 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
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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_input.h" 10 #include "chrome/browser/autocomplete/autocomplete_input.h"
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 search_terms_data_); 1468 search_terms_data_);
1469 EXPECT_EQ("http://bar/_/contextualsearch?" 1469 EXPECT_EQ("http://bar/_/contextualsearch?"
1470 "ctxs=1&" 1470 "ctxs=1&"
1471 "ctxs_start=6&" 1471 "ctxs_start=6&"
1472 "ctxs_end=11&" 1472 "ctxs_end=11&"
1473 "q=allen&" 1473 "q=allen&"
1474 "ctxs_content=woody+allen+movies&" 1474 "ctxs_content=woody+allen+movies&"
1475 "ctxs_url=www.wikipedia.org&" 1475 "ctxs_url=www.wikipedia.org&"
1476 "ctxs_encoding=utf-8&", result); 1476 "ctxs_encoding=utf-8&", result);
1477 } 1477 }
1478
1479 TEST_F(TemplateURLTest, GenerateKeyword) {
1480 ASSERT_EQ(ASCIIToUTF16("foo"),
1481 TemplateURL::GenerateKeyword(GURL("http://foo")));
1482 // www. should be stripped.
1483 ASSERT_EQ(ASCIIToUTF16("foo"),
1484 TemplateURL::GenerateKeyword(GURL("http://www.foo")));
1485 // Make sure we don't get a trailing '/'.
1486 ASSERT_EQ(ASCIIToUTF16("blah"),
1487 TemplateURL::GenerateKeyword(GURL("http://blah/")));
1488 // Don't generate the empty string.
1489 ASSERT_EQ(ASCIIToUTF16("www"),
1490 TemplateURL::GenerateKeyword(GURL("http://www.")));
1491 }
1492
1493 TEST_F(TemplateURLTest, GenerateSearchURL) {
1494 struct GenerateSearchURLCase {
1495 const char* test_name;
1496 const char* url;
1497 const char* expected;
1498 } generate_url_cases[] = {
1499 { "invalid URL", "foo{searchTerms}", "" },
1500 { "URL with no replacements", "http://foo/", "http://foo/" },
1501 { "basic functionality", "http://foo/{searchTerms}",
1502 "http://foo/blah.blah.blah.blah.blah" }
1503 };
1504
1505 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
1506 TemplateURLData data;
1507 data.SetURL(generate_url_cases[i].url);
1508 TemplateURL t_url(data);
1509 EXPECT_EQ(t_url.GenerateSearchURL(search_terms_data_).spec(),
1510 generate_url_cases[i].expected)
1511 << generate_url_cases[i].test_name << " failed.";
1512 }
1513 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698