diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-25 20:39:54 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-25 20:39:54 +0000 |
commit | 6f9396659fe310830483e1239816ec90d27a4b35 (patch) | |
tree | 1ab2b1ec89c7cf0f8548e8cad19d4116373f25b3 | |
parent | 53a6c1eff8bedf9638d4d4c3f2c23898b4587bcc (diff) | |
download | chromium_src-6f9396659fe310830483e1239816ec90d27a4b35.zip chromium_src-6f9396659fe310830483e1239816ec90d27a4b35.tar.gz chromium_src-6f9396659fe310830483e1239816ec90d27a4b35.tar.bz2 |
Eliminate use of sim unlock UI notifications
This includes some changes to the Fake Shill implementation to support
enabling sim lock to test the UI. (Was also tested using pseudomodem).
BUG=279351
For c/b/resources
TBR=xiyuan@chromium.org
Review URL: https://codereview.chromium.org/399303003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285666 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chrome_notification_types.h | 12 | ||||
-rw-r--r-- | chrome/browser/chromeos/sim_dialog_delegate.cc | 19 | ||||
-rw-r--r-- | chrome/browser/resources/chromeos/sim_unlock.js | 1 | ||||
-rw-r--r-- | chrome/browser/resources/options/chromeos/internet_detail.js | 29 | ||||
-rw-r--r-- | chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc | 69 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc | 40 | ||||
-rw-r--r-- | chrome/browser/ui/webui/options/chromeos/internet_options_handler.h | 14 | ||||
-rw-r--r-- | chromeos/chromeos_switches.cc | 7 | ||||
-rw-r--r-- | chromeos/dbus/fake_shill_device_client.cc | 37 | ||||
-rw-r--r-- | chromeos/dbus/fake_shill_manager_client.cc | 80 | ||||
-rw-r--r-- | chromeos/dbus/fake_shill_manager_client.h | 3 | ||||
-rw-r--r-- | chromeos/network/network_device_handler_unittest.cc | 21 |
12 files changed, 157 insertions, 175 deletions
diff --git a/chrome/browser/chrome_notification_types.h b/chrome/browser/chrome_notification_types.h index eddec14..8810e5a 100644 --- a/chrome/browser/chrome_notification_types.h +++ b/chrome/browser/chrome_notification_types.h @@ -767,18 +767,6 @@ enum NotificationType { // Other singleton-based services can't use that because Observer // unregistration is impossible due to unpredictable deletion order. NOTIFICATION_OWNERSHIP_STATUS_CHANGED, - - // Sent by SIM unlock dialog when it has finished with the process of - // updating RequirePin setting. RequirePin setting might have been changed - // to a new value or update might have been canceled. - // In either case notification is sent and details contain a bool - // that represents current value. - NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, - - // Sent by SIM unlock dialog when it has finished the EnterPin or - // EnterPuk dialog, either because the user cancelled, or entered a - // PIN or PUK. - NOTIFICATION_ENTER_PIN_ENDED, #endif #if defined(TOOLKIT_VIEWS) diff --git a/chrome/browser/chromeos/sim_dialog_delegate.cc b/chrome/browser/chromeos/sim_dialog_delegate.cc index d61c0e4..ebb819f 100644 --- a/chrome/browser/chromeos/sim_dialog_delegate.cc +++ b/chrome/browser/chromeos/sim_dialog_delegate.cc @@ -24,14 +24,6 @@ const int kDefaultHeight = 225; const int kChangePinWidth = 350; const int kChangePinHeight = 245; -// URL that includes additional mode (other than Unlock flow) that we're using -// dialog for. Possible values: -// change-pin - use dialog to change PIN, ask for old & new PIN. -// set-lock-on - enable RequirePin restriction. -// set-lock-off - disable RequirePin restriction. -// In general SIM unlock case sim-unlock URL is loaded w/o parameters. -const char kSimDialogSpecialModeURL[] = "chrome://sim-unlock/?mode=%s"; - // Dialog mode constants. const char kSimDialogChangePinMode[] = "change-pin"; const char kSimDialogSetLockOnMode[] = "set-lock-on"; @@ -76,8 +68,15 @@ GURL SimDialogDelegate::GetDialogContentURL() const { mode_value = kSimDialogSetLockOnMode; else mode_value = kSimDialogSetLockOffMode; - return GURL( - base::StringPrintf(kSimDialogSpecialModeURL, mode_value.c_str())); + + // Create a URL that includes an additional mode (other than Unlock flow). + // Possible values for mode are: + // change-pin - use dialog to change PIN, ask for old & new PIN. + // set-lock-on - enable RequirePin restriction. + // set-lock-off - disable RequirePin restriction. + std::string url_string = + std::string(chrome::kChromeUISimUnlockURL) + "?mode=" + mode_value; + return GURL(url_string); } } diff --git a/chrome/browser/resources/chromeos/sim_unlock.js b/chrome/browser/resources/chromeos/sim_unlock.js index c77ccbd..eba753a 100644 --- a/chrome/browser/resources/chromeos/sim_unlock.js +++ b/chrome/browser/resources/chromeos/sim_unlock.js @@ -207,7 +207,6 @@ cr.define('mobile', function() { }; SimUnlock.cancel = function() { - chrome.send('cancel'); SimUnlock.close(); }; diff --git a/chrome/browser/resources/options/chromeos/internet_detail.js b/chrome/browser/resources/options/chromeos/internet_detail.js index c3cc240..0803e11 100644 --- a/chrome/browser/resources/options/chromeos/internet_detail.js +++ b/chrome/browser/resources/options/chromeos/internet_detail.js @@ -435,20 +435,26 @@ cr.define('options.internet', function() { updateHidden('#details-internet-page .wimax-details', !this.wimax); updateHidden('#details-internet-page .vpn-details', !this.vpn); updateHidden('#details-internet-page .proxy-details', !this.showProxy); + + // Cellular + // Conditionally call updateHidden on .gsm-only, so that we don't unhide // a previously hidden element. if (this.gsm) updateHidden('#details-internet-page .cdma-only', true); else updateHidden('#details-internet-page .gsm-only', true); - /* Network information merged into the Wifi tab for wireless networks - unless the option is set for enabling a static IP configuration. */ + + // Wifi + + // Network information merged into the Wifi tab for wireless networks + // unless the option is set for enabling a static IP configuration. updateHidden('#details-internet-page .network-details', (this.wireless && !this.showStaticIPConfig) || this.vpn); updateHidden('#details-internet-page .wifi-network-setting', this.showStaticIPConfig); - // Wifi - Password and shared. + // Password and shared. updateHidden('#details-internet-page #password-details', !this.wireless || !this.hasSecurity); updateHidden('#details-internet-page #wifi-shared-network', @@ -703,11 +709,6 @@ cr.define('options.internet', function() { DetailsInternetPage.showCarrierChangeSpinner(false); }; - DetailsInternetPage.updateSecurityTab = function(requirePin) { - $('sim-card-lock-enabled').checked = requirePin; - $('change-pin').hidden = !requirePin; - }; - DetailsInternetPage.loginFromDetails = function() { var data = $('connection-state').data; var servicePath = data.servicePath; @@ -881,6 +882,13 @@ cr.define('options.internet', function() { $('activate-details').hidden = !data.showActivateButton; if (data.showActivateButton) $('details-internet-login').hidden = true; + + if (detailsPage.gsm) { + // TODO(stevenjb): Use managed properties for policy controlled values. + var lockEnabled = data.simCardLockEnabled.value; + $('sim-card-lock-enabled').checked = lockEnabled; + $('change-pin').hidden = !lockEnabled; + } } $('connection-state').data = data; @@ -1223,7 +1231,10 @@ cr.define('options.internet', function() { apnSelector.selectedIndex = data.selectedApn; updateHidden('.apn-list-view', false); updateHidden('.apn-details-view', true); - DetailsInternetPage.updateSecurityTab(data.simCardLockEnabled.value); + // TODO(stevenjb): Used managed properties for policy controlled value. + var lockEnabled = data.simCardLockEnabled.value; + $('sim-card-lock-enabled').checked = lockEnabled; + $('change-pin').hidden = !lockEnabled; } $('auto-connect-network-cellular').checked = data.autoConnect.value; $('auto-connect-network-cellular').disabled = false; diff --git a/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc b/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc index d983a23..906795c 100644 --- a/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc +++ b/chrome/browser/ui/webui/chromeos/sim_unlock_ui.cc @@ -16,7 +16,6 @@ #include "base/message_loop/message_loop.h" #include "base/strings/string_piece.h" #include "base/values.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/sim_dialog_delegate.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/url_constants.h" @@ -26,7 +25,6 @@ #include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler_observer.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" @@ -46,7 +44,6 @@ using content::WebUIMessageHandler; namespace { // JS API callbacks names. -const char kJsApiCancel[] = "cancel"; const char kJsApiChangePinCode[] = "changePinCode"; const char kJsApiEnterPinCode[] = "enterPinCode"; const char kJsApiEnterPukCode[] = "enterPukCode"; @@ -162,11 +159,6 @@ class SimUnlockHandler : public WebUIMessageHandler, code_type_(code_type) { } - void HandleCancel() { - if (handler_) - handler_->CancelDialog(); - } - void HandleEnterCode() { if (handler_) handler_->EnterCode(code_, code_type_); @@ -201,9 +193,6 @@ class SimUnlockHandler : public WebUIMessageHandler, // Returns the cellular device that this dialog currently corresponds to. const DeviceState* GetCellularDevice(); - // Processing for the cases when dialog was cancelled. - void CancelDialog(); - // Pass PIN/PUK code to shill and check status. void EnterCode(const std::string& code, SimUnlockCode code_type); @@ -224,7 +213,6 @@ class SimUnlockHandler : public WebUIMessageHandler, void HandleEnterCode(SimUnlockCode code_type, const std::string& code); // Handlers for JS WebUI messages. - void HandleCancel(const base::ListValue* args); void HandleChangePinCode(const base::ListValue* args); void HandleEnterPinCode(const base::ListValue* args); void HandleEnterPukCode(const base::ListValue* args); @@ -234,14 +222,6 @@ class SimUnlockHandler : public WebUIMessageHandler, // Initialize current SIM card status, passes that to page. void InitializeSimStatus(); - // Notifies SIM Security tab handler that RequirePin preference change - // has been ended (either updated or cancelled). - void NotifyOnRequirePinChangeEnded(bool new_value); - - // Notifies observers that the EnterPin or EnterPuk dialog has been - // completed (either cancelled or with entry of PIN/PUK). - void NotifyOnEnterPinEnded(bool cancelled); - // Checks whether SIM card is in PUK locked state and proceeds to PUK input. void ProceedToPukInput(); @@ -295,7 +275,6 @@ void SimUnlockUIHTMLSource::StartDataRequest( strings.SetString("title", l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); strings.SetString("ok", l10n_util::GetStringUTF16(IDS_OK)); - strings.SetString("cancel", l10n_util::GetStringUTF16(IDS_CANCEL)); strings.SetString("enterPinTitle", l10n_util::GetStringUTF16(IDS_SIM_UNLOCK_ENTER_PIN_TITLE)); strings.SetString("enterPinMessage", @@ -373,9 +352,6 @@ SimUnlockHandler::~SimUnlockHandler() { } void SimUnlockHandler::RegisterMessages() { - web_ui()->RegisterMessageCallback(kJsApiCancel, - base::Bind(&SimUnlockHandler::HandleCancel, - base::Unretained(this))); web_ui()->RegisterMessageCallback(kJsApiChangePinCode, base::Bind(&SimUnlockHandler::HandleChangePinCode, base::Unretained(this))); @@ -428,9 +404,6 @@ void SimUnlockHandler::OnPinOperationCompleted(PinOperationError error) { if (state_ == SIM_NOT_LOCKED_ASK_PIN && error == PIN_ERROR_NONE) { CHECK(dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON || dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF); - // Async change RequirePin operation has finished OK. - NotifyOnRequirePinChangeEnded( - dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON); // Dialog will close itself. state_ = SIM_ABSENT_NOT_LOCKED; } else if (state_ == SIM_NOT_LOCKED_CHANGE_PIN && error == PIN_ERROR_NONE) { @@ -443,29 +416,12 @@ void SimUnlockHandler::OnPinOperationCompleted(PinOperationError error) { // NO_PIN_RETRIES_LEFT step. if (!(state_ == SIM_LOCKED_NO_PIN_TRIES_LEFT && error == PIN_ERROR_BLOCKED)) ProcessSimCardState(cellular); - if (dialog_mode_ == SimDialogDelegate::SIM_DIALOG_UNLOCK && - state_ == SIM_ABSENT_NOT_LOCKED) - NotifyOnEnterPinEnded(false); } const DeviceState* SimUnlockHandler::GetCellularDevice() { return GetNetworkStateHandler()->GetDeviceState(cellular_device_path_); } -void SimUnlockHandler::CancelDialog() { - if (dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON || - dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF) { - // When async change RequirePin operation is performed, - // dialog UI controls such as Cancel button are disabled. - // If dialog was cancelled that means RequirePin preference hasn't been - // changed and is not in process of changing at the moment. - NotifyOnRequirePinChangeEnded( - !(dialog_mode_ == SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON)); - } else if (dialog_mode_ == SimDialogDelegate::SIM_DIALOG_UNLOCK) { - NotifyOnEnterPinEnded(true); - } -} - void SimUnlockHandler::EnterCode(const std::string& code, SimUnlockCode code_type) { DCHECK_CURRENTLY_ON(BrowserThread::UI); @@ -605,31 +561,6 @@ void SimUnlockHandler::PinOperationErrorCallback( OnPinOperationCompleted(pin_error); } -void SimUnlockHandler::NotifyOnEnterPinEnded(bool cancelled) { - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_ENTER_PIN_ENDED, - content::NotificationService::AllSources(), - content::Details<bool>(&cancelled)); -} - -void SimUnlockHandler::NotifyOnRequirePinChangeEnded(bool new_value) { - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, - content::NotificationService::AllSources(), - content::Details<bool>(&new_value)); -} - -void SimUnlockHandler::HandleCancel(const base::ListValue* args) { - const size_t kEnterCodeParamCount = 0; - if (args->GetSize() != kEnterCodeParamCount) { - NOTREACHED(); - return; - } - scoped_refptr<TaskProxy> task = new TaskProxy(AsWeakPtr()); - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - base::Bind(&TaskProxy::HandleCancel, task.get())); -} - void SimUnlockHandler::HandleChangePinCode(const base::ListValue* args) { const size_t kChangePinParamCount = 2; std::string pin; diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc index a31fe74..ca679e2 100644 --- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc +++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc @@ -18,7 +18,6 @@ #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/mobile_config.h" #include "chrome/browser/chromeos/net/onc_utils.h" #include "chrome/browser/chromeos/options/network_config_view.h" @@ -46,7 +45,6 @@ #include "chromeos/network/onc/onc_signature.h" #include "chromeos/network/onc/onc_translator.h" #include "components/onc/onc_constants.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" @@ -102,8 +100,6 @@ const char kUpdateConnectionDataFunction[] = "options.internet.DetailsInternetPage.updateConnectionData"; const char kUpdateCarrierFunction[] = "options.internet.DetailsInternetPage.updateCarrier"; -const char kUpdateSecurityTabFunction[] = - "options.internet.DetailsInternetPage.updateSecurityTab"; // These are used to register message handlers with JavaScript. const char kBuyDataPlanMessage[] = "buyDataPlan"; @@ -708,10 +704,6 @@ void RequestReconnect(const std::string& service_path, InternetOptionsHandler::InternetOptionsHandler() : weak_factory_(this) { - registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, - content::NotificationService::AllSources()); - registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, - content::NotificationService::AllSources()); NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); } @@ -1004,7 +996,8 @@ void InternetOptionsHandler::SetSimCardLockCallback( // 2. Dialog will ask for current PIN in any case. // 3. If card is locked it will first call PIN unlock operation // 4. Then it will call Set RequirePin, passing the same PIN. - // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification. + // 5. The dialog may change device properties, in which case + // DevicePropertiesUpdated() will get called which will update the UI. SimDialogDelegate::SimDialogMode mode; if (require_pin_new_value) mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON; @@ -1091,24 +1084,17 @@ void InternetOptionsHandler::NetworkPropertiesUpdated( UpdateConnectionData(network->path()); } -void InternetOptionsHandler::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) { - base::FundamentalValue require_pin(*content::Details<bool>(details).ptr()); - web_ui()->CallJavascriptFunction( - kUpdateSecurityTabFunction, require_pin); - } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) { - // We make an assumption (which is valid for now) that the SIM - // unlock dialog is put up only when the user is trying to enable - // mobile data. - bool cancelled = *content::Details<bool>(details).ptr(); - if (cancelled) - RefreshNetworkData(); - // The case in which the correct PIN was entered and the SIM is - // now unlocked is handled in NetworkMenuButton. - } +void InternetOptionsHandler::DevicePropertiesUpdated( + const DeviceState* device) { + if (!web_ui()) + return; + if (device->type() != shill::kTypeCellular) + return; + const NetworkState* network = + NetworkHandler::Get()->network_state_handler()->FirstNetworkByType( + NetworkTypePattern::Cellular()); + if (network) + UpdateConnectionData(network->path()); // Update sim lock status. } void InternetOptionsHandler::SetServerHostnameCallback( diff --git a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h index 06c7054..f209b64 100644 --- a/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h +++ b/chrome/browser/ui/webui/options/chromeos/internet_options_handler.h @@ -11,8 +11,6 @@ #include "base/memory/weak_ptr.h" #include "chrome/browser/ui/webui/options/options_ui.h" #include "chromeos/network/network_state_handler_observer.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "ui/gfx/native_widget_types.h" class Browser; @@ -38,8 +36,7 @@ namespace options { // ChromeOS internet options page UI handler. class InternetOptionsHandler : public ::options::OptionsPageUIHandler, - public chromeos::NetworkStateHandlerObserver, - public content::NotificationObserver { + public chromeos::NetworkStateHandlerObserver { public: InternetOptionsHandler(); virtual ~InternetOptionsHandler(); @@ -94,15 +91,12 @@ class InternetOptionsHandler const chromeos::NetworkState* network) OVERRIDE; virtual void NetworkPropertiesUpdated( const chromeos::NetworkState* network) OVERRIDE; + virtual void DevicePropertiesUpdated( + const chromeos::DeviceState* device) OVERRIDE; // Updates the logged in user type. void UpdateLoggedInUserType(); - // content::NotificationObserver - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - // Additional callbacks to set network state properties. void SetServerHostnameCallback(const base::ListValue* args); void SetPreferNetworkCallback(const base::ListValue* args); @@ -151,8 +145,6 @@ class InternetOptionsHandler // Fills network information into JS dictionary for displaying network lists. void FillNetworkInfo(base::DictionaryValue* dictionary); - content::NotificationRegistrar registrar_; - // Keep track of the service path for the network shown in the Details view. std::string details_path_; diff --git a/chromeos/chromeos_switches.cc b/chromeos/chromeos_switches.cc index 52b60a0..d027ef0 100644 --- a/chromeos/chromeos_switches.cc +++ b/chromeos/chromeos_switches.cc @@ -203,11 +203,12 @@ const char kOobeGuestSession[] = "oobe-guest-session"; // See FakeDBusThreadManager::ParsePowerCommandLineSwitch for full details. const char kPowerStub[] = "power-stub"; -// Specifies network stub behavior. If this switch is not specified, -// ethernet, wifi and vpn are enabled by default, and transitions occur -// instantaneously. Multiple options can be comma separated (no spaces). +// Overrides network stub behavior. By default, ethernet, wifi and vpn are +// enabled, and transitions occur instantaneously. Multiple options can be +// comma separated (no spaces). Note: all options are in the format 'foo=x'. // See FakeShillManagerClient::SetInitialNetworkState for implementation. // Examples: +// 'clear=1' - Clears all default configurations // 'wifi=on' - A wifi network is initially connected ('1' also works) // 'wifi=off' - Wifi networks are all initially disconnected ('0' also works) // 'wifi=disabled' - Wifi is initially disabled diff --git a/chromeos/dbus/fake_shill_device_client.cc b/chromeos/dbus/fake_shill_device_client.cc index de352b1..623487b 100644 --- a/chromeos/dbus/fake_shill_device_client.cc +++ b/chromeos/dbus/fake_shill_device_client.cc @@ -22,6 +22,8 @@ namespace chromeos { namespace { +std::string kSimPin = "1111"; + void ErrorFunction(const std::string& device_path, const std::string& error_name, const std::string& error_message) { @@ -129,10 +131,34 @@ void FakeShillDeviceClient::RequirePin(const dbus::ObjectPath& device_path, bool require, const base::Closure& callback, const ErrorCallback& error_callback) { - if (!stub_devices_.HasKey(device_path.value())) { + VLOG(1) << "RequirePin: " << device_path.value(); + if (pin != kSimPin) { + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); + return; + } + base::DictionaryValue* device_properties = NULL; + if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(), + &device_properties)) { PostDeviceNotFoundError(error_callback); return; } + base::DictionaryValue* simlock_dict = NULL; + if (!device_properties->GetDictionaryWithoutPathExpansion( + shill::kSIMLockStatusProperty, &simlock_dict)) { + simlock_dict = new base::DictionaryValue; + device_properties->SetWithoutPathExpansion( + shill::kSIMLockStatusProperty, simlock_dict); + } + simlock_dict->Clear(); + simlock_dict->SetBoolean(shill::kSIMLockEnabledProperty, require); + // TODO(stevenjb): Investigate why non-empty value breaks UI. + std::string lock_type = ""; // shill::kSIMLockPin + simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type); + simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5); + + NotifyObserversPropertyChanged(device_path, shill::kSIMLockStatusProperty); base::MessageLoop::current()->PostTask(FROM_HERE, callback); } @@ -140,6 +166,13 @@ void FakeShillDeviceClient::EnterPin(const dbus::ObjectPath& device_path, const std::string& pin, const base::Closure& callback, const ErrorCallback& error_callback) { + VLOG(1) << "EnterPin: " << device_path.value(); + if (pin != kSimPin) { + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(error_callback, shill::kErrorResultIncorrectPin, "")); + return; + } if (!stub_devices_.HasKey(device_path.value())) { PostDeviceNotFoundError(error_callback); return; @@ -152,6 +185,7 @@ void FakeShillDeviceClient::UnblockPin(const dbus::ObjectPath& device_path, const std::string& pin, const base::Closure& callback, const ErrorCallback& error_callback) { + VLOG(1) << "UnblockPin: " << device_path.value(); if (!stub_devices_.HasKey(device_path.value())) { PostDeviceNotFoundError(error_callback); return; @@ -164,6 +198,7 @@ void FakeShillDeviceClient::ChangePin(const dbus::ObjectPath& device_path, const std::string& new_pin, const base::Closure& callback, const ErrorCallback& error_callback) { + VLOG(1) << "ChangePin: " << device_path.value(); if (!stub_devices_.HasKey(device_path.value())) { PostDeviceNotFoundError(error_callback); return; diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc index c9aee95e..d56c545 100644 --- a/chromeos/dbus/fake_shill_manager_client.cc +++ b/chromeos/dbus/fake_shill_manager_client.cc @@ -105,6 +105,7 @@ void UpdatePortaledWifiState(const std::string& service_path) { const char* kTechnologyUnavailable = "unavailable"; const char* kNetworkActivated = "activated"; const char* kNetworkDisabled = "disabled"; +const char* kCellularServicePath = "/service/cellular1"; } // namespace @@ -582,9 +583,6 @@ void FakeShillManagerClient::SetupDefaultEnvironment() { const bool add_to_visible = true; - bool enabled; - std::string state; - // IPConfigs base::DictionaryValue ipconfig_v4_dictionary; ipconfig_v4_dictionary.SetStringWithoutPathExpansion( @@ -603,6 +601,9 @@ void FakeShillManagerClient::SetupDefaultEnvironment() { shill::kMethodProperty, shill::kTypeIPv6); ip_configs->AddIPConfig("ipconfig_v6_path", ipconfig_v6_dictionary); + bool enabled; + std::string state; + // Ethernet state = GetInitialStateForType(shill::kTypeEthernet, &enabled); if (state == shill::kStateOnline) { @@ -733,33 +734,33 @@ void FakeShillManagerClient::SetupDefaultEnvironment() { shill::kCarrierProperty, base::StringValue(shill::kCarrierSprint)); - services->AddService("/service/cellular1", + services->AddService(kCellularServicePath, "cellular1_guid", "cellular1" /* name */, shill::kTypeCellular, state, add_to_visible); base::StringValue technology_value(shill::kNetworkTechnologyGsm); - services->SetServiceProperty("/service/cellular1", + services->SetServiceProperty(kCellularServicePath, shill::kNetworkTechnologyProperty, technology_value); if (activated) { services->SetServiceProperty( - "/service/cellular1", + kCellularServicePath, shill::kActivationStateProperty, base::StringValue(shill::kActivationStateActivated)); - services->SetServiceProperty("/service/cellular1", + services->SetServiceProperty(kCellularServicePath, shill::kConnectableProperty, base::FundamentalValue(true)); } else { services->SetServiceProperty( - "/service/cellular1", + kCellularServicePath, shill::kActivationStateProperty, base::StringValue(shill::kActivationStateNotActivated)); } - services->SetServiceProperty("/service/cellular1", + services->SetServiceProperty(kCellularServicePath, shill::kRoamingStateProperty, base::StringValue(shill::kRoamingStateHome)); } @@ -796,6 +797,18 @@ void FakeShillManagerClient::SetupDefaultEnvironment() { "/service/vpn2", shill::kProviderProperty, provider_properties); } + // Additional device states + for (DevicePropertyMap::iterator iter1 = shill_device_property_map_.begin(); + iter1 != shill_device_property_map_.end(); ++iter1) { + std::string device_type = iter1->first; + std::string device_path = devices->GetDevicePathForType(device_type); + for (ShillPropertyMap::iterator iter2 = iter1->second.begin(); + iter2 != iter1->second.end(); ++iter2) { + devices->SetDeviceProperty(device_path, iter2->first, *(iter2->second)); + delete iter2->second; + } + } + SortManagerServices(true); } @@ -932,33 +945,56 @@ void FakeShillManagerClient::ScanCompleted(const std::string& device_path, } void FakeShillManagerClient::ParseCommandLineSwitch() { - CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kShillStub)) { - std::string option_str = - command_line->GetSwitchValueASCII(switches::kShillStub); - base::StringPairs string_pairs; - base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); - for (base::StringPairs::iterator iter = string_pairs.begin(); - iter != string_pairs.end(); ++iter) { - ParseOption((*iter).first, (*iter).second); - } - return; - } // Default setup SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); + + // Parse additional options + CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (!command_line->HasSwitch(switches::kShillStub)) + return; + + std::string option_str = + command_line->GetSwitchValueASCII(switches::kShillStub); + VLOG(1) << "Parsing command line:" << option_str; + base::StringPairs string_pairs; + base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); + for (base::StringPairs::iterator iter = string_pairs.begin(); + iter != string_pairs.end(); ++iter) { + ParseOption((*iter).first, (*iter).second); + } } bool FakeShillManagerClient::ParseOption(const std::string& arg0, const std::string& arg1) { - if (arg0 == "interactive") { + VLOG(1) << "Parsing command line option: '" << arg0 << "=" << arg1 << "'"; + if ((arg0 == "clear" || arg0 == "reset") && arg1 == "1") { + shill_initial_state_map_.clear(); + return true; + } else if (arg0 == "interactive") { int seconds = 3; if (!arg1.empty()) base::StringToInt(arg1, &seconds); interactive_delay_ = seconds; return true; + } else if (arg0 == "sim_lock") { + bool locked = (arg1 == "1") ? true : false; + base::DictionaryValue* simlock_dict = new base::DictionaryValue; + simlock_dict->Set(shill::kSIMLockEnabledProperty, + new base::FundamentalValue(locked)); + // TODO(stevenjb): Investigate why non-empty value breaks UI. + std::string lock_type = ""; // shill::kSIMLockPin + simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type); + simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5); + + shill_device_property_map_ + [shill::kTypeCellular][shill::kSIMLockStatusProperty] = simlock_dict; + shill_device_property_map_ + [shill::kTypeCellular][shill::kTechnologyFamilyProperty] = + new base::StringValue(shill::kNetworkTechnologyGsm); + return true; } return SetInitialNetworkState(arg0, arg1); } diff --git a/chromeos/dbus/fake_shill_manager_client.h b/chromeos/dbus/fake_shill_manager_client.h index 4a94199..34b10a5 100644 --- a/chromeos/dbus/fake_shill_manager_client.h +++ b/chromeos/dbus/fake_shill_manager_client.h @@ -144,6 +144,9 @@ class CHROMEOS_EXPORT FakeShillManagerClient // Initial state for fake services. std::map<std::string, std::string> shill_initial_state_map_; + typedef std::map<std::string, base::Value*> ShillPropertyMap; + typedef std::map<std::string, ShillPropertyMap> DevicePropertyMap; + DevicePropertyMap shill_device_property_map_; ObserverList<ShillPropertyChangedObserver> observer_list_; diff --git a/chromeos/network/network_device_handler_unittest.cc b/chromeos/network/network_device_handler_unittest.cc index fb1fc29..af4b93f 100644 --- a/chromeos/network/network_device_handler_unittest.cc +++ b/chromeos/network/network_device_handler_unittest.cc @@ -22,6 +22,7 @@ const char kDefaultCellularDevicePath[] = "stub_cellular_device"; const char kUnknownCellularDevicePath[] = "unknown_cellular_device"; const char kDefaultWifiDevicePath[] = "stub_wifi_device"; const char kResultSuccess[] = "success"; +const char kDefaultPin[] = "1111"; } // namespace @@ -299,12 +300,10 @@ TEST_F(NetworkDeviceHandlerTest, SetCarrier) { } TEST_F(NetworkDeviceHandlerTest, RequirePin) { - const char kPin[] = "1234"; - // Test that the success callback gets called. network_device_handler_->RequirePin(kDefaultCellularDevicePath, true, - kPin, + kDefaultPin, success_callback_, error_callback_); message_loop_.RunUntilIdle(); @@ -313,7 +312,7 @@ TEST_F(NetworkDeviceHandlerTest, RequirePin) { // Test that the shill error propagates to the error callback. network_device_handler_->RequirePin(kUnknownCellularDevicePath, true, - kPin, + kDefaultPin, success_callback_, error_callback_); message_loop_.RunUntilIdle(); @@ -321,17 +320,19 @@ TEST_F(NetworkDeviceHandlerTest, RequirePin) { } TEST_F(NetworkDeviceHandlerTest, EnterPin) { - const char kPin[] = "1234"; - // Test that the success callback gets called. - network_device_handler_->EnterPin( - kDefaultCellularDevicePath, kPin, success_callback_, error_callback_); + network_device_handler_->EnterPin(kDefaultCellularDevicePath, + kDefaultPin, + success_callback_, + error_callback_); message_loop_.RunUntilIdle(); EXPECT_EQ(kResultSuccess, result_); // Test that the shill error propagates to the error callback. - network_device_handler_->EnterPin( - kUnknownCellularDevicePath, kPin, success_callback_, error_callback_); + network_device_handler_->EnterPin(kUnknownCellularDevicePath, + kDefaultPin, + success_callback_, + error_callback_); message_loop_.RunUntilIdle(); EXPECT_EQ(NetworkDeviceHandler::kErrorDeviceMissing, result_); } |