OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chooser_controller/mock_chooser_controller.h" | 5 #include "chrome/browser/chooser_controller/mock_chooser_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 int MockChooserController::GetSignalStrengthLevel(size_t index) const { | 39 int MockChooserController::GetSignalStrengthLevel(size_t index) const { |
40 return options_[index].signal_strength_level; | 40 return options_[index].signal_strength_level; |
41 } | 41 } |
42 | 42 |
43 base::string16 MockChooserController::GetOption(size_t index) const { | 43 base::string16 MockChooserController::GetOption(size_t index) const { |
44 return options_[index].name; | 44 return options_[index].name; |
45 } | 45 } |
46 | 46 |
| 47 bool MockChooserController::IsConnected(size_t index) const { |
| 48 return options_[index].is_connected; |
| 49 } |
| 50 |
| 51 bool MockChooserController::IsPaired(size_t index) const { |
| 52 return options_[index].is_paired; |
| 53 } |
| 54 |
47 base::string16 MockChooserController::GetStatus() const { | 55 base::string16 MockChooserController::GetStatus() const { |
48 return status_text_; | 56 return status_text_; |
49 } | 57 } |
50 | 58 |
51 void MockChooserController::OnAdapterPresenceChanged( | 59 void MockChooserController::OnAdapterPresenceChanged( |
52 content::BluetoothChooser::AdapterPresence presence) { | 60 content::BluetoothChooser::AdapterPresence presence) { |
53 ClearAllOptions(); | 61 ClearAllOptions(); |
54 switch (presence) { | 62 switch (presence) { |
55 case content::BluetoothChooser::AdapterPresence::ABSENT: | 63 case content::BluetoothChooser::AdapterPresence::ABSENT: |
56 NOTREACHED(); | 64 NOTREACHED(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 99 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
92 if (view()) { | 100 if (view()) { |
93 view()->OnRefreshStateChanged( | 101 view()->OnRefreshStateChanged( |
94 false /* Refreshing options is complete */); | 102 false /* Refreshing options is complete */); |
95 } | 103 } |
96 break; | 104 break; |
97 } | 105 } |
98 } | 106 } |
99 | 107 |
100 void MockChooserController::OptionAdded(const base::string16& option_name, | 108 void MockChooserController::OptionAdded(const base::string16& option_name, |
101 int signal_strength_level) { | 109 int signal_strength_level, |
102 options_.push_back({option_name, signal_strength_level}); | 110 bool is_connected, |
| 111 bool is_paired) { |
| 112 options_.push_back( |
| 113 {option_name, signal_strength_level, is_connected, is_paired}); |
103 if (view()) | 114 if (view()) |
104 view()->OnOptionAdded(options_.size() - 1); | 115 view()->OnOptionAdded(options_.size() - 1); |
105 } | 116 } |
106 | 117 |
107 void MockChooserController::OptionRemoved(const base::string16& option_name) { | 118 void MockChooserController::OptionRemoved(const base::string16& option_name) { |
108 auto it = std::find_if(options_.begin(), options_.end(), | 119 auto it = std::find_if(options_.begin(), options_.end(), |
109 [&option_name](const OptionInfo& option) { | 120 [&option_name](const OptionInfo& option) { |
110 return option.name == option_name; | 121 return option.name == option_name; |
111 }); | 122 }); |
112 | 123 |
113 if (it != options_.end()) { | 124 if (it != options_.end()) { |
114 size_t index = it - options_.begin(); | 125 size_t index = it - options_.begin(); |
115 options_.erase(it); | 126 options_.erase(it); |
116 if (view()) | 127 if (view()) |
117 view()->OnOptionRemoved(index); | 128 view()->OnOptionRemoved(index); |
118 } | 129 } |
119 } | 130 } |
120 | 131 |
121 void MockChooserController::OptionUpdated( | 132 void MockChooserController::OptionUpdated( |
122 const base::string16& previous_option_name, | 133 const base::string16& previous_option_name, |
123 const base::string16& new_option_name, | 134 const base::string16& new_option_name, |
124 int new_signal_strength_level) { | 135 int new_signal_strength_level, |
| 136 bool new_is_connected, |
| 137 bool new_is_paired) { |
125 auto it = std::find_if(options_.begin(), options_.end(), | 138 auto it = std::find_if(options_.begin(), options_.end(), |
126 [&previous_option_name](const OptionInfo& option) { | 139 [&previous_option_name](const OptionInfo& option) { |
127 return option.name == previous_option_name; | 140 return option.name == previous_option_name; |
128 }); | 141 }); |
129 | 142 |
130 if (it != options_.end()) { | 143 if (it != options_.end()) { |
131 *it = {new_option_name, new_signal_strength_level}; | 144 *it = {new_option_name, new_signal_strength_level, new_is_connected, |
| 145 new_is_paired}; |
132 if (view()) | 146 if (view()) |
133 view()->OnOptionUpdated(it - options_.begin()); | 147 view()->OnOptionUpdated(it - options_.begin()); |
134 } | 148 } |
135 } | 149 } |
136 | 150 |
137 const int MockChooserController::kNoImage = -1; | 151 const int MockChooserController::kNoSignalStrengthLevelImage = -1; |
138 const int MockChooserController::kSignalStrengthLevel0Bar = 0; | 152 const int MockChooserController::kSignalStrengthLevel0Bar = 0; |
139 const int MockChooserController::kSignalStrengthLevel1Bar = 1; | 153 const int MockChooserController::kSignalStrengthLevel1Bar = 1; |
140 const int MockChooserController::kSignalStrengthLevel2Bar = 2; | 154 const int MockChooserController::kSignalStrengthLevel2Bar = 2; |
141 const int MockChooserController::kSignalStrengthLevel3Bar = 3; | 155 const int MockChooserController::kSignalStrengthLevel3Bar = 3; |
142 const int MockChooserController::kSignalStrengthLevel4Bar = 4; | 156 const int MockChooserController::kSignalStrengthLevel4Bar = 4; |
| 157 const bool MockChooserController::kConnected = true; |
| 158 const bool MockChooserController::kNotConnected = false; |
| 159 const bool MockChooserController::kPaired = true; |
| 160 const bool MockChooserController::kNotPaired = false; |
143 | 161 |
144 void MockChooserController::ClearAllOptions() { | 162 void MockChooserController::ClearAllOptions() { |
145 options_.clear(); | 163 options_.clear(); |
146 } | 164 } |
OLD | NEW |