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" |
11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 | 13 |
14 MockChooserController::MockChooserController(content::RenderFrameHost* owner) | 14 MockChooserController::MockChooserController(content::RenderFrameHost* owner) |
15 : ChooserController(owner, | 15 : ChooserController(owner, |
16 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, | 16 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, |
17 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 17 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
18 no_options_text_(l10n_util::GetStringUTF16( | 18 no_options_text_(l10n_util::GetStringUTF16( |
19 IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT)) {} | 19 IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT)) {} |
20 | 20 |
21 MockChooserController::~MockChooserController() {} | 21 MockChooserController::~MockChooserController() {} |
22 | 22 |
| 23 bool MockChooserController::ShouldShowIconBeforeText() const { |
| 24 return true; |
| 25 } |
| 26 |
23 base::string16 MockChooserController::GetNoOptionsText() const { | 27 base::string16 MockChooserController::GetNoOptionsText() const { |
24 return no_options_text_; | 28 return no_options_text_; |
25 } | 29 } |
26 | 30 |
27 base::string16 MockChooserController::GetOkButtonLabel() const { | 31 base::string16 MockChooserController::GetOkButtonLabel() const { |
28 return l10n_util::GetStringUTF16(IDS_USB_DEVICE_CHOOSER_CONNECT_BUTTON_TEXT); | 32 return l10n_util::GetStringUTF16(IDS_USB_DEVICE_CHOOSER_CONNECT_BUTTON_TEXT); |
29 } | 33 } |
30 | 34 |
31 size_t MockChooserController::NumOptions() const { | 35 size_t MockChooserController::NumOptions() const { |
32 return option_names_.size(); | 36 return options_.size(); |
| 37 } |
| 38 |
| 39 int MockChooserController::GetSignalStrengthLevel(size_t index) const { |
| 40 return options_[index].signal_strength_level; |
33 } | 41 } |
34 | 42 |
35 base::string16 MockChooserController::GetOption(size_t index) const { | 43 base::string16 MockChooserController::GetOption(size_t index) const { |
36 return option_names_[index]; | 44 return options_[index].name; |
37 } | 45 } |
38 | 46 |
39 base::string16 MockChooserController::GetStatus() const { | 47 base::string16 MockChooserController::GetStatus() const { |
40 return status_text_; | 48 return status_text_; |
41 } | 49 } |
42 | 50 |
43 void MockChooserController::OnAdapterPresenceChanged( | 51 void MockChooserController::OnAdapterPresenceChanged( |
44 content::BluetoothChooser::AdapterPresence presence) { | 52 content::BluetoothChooser::AdapterPresence presence) { |
45 ClearAllOptions(); | 53 ClearAllOptions(); |
46 switch (presence) { | 54 switch (presence) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 status_text_ = | 90 status_text_ = |
83 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 91 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
84 if (view()) { | 92 if (view()) { |
85 view()->OnRefreshStateChanged( | 93 view()->OnRefreshStateChanged( |
86 false /* Refreshing options is complete */); | 94 false /* Refreshing options is complete */); |
87 } | 95 } |
88 break; | 96 break; |
89 } | 97 } |
90 } | 98 } |
91 | 99 |
92 void MockChooserController::OptionAdded(const base::string16& option_name) { | 100 void MockChooserController::OptionAdded(const base::string16& option_name, |
93 option_names_.push_back(option_name); | 101 int signal_strength_level) { |
| 102 options_.push_back({option_name, signal_strength_level}); |
94 if (view()) | 103 if (view()) |
95 view()->OnOptionAdded(option_names_.size() - 1); | 104 view()->OnOptionAdded(options_.size() - 1); |
96 } | 105 } |
97 | 106 |
98 void MockChooserController::OptionRemoved(const base::string16& option_name) { | 107 void MockChooserController::OptionRemoved(const base::string16& option_name) { |
99 auto it = std::find(option_names_.begin(), option_names_.end(), option_name); | 108 auto it = std::find_if(options_.begin(), options_.end(), |
100 if (it != option_names_.end()) { | 109 [&option_name](const OptionInfo& option) { |
101 size_t index = std::distance(option_names_.begin(), it); | 110 return option.name == option_name; |
102 option_names_.erase(it); | 111 }); |
| 112 |
| 113 if (it != options_.end()) { |
| 114 size_t index = it - options_.begin(); |
| 115 options_.erase(it); |
103 if (view()) | 116 if (view()) |
104 view()->OnOptionRemoved(index); | 117 view()->OnOptionRemoved(index); |
105 } | 118 } |
106 } | 119 } |
107 | 120 |
108 void MockChooserController::OptionUpdated( | 121 void MockChooserController::OptionUpdated( |
109 const base::string16& previous_option_name, | 122 const base::string16& previous_option_name, |
110 const base::string16& new_option_name) { | 123 const base::string16& new_option_name, |
111 auto it = std::find(option_names_.begin(), option_names_.end(), | 124 int new_signal_strength_level) { |
112 previous_option_name); | 125 auto it = std::find_if(options_.begin(), options_.end(), |
113 DCHECK(it != option_names_.end()); | 126 [&previous_option_name](const OptionInfo& option) { |
114 size_t index = std::distance(option_names_.begin(), it); | 127 return option.name == previous_option_name; |
115 *it = new_option_name; | 128 }); |
116 if (view()) | 129 |
117 view()->OnOptionUpdated(index); | 130 if (it != options_.end()) { |
| 131 *it = {new_option_name, new_signal_strength_level}; |
| 132 if (view()) |
| 133 view()->OnOptionUpdated(it - options_.begin()); |
| 134 } |
118 } | 135 } |
119 | 136 |
| 137 const int MockChooserController::kNoImage = -1; |
| 138 const int MockChooserController::kSignalStrengthLevel0Bar = 0; |
| 139 const int MockChooserController::kSignalStrengthLevel1Bar = 1; |
| 140 const int MockChooserController::kSignalStrengthLevel2Bar = 2; |
| 141 const int MockChooserController::kSignalStrengthLevel3Bar = 3; |
| 142 const int MockChooserController::kSignalStrengthLevel4Bar = 4; |
| 143 |
120 void MockChooserController::ClearAllOptions() { | 144 void MockChooserController::ClearAllOptions() { |
121 option_names_.clear(); | 145 options_.clear(); |
122 } | 146 } |
OLD | NEW |