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..dbc3960b027c48c54adba0929d865c9c0fb343a0 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,8 @@ class ChooserContentViewTest : public testing::Test { |
TEST_F(ChooserContentViewTest, InitialState) { |
EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0); |
+ // |table_view_| is visible. |
msw
2016/07/22 23:37:04
nit: comments that just repeat code aren't worthwh
juncai
2016/07/25 20:14:10
Done.
|
+ 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 +86,10 @@ TEST_F(ChooserContentViewTest, InitialState) { |
// No option selected. |
EXPECT_EQ(0, table_view_->SelectedRowCount()); |
EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
+ // |throbber_| is not visible. |
+ EXPECT_FALSE(throbber_->visible()); |
+ // |discovery_state_|'s text is an empty string. |
+ EXPECT_EQ(base::string16(), discovery_state_->text()); |
msw
2016/07/22 23:37:04
nit: EXPECT_TRUE(discovery_state_->text().empty())
juncai
2016/07/25 20:14:10
Done.
|
} |
TEST_F(ChooserContentViewTest, AddOption) { |
@@ -293,6 +310,75 @@ 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( |
+ MockChooserController::AdapterPresence::ON); |
+ // |table_view_| is visible. |
+ 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()); |
+ // |throbber_| is not visible. |
+ 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_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); |
+ EXPECT_EQ(base::ASCIIToUTF16("b"), table_model_->GetText(1, 0)); |
+ EXPECT_EQ(base::ASCIIToUTF16("c"), table_model_->GetText(2, 0)); |
+ EXPECT_TRUE(table_view_->enabled()); |
+ // No option selected. |
+ EXPECT_EQ(0, table_view_->SelectedRowCount()); |
+ EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
+ // Select option 1. |
+ table_view_->Select(1); |
+ EXPECT_EQ(1, table_view_->SelectedRowCount()); |
+ EXPECT_EQ(1, table_view_->FirstSelectedRow()); |
+ |
+ mock_chooser_controller_->OnAdapterPresenceChanged( |
+ MockChooserController::AdapterPresence::OFF); |
+ // |table_view_| is visible. |
+ EXPECT_TRUE(table_view_->visible()); |
+ // Since "Adapter turned off." needs to be displayed on the |table_view_|, |
+ // the number of rows is 1. |
+ EXPECT_EQ(1, table_view_->RowCount()); |
+ EXPECT_EQ(base::ASCIIToUTF16("Adapter turned 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()); |
+ // |throbber_| is not visible. |
msw
2016/07/22 23:37:04
Can you test the throbber actually being visible i
juncai
2016/07/25 20:14:10
I tried testing the throbber in a unit test and it
msw
2016/07/26 00:18:56
Can you try constructing a base::TestSimpleTaskRun
juncai
2016/07/26 23:30:01
Thanks! Added base::TestSimpleTaskRunner and base:
|
+ EXPECT_FALSE(throbber_->visible()); |
+ // |discovery_state_| is disabled and show a label instead of a link. |
msw
2016/07/22 23:37:04
nit: "and shows an empty string" and nix comment b
juncai
2016/07/25 20:14:10
Done.
|
+ EXPECT_FALSE(discovery_state_->enabled()); |
+ // |discovery_state_|'s text is an empty string. |
+ EXPECT_EQ(base::string16(), discovery_state_->text()); |
+} |
+ |
+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); |