Commit 1d833f23 authored by juncai's avatar juncai Committed by Commit bot

Show device connection and paired status in chooser on non-Mac

This CL added code to show an icon for connected device in the
chooser, and added "- Paired" text after the device name if the
device is paired.

I uploaded some screenshots from ChromeOS in the issue page.

BUG=543466

Review-Url: https://codereview.chromium.org/2330593002
Cr-Commit-Position: refs/heads/master@{#418916}
parent 6bca3b79
...@@ -15113,6 +15113,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@gmail.com</ex ...@@ -15113,6 +15113,9 @@ Please check your email at <ph name="ACCOUNT_EMAIL">$2<ex>jane.doe@gmail.com</ex
<message name="IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT" desc="The label that is used to inform the user that the device is paired."> <message name="IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT" desc="The label that is used to inform the user that the device is paired.">
Paired Paired
</message> </message>
<message name="IDS_DEVICE_CHOOSER_DEVICE_NAME_AND_PAIRED_STATUS_TEXT" desc="Text of the device name and paired status.">
<ph name="DEVICE_NAME">$1<ex>device name</ex></ph> - Paired
</message>
</if> </if>
<if expr="is_android"> <if expr="is_android">
......
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icons_public.h"
#include "ui/resources/grit/ui_resources.h" #include "ui/resources/grit/ui_resources.h"
#include "ui/views/controls/link.h" #include "ui/views/controls/link.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
...@@ -88,7 +91,12 @@ base::string16 ChooserContentView::GetText(int row, int column_id) { ...@@ -88,7 +91,12 @@ base::string16 ChooserContentView::GetText(int row, int column_id) {
DCHECK_GE(row, 0); DCHECK_GE(row, 0);
DCHECK_LT(row, num_options); DCHECK_LT(row, num_options);
return chooser_controller_->GetOption(static_cast<size_t>(row)); base::string16 text =
chooser_controller_->GetOption(static_cast<size_t>(row));
return chooser_controller_->IsPaired(row)
? l10n_util::GetStringFUTF16(
IDS_DEVICE_CHOOSER_DEVICE_NAME_AND_PAIRED_STATUS_TEXT, text)
: text;
} }
void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {}
...@@ -105,6 +113,11 @@ gfx::ImageSkia ChooserContentView::GetIcon(int row) { ...@@ -105,6 +113,11 @@ gfx::ImageSkia ChooserContentView::GetIcon(int row) {
DCHECK_GE(row, 0); DCHECK_GE(row, 0);
DCHECK_LT(row, base::checked_cast<int>(num_options)); DCHECK_LT(row, base::checked_cast<int>(num_options));
if (chooser_controller_->IsConnected(row)) {
return gfx::CreateVectorIcon(gfx::VectorIconId::BLUETOOTH_CONNECTED,
gfx::kChromeIconGrey);
}
int level = chooser_controller_->GetSignalStrengthLevel(row); int level = chooser_controller_->GetSignalStrengthLevel(row);
if (level == -1) if (level == -1)
......
...@@ -28,6 +28,12 @@ class MockTableViewObserver : public views::TableViewObserver { ...@@ -28,6 +28,12 @@ class MockTableViewObserver : public views::TableViewObserver {
MOCK_METHOD0(OnSelectionChanged, void()); MOCK_METHOD0(OnSelectionChanged, void());
}; };
base::string16 GetPairedText(const std::string& device_name) {
return l10n_util::GetStringFUTF16(
IDS_DEVICE_CHOOSER_DEVICE_NAME_AND_PAIRED_STATUS_TEXT,
base::ASCIIToUTF16(device_name));
}
} // namespace } // namespace
class ChooserContentViewTest : public views::ViewsTestBase { class ChooserContentViewTest : public views::ViewsTestBase {
...@@ -100,7 +106,7 @@ TEST_F(ChooserContentViewTest, AddOption) { ...@@ -100,7 +106,7 @@ TEST_F(ChooserContentViewTest, AddOption) {
MockChooserController::ConnectedPairedStatus::CONNECTED | MockChooserController::ConnectedPairedStatus::CONNECTED |
MockChooserController::ConnectedPairedStatus::PAIRED); MockChooserController::ConnectedPairedStatus::PAIRED);
EXPECT_EQ(1, table_view_->RowCount()); EXPECT_EQ(1, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
// |table_view_| should be enabled since there is an option. // |table_view_| should be enabled since there is an option.
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
// No option selected. // No option selected.
...@@ -144,7 +150,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) { ...@@ -144,7 +150,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) {
mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("b")); mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("b"));
EXPECT_EQ(2, table_view_->RowCount()); EXPECT_EQ(2, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0)); EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0));
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
EXPECT_EQ(0, table_view_->SelectedRowCount()); EXPECT_EQ(0, table_view_->SelectedRowCount());
...@@ -153,7 +159,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) { ...@@ -153,7 +159,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) {
// Remove a non-existent option, the number of rows should not change. // Remove a non-existent option, the number of rows should not change.
mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("non-existent")); mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("non-existent"));
EXPECT_EQ(2, table_view_->RowCount()); EXPECT_EQ(2, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0)); EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0));
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
EXPECT_EQ(0, table_view_->SelectedRowCount()); EXPECT_EQ(0, table_view_->SelectedRowCount());
...@@ -161,7 +167,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) { ...@@ -161,7 +167,7 @@ TEST_F(ChooserContentViewTest, RemoveOption) {
mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("c")); mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("c"));
EXPECT_EQ(1, table_view_->RowCount()); EXPECT_EQ(1, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
EXPECT_EQ(0, table_view_->SelectedRowCount()); EXPECT_EQ(0, table_view_->SelectedRowCount());
EXPECT_EQ(-1, table_view_->FirstSelectedRow()); EXPECT_EQ(-1, table_view_->FirstSelectedRow());
...@@ -200,8 +206,8 @@ TEST_F(ChooserContentViewTest, UpdateOption) { ...@@ -200,8 +206,8 @@ TEST_F(ChooserContentViewTest, UpdateOption) {
MockChooserController::ConnectedPairedStatus::CONNECTED | MockChooserController::ConnectedPairedStatus::CONNECTED |
MockChooserController::ConnectedPairedStatus::PAIRED); MockChooserController::ConnectedPairedStatus::PAIRED);
EXPECT_EQ(3, table_view_->RowCount()); EXPECT_EQ(3, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_EQ(base::ASCIIToUTF16("d"), table_model_->GetText(1, 0)); EXPECT_EQ(GetPairedText("d"), table_model_->GetText(1, 0));
EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(2, 0)); EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(2, 0));
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
EXPECT_EQ(0, table_view_->SelectedRowCount()); EXPECT_EQ(0, table_view_->SelectedRowCount());
...@@ -263,7 +269,7 @@ TEST_F(ChooserContentViewTest, UpdateAndRemoveTheUpdatedOption) { ...@@ -263,7 +269,7 @@ TEST_F(ChooserContentViewTest, UpdateAndRemoveTheUpdatedOption) {
mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("d")); mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("d"));
EXPECT_EQ(2, table_view_->RowCount()); EXPECT_EQ(2, table_view_->RowCount());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0)); EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(1, 0));
EXPECT_TRUE(table_view_->enabled()); EXPECT_TRUE(table_view_->enabled());
EXPECT_EQ(0, table_view_->SelectedRowCount()); EXPECT_EQ(0, table_view_->SelectedRowCount());
...@@ -429,8 +435,8 @@ TEST_F(ChooserContentViewTest, SelectAnOptionAndUpdateTheSelectedOption) { ...@@ -429,8 +435,8 @@ TEST_F(ChooserContentViewTest, SelectAnOptionAndUpdateTheSelectedOption) {
EXPECT_EQ(1, table_view_->SelectedRowCount()); EXPECT_EQ(1, table_view_->SelectedRowCount());
EXPECT_EQ(1, table_view_->FirstSelectedRow()); EXPECT_EQ(1, table_view_->FirstSelectedRow());
EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); EXPECT_EQ(GetPairedText("a"), table_model_->GetText(0, 0));
EXPECT_EQ(base::ASCIIToUTF16("d"), table_model_->GetText(1, 0)); EXPECT_EQ(GetPairedText("d"), table_model_->GetText(1, 0));
EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(2, 0)); EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(2, 0));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment