Update mojo surfaces bindings and mojo/cc/ glue
[chromium-blink-merge.git] / chrome / browser / local_discovery / privetv3_session_unittest.cc
blob6a2176042679afc2e7efd1734865c98955914615
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 {
15 namespace {
17 using testing::Invoke;
18 using testing::InvokeWithoutArgs;
19 using testing::StrictMock;
20 using testing::_;
22 class MockDelegate : public PrivetV3Session::Delegate {
23 public:
24 MOCK_METHOD1(OnSetupConfirmationNeeded, void(const std::string&));
25 MOCK_METHOD0(OnSessionEstablished, void());
26 MOCK_METHOD0(OnCannotEstablishSession, void());
29 class PrivetV3SessionTest : public testing::Test {
30 public:
31 PrivetV3SessionTest()
32 : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {}
34 virtual ~PrivetV3SessionTest() {}
36 void QuitLoop() {
37 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
40 protected:
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));
58 session_.Start();
59 run_loop_.Run();
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));
67 session_.Start();
68 run_loop_.Run();
71 } // namespace
73 } // namespace local_discovery