shill: Move PIN management to the capability delegates.

BUG=chromium-os:18735
TEST=unit tests

Change-Id: Icdaca0ee95f56d84e15a10029551a0abeaee79c1
Reviewed-on: https://gerrit.chromium.org/gerrit/11261
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/cellular_capability_gsm_unittest.cc b/cellular_capability_gsm_unittest.cc
new file mode 100644
index 0000000..01d6397
--- /dev/null
+++ b/cellular_capability_gsm_unittest.cc
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "shill/cellular_capability_gsm.h"
+
+#include <gtest/gtest.h>
+
+#include "shill/cellular.h"
+#include "shill/error.h"
+#include "shill/event_dispatcher.h"
+#include "shill/mock_modem_gsm_card_proxy.h"
+#include "shill/nice_mock_control.h"
+
+namespace shill {
+
+class CellularCapabilityGSMTest : public testing::Test {
+ public:
+  CellularCapabilityGSMTest()
+      : cellular_(new Cellular(&control_,
+                               &dispatcher_,
+                               NULL,
+                               "",
+                               "",
+                               0,
+                               Cellular::kTypeGSM,
+                               "",
+                               "",
+                               NULL)),
+        gsm_card_proxy_(new MockModemGSMCardProxy()),
+        capability_(cellular_.get()) {}
+
+ protected:
+  static const char kPIN[];
+  static const char kPUK[];
+
+  NiceMockControl control_;
+  EventDispatcher dispatcher_;
+  CellularRefPtr cellular_;
+  scoped_ptr<MockModemGSMCardProxy> gsm_card_proxy_;
+  CellularCapabilityGSM capability_;
+};
+
+const char CellularCapabilityGSMTest::kPIN[] = "9876";
+const char CellularCapabilityGSMTest::kPUK[] = "8765";
+
+TEST_F(CellularCapabilityGSMTest, RequirePIN) {
+  Error error;
+  EXPECT_CALL(*gsm_card_proxy_, EnablePIN(kPIN, true)).Times(1);
+  capability_.RequirePIN(kPIN, true, &error);
+  EXPECT_TRUE(error.IsSuccess());
+  cellular_->set_modem_gsm_card_proxy(gsm_card_proxy_.release());
+  dispatcher_.DispatchPendingEvents();
+}
+
+TEST_F(CellularCapabilityGSMTest, EnterPIN) {
+  Error error;
+  EXPECT_CALL(*gsm_card_proxy_, SendPIN(kPIN)).Times(1);
+  capability_.EnterPIN(kPIN, &error);
+  EXPECT_TRUE(error.IsSuccess());
+  cellular_->set_modem_gsm_card_proxy(gsm_card_proxy_.release());
+  dispatcher_.DispatchPendingEvents();
+}
+
+TEST_F(CellularCapabilityGSMTest, UnblockPIN) {
+  Error error;
+  EXPECT_CALL(*gsm_card_proxy_, SendPUK(kPUK, kPIN)).Times(1);
+  capability_.UnblockPIN(kPUK, kPIN, &error);
+  EXPECT_TRUE(error.IsSuccess());
+  cellular_->set_modem_gsm_card_proxy(gsm_card_proxy_.release());
+  dispatcher_.DispatchPendingEvents();
+}
+
+TEST_F(CellularCapabilityGSMTest, ChangePIN) {
+  static const char kOldPIN[] = "1111";
+  Error error;
+  EXPECT_CALL(*gsm_card_proxy_, ChangePIN(kOldPIN, kPIN)).Times(1);
+  capability_.ChangePIN(kOldPIN, kPIN, &error);
+  EXPECT_TRUE(error.IsSuccess());
+  cellular_->set_modem_gsm_card_proxy(gsm_card_proxy_.release());
+  dispatcher_.DispatchPendingEvents();
+}
+
+}  // namespace shill