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
3 // found in the LICENSE file.
5 #include "chrome/browser/local_discovery/privetv3_session.h"
7 #include "chrome/browser/local_discovery/privet_http.h"
8 #include "content/public/test/test_utils.h"
9 #include "net/url_request/test_url_fetcher_factory.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace local_discovery
{
17 using testing::Invoke
;
18 using testing::InvokeWithoutArgs
;
19 using testing::StrictMock
;
22 class PrivetV3SessionTest
: public testing::Test
{
24 PrivetV3SessionTest() : session_(scoped_ptr
<PrivetHTTPClient
>()) {}
26 virtual ~PrivetV3SessionTest() {}
28 MOCK_METHOD2(OnInitialized
,
29 void(PrivetV3Session::Result
,
30 const std::vector
<PrivetV3Session::PairingType
>&));
31 MOCK_METHOD1(OnPairingStarted
, void(PrivetV3Session::Result
));
32 MOCK_METHOD1(OnCodeConfirmed
, void(PrivetV3Session::Result
));
33 MOCK_METHOD2(OnMessageSend
,
34 void(PrivetV3Session::Result
,
35 const base::DictionaryValue
& value
));
38 virtual void SetUp() override
{
39 EXPECT_CALL(*this, OnInitialized(_
, _
)).Times(0);
40 EXPECT_CALL(*this, OnPairingStarted(_
)).Times(0);
41 EXPECT_CALL(*this, OnCodeConfirmed(_
)).Times(0);
44 PrivetV3Session session_
;
45 base::MessageLoop loop_
;
46 base::Closure quit_closure_
;
49 TEST_F(PrivetV3SessionTest
, Pairing
) {
51 base::RunLoop run_loop
;
53 OnInitialized(PrivetV3Session::Result::STATUS_SUCCESS
, _
))
55 .WillOnce(InvokeWithoutArgs(&run_loop
, &base::RunLoop::Quit
));
56 session_
.Init(base::Bind(&PrivetV3SessionTest::OnInitialized
,
57 base::Unretained(this)));
62 base::RunLoop run_loop
;
64 OnPairingStarted(PrivetV3Session::Result::STATUS_SUCCESS
))
66 .WillOnce(InvokeWithoutArgs(&run_loop
, &base::RunLoop::Quit
));
67 session_
.StartPairing(PrivetV3Session::PairingType::PAIRING_TYPE_PINCODE
,
68 base::Bind(&PrivetV3SessionTest::OnPairingStarted
,
69 base::Unretained(this)));
74 base::RunLoop run_loop
;
75 EXPECT_CALL(*this, OnCodeConfirmed(PrivetV3Session::Result::STATUS_SUCCESS
))
77 .WillOnce(InvokeWithoutArgs(&run_loop
, &base::RunLoop::Quit
));
78 session_
.ConfirmCode("1234",
79 base::Bind(&PrivetV3SessionTest::OnCodeConfirmed
,
80 base::Unretained(this)));
85 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and
86 // implement SendMessage test.
90 } // namespace local_discovery