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

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: rebase 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/search_engines/template_url.h" 10 #include "chrome/browser/search_engines/template_url.h"
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 search_terms_data_); 1452 search_terms_data_);
1453 EXPECT_EQ("http://bar/_/contextualsearch?" 1453 EXPECT_EQ("http://bar/_/contextualsearch?"
1454 "ctxs=1&" 1454 "ctxs=1&"
1455 "ctxs_start=6&" 1455 "ctxs_start=6&"
1456 "ctxs_end=11&" 1456 "ctxs_end=11&"
1457 "q=allen&" 1457 "q=allen&"
1458 "ctxs_content=woody+allen+movies&" 1458 "ctxs_content=woody+allen+movies&"
1459 "ctxs_url=www.wikipedia.org&" 1459 "ctxs_url=www.wikipedia.org&"
1460 "ctxs_encoding=utf-8&", result); 1460 "ctxs_encoding=utf-8&", result);
1461 } 1461 }
1462
1463 TEST_F(TemplateURLTest, GenerateKeyword) {
1464 ASSERT_EQ(ASCIIToUTF16("foo"),
1465 TemplateURL::GenerateKeyword(GURL("http://foo")));
1466 // www. should be stripped.
1467 ASSERT_EQ(ASCIIToUTF16("foo"),
1468 TemplateURL::GenerateKeyword(GURL("http://www.foo")));
1469 // Make sure we don't get a trailing '/'.
1470 ASSERT_EQ(ASCIIToUTF16("blah"),
1471 TemplateURL::GenerateKeyword(GURL("http://blah/")));
1472 // Don't generate the empty string.
1473 ASSERT_EQ(ASCIIToUTF16("www"),
1474 TemplateURL::GenerateKeyword(GURL("http://www.")));
1475 }
1476
1477 TEST_F(TemplateURLTest, GenerateSearchURL) {
1478 struct GenerateSearchURLCase {
1479 const char* test_name;
1480 const char* url;
1481 const char* expected;
1482 } generate_url_cases[] = {
1483 { "invalid URL", "foo{searchTerms}", "" },
1484 { "URL with no replacements", "http://foo/", "http://foo/" },
1485 { "basic functionality", "http://foo/{searchTerms}",
1486 "http://foo/blah.blah.blah.blah.blah" }
1487 };
1488
1489 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(generate_url_cases); ++i) {
1490 TemplateURLData data;
1491 data.SetURL(generate_url_cases[i].url);
1492 TemplateURL t_url(data);
1493 EXPECT_EQ(t_url.GenerateSearchURL(search_terms_data_).spec(),
1494 generate_url_cases[i].expected)
1495 << generate_url_cases[i].test_name << " failed.";
1496 }
1497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698