| 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/ui/views/chooser_content_view.h" | 5 #include "chrome/browser/ui/views/chooser_content_view.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 10 #include "components/chooser_controller/mock_chooser_controller.h" | 10 #include "components/chooser_controller/mock_chooser_controller.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 private: | 67 private: |
| 68 DISALLOW_COPY_AND_ASSIGN(ChooserContentViewTest); | 68 DISALLOW_COPY_AND_ASSIGN(ChooserContentViewTest); |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 TEST_F(ChooserContentViewTest, InitialState) { | 71 TEST_F(ChooserContentViewTest, InitialState) { |
| 72 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0); | 72 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0); |
| 73 | 73 |
| 74 // Since "No devices found." needs to be displayed on the |table_view_|, | 74 // Since "No devices found." needs to be displayed on the |table_view_|, |
| 75 // the number of rows is 1. | 75 // the number of rows is 1. |
| 76 EXPECT_EQ(1, table_view_->RowCount()); | 76 EXPECT_EQ(1, table_view_->RowCount()); |
| 77 EXPECT_EQ( | 77 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_CHOOSER_NO_DEVICES_FOUND_PROMPT), |
| 78 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT), | 78 table_model_->GetText(0, 0)); |
| 79 table_model_->GetText(0, 0)); | |
| 80 // |table_view_| should be disabled since there is no option shown. | 79 // |table_view_| should be disabled since there is no option shown. |
| 81 EXPECT_FALSE(table_view_->enabled()); | 80 EXPECT_FALSE(table_view_->enabled()); |
| 82 // No option selected. | 81 // No option selected. |
| 83 EXPECT_EQ(0, table_view_->SelectedRowCount()); | 82 EXPECT_EQ(0, table_view_->SelectedRowCount()); |
| 84 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); | 83 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
| 85 } | 84 } |
| 86 | 85 |
| 87 TEST_F(ChooserContentViewTest, AddOption) { | 86 TEST_F(ChooserContentViewTest, AddOption) { |
| 88 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0); | 87 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(0); |
| 89 | 88 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 EXPECT_EQ(1, table_view_->RowCount()); | 139 EXPECT_EQ(1, table_view_->RowCount()); |
| 141 EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); | 140 EXPECT_EQ(base::ASCIIToUTF16("a"), table_model_->GetText(0, 0)); |
| 142 EXPECT_TRUE(table_view_->enabled()); | 141 EXPECT_TRUE(table_view_->enabled()); |
| 143 EXPECT_EQ(0, table_view_->SelectedRowCount()); | 142 EXPECT_EQ(0, table_view_->SelectedRowCount()); |
| 144 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); | 143 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
| 145 | 144 |
| 146 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("a")); | 145 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("a")); |
| 147 // There is no option shown now. But since "No devices found." | 146 // There is no option shown now. But since "No devices found." |
| 148 // needs to be displayed on the |table_view_|, the number of rows is 1. | 147 // needs to be displayed on the |table_view_|, the number of rows is 1. |
| 149 EXPECT_EQ(1, table_view_->RowCount()); | 148 EXPECT_EQ(1, table_view_->RowCount()); |
| 150 EXPECT_EQ( | 149 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_CHOOSER_NO_DEVICES_FOUND_PROMPT), |
| 151 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT), | 150 table_model_->GetText(0, 0)); |
| 152 table_model_->GetText(0, 0)); | |
| 153 // |table_view_| should be disabled since all options are removed. | 151 // |table_view_| should be disabled since all options are removed. |
| 154 EXPECT_FALSE(table_view_->enabled()); | 152 EXPECT_FALSE(table_view_->enabled()); |
| 155 EXPECT_EQ(0, table_view_->SelectedRowCount()); | 153 EXPECT_EQ(0, table_view_->SelectedRowCount()); |
| 156 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); | 154 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
| 157 } | 155 } |
| 158 | 156 |
| 159 TEST_F(ChooserContentViewTest, AddAndRemoveOption) { | 157 TEST_F(ChooserContentViewTest, AddAndRemoveOption) { |
| 160 // Called from TableView::OnItemsRemoved(). | 158 // Called from TableView::OnItemsRemoved(). |
| 161 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(3); | 159 EXPECT_CALL(*mock_table_view_observer_, OnSelectionChanged()).Times(3); |
| 162 | 160 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // Select option 0. | 283 // Select option 0. |
| 286 table_view_->Select(0); | 284 table_view_->Select(0); |
| 287 EXPECT_EQ(1, table_view_->SelectedRowCount()); | 285 EXPECT_EQ(1, table_view_->SelectedRowCount()); |
| 288 EXPECT_EQ(0, table_view_->FirstSelectedRow()); | 286 EXPECT_EQ(0, table_view_->FirstSelectedRow()); |
| 289 | 287 |
| 290 // Remove option 0. | 288 // Remove option 0. |
| 291 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("a")); | 289 mock_chooser_controller_->OptionRemoved(base::ASCIIToUTF16("a")); |
| 292 // There is no option shown now. But since "No devices found." | 290 // There is no option shown now. But since "No devices found." |
| 293 // needs to be displayed on the |table_view_|, the number of rows is 1. | 291 // needs to be displayed on the |table_view_|, the number of rows is 1. |
| 294 EXPECT_EQ(1, table_view_->RowCount()); | 292 EXPECT_EQ(1, table_view_->RowCount()); |
| 295 EXPECT_EQ( | 293 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_CHOOSER_NO_DEVICES_FOUND_PROMPT), |
| 296 l10n_util::GetStringUTF16(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT), | 294 table_model_->GetText(0, 0)); |
| 297 table_model_->GetText(0, 0)); | |
| 298 // |table_view_| should be disabled since all options are removed. | 295 // |table_view_| should be disabled since all options are removed. |
| 299 EXPECT_FALSE(table_view_->enabled()); | 296 EXPECT_FALSE(table_view_->enabled()); |
| 300 // No option selected. | 297 // No option selected. |
| 301 EXPECT_EQ(0, table_view_->SelectedRowCount()); | 298 EXPECT_EQ(0, table_view_->SelectedRowCount()); |
| 302 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); | 299 EXPECT_EQ(-1, table_view_->FirstSelectedRow()); |
| 303 } | 300 } |
| 304 | 301 |
| 305 TEST_F(ChooserContentViewTest, ClickStyledLabelLink) { | 302 TEST_F(ChooserContentViewTest, ClickStyledLabelLink) { |
| 306 EXPECT_CALL(*mock_styled_label_listener_, | 303 EXPECT_CALL(*mock_styled_label_listener_, |
| 307 StyledLabelLinkClicked(styled_label_.get(), testing::_, 0)) | 304 StyledLabelLinkClicked(styled_label_.get(), testing::_, 0)) |
| 308 .Times(1); | 305 .Times(1); |
| 309 styled_label_->LinkClicked(nullptr, 0); | 306 styled_label_->LinkClicked(nullptr, 0); |
| 310 } | 307 } |
| OLD | NEW |