Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/local_discovery/privetv3_session_unittest.cc

Issue 695253002: chrome.gcdPrivate allows app to choose pairing method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mon Nov 3 17:47:42 PST 2014 Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/local_discovery/privetv3_session.h" 5 #include "chrome/browser/local_discovery/privetv3_session.h"
6 6
7 #include "chrome/browser/local_discovery/privet_http.h" 7 #include "chrome/browser/local_discovery/privet_http.h"
8 #include "content/public/test/test_utils.h" 8 #include "content/public/test/test_utils.h"
9 #include "net/url_request/test_url_fetcher_factory.h" 9 #include "net/url_request/test_url_fetcher_factory.h"
10 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace local_discovery { 13 namespace local_discovery {
14 14
15 namespace { 15 namespace {
16 16
17 using testing::Invoke; 17 using testing::Invoke;
18 using testing::InvokeWithoutArgs; 18 using testing::InvokeWithoutArgs;
19 using testing::StrictMock; 19 using testing::StrictMock;
20 using testing::_; 20 using testing::_;
21 21
22 class MockDelegate : public PrivetV3Session::Delegate {
23 public:
24 MOCK_METHOD2(OnSetupConfirmationNeeded,
25 void(const std::string&,
26 extensions::api::gcd_private::ConfirmationType));
27 MOCK_METHOD1(OnSessionStatus, void(extensions::api::gcd_private::Status));
28 };
29
30 class PrivetV3SessionTest : public testing::Test { 22 class PrivetV3SessionTest : public testing::Test {
31 public: 23 public:
32 PrivetV3SessionTest() 24 PrivetV3SessionTest() : session_(scoped_ptr<PrivetHTTPClient>()) {}
33 : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {}
34 25
35 virtual ~PrivetV3SessionTest() {} 26 virtual ~PrivetV3SessionTest() {}
36 27
37 void QuitLoop() { 28 MOCK_METHOD2(OnInitialized,
38 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); 29 void(PrivetV3Session::Result,
39 } 30 const std::vector<PrivetV3Session::PairingType>&));
40 31 MOCK_METHOD1(OnPairingStarted, void(PrivetV3Session::Result));
41 void ConfirmCode(const std::string& code, 32 MOCK_METHOD1(OnCodeConfirmed, void(PrivetV3Session::Result));
42 extensions::api::gcd_private::ConfirmationType type) { 33 MOCK_METHOD2(OnMessageSend,
43 session_.ConfirmCode(code); 34 void(PrivetV3Session::Result,
44 } 35 const base::DictionaryValue& value));
45 36
46 protected: 37 protected:
47 virtual void SetUp() override { 38 virtual void SetUp() override {
48 quit_closure_ = run_loop_.QuitClosure(); 39 EXPECT_CALL(*this, OnInitialized(_, _)).Times(0);
49 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(0); 40 EXPECT_CALL(*this, OnPairingStarted(_)).Times(0);
50 EXPECT_CALL(delegate_, OnSessionStatus(_)).Times(0); 41 EXPECT_CALL(*this, OnCodeConfirmed(_)).Times(0);
51 } 42 }
52 43
53 StrictMock<MockDelegate> delegate_;
54 PrivetV3Session session_; 44 PrivetV3Session session_;
55 base::MessageLoop loop_; 45 base::MessageLoop loop_;
56 base::RunLoop run_loop_;
57 base::Closure quit_closure_; 46 base::Closure quit_closure_;
58 }; 47 };
59 48
60 TEST_F(PrivetV3SessionTest, NotConfirmed) { 49 TEST_F(PrivetV3SessionTest, Pairing) {
61 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce( 50 {
62 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); 51 base::RunLoop run_loop;
63 session_.Start(); 52 EXPECT_CALL(*this,
64 run_loop_.Run(); 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();
59 }
60
61 {
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();
71 }
72
73 {
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();
82 }
65 } 83 }
66 84
67 TEST_F(PrivetV3SessionTest, Confirmed) { 85 // TODO(vitalybuka): replace PrivetHTTPClient with regular URL fetcher and
68 EXPECT_CALL(delegate_, 86 // implement SendMessage test.
69 OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS))
70 .Times(1)
71 .WillOnce(InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop));
72 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce(
73 Invoke(this, &PrivetV3SessionTest::ConfirmCode));
74 session_.Start();
75 run_loop_.Run();
76 }
77 87
78 } // namespace 88 } // namespace
79 89
80 } // namespace local_discovery 90 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698