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

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

Issue 468613003: API change to allow sticker authentication for devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 months 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 | Annotate | Revision Log
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 { 22 class MockDelegate : public PrivetV3Session::Delegate {
23 public: 23 public:
24 MOCK_METHOD1(OnSetupConfirmationNeeded, void(const std::string&)); 24 MOCK_METHOD2(OnSetupConfirmationNeeded,
25 MOCK_METHOD0(OnSessionEstablished, void()); 25 void(const std::string&,
26 MOCK_METHOD0(OnCannotEstablishSession, void()); 26 extensions::api::gcd_private::ConfirmationType));
27 MOCK_METHOD1(OnSessionStatus, void(extensions::api::gcd_private::Status));
27 }; 28 };
28 29
29 class PrivetV3SessionTest : public testing::Test { 30 class PrivetV3SessionTest : public testing::Test {
30 public: 31 public:
31 PrivetV3SessionTest() 32 PrivetV3SessionTest()
32 : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {} 33 : session_(scoped_ptr<PrivetHTTPClient>(), &delegate_) {}
33 34
34 virtual ~PrivetV3SessionTest() {} 35 virtual ~PrivetV3SessionTest() {}
35 36
36 void QuitLoop() { 37 void QuitLoop() {
37 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); 38 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_);
38 } 39 }
39 40
41 void ConfirmCode(const std::string& code,
42 extensions::api::gcd_private::ConfirmationType type) {
43 session_.ConfirmCode(code);
44 }
45
40 protected: 46 protected:
41 virtual void SetUp() OVERRIDE { 47 virtual void SetUp() OVERRIDE {
42 quit_closure_ = run_loop_.QuitClosure(); 48 quit_closure_ = run_loop_.QuitClosure();
43 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(0); 49 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(0);
44 EXPECT_CALL(delegate_, OnSessionEstablished()).Times(0); 50 EXPECT_CALL(delegate_, OnSessionStatus(_)).Times(0);
45 EXPECT_CALL(delegate_, OnCannotEstablishSession()).Times(0);
46 } 51 }
47 52
48 StrictMock<MockDelegate> delegate_; 53 StrictMock<MockDelegate> delegate_;
49 PrivetV3Session session_; 54 PrivetV3Session session_;
50 base::MessageLoop loop_; 55 base::MessageLoop loop_;
51 base::RunLoop run_loop_; 56 base::RunLoop run_loop_;
52 base::Closure quit_closure_; 57 base::Closure quit_closure_;
53 }; 58 };
54 59
55 TEST_F(PrivetV3SessionTest, NotConfirmed) { 60 TEST_F(PrivetV3SessionTest, NotConfirmed) {
56 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1).WillOnce( 61 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce(
57 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); 62 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop));
58 session_.Start(); 63 session_.Start();
59 run_loop_.Run(); 64 run_loop_.Run();
60 } 65 }
61 66
62 TEST_F(PrivetV3SessionTest, Confirmed) { 67 TEST_F(PrivetV3SessionTest, Confirmed) {
63 EXPECT_CALL(delegate_, OnSessionEstablished()).Times(1).WillOnce( 68 EXPECT_CALL(delegate_,
64 InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop)); 69 OnSessionStatus(extensions::api::gcd_private::STATUS_SUCCESS))
65 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_)).Times(1).WillOnce( 70 .Times(1)
66 InvokeWithoutArgs(&session_, &PrivetV3Session::ConfirmCode)); 71 .WillOnce(InvokeWithoutArgs(this, &PrivetV3SessionTest::QuitLoop));
72 EXPECT_CALL(delegate_, OnSetupConfirmationNeeded(_, _)).Times(1).WillOnce(
73 Invoke(this, &PrivetV3SessionTest::ConfirmCode));
67 session_.Start(); 74 session_.Start();
68 run_loop_.Run(); 75 run_loop_.Run();
69 } 76 }
70 77
71 } // namespace 78 } // namespace
72 79
73 } // namespace local_discovery 80 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privetv3_session.cc ('k') | chrome/browser/local_discovery/privetv3_setup_flow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698