| Index: chrome/browser/ui/views/chooser_content_view_unittest.cc
|
| diff --git a/chrome/browser/ui/views/chooser_content_view_unittest.cc b/chrome/browser/ui/views/chooser_content_view_unittest.cc
|
| index b3fe186557353c88d4cf7400c87ac889dc56dbb4..774cc2dbabdedad97977edbd10ca4547343457c7 100644
|
| --- a/chrome/browser/ui/views/chooser_content_view_unittest.cc
|
| +++ b/chrome/browser/ui/views/chooser_content_view_unittest.cc
|
| @@ -13,9 +13,11 @@
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/views/controls/link.h"
|
| #include "ui/views/controls/styled_label.h"
|
| #include "ui/views/controls/table/table_view.h"
|
| #include "ui/views/controls/table/table_view_observer.h"
|
| +#include "ui/views/controls/throbber.h"
|
|
|
| namespace {
|
|
|
| @@ -43,16 +45,25 @@ class ChooserContentViewTest : public testing::Test {
|
| ASSERT_TRUE(table_view_);
|
| table_model_ = table_view_->model();
|
| ASSERT_TRUE(table_model_);
|
| + throbber_ = chooser_content_view_->throbber_for_test();
|
| + ASSERT_TRUE(throbber_);
|
| + discovery_state_.reset(chooser_content_view_->CreateExtraView());
|
| + ASSERT_TRUE(discovery_state_);
|
| styled_label_.reset(chooser_content_view_->CreateFootnoteView());
|
| ASSERT_TRUE(styled_label_);
|
| }
|
|
|
| protected:
|
| + // |discovery_state_| needs to be valid when |chooser_content_view_| is
|
| + // released, since ChooserContentView's destructor needs to access it.
|
| + // So it is declared before |chooser_content_view_|.
|
| + std::unique_ptr<views::Link> discovery_state_;
|
| std::unique_ptr<MockTableViewObserver> mock_table_view_observer_;
|
| std::unique_ptr<ChooserContentView> chooser_content_view_;
|
| MockChooserController* mock_chooser_controller_;
|
| views::TableView* table_view_;
|
| ui::TableModel* table_model_;
|
| + views::Throbber* throbber_;
|
| std::unique_ptr<views::StyledLabel> styled_label_;
|
|
|
| private:
|
| @@ -62,6 +73,7 @@ class ChooserContentViewTest : public testing::Test {
|
| TEST_F(ChooserContentViewTest, InitialState) {
|
| EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0);
|
|
|
| + EXPECT_TRUE(table_view_->visible());
|
| // Since "No devices found." needs to be displayed on the |table_view_|,
|
| // the number of rows is 1.
|
| EXPECT_EQ(1, table_view_->RowCount());
|
| @@ -73,6 +85,9 @@ TEST_F(ChooserContentViewTest, InitialState) {
|
| // No option selected.
|
| EXPECT_EQ(0, table_view_->SelectedRowCount());
|
| EXPECT_EQ(-1, table_view_->FirstSelectedRow());
|
| + EXPECT_FALSE(throbber_->visible());
|
| + // |discovery_state_|'s text is an empty string.
|
| + EXPECT_TRUE(discovery_state_->text().empty());
|
| }
|
|
|
| TEST_F(ChooserContentViewTest, AddOption) {
|
| @@ -293,6 +308,64 @@ TEST_F(ChooserContentViewTest,
|
| EXPECT_EQ(-1, table_view_->FirstSelectedRow());
|
| }
|
|
|
| +TEST_F(ChooserContentViewTest, AdapterOnAndOff) {
|
| + EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(2);
|
| +
|
| + mock_chooser_controller_->OnAdapterPresenceChanged(
|
| + content::BluetoothChooser::AdapterPresence::POWERED_ON);
|
| + EXPECT_TRUE(table_view_->visible());
|
| + // Since "No devices found." needs to be displayed on the |table_view_|,
|
| + // the number of rows is 1.
|
| + EXPECT_EQ(1, table_view_->RowCount());
|
| + EXPECT_EQ(
|
| + l10n_util::GetStringUTF16(IDS_DEVICE_CHOOSER_NO_DEVICES_FOUND_PROMPT),
|
| + table_model_->GetText(0, 0));
|
| + // |table_view_| should be disabled since there is no option shown.
|
| + EXPECT_FALSE(table_view_->enabled());
|
| + // No option selected.
|
| + EXPECT_EQ(0, table_view_->SelectedRowCount());
|
| + EXPECT_EQ(-1, table_view_->FirstSelectedRow());
|
| + EXPECT_FALSE(throbber_->visible());
|
| + // |discovery_state_| is enabled and show a link.
|
| + EXPECT_TRUE(discovery_state_->enabled());
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN),
|
| + discovery_state_->text());
|
| +
|
| + // Add options.
|
| + mock_chooser_controller_->OptionAdded(base::ASCIIToUTF16("a"));
|
| + mock_chooser_controller_->OptionAdded(base::ASCIIToUTF16("b"));
|
| + mock_chooser_controller_->OptionAdded(base::ASCIIToUTF16("c"));
|
| + EXPECT_EQ(3, table_view_->RowCount());
|
| + EXPECT_TRUE(table_view_->enabled());
|
| + // Select option 1.
|
| + table_view_->Select(1);
|
| + EXPECT_EQ(1, table_view_->SelectedRowCount());
|
| + EXPECT_EQ(1, table_view_->FirstSelectedRow());
|
| +
|
| + mock_chooser_controller_->OnAdapterPresenceChanged(
|
| + content::BluetoothChooser::AdapterPresence::POWERED_OFF);
|
| + EXPECT_TRUE(table_view_->visible());
|
| + // Since "Bluetooth turned off." needs to be displayed on the |table_view_|,
|
| + // the number of rows is 1.
|
| + EXPECT_EQ(1, table_view_->RowCount());
|
| + EXPECT_EQ(l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_ADAPTER_OFF),
|
| + table_model_->GetText(0, 0));
|
| + // |table_view_| should be disabled since there is no option shown.
|
| + EXPECT_FALSE(table_view_->enabled());
|
| + // No option selected.
|
| + EXPECT_EQ(0, table_view_->SelectedRowCount());
|
| + EXPECT_EQ(-1, table_view_->FirstSelectedRow());
|
| + EXPECT_FALSE(throbber_->visible());
|
| + // |discovery_state_| is disabled and and shows an empty string.
|
| + EXPECT_FALSE(discovery_state_->enabled());
|
| + EXPECT_TRUE(discovery_state_->text().empty());
|
| +}
|
| +
|
| +TEST_F(ChooserContentViewTest, ClickRescanLink) {
|
| + EXPECT_CALL(*mock_chooser_controller_, RefreshOptions()).Times(1);
|
| + chooser_content_view_->LinkClicked(nullptr, 0);
|
| +}
|
| +
|
| TEST_F(ChooserContentViewTest, ClickStyledLabelLink) {
|
| EXPECT_CALL(*mock_chooser_controller_, OpenHelpCenterUrl()).Times(1);
|
| styled_label_->LinkClicked(nullptr, 0);
|
|
|