OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/net/browser_url_util.h" | 5 #include "chrome/browser/net/browser_url_util.h" |
6 | 6 |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace chrome_browser_net { | 10 namespace chrome_browser_net { |
11 | 11 |
(...skipping 10 matching lines...) Expand all Loading... |
22 AppendQueryParameter(GURL("http://example.com/path?existing=one"), | 22 AppendQueryParameter(GURL("http://example.com/path?existing=one"), |
23 "name", "value").spec()); | 23 "name", "value").spec()); |
24 | 24 |
25 // Appending a name-value pair with unsafe characters included. The | 25 // Appending a name-value pair with unsafe characters included. The |
26 // unsafe characters should be escaped. | 26 // unsafe characters should be escaped. |
27 EXPECT_EQ("http://example.com/path?existing=one&na+me=v.alue%3D", | 27 EXPECT_EQ("http://example.com/path?existing=one&na+me=v.alue%3D", |
28 AppendQueryParameter(GURL("http://example.com/path?existing=one"), | 28 AppendQueryParameter(GURL("http://example.com/path?existing=one"), |
29 "na me", "v.alue=").spec()); | 29 "na me", "v.alue=").spec()); |
30 } | 30 } |
31 | 31 |
32 TEST(BrowserUrlUtilTest, GetValueForKeyInQuery) { | |
33 GURL url("http://example.com/path?name=value&boolParam&" | |
34 "url=http://test.com/q?n1%3Dv1%26n2"); | |
35 std::string value; | |
36 | |
37 // False when getting a non-existent query param. | |
38 EXPECT_FALSE(GetValueForKeyInQuery(url, "non-exist", &value)); | |
39 | |
40 // True when query param exist. | |
41 EXPECT_TRUE(GetValueForKeyInQuery(url, "name", &value)); | |
42 EXPECT_EQ("value", value); | |
43 | |
44 EXPECT_TRUE(GetValueForKeyInQuery(url, "boolParam", &value)); | |
45 EXPECT_EQ("", value); | |
46 | |
47 EXPECT_TRUE(GetValueForKeyInQuery(url, "url", &value)); | |
48 EXPECT_EQ("http://test.com/q?n1=v1&n2", value); | |
49 } | |
50 | |
51 } // namespace chrome_browser_net. | 32 } // namespace chrome_browser_net. |
OLD | NEW |