Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / local_discovery / privetv3_session_unittest.cc
index fd117a4..c7e7943 100644 (file)
@@ -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);
+  virtual void SetUp() override {
+    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