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

Side by Side Diff: components/dom_distiller/core/url_utils_unittest.cc

Issue 1349783006: Cleanup: Pass std::string as const reference if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert third_party changes Created 5 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/dom_distiller/core/url_utils.h" 5 #include "components/dom_distiller/core/url_utils.h"
6 6
7 #include "components/dom_distiller/core/url_constants.h" 7 #include "components/dom_distiller/core/url_constants.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h" 9 #include "url/gurl.h"
10 10
(...skipping 23 matching lines...) Expand all
34 // Test a valid URL without the key we are searching for. 34 // Test a valid URL without the key we are searching for.
35 const std::string valid_url_no_key = "http://www.google.com"; 35 const std::string valid_url_no_key = "http://www.google.com";
36 EXPECT_EQ("", GetValueForKeyInUrlPathQuery(valid_url_no_key, "key")); 36 EXPECT_EQ("", GetValueForKeyInUrlPathQuery(valid_url_no_key, "key"));
37 37
38 // Test a valid URL with 2 values of the key we are searching for. 38 // Test a valid URL with 2 values of the key we are searching for.
39 const std::string valid_url_two_keys = 39 const std::string valid_url_two_keys =
40 "http://www.google.com?key=foo&key=bar"; 40 "http://www.google.com?key=foo&key=bar";
41 EXPECT_EQ("foo", GetValueForKeyInUrlPathQuery(valid_url_two_keys, "key")); 41 EXPECT_EQ("foo", GetValueForKeyInUrlPathQuery(valid_url_two_keys, "key"));
42 } 42 }
43 43
44 std::string ThroughDistiller(std::string url) { 44 std::string ThroughDistiller(const std::string& url) {
45 return GetOriginalUrlFromDistillerUrl( 45 return GetOriginalUrlFromDistillerUrl(
46 GetDistillerViewUrlFromUrl(kDomDistillerScheme, GURL(url))).spec(); 46 GetDistillerViewUrlFromUrl(kDomDistillerScheme, GURL(url))).spec();
47 } 47 }
48 48
49 std::string GetOriginalUrlFromDistillerUrl(std::string url) { 49 std::string GetOriginalUrlFromDistillerUrl(const std::string& url) {
50 return GetOriginalUrlFromDistillerUrl(GURL(url)).spec(); 50 return GetOriginalUrlFromDistillerUrl(GURL(url)).spec();
51 } 51 }
52 52
53 TEST(DomDistillerUrlUtilsTest, TestDistillerEndToEnd) { 53 TEST(DomDistillerUrlUtilsTest, TestDistillerEndToEnd) {
54 // Tests a normal url. 54 // Tests a normal url.
55 const std::string url = "http://example.com/"; 55 const std::string url = "http://example.com/";
56 EXPECT_EQ(url, ThroughDistiller(url)); 56 EXPECT_EQ(url, ThroughDistiller(url));
57 EXPECT_EQ(url, GetOriginalUrlFromDistillerUrl(url)); 57 EXPECT_EQ(url, GetOriginalUrlFromDistillerUrl(url));
58 58
59 // Tests a url with arguments and anchor points. 59 // Tests a url with arguments and anchor points.
60 const std::string url_arguments = 60 const std::string url_arguments =
61 "https://example.com/?key=value&key=value2&key2=value3#here"; 61 "https://example.com/?key=value&key=value2&key2=value3#here";
62 EXPECT_EQ(url_arguments, ThroughDistiller(url_arguments)); 62 EXPECT_EQ(url_arguments, ThroughDistiller(url_arguments));
63 EXPECT_EQ(url_arguments, GetOriginalUrlFromDistillerUrl(url_arguments)); 63 EXPECT_EQ(url_arguments, GetOriginalUrlFromDistillerUrl(url_arguments));
64 64
65 // Tests a url with file:// scheme. 65 // Tests a url with file:// scheme.
66 const std::string url_file = "file:///home/userid/path/index.html"; 66 const std::string url_file = "file:///home/userid/path/index.html";
67 EXPECT_EQ(url_file, ThroughDistiller(url_file)); 67 EXPECT_EQ(url_file, ThroughDistiller(url_file));
68 EXPECT_EQ(url_file, GetOriginalUrlFromDistillerUrl(url_file)); 68 EXPECT_EQ(url_file, GetOriginalUrlFromDistillerUrl(url_file));
69 } 69 }
70 } // namespace url_utils 70 } // namespace url_utils
71 71
72 } // namespace dom_distiller 72 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698