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_METHOD1(OnSetupConfirmationNeeded
, void(const std::string
&));
25 MOCK_METHOD0(OnSessionEstablished
, void());
26 MOCK_METHOD0(OnCannotEstablishSession
, void());
29 class PrivetV3SessionTest
: public testing::Test
{
32 : session_(scoped_ptr
<PrivetHTTPClient
>(), &delegate_
) {}
34 virtual ~PrivetV3SessionTest() {}
37 base::MessageLoop::current()->PostTask(FROM_HERE
, quit_closure_
);
41 virtual void SetUp() OVERRIDE
{
42 quit_closure_
= run_loop_
.QuitClosure();
43 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
)).Times(0);
44 EXPECT_CALL(delegate_
, OnSessionEstablished()).Times(0);
45 EXPECT_CALL(delegate_
, OnCannotEstablishSession()).Times(0);
48 StrictMock
<MockDelegate
> delegate_
;
49 PrivetV3Session session_
;
50 base::MessageLoop loop_
;
51 base::RunLoop run_loop_
;
52 base::Closure quit_closure_
;
55 TEST_F(PrivetV3SessionTest
, NotConfirmed
) {
56 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
)).Times(1).WillOnce(
57 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop
));
62 TEST_F(PrivetV3SessionTest
, Confirmed
) {
63 EXPECT_CALL(delegate_
, OnSessionEstablished()).Times(1).WillOnce(
64 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop
));
65 EXPECT_CALL(delegate_
, OnSetupConfirmationNeeded(_
)).Times(1).WillOnce(
66 InvokeWithoutArgs(&session_
, &PrivetV3Session::ConfirmCode
));
73 } // namespace local_discovery