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 MockDelegate
: public PrivetV3Session::Delegate
{
24 MOCK_METHOD2(OnSetupConfirmationNeeded
,
25 void(const std::string
&,
26 extensions::api::gcd_private::ConfirmationType
));
27 MOCK_METHOD1(OnSessionStatus
, void(extensions::api::gcd_private::Status
));
30 class PrivetV3SessionTest
: public testing::Test
{
33 : session_(scoped_ptr
<PrivetHTTPClient
>(), &delegate_
) {}
35 virtual ~PrivetV3SessionTest() {}
38 base::MessageLoop::current()->PostTask(FROM_HERE
, quit_closure_
);
41 void ConfirmCode(const std::string
& code
,
42 extensions::api::gcd_private::ConfirmationType type
) {
43 session_
.ConfirmCode(code
);
47 virtual void SetUp() OVERRIDE
{
48 quit_closure_
= run_loop_
.QuitClosure();
49 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
, _
)).Times(0);
50 EXPECT_CALL(delegate_
, OnSessionStatus(_
)).Times(0);
53 StrictMock
<MockDelegate
> delegate_
;
54 PrivetV3Session session_
;
55 base::MessageLoop loop_
;
56 base::RunLoop run_loop_
;
57 base::Closure quit_closure_
;
60 TEST_F(PrivetV3SessionTest
, NotConfirmed
) {
61 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
, _
)).Times(1).WillOnce(
62 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop
));
67 TEST_F(PrivetV3SessionTest
, Confirmed
) {
68 EXPECT_CALL(delegate_
,
69 OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS
))
71 .WillOnce(InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop
));
72 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
, _
)).Times(1).WillOnce(
73 Invoke(this, &PrivetV3SessionTest::ConfirmCode
));
80 } // namespace local_discovery