Chromium Code Reviews| 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/input_method/candidate_view.h" | 10 #include "chrome/browser/chromeos/input_method/candidate_view.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 table->annotations.clear(); | 28 table->annotations.clear(); |
| 29 table->mozc_candidates.Clear(); | 29 table->mozc_candidates.Clear(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void InitializeMozcCandidates(InputMethodLookupTable* table) { | 32 void InitializeMozcCandidates(InputMethodLookupTable* table) { |
| 33 table->mozc_candidates.Clear(); | 33 table->mozc_candidates.Clear(); |
| 34 table->mozc_candidates.set_position(0); | 34 table->mozc_candidates.set_position(0); |
| 35 table->mozc_candidates.set_size(0); | 35 table->mozc_candidates.set_size(0); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void SetCaretRectIntoMozcCandidates( | 38 void AppendCandidateIntoLookupTable(InputMethodLookupTable* table, |
| 39 InputMethodLookupTable* table, | 39 std::string value) { |
|
Yusuke Sato
2012/06/13 14:31:26
const reference
Seigo Nonaka
2012/06/13 15:07:18
Done.
| |
| 40 mozc::commands::Candidates::CandidateWindowLocation location, | |
| 41 int x, | |
| 42 int y, | |
| 43 int width, | |
| 44 int height) { | |
| 45 table->mozc_candidates.set_window_location(location); | |
| 46 mozc::commands::Rectangle *rect = | |
| 47 table->mozc_candidates.mutable_composition_rectangle(); | |
| 48 rect->set_x(x); | |
| 49 rect->set_y(y); | |
| 50 rect->set_width(width); | |
| 51 rect->set_height(height); | |
| 52 } | |
| 53 | |
| 54 void AppendCandidateIntoMozcCandidates(InputMethodLookupTable* table, | |
| 55 std::string value) { | |
| 56 mozc::commands::Candidates::Candidate *candidate = | 40 mozc::commands::Candidates::Candidate *candidate = |
| 57 table->mozc_candidates.add_candidate(); | 41 table->mozc_candidates.add_candidate(); |
| 58 | 42 |
| 59 int current_entry_count = table->mozc_candidates.candidate_size(); | 43 int current_entry_count = table->mozc_candidates.candidate_size(); |
| 44 table->candidates.push_back(value); | |
| 60 candidate->set_index(current_entry_count); | 45 candidate->set_index(current_entry_count); |
| 61 candidate->set_value(value); | 46 candidate->set_value(value); |
| 62 candidate->set_id(current_entry_count); | 47 candidate->set_id(current_entry_count); |
| 63 candidate->set_information_id(current_entry_count); | 48 candidate->set_information_id(current_entry_count); |
| 64 } | 49 } |
| 65 | 50 |
| 66 } // namespace | 51 } // namespace |
| 67 | 52 |
| 68 class CandidateWindowViewTest : public views::ViewsTestBase { | 53 class CandidateWindowViewTest : public views::ViewsTestBase { |
| 69 protected: | 54 protected: |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 176 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
| 192 new_table)); | 177 new_table)); |
| 193 } | 178 } |
| 194 | 179 |
| 195 TEST_F(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { | 180 TEST_F(CandidateWindowViewTest, MozcSuggestWindowShouldUpdateTest) { |
| 196 // ShouldUpdateCandidateViews method should also judge with consideration of | 181 // ShouldUpdateCandidateViews method should also judge with consideration of |
| 197 // the mozc specific candidate information. Following tests verify them. | 182 // the mozc specific candidate information. Following tests verify them. |
| 198 const char* kSampleCandidate1 = "Sample Candidate 1"; | 183 const char* kSampleCandidate1 = "Sample Candidate 1"; |
| 199 const char* kSampleCandidate2 = "Sample Candidate 2"; | 184 const char* kSampleCandidate2 = "Sample Candidate 2"; |
| 200 | 185 |
| 201 const int kCaretPositionX1 = 10; | |
| 202 const int kCaretPositionY1 = 20; | |
| 203 const int kCaretPositionWidth1 = 30; | |
| 204 const int kCaretPositionHeight1 = 40; | |
| 205 | |
| 206 const int kCaretPositionX2 = 15; | |
| 207 const int kCaretPositionY2 = 25; | |
| 208 const int kCaretPositionWidth2 = 35; | |
| 209 const int kCaretPositionHeight2 = 45; | |
| 210 | |
| 211 const size_t kPageSize = 10; | 186 const size_t kPageSize = 10; |
| 212 | 187 |
| 213 InputMethodLookupTable old_table; | 188 InputMethodLookupTable old_table; |
| 214 InputMethodLookupTable new_table; | 189 InputMethodLookupTable new_table; |
| 215 | 190 |
| 216 // State chagne from using non-mozc candidate to mozc candidate. | 191 // State chagne from using non-mozc candidate to mozc candidate. |
| 217 ClearInputMethodLookupTable(kPageSize, &old_table); | 192 ClearInputMethodLookupTable(kPageSize, &old_table); |
| 218 ClearInputMethodLookupTable(kPageSize, &new_table); | 193 ClearInputMethodLookupTable(kPageSize, &new_table); |
| 219 | 194 |
| 220 old_table.candidates.push_back(kSampleCandidate1); | 195 old_table.candidates.push_back(kSampleCandidate1); |
| 221 InitializeMozcCandidates(&new_table); | 196 InitializeMozcCandidates(&new_table); |
| 222 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | 197 AppendCandidateIntoLookupTable(&new_table, kSampleCandidate2); |
| 223 SetCaretRectIntoMozcCandidates(&new_table, | |
| 224 mozc::commands::Candidates::COMPOSITION, | |
| 225 kCaretPositionX1, | |
| 226 kCaretPositionY1, | |
| 227 kCaretPositionWidth1, | |
| 228 kCaretPositionHeight1); | |
| 229 | 198 |
| 230 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 199 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
| 231 new_table)); | 200 new_table)); |
| 232 | 201 |
| 233 // State change from using mozc candidate to non-mozc candidate | 202 // State change from using mozc candidate to non-mozc candidate |
| 234 ClearInputMethodLookupTable(kPageSize, &old_table); | 203 ClearInputMethodLookupTable(kPageSize, &old_table); |
| 235 ClearInputMethodLookupTable(kPageSize, &new_table); | 204 ClearInputMethodLookupTable(kPageSize, &new_table); |
| 236 | 205 |
| 237 InitializeMozcCandidates(&old_table); | 206 InitializeMozcCandidates(&old_table); |
| 238 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | 207 AppendCandidateIntoLookupTable(&old_table, kSampleCandidate1); |
| 239 SetCaretRectIntoMozcCandidates(&old_table, | |
| 240 mozc::commands::Candidates::COMPOSITION, | |
| 241 kCaretPositionX1, | |
| 242 kCaretPositionY1, | |
| 243 kCaretPositionWidth1, | |
| 244 kCaretPositionHeight1); | |
| 245 | 208 |
| 246 new_table.candidates.push_back(kSampleCandidate1); | 209 new_table.candidates.push_back(kSampleCandidate2); |
| 247 | 210 |
| 248 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 211 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
| 249 new_table)); | 212 new_table)); |
| 250 | 213 |
| 251 // State change from using mozc candidate to mozc candidate | 214 // State change from using mozc candidate to mozc candidate |
| 252 | 215 |
| 253 // No change | 216 // No change |
| 254 ClearInputMethodLookupTable(kPageSize, &old_table); | 217 ClearInputMethodLookupTable(kPageSize, &old_table); |
| 255 ClearInputMethodLookupTable(kPageSize, &new_table); | 218 ClearInputMethodLookupTable(kPageSize, &new_table); |
| 256 | 219 |
| 257 InitializeMozcCandidates(&old_table); | 220 InitializeMozcCandidates(&old_table); |
| 258 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | 221 AppendCandidateIntoLookupTable(&old_table, kSampleCandidate1); |
| 259 SetCaretRectIntoMozcCandidates(&old_table, | |
| 260 mozc::commands::Candidates::COMPOSITION, | |
| 261 kCaretPositionX1, | |
| 262 kCaretPositionY1, | |
| 263 kCaretPositionWidth1, | |
| 264 kCaretPositionHeight1); | |
| 265 | 222 |
| 266 InitializeMozcCandidates(&new_table); | 223 InitializeMozcCandidates(&new_table); |
| 267 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | 224 AppendCandidateIntoLookupTable(&new_table, kSampleCandidate1); |
| 268 SetCaretRectIntoMozcCandidates(&new_table, | |
| 269 mozc::commands::Candidates::COMPOSITION, | |
| 270 kCaretPositionX1, | |
| 271 kCaretPositionY1, | |
| 272 kCaretPositionWidth1, | |
| 273 kCaretPositionHeight1); | |
| 274 | 225 |
| 275 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 226 EXPECT_FALSE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
| 276 new_table)); | 227 new_table)); |
| 277 // Position change only | 228 // Candidate contents |
| 278 ClearInputMethodLookupTable(kPageSize, &old_table); | 229 ClearInputMethodLookupTable(kPageSize, &old_table); |
| 279 ClearInputMethodLookupTable(kPageSize, &new_table); | 230 ClearInputMethodLookupTable(kPageSize, &new_table); |
| 280 | 231 |
| 281 InitializeMozcCandidates(&old_table); | 232 InitializeMozcCandidates(&old_table); |
| 282 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | 233 AppendCandidateIntoLookupTable(&old_table, kSampleCandidate1); |
| 283 SetCaretRectIntoMozcCandidates(&old_table, | |
| 284 mozc::commands::Candidates::COMPOSITION, | |
| 285 kCaretPositionX1, | |
| 286 kCaretPositionY1, | |
| 287 kCaretPositionWidth1, | |
| 288 kCaretPositionHeight1); | |
| 289 | 234 |
| 290 InitializeMozcCandidates(&new_table); | 235 InitializeMozcCandidates(&new_table); |
| 291 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate1); | 236 AppendCandidateIntoLookupTable(&new_table, kSampleCandidate2); |
| 292 SetCaretRectIntoMozcCandidates(&new_table, | |
| 293 mozc::commands::Candidates::COMPOSITION, | |
| 294 kCaretPositionX2, | |
| 295 kCaretPositionY2, | |
| 296 kCaretPositionWidth2, | |
| 297 kCaretPositionHeight2); | |
| 298 | 237 |
| 299 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | 238 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, |
| 300 new_table)); | 239 new_table)); |
| 301 // Candidate contents only | |
| 302 ClearInputMethodLookupTable(kPageSize, &old_table); | |
| 303 ClearInputMethodLookupTable(kPageSize, &new_table); | |
| 304 | |
| 305 InitializeMozcCandidates(&old_table); | |
| 306 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
| 307 SetCaretRectIntoMozcCandidates(&old_table, | |
| 308 mozc::commands::Candidates::COMPOSITION, | |
| 309 kCaretPositionX1, | |
| 310 kCaretPositionY1, | |
| 311 kCaretPositionWidth1, | |
| 312 kCaretPositionHeight1); | |
| 313 | |
| 314 InitializeMozcCandidates(&new_table); | |
| 315 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2); | |
| 316 SetCaretRectIntoMozcCandidates(&new_table, | |
| 317 mozc::commands::Candidates::COMPOSITION, | |
| 318 kCaretPositionX1, | |
| 319 kCaretPositionY1, | |
| 320 kCaretPositionWidth1, | |
| 321 kCaretPositionHeight1); | |
| 322 | |
| 323 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
| 324 new_table)); | |
| 325 | |
| 326 // Both candidate and position | |
| 327 ClearInputMethodLookupTable(kPageSize, &old_table); | |
| 328 ClearInputMethodLookupTable(kPageSize, &new_table); | |
| 329 | |
| 330 InitializeMozcCandidates(&old_table); | |
| 331 AppendCandidateIntoMozcCandidates(&old_table, kSampleCandidate1); | |
| 332 SetCaretRectIntoMozcCandidates(&old_table, | |
| 333 mozc::commands::Candidates::COMPOSITION, | |
| 334 kCaretPositionX1, | |
| 335 kCaretPositionY1, | |
| 336 kCaretPositionWidth1, | |
| 337 kCaretPositionHeight1); | |
| 338 | |
| 339 InitializeMozcCandidates(&new_table); | |
| 340 AppendCandidateIntoMozcCandidates(&new_table, kSampleCandidate2); | |
| 341 SetCaretRectIntoMozcCandidates(&new_table, | |
| 342 mozc::commands::Candidates::COMPOSITION, | |
| 343 kCaretPositionX2, | |
| 344 kCaretPositionY2, | |
| 345 kCaretPositionWidth2, | |
| 346 kCaretPositionHeight2); | |
| 347 | |
| 348 EXPECT_TRUE(CandidateWindowView::ShouldUpdateCandidateViews(old_table, | |
| 349 new_table)); | |
| 350 } | 240 } |
| 351 | 241 |
| 352 TEST_F(CandidateWindowViewTest, MozcUpdateCandidateTest) { | 242 TEST_F(CandidateWindowViewTest, MozcUpdateCandidateTest) { |
| 353 // This test verifies whether UpdateCandidates function updates window mozc | 243 // This test verifies whether UpdateCandidates function updates window mozc |
| 354 // specific candidate position correctly on the correct condition. | 244 // specific candidate position correctly on the correct condition. |
| 355 | 245 |
| 356 // For testing, we have to prepare empty widget. | 246 // For testing, we have to prepare empty widget. |
| 357 // We should NOT manually free widget by default, otherwise double free will | 247 // We should NOT manually free widget by default, otherwise double free will |
| 358 // be occurred. So, we should instantiate widget class with "new" operation. | 248 // be occurred. So, we should instantiate widget class with "new" operation. |
| 359 views::Widget* widget = new views::Widget; | 249 views::Widget* widget = new views::Widget; |
| 360 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 250 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 361 widget->Init(params); | 251 widget->Init(params); |
| 362 | 252 |
| 363 CandidateWindowView candidate_window_view(widget); | 253 CandidateWindowView candidate_window_view(widget); |
| 364 candidate_window_view.Init(); | 254 candidate_window_view.Init(); |
| 365 | 255 |
| 366 const int kCaretPositionX1 = 10; | |
| 367 const int kCaretPositionY1 = 20; | |
| 368 const int kCaretPositionWidth1 = 30; | |
| 369 const int kCaretPositionHeight1 = 40; | |
| 370 | |
| 371 const int kCaretPositionX2 = 15; | |
| 372 const int kCaretPositionY2 = 25; | |
| 373 const int kCaretPositionWidth2 = 35; | |
| 374 const int kCaretPositionHeight2 = 45; | |
| 375 | |
| 376 const size_t kPageSize = 10; | 256 const size_t kPageSize = 10; |
| 377 | 257 |
| 378 InputMethodLookupTable new_table; | 258 InputMethodLookupTable new_table; |
| 379 ClearInputMethodLookupTable(kPageSize, &new_table); | 259 ClearInputMethodLookupTable(kPageSize, &new_table); |
| 380 InitializeMozcCandidates(&new_table); | 260 InitializeMozcCandidates(&new_table); |
| 381 | 261 |
| 382 // If window location is CARET, use default position. So | 262 // If candidate category is SUGGESTION, should not show at composition head. |
| 383 // is_suggestion_window_location_available_ should be false. | 263 new_table.mozc_candidates.set_category(mozc::commands::CONVERSION); |
| 384 SetCaretRectIntoMozcCandidates(&new_table, | |
| 385 mozc::commands::Candidates::CARET, | |
| 386 kCaretPositionX1, | |
| 387 kCaretPositionY1, | |
| 388 kCaretPositionWidth1, | |
| 389 kCaretPositionHeight1); | |
| 390 candidate_window_view.UpdateCandidates(new_table); | 264 candidate_window_view.UpdateCandidates(new_table); |
| 391 EXPECT_FALSE(candidate_window_view.is_suggestion_window_location_available_); | 265 EXPECT_FALSE(candidate_window_view.should_show_at_composition_head_); |
| 392 | 266 |
| 393 // If window location is COMPOSITION, update position and set | 267 // If candidate category is SUGGESTION, should show at composition head. |
| 394 // is_suggestion_window_location_available_ as true. | 268 new_table.mozc_candidates.set_category(mozc::commands::SUGGESTION); |
| 395 SetCaretRectIntoMozcCandidates(&new_table, | |
| 396 mozc::commands::Candidates::COMPOSITION, | |
| 397 kCaretPositionX1, | |
| 398 kCaretPositionY1, | |
| 399 kCaretPositionWidth1, | |
| 400 kCaretPositionHeight1); | |
| 401 candidate_window_view.UpdateCandidates(new_table); | 269 candidate_window_view.UpdateCandidates(new_table); |
| 402 EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_); | 270 EXPECT_TRUE(candidate_window_view.should_show_at_composition_head_); |
| 403 EXPECT_EQ(kCaretPositionX1, | |
| 404 candidate_window_view.suggestion_window_location_.x()); | |
| 405 EXPECT_EQ(kCaretPositionY1, | |
| 406 candidate_window_view.suggestion_window_location_.y()); | |
| 407 EXPECT_EQ(kCaretPositionWidth1, | |
| 408 candidate_window_view.suggestion_window_location_.width()); | |
| 409 EXPECT_EQ(kCaretPositionHeight1, | |
| 410 candidate_window_view.suggestion_window_location_.height()); | |
| 411 | |
| 412 SetCaretRectIntoMozcCandidates(&new_table, | |
| 413 mozc::commands::Candidates::COMPOSITION, | |
| 414 kCaretPositionX2, | |
| 415 kCaretPositionY2, | |
| 416 kCaretPositionWidth2, | |
| 417 kCaretPositionHeight2); | |
| 418 candidate_window_view.UpdateCandidates(new_table); | |
| 419 EXPECT_TRUE(candidate_window_view.is_suggestion_window_location_available_); | |
| 420 EXPECT_EQ(kCaretPositionX2, | |
| 421 candidate_window_view.suggestion_window_location_.x()); | |
| 422 EXPECT_EQ(kCaretPositionY2, | |
| 423 candidate_window_view.suggestion_window_location_.y()); | |
| 424 EXPECT_EQ(kCaretPositionWidth2, | |
| 425 candidate_window_view.suggestion_window_location_.width()); | |
| 426 EXPECT_EQ(kCaretPositionHeight2, | |
| 427 candidate_window_view.suggestion_window_location_.height()); | |
| 428 | 271 |
| 429 // We should call CloseNow method, otherwise this test will leak memory. | 272 // We should call CloseNow method, otherwise this test will leak memory. |
| 430 widget->CloseNow(); | 273 widget->CloseNow(); |
| 431 } | 274 } |
| 432 | 275 |
| 433 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { | 276 TEST_F(CandidateWindowViewTest, ShortcutSettingTest) { |
| 434 const char* kSampleCandidate[] = { | 277 const char* kSampleCandidate[] = { |
| 435 "Sample Candidate 1", | 278 "Sample Candidate 1", |
| 436 "Sample Candidate 2", | 279 "Sample Candidate 2", |
| 437 "Sample Candidate 3" | 280 "Sample Candidate 3" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { | 616 for (size_t i = 1; i < candidate_window_view.candidate_views_.size(); ++i) { |
| 774 const CandidateView* view = candidate_window_view.candidate_views_[i]; | 617 const CandidateView* view = candidate_window_view.candidate_views_[i]; |
| 775 EXPECT_EQ(before_height, view->GetContentsBounds().height()); | 618 EXPECT_EQ(before_height, view->GetContentsBounds().height()); |
| 776 } | 619 } |
| 777 | 620 |
| 778 // We should call CloseNow method, otherwise this test will leak memory. | 621 // We should call CloseNow method, otherwise this test will leak memory. |
| 779 widget->CloseNow(); | 622 widget->CloseNow(); |
| 780 } | 623 } |
| 781 } // namespace input_method | 624 } // namespace input_method |
| 782 } // namespace chromeos | 625 } // namespace chromeos |
| OLD | NEW |