privetv3_session_unittest.cc revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4
5#include "chrome/browser/local_discovery/privetv3_session.h"
6
7#include "chrome/browser/local_discovery/privet_http.h"
8#include "net/url_request/test_url_fetcher_factory.h"
9#include "testing/gmock/include/gmock/gmock.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace local_discovery {
13
14namespace {
15
16using testing::InvokeWithoutArgs;
17using testing::StrictMock;
18using testing::_;
19
20class MockDelegate : public PrivetV3Session::Delegate {
21 public:
22  MOCK_METHOD1(OnSetupConfirmationNeeded, void(const std::string&));
23  MOCK_METHOD0(OnSessionEstablished, void());
24  MOCK_METHOD0(OnCannotEstablishSession, void());
25};
26
27class PrivetV3SessionTest : public testing::Test {
28 public:
29  PrivetV3SessionTest()
30      : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {}
31
32  virtual ~PrivetV3SessionTest() {}
33
34 protected:
35  virtual void SetUp() OVERRIDE {
36    EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(0);
37    EXPECT_CALL(delegate_, OnSessionEstablished()).Times(0);
38    EXPECT_CALL(delegate_, OnCannotEstablishSession()).Times(0);
39  }
40
41  StrictMock<MockDelegate> delegate_;
42  PrivetV3Session session_;
43};
44
45TEST_F(PrivetV3SessionTest, NotConfirmed) {
46  EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1);
47  session_.Start();
48}
49
50TEST_F(PrivetV3SessionTest, Confirmed) {
51  EXPECT_CALL(delegate_, OnSessionEstablished()).Times(1);
52  EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1).WillOnce(
53      InvokeWithoutArgs(&session_, &PrivetV3Session::ConfirmCode));
54  session_.Start();
55}
56
57}  // namespace
58
59}  // namespace local_discovery
60