| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/input_method/candidate_window_view.h" | 5 #include "chrome/browser/chromeos/input_method/candidate_window_view.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 static_cast<unsigned long long>(i)); | 56 static_cast<unsigned long long>(i)); |
| 57 entry.label = base::StringPrintf("%lld", | 57 entry.label = base::StringPrintf("%lld", |
| 58 static_cast<unsigned long long>(i)); | 58 static_cast<unsigned long long>(i)); |
| 59 candidate_window->mutable_candidates()->push_back(entry); | 59 candidate_window->mutable_candidates()->push_back(entry); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 class CandidateWindowViewTest : public views::ViewsTestBase { | 65 class CandidateWindowViewTest : public views::ViewsTestBase { |
| 66 public: |
| 67 CandidateWindowViewTest() {} |
| 68 virtual ~CandidateWindowViewTest() {} |
| 69 |
| 66 protected: | 70 protected: |
| 71 virtual void SetUp() { |
| 72 views::ViewsTestBase::SetUp(); |
| 73 candidate_window_view_ = new CandidateWindowView(GetContext()); |
| 74 candidate_window_view_->InitWidget(); |
| 75 } |
| 76 |
| 77 CandidateWindowView* candidate_window_view() { |
| 78 return candidate_window_view_; |
| 79 } |
| 80 |
| 81 int selected_candidate_index_in_page() { |
| 82 return candidate_window_view_->selected_candidate_index_in_page_; |
| 83 } |
| 84 |
| 85 size_t GetCandidatesSize() const { |
| 86 return candidate_window_view_->candidate_views_.size(); |
| 87 } |
| 88 |
| 89 CandidateView* GetCandidateAt(size_t i) { |
| 90 return candidate_window_view_->candidate_views_[i]; |
| 91 } |
| 92 |
| 93 void SelectCandidateAt(int index_in_page) { |
| 94 candidate_window_view_->SelectCandidateAt(index_in_page); |
| 95 } |
| 96 |
| 97 void MaybeInitializeCandidateViews(const CandidateWindow& candidate_window) { |
| 98 candidate_window_view_->MaybeInitializeCandidateViews(candidate_window); |
| 99 } |
| 100 |
| 67 void ExpectLabels(const std::string& shortcut, | 101 void ExpectLabels(const std::string& shortcut, |
| 68 const std::string& candidate, | 102 const std::string& candidate, |
| 69 const std::string& annotation, | 103 const std::string& annotation, |
| 70 const CandidateView* row) { | 104 const CandidateView* row) { |
| 71 EXPECT_EQ(shortcut, base::UTF16ToUTF8(row->shortcut_label_->text())); | 105 EXPECT_EQ(shortcut, base::UTF16ToUTF8(row->shortcut_label_->text())); |
| 72 EXPECT_EQ(candidate, base::UTF16ToUTF8(row->candidate_label_->text())); | 106 EXPECT_EQ(candidate, base::UTF16ToUTF8(row->candidate_label_->text())); |
| 73 EXPECT_EQ(annotation, base::UTF16ToUTF8(row->annotation_label_->text())); | 107 EXPECT_EQ(annotation, base::UTF16ToUTF8(row->annotation_label_->text())); |
| 74 } | 108 } |
| 109 |
| 110 private: |
| 111 // owned by |parent_|. |
| 112 CandidateWindowView* candidate_window_view_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(CandidateWindowViewTest); |
| 75 }; | 115 }; |
| 76 | 116 |
| 77 TEST_F(CandidateWindowViewTest, UpdateCandidatesTest_CursorVisibility) { | 117 TEST_F(CandidateWindowViewTest, UpdateCandidatesTest_CursorVisibility) { |
| 78 views::Widget* widget = new views::Widget; | |
| 79 views::Widget::InitParams params = | |
| 80 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 81 widget->Init(params); | |
| 82 | |
| 83 CandidateWindowView candidate_window_view(widget); | |
| 84 candidate_window_view.Init(); | |
| 85 | |
| 86 // Visible (by default) cursor. | 118 // Visible (by default) cursor. |
| 87 CandidateWindow candidate_window; | 119 CandidateWindow candidate_window; |
| 88 const int candidate_window_size = 9; | 120 const int candidate_window_size = 9; |
| 89 InitCandidateWindowWithCandidatesFilled(candidate_window_size, | 121 InitCandidateWindowWithCandidatesFilled(candidate_window_size, |
| 90 &candidate_window); | 122 &candidate_window); |
| 91 candidate_window_view.UpdateCandidates(candidate_window); | 123 candidate_window_view()->UpdateCandidates(candidate_window); |
| 92 EXPECT_EQ(0, candidate_window_view.selected_candidate_index_in_page_); | 124 EXPECT_EQ(0, selected_candidate_index_in_page()); |
| 93 | 125 |
| 94 // Invisible cursor. | 126 // Invisible cursor. |
| 95 candidate_window.set_is_cursor_visible(false); | 127 candidate_window.set_is_cursor_visible(false); |
| 96 candidate_window_view.UpdateCandidates(candidate_window); | 128 candidate_window_view()->UpdateCandidates(candidate_window); |
| 97 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 129 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 98 | 130 |
| 99 // Move the cursor to the end. | 131 // Move the cursor to the end. |
| 100 candidate_window.set_cursor_position(candidate_window_size - 1); | 132 candidate_window.set_cursor_position(candidate_window_size - 1); |
| 101 candidate_window_view.UpdateCandidates(candidate_window); | 133 candidate_window_view()->UpdateCandidates(candidate_window); |
| 102 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 134 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 103 | 135 |
| 104 // Change the cursor to visible. The cursor must be at the end. | 136 // Change the cursor to visible. The cursor must be at the end. |
| 105 candidate_window.set_is_cursor_visible(true); | 137 candidate_window.set_is_cursor_visible(true); |
| 106 candidate_window_view.UpdateCandidates(candidate_window); | 138 candidate_window_view()->UpdateCandidates(candidate_window); |
| 107 EXPECT_EQ(candidate_window_size - 1, | 139 EXPECT_EQ(candidate_window_size - 1, selected_candidate_index_in_page()); |
| 108 candidate_window_view.selected_candidate_index_in_page_); | |
| 109 } | 140 } |
| 110 | 141 |
| 111 TEST_F(CandidateWindowViewTest, SelectCandidateAtTest) { | 142 TEST_F(CandidateWindowViewTest, SelectCandidateAtTest) { |
| 112 views::Widget* widget = new views::Widget; | |
| 113 views::Widget::InitParams params = | |
| 114 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 115 widget->Init(params); | |
| 116 | |
| 117 CandidateWindowView candidate_window_view(widget); | |
| 118 candidate_window_view.Init(); | |
| 119 | |
| 120 // Set 9 candidates. | 143 // Set 9 candidates. |
| 121 CandidateWindow candidate_window_large; | 144 CandidateWindow candidate_window_large; |
| 122 const int candidate_window_large_size = 9; | 145 const int candidate_window_large_size = 9; |
| 123 InitCandidateWindowWithCandidatesFilled(candidate_window_large_size, | 146 InitCandidateWindowWithCandidatesFilled(candidate_window_large_size, |
| 124 &candidate_window_large); | 147 &candidate_window_large); |
| 125 candidate_window_large.set_cursor_position(candidate_window_large_size - 1); | 148 candidate_window_large.set_cursor_position(candidate_window_large_size - 1); |
| 126 candidate_window_view.UpdateCandidates(candidate_window_large); | 149 candidate_window_view()->UpdateCandidates(candidate_window_large); |
| 127 | 150 |
| 128 // Select the last candidate. | 151 // Select the last candidate. |
| 129 candidate_window_view.SelectCandidateAt(candidate_window_large_size - 1); | 152 SelectCandidateAt(candidate_window_large_size - 1); |
| 130 | 153 |
| 131 // Reduce the number of candidates to 3. | 154 // Reduce the number of candidates to 3. |
| 132 CandidateWindow candidate_window_small; | 155 CandidateWindow candidate_window_small; |
| 133 const int candidate_window_small_size = 3; | 156 const int candidate_window_small_size = 3; |
| 134 InitCandidateWindowWithCandidatesFilled(candidate_window_small_size, | 157 InitCandidateWindowWithCandidatesFilled(candidate_window_small_size, |
| 135 &candidate_window_small); | 158 &candidate_window_small); |
| 136 candidate_window_small.set_cursor_position(candidate_window_small_size - 1); | 159 candidate_window_small.set_cursor_position(candidate_window_small_size - 1); |
| 137 // Make sure the test doesn't crash if the candidate window reduced | 160 // Make sure the test doesn't crash if the candidate window reduced |
| 138 // its size. (crbug.com/174163) | 161 // its size. (crbug.com/174163) |
| 139 candidate_window_view.UpdateCandidates(candidate_window_small); | 162 candidate_window_view()->UpdateCandidates(candidate_window_small); |
| 140 candidate_window_view.SelectCandidateAt(candidate_window_small_size - 1); | 163 SelectCandidateAt(candidate_window_small_size - 1); |
| 141 } | 164 } |
| 142 | 165 |
| 143 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { | 166 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { |
| 144 const char* kEmptyLabel = ""; | 167 const char* kEmptyLabel = ""; |
| 145 const char* kCustomizedLabel[] = { "a", "s", "d" }; | 168 const char* kCustomizedLabel[] = { "a", "s", "d" }; |
| 146 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; | 169 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; |
| 147 | 170 |
| 148 views::Widget* widget = new views::Widget; | |
| 149 views::Widget::InitParams params = | |
| 150 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 151 widget->Init(params); | |
| 152 | |
| 153 CandidateWindowView candidate_window_view(widget); | |
| 154 candidate_window_view.Init(); | |
| 155 | |
| 156 { | 171 { |
| 157 SCOPED_TRACE("candidate_views allocation test"); | 172 SCOPED_TRACE("candidate_views allocation test"); |
| 158 const size_t kMaxPageSize = 16; | 173 const size_t kMaxPageSize = 16; |
| 159 for (size_t i = 1; i < kMaxPageSize; ++i) { | 174 for (size_t i = 1; i < kMaxPageSize; ++i) { |
| 160 CandidateWindow candidate_window; | 175 CandidateWindow candidate_window; |
| 161 InitCandidateWindow(i, &candidate_window); | 176 InitCandidateWindow(i, &candidate_window); |
| 162 candidate_window_view.UpdateCandidates(candidate_window); | 177 candidate_window_view()->UpdateCandidates(candidate_window); |
| 163 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); | 178 EXPECT_EQ(i, GetCandidatesSize()); |
| 164 } | 179 } |
| 165 } | 180 } |
| 166 { | 181 { |
| 167 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); | 182 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); |
| 168 const size_t kPageSize = 3; | 183 const size_t kPageSize = 3; |
| 169 CandidateWindow candidate_window; | 184 CandidateWindow candidate_window; |
| 170 InitCandidateWindow(kPageSize, &candidate_window); | 185 InitCandidateWindow(kPageSize, &candidate_window); |
| 171 | 186 |
| 172 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 187 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 173 for (size_t i = 0; i < kPageSize; ++i) { | 188 for (size_t i = 0; i < kPageSize; ++i) { |
| 174 CandidateWindow::Entry entry; | 189 CandidateWindow::Entry entry; |
| 175 entry.value = kSampleCandidate[i]; | 190 entry.value = kSampleCandidate[i]; |
| 176 entry.annotation = kSampleAnnotation[i]; | 191 entry.annotation = kSampleAnnotation[i]; |
| 177 entry.description_title = kSampleDescriptionTitle[i]; | 192 entry.description_title = kSampleDescriptionTitle[i]; |
| 178 entry.description_body = kSampleDescriptionBody[i]; | 193 entry.description_body = kSampleDescriptionBody[i]; |
| 179 entry.label = kEmptyLabel; | 194 entry.label = kEmptyLabel; |
| 180 candidate_window.mutable_candidates()->push_back(entry); | 195 candidate_window.mutable_candidates()->push_back(entry); |
| 181 } | 196 } |
| 182 | 197 |
| 183 candidate_window_view.UpdateCandidates(candidate_window); | 198 candidate_window_view()->UpdateCandidates(candidate_window); |
| 184 | 199 |
| 185 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 200 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 186 for (size_t i = 0; i < kPageSize; ++i) { | 201 for (size_t i = 0; i < kPageSize; ++i) { |
| 187 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 202 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 188 candidate_window_view.candidate_views_[i]); | 203 GetCandidateAt(i)); |
| 189 } | 204 } |
| 190 } | 205 } |
| 191 { | 206 { |
| 192 SCOPED_TRACE( | 207 SCOPED_TRACE( |
| 193 "Empty string for each labels expect empty labels(horizontal)"); | 208 "Empty string for each labels expect empty labels(horizontal)"); |
| 194 const size_t kPageSize = 3; | 209 const size_t kPageSize = 3; |
| 195 CandidateWindow candidate_window; | 210 CandidateWindow candidate_window; |
| 196 InitCandidateWindow(kPageSize, &candidate_window); | 211 InitCandidateWindow(kPageSize, &candidate_window); |
| 197 | 212 |
| 198 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); | 213 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
| 199 for (size_t i = 0; i < kPageSize; ++i) { | 214 for (size_t i = 0; i < kPageSize; ++i) { |
| 200 CandidateWindow::Entry entry; | 215 CandidateWindow::Entry entry; |
| 201 entry.value = kSampleCandidate[i]; | 216 entry.value = kSampleCandidate[i]; |
| 202 entry.annotation = kSampleAnnotation[i]; | 217 entry.annotation = kSampleAnnotation[i]; |
| 203 entry.description_title = kSampleDescriptionTitle[i]; | 218 entry.description_title = kSampleDescriptionTitle[i]; |
| 204 entry.description_body = kSampleDescriptionBody[i]; | 219 entry.description_body = kSampleDescriptionBody[i]; |
| 205 entry.label = kEmptyLabel; | 220 entry.label = kEmptyLabel; |
| 206 candidate_window.mutable_candidates()->push_back(entry); | 221 candidate_window.mutable_candidates()->push_back(entry); |
| 207 } | 222 } |
| 208 | 223 |
| 209 candidate_window_view.UpdateCandidates(candidate_window); | 224 candidate_window_view()->UpdateCandidates(candidate_window); |
| 210 | 225 |
| 211 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 226 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 212 // Confirm actual labels not containing ".". | 227 // Confirm actual labels not containing ".". |
| 213 for (size_t i = 0; i < kPageSize; ++i) { | 228 for (size_t i = 0; i < kPageSize; ++i) { |
| 214 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 229 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 215 candidate_window_view.candidate_views_[i]); | 230 GetCandidateAt(i)); |
| 216 } | 231 } |
| 217 } | 232 } |
| 218 { | 233 { |
| 219 SCOPED_TRACE("Vertical customized label case"); | 234 SCOPED_TRACE("Vertical customized label case"); |
| 220 const size_t kPageSize = 3; | 235 const size_t kPageSize = 3; |
| 221 CandidateWindow candidate_window; | 236 CandidateWindow candidate_window; |
| 222 InitCandidateWindow(kPageSize, &candidate_window); | 237 InitCandidateWindow(kPageSize, &candidate_window); |
| 223 | 238 |
| 224 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 239 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 225 for (size_t i = 0; i < kPageSize; ++i) { | 240 for (size_t i = 0; i < kPageSize; ++i) { |
| 226 CandidateWindow::Entry entry; | 241 CandidateWindow::Entry entry; |
| 227 entry.value = kSampleCandidate[i]; | 242 entry.value = kSampleCandidate[i]; |
| 228 entry.annotation = kSampleAnnotation[i]; | 243 entry.annotation = kSampleAnnotation[i]; |
| 229 entry.description_title = kSampleDescriptionTitle[i]; | 244 entry.description_title = kSampleDescriptionTitle[i]; |
| 230 entry.description_body = kSampleDescriptionBody[i]; | 245 entry.description_body = kSampleDescriptionBody[i]; |
| 231 entry.label = kCustomizedLabel[i]; | 246 entry.label = kCustomizedLabel[i]; |
| 232 candidate_window.mutable_candidates()->push_back(entry); | 247 candidate_window.mutable_candidates()->push_back(entry); |
| 233 } | 248 } |
| 234 | 249 |
| 235 candidate_window_view.UpdateCandidates(candidate_window); | 250 candidate_window_view()->UpdateCandidates(candidate_window); |
| 236 | 251 |
| 237 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 252 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 238 // Confirm actual labels not containing ".". | 253 // Confirm actual labels not containing ".". |
| 239 for (size_t i = 0; i < kPageSize; ++i) { | 254 for (size_t i = 0; i < kPageSize; ++i) { |
| 240 ExpectLabels(kCustomizedLabel[i], | 255 ExpectLabels(kCustomizedLabel[i], |
| 241 kSampleCandidate[i], | 256 kSampleCandidate[i], |
| 242 kSampleAnnotation[i], | 257 kSampleAnnotation[i], |
| 243 candidate_window_view.candidate_views_[i]); | 258 GetCandidateAt(i)); |
| 244 } | 259 } |
| 245 } | 260 } |
| 246 { | 261 { |
| 247 SCOPED_TRACE("Horizontal customized label case"); | 262 SCOPED_TRACE("Horizontal customized label case"); |
| 248 const size_t kPageSize = 3; | 263 const size_t kPageSize = 3; |
| 249 CandidateWindow candidate_window; | 264 CandidateWindow candidate_window; |
| 250 InitCandidateWindow(kPageSize, &candidate_window); | 265 InitCandidateWindow(kPageSize, &candidate_window); |
| 251 | 266 |
| 252 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); | 267 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
| 253 for (size_t i = 0; i < kPageSize; ++i) { | 268 for (size_t i = 0; i < kPageSize; ++i) { |
| 254 CandidateWindow::Entry entry; | 269 CandidateWindow::Entry entry; |
| 255 entry.value = kSampleCandidate[i]; | 270 entry.value = kSampleCandidate[i]; |
| 256 entry.annotation = kSampleAnnotation[i]; | 271 entry.annotation = kSampleAnnotation[i]; |
| 257 entry.description_title = kSampleDescriptionTitle[i]; | 272 entry.description_title = kSampleDescriptionTitle[i]; |
| 258 entry.description_body = kSampleDescriptionBody[i]; | 273 entry.description_body = kSampleDescriptionBody[i]; |
| 259 entry.label = kCustomizedLabel[i]; | 274 entry.label = kCustomizedLabel[i]; |
| 260 candidate_window.mutable_candidates()->push_back(entry); | 275 candidate_window.mutable_candidates()->push_back(entry); |
| 261 } | 276 } |
| 262 | 277 |
| 263 candidate_window_view.UpdateCandidates(candidate_window); | 278 candidate_window_view()->UpdateCandidates(candidate_window); |
| 264 | 279 |
| 265 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 280 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 266 // Confirm actual labels not containing ".". | 281 // Confirm actual labels not containing ".". |
| 267 for (size_t i = 0; i < kPageSize; ++i) { | 282 for (size_t i = 0; i < kPageSize; ++i) { |
| 268 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], | 283 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
| 269 kSampleCandidate[i], | 284 kSampleCandidate[i], |
| 270 kSampleAnnotation[i], | 285 kSampleAnnotation[i], |
| 271 candidate_window_view.candidate_views_[i]); | 286 GetCandidateAt(i)); |
| 272 } | 287 } |
| 273 } | 288 } |
| 274 | |
| 275 // We should call CloseNow method, otherwise this test will leak memory. | |
| 276 widget->CloseNow(); | |
| 277 } | 289 } |
| 278 | 290 |
| 279 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { | 291 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { |
| 280 const size_t kPageSize = 10; | 292 const size_t kPageSize = 10; |
| 281 CandidateWindow candidate_window; | 293 CandidateWindow candidate_window; |
| 282 CandidateWindow no_shortcut_candidate_window; | 294 CandidateWindow no_shortcut_candidate_window; |
| 283 | 295 |
| 284 const char kSampleCandidate1[] = "Sample String 1"; | 296 const char kSampleCandidate1[] = "Sample String 1"; |
| 285 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 297 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. |
| 286 const char kSampleCandidate3[] = "....."; | 298 const char kSampleCandidate3[] = "....."; |
| 287 | 299 |
| 288 const char kSampleShortcut1[] = "1"; | 300 const char kSampleShortcut1[] = "1"; |
| 289 const char kSampleShortcut2[] = "b"; | 301 const char kSampleShortcut2[] = "b"; |
| 290 const char kSampleShortcut3[] = "C"; | 302 const char kSampleShortcut3[] = "C"; |
| 291 | 303 |
| 292 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 304 const char kSampleAnnotation1[] = "Sample Annotation 1"; |
| 293 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. | 305 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. |
| 294 const char kSampleAnnotation3[] = "......"; | 306 const char kSampleAnnotation3[] = "......"; |
| 295 | 307 |
| 296 // For testing, we have to prepare empty widget. | |
| 297 // We should NOT manually free widget by default, otherwise double free will | |
| 298 // be occurred. So, we should instantiate widget class with "new" operation. | |
| 299 views::Widget* widget = new views::Widget; | |
| 300 views::Widget::InitParams params = | |
| 301 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 302 widget->Init(params); | |
| 303 | |
| 304 CandidateWindowView candidate_window_view(widget); | |
| 305 candidate_window_view.Init(); | |
| 306 | |
| 307 // Create CandidateWindow object. | 308 // Create CandidateWindow object. |
| 308 InitCandidateWindow(kPageSize, &candidate_window); | 309 InitCandidateWindow(kPageSize, &candidate_window); |
| 309 | 310 |
| 310 candidate_window.set_cursor_position(0); | 311 candidate_window.set_cursor_position(0); |
| 311 candidate_window.set_page_size(3); | 312 candidate_window.set_page_size(3); |
| 312 candidate_window.mutable_candidates()->clear(); | 313 candidate_window.mutable_candidates()->clear(); |
| 313 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 314 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 314 no_shortcut_candidate_window.CopyFrom(candidate_window); | 315 no_shortcut_candidate_window.CopyFrom(candidate_window); |
| 315 | 316 |
| 316 CandidateWindow::Entry entry; | 317 CandidateWindow::Entry entry; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 329 entry.value = kSampleCandidate3; | 330 entry.value = kSampleCandidate3; |
| 330 entry.annotation = kSampleAnnotation3; | 331 entry.annotation = kSampleAnnotation3; |
| 331 candidate_window.mutable_candidates()->push_back(entry); | 332 candidate_window.mutable_candidates()->push_back(entry); |
| 332 entry.label = kSampleShortcut3; | 333 entry.label = kSampleShortcut3; |
| 333 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); | 334 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); |
| 334 | 335 |
| 335 int before_height = 0; | 336 int before_height = 0; |
| 336 | 337 |
| 337 // Test for shortcut mode to no-shortcut mode. | 338 // Test for shortcut mode to no-shortcut mode. |
| 338 // Initialize with a shortcut mode candidate window. | 339 // Initialize with a shortcut mode candidate window. |
| 339 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); | 340 MaybeInitializeCandidateViews(candidate_window); |
| 340 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 341 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 341 // Check the selected index is invalidated. | 342 // Check the selected index is invalidated. |
| 342 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 343 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 343 before_height = | 344 before_height = |
| 344 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | 345 GetCandidateAt(0)->GetContentsBounds().height(); |
| 345 // Checks all entry have same row height. | 346 // Checks all entry have same row height. |
| 346 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 347 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 347 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 348 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 348 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 349 } | |
| 350 | 349 |
| 351 // Initialize with a no shortcut mode candidate window. | 350 // Initialize with a no shortcut mode candidate window. |
| 352 candidate_window_view.MaybeInitializeCandidateViews( | 351 MaybeInitializeCandidateViews(no_shortcut_candidate_window); |
| 353 no_shortcut_candidate_window); | 352 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 354 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | |
| 355 // Check the selected index is invalidated. | 353 // Check the selected index is invalidated. |
| 356 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 354 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 357 EXPECT_EQ(before_height, | 355 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); |
| 358 candidate_window_view.candidate_views_[0]->GetContentsBounds() | |
| 359 .height()); | |
| 360 // Checks all entry have same row height. | 356 // Checks all entry have same row height. |
| 361 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 357 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 362 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 358 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 363 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 364 } | |
| 365 | 359 |
| 366 // Test for no-shortcut mode to shortcut mode. | 360 // Test for no-shortcut mode to shortcut mode. |
| 367 // Initialize with a no shortcut mode candidate window. | 361 // Initialize with a no shortcut mode candidate window. |
| 368 candidate_window_view.MaybeInitializeCandidateViews( | 362 MaybeInitializeCandidateViews(no_shortcut_candidate_window); |
| 369 no_shortcut_candidate_window); | 363 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 370 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | |
| 371 // Check the selected index is invalidated. | 364 // Check the selected index is invalidated. |
| 372 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 365 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 373 before_height = | 366 before_height = GetCandidateAt(0)->GetContentsBounds().height(); |
| 374 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | |
| 375 // Checks all entry have same row height. | 367 // Checks all entry have same row height. |
| 376 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 368 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 377 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 369 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 378 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 379 } | |
| 380 | 370 |
| 381 // Initialize with a shortcut mode candidate window. | 371 // Initialize with a shortcut mode candidate window. |
| 382 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); | 372 MaybeInitializeCandidateViews(candidate_window); |
| 383 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 373 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 384 // Check the selected index is invalidated. | 374 // Check the selected index is invalidated. |
| 385 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 375 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 386 EXPECT_EQ(before_height, | 376 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); |
| 387 candidate_window_view.candidate_views_[0]->GetContentsBounds() | |
| 388 .height()); | |
| 389 // Checks all entry have same row height. | 377 // Checks all entry have same row height. |
| 390 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 378 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 391 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 379 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 392 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 393 } | |
| 394 | |
| 395 // We should call CloseNow method, otherwise this test will leak memory. | |
| 396 widget->CloseNow(); | |
| 397 } | 380 } |
| 398 } // namespace input_method | 381 } // namespace input_method |
| 399 } // namespace chromeos | 382 } // namespace chromeos |
| OLD | NEW |