| Index: chromeos/dbus/shill_manager_client.cc | 
| diff --git a/chromeos/dbus/shill_manager_client.cc b/chromeos/dbus/shill_manager_client.cc | 
| index 08f163b9f962bdb33823934a4768f8f74642e5b7..c63efc00875c1d0caac8e8ca2e2453ca1eda3a0b 100644 | 
| --- a/chromeos/dbus/shill_manager_client.cc | 
| +++ b/chromeos/dbus/shill_manager_client.cc | 
| @@ -161,6 +161,10 @@ class ShillManagerClientImpl : public ShillManagerClient { | 
| error_callback); | 
| } | 
|  | 
| +  virtual TestInterface* GetTestInterface() OVERRIDE { | 
| +    return NULL; | 
| +  } | 
| + | 
| private: | 
| dbus::ObjectProxy* proxy_; | 
| ShillClientHelper helper_; | 
| @@ -168,31 +172,45 @@ class ShillManagerClientImpl : public ShillManagerClient { | 
| DISALLOW_COPY_AND_ASSIGN(ShillManagerClientImpl); | 
| }; | 
|  | 
| +namespace { | 
| + | 
| +struct ValueEquals { | 
| +  ValueEquals(const Value* first) : first_(first) {} | 
| +  bool operator ()(const Value* second) const { | 
| +    return first_->Equals(second); | 
| +  } | 
| +  const Value* first_; | 
| +}; | 
| + | 
| +}  // namespace | 
| + | 
| // A stub implementation of ShillManagerClient. | 
| -// Implemented: Stub cellular DeviceList entry for SMS testing. | 
| -class ShillManagerClientStubImpl : public ShillManagerClient { | 
| +// Implemented: Stub devices and services for NetworkStateManager tests. | 
| +// Implemented: Stub cellular device entry for SMS tests. | 
| +class ShillManagerClientStubImpl : public ShillManagerClient, | 
| +                                   public ShillManagerClient::TestInterface { | 
| public: | 
| -  ShillManagerClientStubImpl() : weak_ptr_factory_(this) { | 
| -    base::ListValue* device_list = new base::ListValue; | 
| -    // Note: names match Device stub map. | 
| -    const char kStubCellular1[] = "stub_cellular1"; | 
| -    const char kStubCellular2[] = "stub_cellular2"; | 
| -    device_list->Append(base::Value::CreateStringValue(kStubCellular1)); | 
| -    device_list->Append(base::Value::CreateStringValue(kStubCellular2)); | 
| -    stub_properties_.Set(flimflam::kDevicesProperty, device_list); | 
| +  ShillManagerClientStubImpl() | 
| +      : initialized_(false), | 
| +        weak_ptr_factory_(this) { | 
| +    SetDefaultProperties(); | 
| +    initialized_ = true; | 
| } | 
|  | 
| virtual ~ShillManagerClientStubImpl() {} | 
|  | 
| -  ////////////////////////////////// | 
| // ShillManagerClient overrides. | 
| + | 
| virtual void AddPropertyChangedObserver( | 
| -      ShillPropertyChangedObserver* observer) OVERRIDE {} | 
| +      ShillPropertyChangedObserver* observer) OVERRIDE { | 
| +    observer_list_.AddObserver(observer); | 
| +  } | 
|  | 
| virtual void RemovePropertyChangedObserver( | 
| -      ShillPropertyChangedObserver* observer) OVERRIDE {} | 
| +      ShillPropertyChangedObserver* observer) OVERRIDE { | 
| +    observer_list_.RemoveObserver(observer); | 
| +  } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void GetProperties(const DictionaryValueCallback& callback) OVERRIDE { | 
| MessageLoop::current()->PostTask( | 
| FROM_HERE, base::Bind( | 
| @@ -201,12 +219,10 @@ class ShillManagerClientStubImpl : public ShillManagerClient { | 
| callback)); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual base::DictionaryValue* CallGetPropertiesAndBlock() OVERRIDE { | 
| -    return new base::DictionaryValue; | 
| +    return stub_properties_.DeepCopy(); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void SetProperty(const std::string& name, | 
| const base::Value& value, | 
| const base::Closure& callback, | 
| @@ -215,30 +231,52 @@ class ShillManagerClientStubImpl : public ShillManagerClient { | 
| MessageLoop::current()->PostTask(FROM_HERE, callback); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void RequestScan(const std::string& type, | 
| const base::Closure& callback, | 
| const ErrorCallback& error_callback) OVERRIDE { | 
| MessageLoop::current()->PostTask(FROM_HERE, callback); | 
| +    const int kScanDelaySeconds = 3; | 
| +    CallNotifyObserversPropertyChanged( | 
| +        flimflam::kServicesProperty, kScanDelaySeconds); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void EnableTechnology( | 
| const std::string& type, | 
| const base::Closure& callback, | 
| const ErrorCallback& error_callback) OVERRIDE { | 
| +    base::ListValue* enabled_list = NULL; | 
| +    if (!stub_properties_.GetListWithoutPathExpansion( | 
| +            flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 
| +      MessageLoop::current()->PostTask( | 
| +          FROM_HERE, | 
| +          base::Bind(error_callback, "StubError", "Property not found")); | 
| +      return; | 
| +    } | 
| MessageLoop::current()->PostTask(FROM_HERE, callback); | 
| +    enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 
| +    CallNotifyObserversPropertyChanged( | 
| +        flimflam::kEnabledTechnologiesProperty, 0); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void DisableTechnology( | 
| const std::string& type, | 
| const base::Closure& callback, | 
| const ErrorCallback& error_callback) OVERRIDE { | 
| +    base::ListValue* enabled_list = NULL; | 
| +    if (!stub_properties_.GetListWithoutPathExpansion( | 
| +            flimflam::kEnabledTechnologiesProperty, &enabled_list)) { | 
| +      MessageLoop::current()->PostTask( | 
| +          FROM_HERE, | 
| +          base::Bind(error_callback, "StubError", "Property not found")); | 
| +      return; | 
| +    } | 
| MessageLoop::current()->PostTask(FROM_HERE, callback); | 
| +    base::StringValue type_value(type); | 
| +    enabled_list->Remove(type_value, NULL); | 
| +    CallNotifyObserversPropertyChanged( | 
| +        flimflam::kEnabledTechnologiesProperty, 0); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void ConfigureService( | 
| const base::DictionaryValue& properties, | 
| const base::Closure& callback, | 
| @@ -246,22 +284,168 @@ class ShillManagerClientStubImpl : public ShillManagerClient { | 
| MessageLoop::current()->PostTask(FROM_HERE, callback); | 
| } | 
|  | 
| -  // ShillManagerClient override. | 
| virtual void GetService( | 
| const base::DictionaryValue& properties, | 
| const ObjectPathCallback& callback, | 
| const ErrorCallback& error_callback) OVERRIDE { | 
| -    MessageLoop::current()->PostTask(FROM_HERE, | 
| -                                     base::Bind(callback, | 
| -                                                dbus::ObjectPath())); | 
| +    MessageLoop::current()->PostTask( | 
| +        FROM_HERE, base::Bind(callback, dbus::ObjectPath())); | 
| +  } | 
| + | 
| +  virtual ShillManagerClient::TestInterface* GetTestInterface() OVERRIDE { | 
| +    return this; | 
| +  } | 
| + | 
| +  // ShillManagerClient::TestInterface overrides. | 
| + | 
| +  virtual void AddDevice(const std::string& device_path) OVERRIDE { | 
| +    if (GetListProperty(flimflam::kDevicesProperty)->AppendIfNotPresent( | 
| +            base::Value::CreateStringValue(device_path))) { | 
| +      CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void RemoveDevice(const std::string& device_path) OVERRIDE { | 
| +    base::StringValue device_path_value(device_path); | 
| +    if (GetListProperty(flimflam::kDevicesProperty)->Remove( | 
| +            device_path_value, NULL)) { | 
| +      CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void AddService(const std::string& service_path, | 
| +                          bool add_to_watch_list) OVERRIDE { | 
| +    if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( | 
| +            base::Value::CreateStringValue(service_path))) { | 
| +      CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 
| +    } | 
| +    if (add_to_watch_list && | 
| +        GetListProperty( | 
| +            flimflam::kServiceWatchListProperty)->AppendIfNotPresent( | 
| +                base::Value::CreateStringValue(service_path))) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kServiceWatchListProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void InsertService(const std::string& service_path, | 
| +                             size_t index) OVERRIDE { | 
| +    base::StringValue path_value(service_path); | 
| +    base::ListValue* service_list = | 
| +        GetListProperty(flimflam::kServicesProperty); | 
| +    base::ListValue::iterator iter = | 
| +        std::find_if(service_list->begin(), service_list->end(), | 
| +                     ValueEquals(&path_value)); | 
| +        service_list->Find(path_value); | 
| +    if (iter != service_list->end()) | 
| +      service_list->Erase(iter, NULL); | 
| +    service_list->Insert(index, path_value.DeepCopy()); | 
| +    CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 
| +  } | 
| + | 
| +  virtual void RemoveService(const std::string& service_path) OVERRIDE { | 
| +    base::StringValue service_path_value(service_path); | 
| +    if (GetListProperty(flimflam::kServicesProperty)->Remove( | 
| +            service_path_value, NULL)) { | 
| +      CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 
| +    } | 
| +    if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( | 
| +            service_path_value, NULL)) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kServiceWatchListProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void AddTechnology(const std::string& type, bool enabled) OVERRIDE { | 
| +    if (GetListProperty(flimflam::kAvailableTechnologiesProperty)-> | 
| +        AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kAvailableTechnologiesProperty, 0); | 
| +    } | 
| +    if (enabled && | 
| +        GetListProperty(flimflam::kEnabledTechnologiesProperty)-> | 
| +        AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kEnabledTechnologiesProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void RemoveTechnology(const std::string& type) OVERRIDE { | 
| +    base::StringValue type_value(type); | 
| +    if (GetListProperty(flimflam::kAvailableTechnologiesProperty)->Remove( | 
| +            type_value, NULL)) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kAvailableTechnologiesProperty, 0); | 
| +    } | 
| +    if (GetListProperty(flimflam::kEnabledTechnologiesProperty)->Remove( | 
| +            type_value, NULL)) { | 
| +      CallNotifyObserversPropertyChanged( | 
| +          flimflam::kEnabledTechnologiesProperty, 0); | 
| +    } | 
| +  } | 
| + | 
| +  virtual void ClearProperties() OVERRIDE { | 
| +    stub_properties_.Clear(); | 
| } | 
|  | 
| private: | 
| +  void SetDefaultProperties() { | 
| +    // Stub Devices, Note: names match Device stub map. | 
| +    AddDevice("stub_wifi_device1"); | 
| +    AddDevice("stub_cellular_device1"); | 
| + | 
| +    // Stub Services, Note: names match Service stub map. | 
| +    AddService("stub_ethernet", true); | 
| +    AddService("stub_wifi1", true); | 
| +    AddService("stub_wifi2", true); | 
| +    AddService("stub_cellular1", true); | 
| + | 
| +    // Stub Technologies | 
| +    AddTechnology(flimflam::kTypeEthernet, true); | 
| +    AddTechnology(flimflam::kTypeWifi, true); | 
| +    AddTechnology(flimflam::kTypeCellular, true); | 
| +  } | 
| + | 
| void PassStubProperties(const DictionaryValueCallback& callback) const { | 
| callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_properties_); | 
| } | 
|  | 
| +  void CallNotifyObserversPropertyChanged(const std::string& property, | 
| +                                          int delay_seconds) { | 
| +    if (!initialized_) | 
| +      return; | 
| +    MessageLoop::current()->PostDelayedTask( | 
| +        FROM_HERE, | 
| +        base::Bind(&ShillManagerClientStubImpl::NotifyObserversPropertyChanged, | 
| +                   weak_ptr_factory_.GetWeakPtr(), | 
| +                   property), | 
| +        base::TimeDelta::FromSeconds(delay_seconds)); | 
| +  } | 
| + | 
| +  void NotifyObserversPropertyChanged(const std::string& property) { | 
| +    base::Value* value = NULL; | 
| +    if (!stub_properties_.GetWithoutPathExpansion(property, &value)) { | 
| +      LOG(ERROR) << "Notify for unknown property: " << property; | 
| +      return; | 
| +    } | 
| +    FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 
| +                      observer_list_, | 
| +                      OnPropertyChanged(property, *value)); | 
| +  } | 
| + | 
| +  base::ListValue* GetListProperty(const std::string& property) { | 
| +    base::ListValue* list_property = NULL; | 
| +    if (!stub_properties_.GetListWithoutPathExpansion( | 
| +            property, &list_property)) { | 
| +      list_property = new base::ListValue; | 
| +      stub_properties_.Set(property, list_property); | 
| +    } | 
| +    return list_property; | 
| +  } | 
| + | 
| +  bool initialized_; | 
| base::DictionaryValue stub_properties_; | 
| +  ObserverList<ShillPropertyChangedObserver> observer_list_; | 
|  | 
| // Note: This should remain the last member so it'll be destroyed and | 
| // invalidate its weak pointers before any other members are destroyed. | 
|  |