| 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 // Select the last candidate. | 150 // Select the last candidate. |
| 128 candidate_window_view.SelectCandidateAt(candidate_window_large_size - 1); | 151 SelectCandidateAt(candidate_window_large_size - 1); |
| 129 | 152 |
| 130 // Reduce the number of candidates to 3. | 153 // Reduce the number of candidates to 3. |
| 131 CandidateWindow candidate_window_small; | 154 CandidateWindow candidate_window_small; |
| 132 const int candidate_window_small_size = 3; | 155 const int candidate_window_small_size = 3; |
| 133 InitCandidateWindowWithCandidatesFilled(candidate_window_small_size, | 156 InitCandidateWindowWithCandidatesFilled(candidate_window_small_size, |
| 134 &candidate_window_small); | 157 &candidate_window_small); |
| 135 candidate_window_small.set_cursor_position(candidate_window_small_size - 1); | 158 candidate_window_small.set_cursor_position(candidate_window_small_size - 1); |
| 136 // Make sure the test doesn't crash if the candidate window reduced | 159 // Make sure the test doesn't crash if the candidate window reduced |
| 137 // its size. (crbug.com/174163) | 160 // its size. (crbug.com/174163) |
| 138 candidate_window_view.UpdateCandidates(candidate_window_small); | 161 candidate_window_view()->UpdateCandidates(candidate_window_small); |
| 139 candidate_window_view.SelectCandidateAt(candidate_window_small_size - 1); | 162 SelectCandidateAt(candidate_window_small_size - 1); |
| 140 } | 163 } |
| 141 | 164 |
| 142 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { | 165 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { |
| 143 const char* kEmptyLabel = ""; | 166 const char* kEmptyLabel = ""; |
| 144 const char* kCustomizedLabel[] = { "a", "s", "d" }; | 167 const char* kCustomizedLabel[] = { "a", "s", "d" }; |
| 145 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; | 168 const char* kExpectedHorizontalCustomizedLabel[] = { "a.", "s.", "d." }; |
| 146 | 169 |
| 147 views::Widget* widget = new views::Widget; | |
| 148 views::Widget::InitParams params = | |
| 149 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 150 widget->Init(params); | |
| 151 | |
| 152 CandidateWindowView candidate_window_view(widget); | |
| 153 candidate_window_view.Init(); | |
| 154 | |
| 155 { | 170 { |
| 156 SCOPED_TRACE("candidate_views allocation test"); | 171 SCOPED_TRACE("candidate_views allocation test"); |
| 157 const size_t kMaxPageSize = 16; | 172 const size_t kMaxPageSize = 16; |
| 158 for (size_t i = 1; i < kMaxPageSize; ++i) { | 173 for (size_t i = 1; i < kMaxPageSize; ++i) { |
| 159 CandidateWindow candidate_window; | 174 CandidateWindow candidate_window; |
| 160 InitCandidateWindow(i, &candidate_window); | 175 InitCandidateWindow(i, &candidate_window); |
| 161 candidate_window_view.UpdateCandidates(candidate_window); | 176 candidate_window_view()->UpdateCandidates(candidate_window); |
| 162 EXPECT_EQ(i, candidate_window_view.candidate_views_.size()); | 177 EXPECT_EQ(i, GetCandidatesSize()); |
| 163 } | 178 } |
| 164 } | 179 } |
| 165 { | 180 { |
| 166 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); | 181 SCOPED_TRACE("Empty string for each labels expects empty labels(vertical)"); |
| 167 const size_t kPageSize = 3; | 182 const size_t kPageSize = 3; |
| 168 CandidateWindow candidate_window; | 183 CandidateWindow candidate_window; |
| 169 InitCandidateWindow(kPageSize, &candidate_window); | 184 InitCandidateWindow(kPageSize, &candidate_window); |
| 170 | 185 |
| 171 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 186 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 172 for (size_t i = 0; i < kPageSize; ++i) { | 187 for (size_t i = 0; i < kPageSize; ++i) { |
| 173 CandidateWindow::Entry entry; | 188 CandidateWindow::Entry entry; |
| 174 entry.value = kSampleCandidate[i]; | 189 entry.value = kSampleCandidate[i]; |
| 175 entry.annotation = kSampleAnnotation[i]; | 190 entry.annotation = kSampleAnnotation[i]; |
| 176 entry.description_title = kSampleDescriptionTitle[i]; | 191 entry.description_title = kSampleDescriptionTitle[i]; |
| 177 entry.description_body = kSampleDescriptionBody[i]; | 192 entry.description_body = kSampleDescriptionBody[i]; |
| 178 entry.label = kEmptyLabel; | 193 entry.label = kEmptyLabel; |
| 179 candidate_window.mutable_candidates()->push_back(entry); | 194 candidate_window.mutable_candidates()->push_back(entry); |
| 180 } | 195 } |
| 181 | 196 |
| 182 candidate_window_view.UpdateCandidates(candidate_window); | 197 candidate_window_view()->UpdateCandidates(candidate_window); |
| 183 | 198 |
| 184 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 199 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 185 for (size_t i = 0; i < kPageSize; ++i) { | 200 for (size_t i = 0; i < kPageSize; ++i) { |
| 186 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 201 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 187 candidate_window_view.candidate_views_[i]); | 202 GetCandidateAt(i)); |
| 188 } | 203 } |
| 189 } | 204 } |
| 190 { | 205 { |
| 191 SCOPED_TRACE( | 206 SCOPED_TRACE( |
| 192 "Empty string for each labels expect empty labels(horizontal)"); | 207 "Empty string for each labels expect empty labels(horizontal)"); |
| 193 const size_t kPageSize = 3; | 208 const size_t kPageSize = 3; |
| 194 CandidateWindow candidate_window; | 209 CandidateWindow candidate_window; |
| 195 InitCandidateWindow(kPageSize, &candidate_window); | 210 InitCandidateWindow(kPageSize, &candidate_window); |
| 196 | 211 |
| 197 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); | 212 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
| 198 for (size_t i = 0; i < kPageSize; ++i) { | 213 for (size_t i = 0; i < kPageSize; ++i) { |
| 199 CandidateWindow::Entry entry; | 214 CandidateWindow::Entry entry; |
| 200 entry.value = kSampleCandidate[i]; | 215 entry.value = kSampleCandidate[i]; |
| 201 entry.annotation = kSampleAnnotation[i]; | 216 entry.annotation = kSampleAnnotation[i]; |
| 202 entry.description_title = kSampleDescriptionTitle[i]; | 217 entry.description_title = kSampleDescriptionTitle[i]; |
| 203 entry.description_body = kSampleDescriptionBody[i]; | 218 entry.description_body = kSampleDescriptionBody[i]; |
| 204 entry.label = kEmptyLabel; | 219 entry.label = kEmptyLabel; |
| 205 candidate_window.mutable_candidates()->push_back(entry); | 220 candidate_window.mutable_candidates()->push_back(entry); |
| 206 } | 221 } |
| 207 | 222 |
| 208 candidate_window_view.UpdateCandidates(candidate_window); | 223 candidate_window_view()->UpdateCandidates(candidate_window); |
| 209 | 224 |
| 210 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 225 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 211 // Confirm actual labels not containing ".". | 226 // Confirm actual labels not containing ".". |
| 212 for (size_t i = 0; i < kPageSize; ++i) { | 227 for (size_t i = 0; i < kPageSize; ++i) { |
| 213 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], | 228 ExpectLabels(kEmptyLabel, kSampleCandidate[i], kSampleAnnotation[i], |
| 214 candidate_window_view.candidate_views_[i]); | 229 GetCandidateAt(i)); |
| 215 } | 230 } |
| 216 } | 231 } |
| 217 { | 232 { |
| 218 SCOPED_TRACE("Vertical customized label case"); | 233 SCOPED_TRACE("Vertical customized label case"); |
| 219 const size_t kPageSize = 3; | 234 const size_t kPageSize = 3; |
| 220 CandidateWindow candidate_window; | 235 CandidateWindow candidate_window; |
| 221 InitCandidateWindow(kPageSize, &candidate_window); | 236 InitCandidateWindow(kPageSize, &candidate_window); |
| 222 | 237 |
| 223 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 238 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 224 for (size_t i = 0; i < kPageSize; ++i) { | 239 for (size_t i = 0; i < kPageSize; ++i) { |
| 225 CandidateWindow::Entry entry; | 240 CandidateWindow::Entry entry; |
| 226 entry.value = kSampleCandidate[i]; | 241 entry.value = kSampleCandidate[i]; |
| 227 entry.annotation = kSampleAnnotation[i]; | 242 entry.annotation = kSampleAnnotation[i]; |
| 228 entry.description_title = kSampleDescriptionTitle[i]; | 243 entry.description_title = kSampleDescriptionTitle[i]; |
| 229 entry.description_body = kSampleDescriptionBody[i]; | 244 entry.description_body = kSampleDescriptionBody[i]; |
| 230 entry.label = kCustomizedLabel[i]; | 245 entry.label = kCustomizedLabel[i]; |
| 231 candidate_window.mutable_candidates()->push_back(entry); | 246 candidate_window.mutable_candidates()->push_back(entry); |
| 232 } | 247 } |
| 233 | 248 |
| 234 candidate_window_view.UpdateCandidates(candidate_window); | 249 candidate_window_view()->UpdateCandidates(candidate_window); |
| 235 | 250 |
| 236 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 251 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 237 // Confirm actual labels not containing ".". | 252 // Confirm actual labels not containing ".". |
| 238 for (size_t i = 0; i < kPageSize; ++i) { | 253 for (size_t i = 0; i < kPageSize; ++i) { |
| 239 ExpectLabels(kCustomizedLabel[i], | 254 ExpectLabels(kCustomizedLabel[i], |
| 240 kSampleCandidate[i], | 255 kSampleCandidate[i], |
| 241 kSampleAnnotation[i], | 256 kSampleAnnotation[i], |
| 242 candidate_window_view.candidate_views_[i]); | 257 GetCandidateAt(i)); |
| 243 } | 258 } |
| 244 } | 259 } |
| 245 { | 260 { |
| 246 SCOPED_TRACE("Horizontal customized label case"); | 261 SCOPED_TRACE("Horizontal customized label case"); |
| 247 const size_t kPageSize = 3; | 262 const size_t kPageSize = 3; |
| 248 CandidateWindow candidate_window; | 263 CandidateWindow candidate_window; |
| 249 InitCandidateWindow(kPageSize, &candidate_window); | 264 InitCandidateWindow(kPageSize, &candidate_window); |
| 250 | 265 |
| 251 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); | 266 candidate_window.set_orientation(CandidateWindow::HORIZONTAL); |
| 252 for (size_t i = 0; i < kPageSize; ++i) { | 267 for (size_t i = 0; i < kPageSize; ++i) { |
| 253 CandidateWindow::Entry entry; | 268 CandidateWindow::Entry entry; |
| 254 entry.value = kSampleCandidate[i]; | 269 entry.value = kSampleCandidate[i]; |
| 255 entry.annotation = kSampleAnnotation[i]; | 270 entry.annotation = kSampleAnnotation[i]; |
| 256 entry.description_title = kSampleDescriptionTitle[i]; | 271 entry.description_title = kSampleDescriptionTitle[i]; |
| 257 entry.description_body = kSampleDescriptionBody[i]; | 272 entry.description_body = kSampleDescriptionBody[i]; |
| 258 entry.label = kCustomizedLabel[i]; | 273 entry.label = kCustomizedLabel[i]; |
| 259 candidate_window.mutable_candidates()->push_back(entry); | 274 candidate_window.mutable_candidates()->push_back(entry); |
| 260 } | 275 } |
| 261 | 276 |
| 262 candidate_window_view.UpdateCandidates(candidate_window); | 277 candidate_window_view()->UpdateCandidates(candidate_window); |
| 263 | 278 |
| 264 ASSERT_EQ(kPageSize, candidate_window_view.candidate_views_.size()); | 279 ASSERT_EQ(kPageSize, GetCandidatesSize()); |
| 265 // Confirm actual labels not containing ".". | 280 // Confirm actual labels not containing ".". |
| 266 for (size_t i = 0; i < kPageSize; ++i) { | 281 for (size_t i = 0; i < kPageSize; ++i) { |
| 267 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], | 282 ExpectLabels(kExpectedHorizontalCustomizedLabel[i], |
| 268 kSampleCandidate[i], | 283 kSampleCandidate[i], |
| 269 kSampleAnnotation[i], | 284 kSampleAnnotation[i], |
| 270 candidate_window_view.candidate_views_[i]); | 285 GetCandidateAt(i)); |
| 271 } | 286 } |
| 272 } | 287 } |
| 273 | |
| 274 // We should call CloseNow method, otherwise this test will leak memory. | |
| 275 widget->CloseNow(); | |
| 276 } | 288 } |
| 277 | 289 |
| 278 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { | 290 TEST_F(CandidateWindowViewTest, DoNotChangeRowHeightWithLabelSwitchTest) { |
| 279 const size_t kPageSize = 10; | 291 const size_t kPageSize = 10; |
| 280 CandidateWindow candidate_window; | 292 CandidateWindow candidate_window; |
| 281 CandidateWindow no_shortcut_candidate_window; | 293 CandidateWindow no_shortcut_candidate_window; |
| 282 | 294 |
| 283 const char kSampleCandidate1[] = "Sample String 1"; | 295 const char kSampleCandidate1[] = "Sample String 1"; |
| 284 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. | 296 const char kSampleCandidate2[] = "\xE3\x81\x82"; // multi byte string. |
| 285 const char kSampleCandidate3[] = "....."; | 297 const char kSampleCandidate3[] = "....."; |
| 286 | 298 |
| 287 const char kSampleShortcut1[] = "1"; | 299 const char kSampleShortcut1[] = "1"; |
| 288 const char kSampleShortcut2[] = "b"; | 300 const char kSampleShortcut2[] = "b"; |
| 289 const char kSampleShortcut3[] = "C"; | 301 const char kSampleShortcut3[] = "C"; |
| 290 | 302 |
| 291 const char kSampleAnnotation1[] = "Sample Annotation 1"; | 303 const char kSampleAnnotation1[] = "Sample Annotation 1"; |
| 292 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. | 304 const char kSampleAnnotation2[] = "\xE3\x81\x82"; // multi byte string. |
| 293 const char kSampleAnnotation3[] = "......"; | 305 const char kSampleAnnotation3[] = "......"; |
| 294 | 306 |
| 295 // For testing, we have to prepare empty widget. | |
| 296 // We should NOT manually free widget by default, otherwise double free will | |
| 297 // be occurred. So, we should instantiate widget class with "new" operation. | |
| 298 views::Widget* widget = new views::Widget; | |
| 299 views::Widget::InitParams params = | |
| 300 CreateParams(views::Widget::InitParams::TYPE_WINDOW); | |
| 301 widget->Init(params); | |
| 302 | |
| 303 CandidateWindowView candidate_window_view(widget); | |
| 304 candidate_window_view.Init(); | |
| 305 | |
| 306 // Create CandidateWindow object. | 307 // Create CandidateWindow object. |
| 307 InitCandidateWindow(kPageSize, &candidate_window); | 308 InitCandidateWindow(kPageSize, &candidate_window); |
| 308 | 309 |
| 309 candidate_window.set_cursor_position(0); | 310 candidate_window.set_cursor_position(0); |
| 310 candidate_window.set_page_size(3); | 311 candidate_window.set_page_size(3); |
| 311 candidate_window.mutable_candidates()->clear(); | 312 candidate_window.mutable_candidates()->clear(); |
| 312 candidate_window.set_orientation(CandidateWindow::VERTICAL); | 313 candidate_window.set_orientation(CandidateWindow::VERTICAL); |
| 313 no_shortcut_candidate_window.CopyFrom(candidate_window); | 314 no_shortcut_candidate_window.CopyFrom(candidate_window); |
| 314 | 315 |
| 315 CandidateWindow::Entry entry; | 316 CandidateWindow::Entry entry; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 328 entry.value = kSampleCandidate3; | 329 entry.value = kSampleCandidate3; |
| 329 entry.annotation = kSampleAnnotation3; | 330 entry.annotation = kSampleAnnotation3; |
| 330 candidate_window.mutable_candidates()->push_back(entry); | 331 candidate_window.mutable_candidates()->push_back(entry); |
| 331 entry.label = kSampleShortcut3; | 332 entry.label = kSampleShortcut3; |
| 332 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); | 333 no_shortcut_candidate_window.mutable_candidates()->push_back(entry); |
| 333 | 334 |
| 334 int before_height = 0; | 335 int before_height = 0; |
| 335 | 336 |
| 336 // Test for shortcut mode to no-shortcut mode. | 337 // Test for shortcut mode to no-shortcut mode. |
| 337 // Initialize with a shortcut mode candidate window. | 338 // Initialize with a shortcut mode candidate window. |
| 338 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); | 339 MaybeInitializeCandidateViews(candidate_window); |
| 339 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 340 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 340 // Check the selected index is invalidated. | 341 // Check the selected index is invalidated. |
| 341 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 342 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 342 before_height = | 343 before_height = |
| 343 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | 344 GetCandidateAt(0)->GetContentsBounds().height(); |
| 344 // Checks all entry have same row height. | 345 // Checks all entry have same row height. |
| 345 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 346 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 346 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 347 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 347 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 348 } | |
| 349 | 348 |
| 350 // Initialize with a no shortcut mode candidate window. | 349 // Initialize with a no shortcut mode candidate window. |
| 351 candidate_window_view.MaybeInitializeCandidateViews( | 350 MaybeInitializeCandidateViews(no_shortcut_candidate_window); |
| 352 no_shortcut_candidate_window); | 351 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 353 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | |
| 354 // Check the selected index is invalidated. | 352 // Check the selected index is invalidated. |
| 355 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 353 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 356 EXPECT_EQ(before_height, | 354 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); |
| 357 candidate_window_view.candidate_views_[0]->GetContentsBounds() | |
| 358 .height()); | |
| 359 // Checks all entry have same row height. | 355 // Checks all entry have same row height. |
| 360 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 356 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 361 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 357 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 362 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 363 } | |
| 364 | 358 |
| 365 // Test for no-shortcut mode to shortcut mode. | 359 // Test for no-shortcut mode to shortcut mode. |
| 366 // Initialize with a no shortcut mode candidate window. | 360 // Initialize with a no shortcut mode candidate window. |
| 367 candidate_window_view.MaybeInitializeCandidateViews( | 361 MaybeInitializeCandidateViews(no_shortcut_candidate_window); |
| 368 no_shortcut_candidate_window); | 362 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 369 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | |
| 370 // Check the selected index is invalidated. | 363 // Check the selected index is invalidated. |
| 371 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 364 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 372 before_height = | 365 before_height = GetCandidateAt(0)->GetContentsBounds().height(); |
| 373 candidate_window_view.candidate_views_[0]->GetContentsBounds().height(); | |
| 374 // Checks all entry have same row height. | 366 // Checks all entry have same row height. |
| 375 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 367 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 376 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 368 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 377 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 378 } | |
| 379 | 369 |
| 380 // Initialize with a shortcut mode candidate window. | 370 // Initialize with a shortcut mode candidate window. |
| 381 candidate_window_view.MaybeInitializeCandidateViews(candidate_window); | 371 MaybeInitializeCandidateViews(candidate_window); |
| 382 ASSERT_EQ(3UL, candidate_window_view.candidate_views_.size()); | 372 ASSERT_EQ(3UL, GetCandidatesSize()); |
| 383 // Check the selected index is invalidated. | 373 // Check the selected index is invalidated. |
| 384 EXPECT_EQ(-1, candidate_window_view.selected_candidate_index_in_page_); | 374 EXPECT_EQ(-1, selected_candidate_index_in_page()); |
| 385 EXPECT_EQ(before_height, | 375 EXPECT_EQ(before_height, GetCandidateAt(0)->GetContentsBounds().height()); |
| 386 candidate_window_view.candidate_views_[0]->GetContentsBounds() | |
| 387 .height()); | |
| 388 // Checks all entry have same row height. | 376 // Checks all entry have same row height. |
| 389 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 377 for (size_t i = 1; i < GetCandidatesSize(); ++i) |
| 390 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 378 EXPECT_EQ(before_height, GetCandidateAt(i)->GetContentsBounds().height()); |
| 391 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | |
| 392 } | |
| 393 | |
| 394 // We should call CloseNow method, otherwise this test will leak memory. | |
| 395 widget->CloseNow(); | |
| 396 } | 379 } |
| 397 } // namespace input_method | 380 } // namespace input_method |
| 398 } // namespace chromeos | 381 } // namespace chromeos |
| OLD | NEW |