OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/http/bidirectional_stream_create_helper.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "net/base/net_errors.h" |
| 10 #include "net/http/http_request_info.h" |
| 11 #include "net/url_request/url_request_test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 namespace { |
| 17 |
| 18 class TestCreateHelperDelegate |
| 19 : public BidirectionalStreamCreateHelper::Delegate { |
| 20 public: |
| 21 TestCreateHelperDelegate() : error_code_(OK), loop_(new base::RunLoop) {} |
| 22 |
| 23 ~TestCreateHelperDelegate() override {} |
| 24 |
| 25 void OnStreamCreated() override { loop_->Quit(); } |
| 26 |
| 27 void OnStreamFailed(int error) override { |
| 28 error_code_ = error; |
| 29 loop_->Quit(); |
| 30 } |
| 31 |
| 32 void CreateBidirectionalStream(const HttpRequestInfo* request_info, |
| 33 RequestPriority priority, |
| 34 const URLRequestContext* context) { |
| 35 helper_.reset(new BidirectionalStreamCreateHelper(request_info, priority, |
| 36 context, this)); |
| 37 helper_->CreateBidirectionalStream(); |
| 38 loop_->Run(); |
| 39 } |
| 40 |
| 41 int error_code_; |
| 42 |
| 43 private: |
| 44 scoped_ptr<base::RunLoop> loop_; |
| 45 scoped_ptr<BidirectionalStreamCreateHelper> helper_; |
| 46 }; |
| 47 } |
| 48 |
| 49 class BidirectionalStreamCreateHelperTest : public testing::Test {}; |
| 50 |
| 51 TEST_F(BidirectionalStreamCreateHelperTest, CreateInsecureStream) { |
| 52 HttpRequestInfo request; |
| 53 request.method = "GET"; |
| 54 request.url = GURL("http://www.example.org/"); |
| 55 |
| 56 TestURLRequestContext context; |
| 57 TestCreateHelperDelegate delegate; |
| 58 delegate.CreateBidirectionalStream(&request, LOWEST, &context); |
| 59 EXPECT_EQ(ERR_DISALLOWED_URL_SCHEME, delegate.error_code_); |
| 60 } |
| 61 |
| 62 } // namespace net |
OLD | NEW |