| Index: chrome/browser/local_discovery/privetv3_session_unittest.cc
|
| diff --git a/chrome/browser/local_discovery/privetv3_session_unittest.cc b/chrome/browser/local_discovery/privetv3_session_unittest.cc
|
| index 1c9f845fca0fbf2fe7c06429d6eeb53682dc473b..c7e794394ee0a82c9b0dd334c29a50e1a5eaa8be 100644
|
| --- a/chrome/browser/local_discovery/privetv3_session_unittest.cc
|
| +++ b/chrome/browser/local_discovery/privetv3_session_unittest.cc
|
| @@ -19,62 +19,72 @@ using testing::InvokeWithoutArgs;
|
| using testing::StrictMock;
|
| using testing::_;
|
|
|
| -class MockDelegate : public PrivetV3Session::Delegate {
|
| - public:
|
| - MOCK_METHOD2(OnSetupConfirmationNeeded,
|
| - void(const std::string&,
|
| - extensions::api::gcd_private::ConfirmationType));
|
| - MOCK_METHOD1(OnSessionStatus, void(extensions::api::gcd_private::Status));
|
| -};
|
| -
|
| class PrivetV3SessionTest : public testing::Test {
|
| public:
|
| - PrivetV3SessionTest()
|
| - : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {}
|
| + PrivetV3SessionTest() : session_(scoped_ptr<PrivetHTTPClient>()) {}
|
|
|
| virtual ~PrivetV3SessionTest() {}
|
|
|
| - void QuitLoop() {
|
| - base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
|
| - }
|
| -
|
| - void ConfirmCode(const std::string& code,
|
| - extensions::api::gcd_private::ConfirmationType type) {
|
| - session_.ConfirmCode(code);
|
| - }
|
| + MOCK_METHOD2(OnInitialized,
|
| + void(PrivetV3Session::Result,
|
| + const std::vector<PrivetV3Session::PairingType>&));
|
| + MOCK_METHOD1(OnPairingStarted, void(PrivetV3Session::Result));
|
| + MOCK_METHOD1(OnCodeConfirmed, void(PrivetV3Session::Result));
|
| + MOCK_METHOD2(OnMessageSend,
|
| + void(PrivetV3Session::Result,
|
| + const base::DictionaryValue& value));
|
|
|
| protected:
|
| virtual void SetUp() override {
|
| - quit_closure_ = run_loop_.QuitClosure();
|
| - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(0);
|
| - EXPECT_CALL(delegate_, OnSessionStatus(_)).Times(0);
|
| + EXPECT_CALL(*this, OnInitialized(_, _)).Times(0);
|
| + EXPECT_CALL(*this, OnPairingStarted(_)).Times(0);
|
| + EXPECT_CALL(*this, OnCodeConfirmed(_)).Times(0);
|
| }
|
|
|
| - StrictMock<MockDelegate> delegate_;
|
| PrivetV3Session session_;
|
| base::MessageLoop loop_;
|
| - base::RunLoop run_loop_;
|
| base::Closure quit_closure_;
|
| };
|
|
|
| -TEST_F(PrivetV3SessionTest, NotConfirmed) {
|
| - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce(
|
| - InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop));
|
| - session_.Start();
|
| - run_loop_.Run();
|
| -}
|
| +TEST_F(PrivetV3SessionTest, Pairing) {
|
| + {
|
| + base::RunLoop run_loop;
|
| + EXPECT_CALL(*this,
|
| + OnInitialized(PrivetV3Session::Result::STATUS_SUCCESS, _))
|
| + .Times(1)
|
| + .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| + session_.Init(base::Bind(&PrivetV3SessionTest::OnInitialized,
|
| + base::Unretained(this)));
|
| + run_loop.Run();
|
| + }
|
| +
|
| + {
|
| + base::RunLoop run_loop;
|
| + EXPECT_CALL(*this,
|
| + OnPairingStarted(PrivetV3Session::Result::STATUS_SUCCESS))
|
| + .Times(1)
|
| + .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| + session_.StartPairing(PrivetV3Session::PairingType::PAIRING_TYPE_PINCODE,
|
| + base::Bind(&PrivetV3SessionTest::OnPairingStarted,
|
| + base::Unretained(this)));
|
| + run_loop.Run();
|
| + }
|
|
|
| -TEST_F(PrivetV3SessionTest, Confirmed) {
|
| - EXPECT_CALL(delegate_,
|
| - OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS))
|
| - .Times(1)
|
| - .WillOnce(InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop));
|
| - EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce(
|
| - Invoke(this, &PrivetV3SessionTest::ConfirmCode));
|
| - session_.Start();
|
| - run_loop_.Run();
|
| + {
|
| + base::RunLoop run_loop;
|
| + EXPECT_CALL(*this, OnCodeConfirmed(PrivetV3Session::Result::STATUS_SUCCESS))
|
| + .Times(1)
|
| + .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
|
| + session_.ConfirmCode("1234",
|
| + base::Bind(&PrivetV3SessionTest::OnCodeConfirmed,
|
| + base::Unretained(this)));
|
| + run_loop.Run();
|
| + }
|
| }
|
|
|
| +// TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and
|
| +// implement SendMessage test.
|
| +
|
| } // namespace
|
|
|
| } // namespace local_discovery
|
|
|