OLD | NEW |
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 "chrome/browser/local_discovery/privetv3_session.h" | 5 #include "chrome/browser/local_discovery/privetv3_session.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/local_discovery/privet_http.h" | 9 #include "chrome/browser/local_discovery/privet_http.h" |
10 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 MockPrivetHTTPClient() { | 42 MockPrivetHTTPClient() { |
43 request_context_ = | 43 request_context_ = |
44 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 44 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); |
45 } | 45 } |
46 | 46 |
47 MOCK_METHOD0(GetName, const std::string&()); | 47 MOCK_METHOD0(GetName, const std::string&()); |
48 MOCK_METHOD1( | 48 MOCK_METHOD1( |
49 CreateInfoOperationPtr, | 49 CreateInfoOperationPtr, |
50 PrivetJSONOperation*(const PrivetJSONOperation::ResultCallback&)); | 50 PrivetJSONOperation*(const PrivetJSONOperation::ResultCallback&)); |
51 | 51 |
52 virtual void RefreshPrivetToken( | 52 void RefreshPrivetToken( |
53 const PrivetURLFetcher::TokenCallback& callback) override { | 53 const PrivetURLFetcher::TokenCallback& callback) override { |
54 FAIL(); | 54 FAIL(); |
55 } | 55 } |
56 | 56 |
57 virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation( | 57 scoped_ptr<PrivetJSONOperation> CreateInfoOperation( |
58 const PrivetJSONOperation::ResultCallback& callback) override { | 58 const PrivetJSONOperation::ResultCallback& callback) override { |
59 return make_scoped_ptr(CreateInfoOperationPtr(callback)); | 59 return make_scoped_ptr(CreateInfoOperationPtr(callback)); |
60 } | 60 } |
61 | 61 |
62 virtual scoped_ptr<PrivetURLFetcher> CreateURLFetcher( | 62 scoped_ptr<PrivetURLFetcher> CreateURLFetcher( |
63 const GURL& url, | 63 const GURL& url, |
64 net::URLFetcher::RequestType request_type, | 64 net::URLFetcher::RequestType request_type, |
65 PrivetURLFetcher::Delegate* delegate) override { | 65 PrivetURLFetcher::Delegate* delegate) override { |
66 return make_scoped_ptr(new PrivetURLFetcher( | 66 return make_scoped_ptr(new PrivetURLFetcher( |
67 url, request_type, request_context_.get(), delegate)); | 67 url, request_type, request_context_.get(), delegate)); |
68 } | 68 } |
69 | 69 |
70 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | 70 scoped_refptr<net::TestURLRequestContextGetter> request_context_; |
71 }; | 71 }; |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 class PrivetV3SessionTest : public testing::Test { | 75 class PrivetV3SessionTest : public testing::Test { |
76 public: | 76 public: |
77 PrivetV3SessionTest() | 77 PrivetV3SessionTest() |
78 : fetcher_factory_(nullptr), | 78 : fetcher_factory_(nullptr), |
79 session_(make_scoped_ptr(new MockPrivetHTTPClient())) {} | 79 session_(make_scoped_ptr(new MockPrivetHTTPClient())) {} |
80 | 80 |
81 virtual ~PrivetV3SessionTest() {} | 81 ~PrivetV3SessionTest() override {} |
82 | 82 |
83 MOCK_METHOD2(OnInitialized, void(Result, const std::vector<PairingType>&)); | 83 MOCK_METHOD2(OnInitialized, void(Result, const std::vector<PairingType>&)); |
84 MOCK_METHOD1(OnPairingStarted, void(Result)); | 84 MOCK_METHOD1(OnPairingStarted, void(Result)); |
85 MOCK_METHOD1(OnCodeConfirmed, void(Result)); | 85 MOCK_METHOD1(OnCodeConfirmed, void(Result)); |
86 MOCK_METHOD2(OnMessageSend, void(Result, const base::DictionaryValue& value)); | 86 MOCK_METHOD2(OnMessageSend, void(Result, const base::DictionaryValue& value)); |
87 MOCK_METHOD1(OnPostData, void(const base::DictionaryValue& data)); | 87 MOCK_METHOD1(OnPostData, void(const base::DictionaryValue& data)); |
88 | 88 |
89 protected: | 89 protected: |
90 virtual void SetUp() override { | 90 void SetUp() override { |
91 EXPECT_CALL(*this, OnInitialized(_, _)).Times(0); | 91 EXPECT_CALL(*this, OnInitialized(_, _)).Times(0); |
92 EXPECT_CALL(*this, OnPairingStarted(_)).Times(0); | 92 EXPECT_CALL(*this, OnPairingStarted(_)).Times(0); |
93 EXPECT_CALL(*this, OnCodeConfirmed(_)).Times(0); | 93 EXPECT_CALL(*this, OnCodeConfirmed(_)).Times(0); |
94 EXPECT_CALL(*this, OnMessageSend(_, _)).Times(0); | 94 EXPECT_CALL(*this, OnMessageSend(_, _)).Times(0); |
95 EXPECT_CALL(*this, OnPostData(_)).Times(0); | 95 EXPECT_CALL(*this, OnPostData(_)).Times(0); |
96 session_.on_post_data_ = | 96 session_.on_post_data_ = |
97 base::Bind(&PrivetV3SessionTest::OnPostData, base::Unretained(this)); | 97 base::Bind(&PrivetV3SessionTest::OnPostData, base::Unretained(this)); |
98 } | 98 } |
99 | 99 |
100 base::MessageLoop loop_; | 100 base::MessageLoop loop_; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 .WillOnce(testing::Invoke([this](const base::DictionaryValue& data) { | 287 .WillOnce(testing::Invoke([this](const base::DictionaryValue& data) { |
288 std::string session_id; | 288 std::string session_id; |
289 EXPECT_TRUE(data.GetString("sessionId", &session_id)); | 289 EXPECT_TRUE(data.GetString("sessionId", &session_id)); |
290 })); | 290 })); |
291 } | 291 } |
292 | 292 |
293 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and | 293 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and |
294 // implement SendMessage test. | 294 // implement SendMessage test. |
295 | 295 |
296 } // namespace local_discovery | 296 } // namespace local_discovery |
OLD | NEW |