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

Side by Side Diff: net/http/url_security_manager_unittest.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/http/url_security_manager.h" 5 #include "net/http/url_security_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "net/http/http_auth_filter.h" 9 #include "net/http/http_auth_filter.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 10 matching lines...) Expand all
21 }; 21 };
22 22
23 const char* kTestAuthWhitelist = "*example.com,*foobar.com,baz"; 23 const char* kTestAuthWhitelist = "*example.com,*foobar.com,baz";
24 24
25 // Under Windows the following will be allowed by default: 25 // Under Windows the following will be allowed by default:
26 // localhost 26 // localhost
27 // host names without a period. 27 // host names without a period.
28 // In Posix systems (or on Windows if a whitelist is specified explicitly), 28 // In Posix systems (or on Windows if a whitelist is specified explicitly),
29 // everything depends on the whitelist. 29 // everything depends on the whitelist.
30 const TestData kTestDataList[] = { 30 const TestData kTestDataList[] = {
31 { "http://localhost", true, false }, 31 {"http://localhost", true, false},
32 { "http://bat", true, false }, 32 {"http://bat", true, false},
33 { "http://www.example.com", false, true }, 33 {"http://www.example.com", false, true},
34 { "http://example.com", false, true }, 34 {"http://example.com", false, true},
35 { "http://foobar.com", false, true }, 35 {"http://foobar.com", false, true},
36 { "http://boo.foobar.com", false, true }, 36 {"http://boo.foobar.com", false, true},
37 { "http://baz", true, true }, 37 {"http://baz", true, true},
38 { "http://www.exampl.com", false, false }, 38 {"http://www.exampl.com", false, false},
39 { "http://example.org", false, false }, 39 {"http://example.org", false, false},
40 { "http://foobar.net", false, false }, 40 {"http://foobar.net", false, false},
41 { "http://boo.fubar.com", false, false }, 41 {"http://boo.fubar.com", false, false},
42 }; 42 };
43 43
44 } // namespace 44 } // namespace
45 45
46 TEST(URLSecurityManager, UseDefaultCredentials) { 46 TEST(URLSecurityManager, UseDefaultCredentials) {
47 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist( 47 HttpAuthFilterWhitelist* auth_filter =
48 kTestAuthWhitelist); 48 new HttpAuthFilterWhitelist(kTestAuthWhitelist);
49 ASSERT_TRUE(auth_filter); 49 ASSERT_TRUE(auth_filter);
50 // The URL security manager takes ownership of |auth_filter|. 50 // The URL security manager takes ownership of |auth_filter|.
51 scoped_ptr<URLSecurityManager> url_security_manager( 51 scoped_ptr<URLSecurityManager> url_security_manager(
52 URLSecurityManager::Create(auth_filter, NULL)); 52 URLSecurityManager::Create(auth_filter, NULL));
53 ASSERT_TRUE(url_security_manager.get()); 53 ASSERT_TRUE(url_security_manager.get());
54 54
55 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 55 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
56 GURL gurl(kTestDataList[i].url); 56 GURL gurl(kTestDataList[i].url);
57 bool can_use_default = 57 bool can_use_default = url_security_manager->CanUseDefaultCredentials(gurl);
58 url_security_manager->CanUseDefaultCredentials(gurl);
59 58
60 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default) 59 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_use_default)
61 << " Run: " << i << " URL: '" << gurl << "'"; 60 << " Run: " << i << " URL: '" << gurl << "'";
62 } 61 }
63 } 62 }
64 63
65 TEST(URLSecurityManager, CanDelegate) { 64 TEST(URLSecurityManager, CanDelegate) {
66 HttpAuthFilterWhitelist* auth_filter = new HttpAuthFilterWhitelist( 65 HttpAuthFilterWhitelist* auth_filter =
67 kTestAuthWhitelist); 66 new HttpAuthFilterWhitelist(kTestAuthWhitelist);
68 ASSERT_TRUE(auth_filter); 67 ASSERT_TRUE(auth_filter);
69 // The URL security manager takes ownership of |auth_filter|. 68 // The URL security manager takes ownership of |auth_filter|.
70 scoped_ptr<URLSecurityManager> url_security_manager( 69 scoped_ptr<URLSecurityManager> url_security_manager(
71 URLSecurityManager::Create(NULL, auth_filter)); 70 URLSecurityManager::Create(NULL, auth_filter));
72 ASSERT_TRUE(url_security_manager.get()); 71 ASSERT_TRUE(url_security_manager.get());
73 72
74 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 73 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
75 GURL gurl(kTestDataList[i].url); 74 GURL gurl(kTestDataList[i].url);
76 bool can_delegate = url_security_manager->CanDelegate(gurl); 75 bool can_delegate = url_security_manager->CanDelegate(gurl);
77 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate) 76 EXPECT_EQ(kTestDataList[i].succeeds_in_whitelist, can_delegate)
78 << " Run: " << i << " URL: '" << gurl << "'"; 77 << " Run: " << i << " URL: '" << gurl << "'";
79 } 78 }
80 } 79 }
81 80
82 TEST(URLSecurityManager, CanDelegate_NoWhitelist) { 81 TEST(URLSecurityManager, CanDelegate_NoWhitelist) {
83 // Nothing can delegate in this case. 82 // Nothing can delegate in this case.
84 scoped_ptr<URLSecurityManager> url_security_manager( 83 scoped_ptr<URLSecurityManager> url_security_manager(
85 URLSecurityManager::Create(NULL, NULL)); 84 URLSecurityManager::Create(NULL, NULL));
86 ASSERT_TRUE(url_security_manager.get()); 85 ASSERT_TRUE(url_security_manager.get());
87 86
88 for (size_t i = 0; i < arraysize(kTestDataList); ++i) { 87 for (size_t i = 0; i < arraysize(kTestDataList); ++i) {
89 GURL gurl(kTestDataList[i].url); 88 GURL gurl(kTestDataList[i].url);
90 bool can_delegate = url_security_manager->CanDelegate(gurl); 89 bool can_delegate = url_security_manager->CanDelegate(gurl);
91 EXPECT_FALSE(can_delegate); 90 EXPECT_FALSE(can_delegate);
92 } 91 }
93 } 92 }
94 93
95
96 } // namespace net 94 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698