Roll src/third_party/WebKit 8b42d1d:744641d (svn 186770:186771)
[chromium-blink-merge.git] / chrome / browser / local_discovery / privetv3_session_unittest.cc
blobc7e794394ee0a82c9b0dd334c29a50e1a5eaa8be
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 PrivetV3SessionTest : public testing::Test {
23 public:
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));
37 protected:
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;
52 EXPECT_CALL(*this,
53 OnInitialized(PrivetV3Session::Result::STATUS_SUCCESS, _))
54 .Times(1)
55 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
56 session_.Init(base::Bind(&PrivetV3SessionTest::OnInitialized,
57 base::Unretained(this)));
58 run_loop.Run();
62 base::RunLoop run_loop;
63 EXPECT_CALL(*this,
64 OnPairingStarted(PrivetV3Session::Result::STATUS_SUCCESS))
65 .Times(1)
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)));
70 run_loop.Run();
74 base::RunLoop run_loop;
75 EXPECT_CALL(*this, OnCodeConfirmed(PrivetV3Session::Result::STATUS_SUCCESS))
76 .Times(1)
77 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
78 session_.ConfirmCode("1234",
79 base::Bind(&PrivetV3SessionTest::OnCodeConfirmed,
80 base::Unretained(this)));
81 run_loop.Run();
85 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and
86 // implement SendMessage test.
88 } // namespace
90 } // namespace local_discovery