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

Side by Side Diff: net/url_request/url_request_http_job_unittest.cc

Issue 2546213003: Implement net/ support for Android's NetworkSecurityPolicy (Closed)
Patch Set: More comments Created 4 years 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <memory> 10 #include <memory>
(...skipping 22 matching lines...) Expand all
33 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
34 #include "net/url_request/url_request_job_factory_impl.h" 34 #include "net/url_request/url_request_job_factory_impl.h"
35 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
36 #include "net/url_request/url_request_test_util.h" 36 #include "net/url_request/url_request_test_util.h"
37 #include "net/websockets/websocket_handshake_stream_base.h" 37 #include "net/websockets/websocket_handshake_stream_base.h"
38 #include "testing/gmock/include/gmock/gmock.h" 38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "url/gurl.h" 40 #include "url/gurl.h"
41 #include "url/url_constants.h" 41 #include "url/url_constants.h"
42 42
43 #if defined(OS_ANDROID)
44 #include "base/android/build_info.h"
45 #include "net/android/network_library.h"
46 #endif
47
43 using net::test::IsError; 48 using net::test::IsError;
44 using net::test::IsOk; 49 using net::test::IsOk;
45 50
46 namespace net { 51 namespace net {
47 52
48 namespace { 53 namespace {
49 54
50 using ::testing::Return; 55 using ::testing::Return;
51 56
52 const char kSimpleGetMockWrite[] = 57 const char kSimpleGetMockWrite[] =
(...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 base::RunLoop().RunUntilIdle(); 936 base::RunLoop().RunUntilIdle();
932 937
933 EXPECT_THAT(delegate.request_status(), IsOk()); 938 EXPECT_THAT(delegate.request_status(), IsOk());
934 EXPECT_EQ(12, request->received_response_content_length()); 939 EXPECT_EQ(12, request->received_response_content_length());
935 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 940 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
936 request->GetTotalSentBytes()); 941 request->GetTotalSentBytes());
937 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 942 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
938 request->GetTotalReceivedBytes()); 943 request->GetTotalReceivedBytes());
939 } 944 }
940 945
946 #if defined(OS_ANDROID)
947 TEST_F(URLRequestHttpJobTest, AndroidCleartextPermittedTest) {
948 context_.set_check_cleartext_permitted(true);
949 android::SetUpSecurityPolicyForTesting();
950
951 struct TestCase {
952 const char* url;
953 bool blocked;
954 } cases[] = {
955 {"http://blocked.test/", true}, {"https://blocked.test/", false},
956 };
957
958 for (const TestCase& test : cases) {
959 TestDelegate delegate;
960 std::unique_ptr<URLRequest> request =
961 context_.CreateRequest(GURL(test.url), DEFAULT_PRIORITY, &delegate);
962 request->Start();
963 base::RunLoop().Run();
964
965 int sdk_int = base::android::BuildInfo::GetInstance()->sdk_int();
966 bool expect_blocked =
967 (sdk_int >= base::android::SDK_VERSION_MARSHMALLOW && test.blocked);
968 if (expect_blocked) {
969 EXPECT_THAT(delegate.request_status(), IsError(ERR_BLOCKED_BY_CLIENT));
970 } else {
971 // Should fail since there's no test server running
972 EXPECT_THAT(delegate.request_status(), IsError(ERR_FAILED));
973 }
974 }
975 }
976 #endif
977
941 // This base class just serves to set up some things before the TestURLRequest 978 // This base class just serves to set up some things before the TestURLRequest
942 // constructor is called. 979 // constructor is called.
943 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test { 980 class URLRequestHttpJobWebSocketTestBase : public ::testing::Test {
944 protected: 981 protected:
945 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0), 982 URLRequestHttpJobWebSocketTestBase() : socket_data_(nullptr, 0, nullptr, 0),
946 context_(true) { 983 context_(true) {
947 // A Network Delegate is required for the WebSocketHandshakeStreamBase 984 // A Network Delegate is required for the WebSocketHandshakeStreamBase
948 // object to be passed on to the HttpNetworkTransaction. 985 // object to be passed on to the HttpNetworkTransaction.
949 context_.set_network_delegate(&network_delegate_); 986 context_.set_network_delegate(&network_delegate_);
950 987
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 base::RunLoop().RunUntilIdle(); 1133 base::RunLoop().RunUntilIdle();
1097 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING)); 1134 EXPECT_THAT(delegate_.request_status(), IsError(ERR_IO_PENDING));
1098 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); 1135 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called());
1099 } 1136 }
1100 1137
1101 #endif // BUILDFLAG(ENABLE_WEBSOCKETS) 1138 #endif // BUILDFLAG(ENABLE_WEBSOCKETS)
1102 1139
1103 } // namespace 1140 } // namespace
1104 1141
1105 } // namespace net 1142 } // namespace net
OLDNEW
« net/url_request/url_request_http_job.cc ('K') | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698