| 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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/mac/scoped_nsautorelease_pool.h" | 8 #include "base/mac/scoped_nsautorelease_pool.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 next_break_point = break_point_queue.front(); | 133 next_break_point = break_point_queue.front(); |
| 134 break_point_queue.pop(); | 134 break_point_queue.pop(); |
| 135 } | 135 } |
| 136 output->push_back(current_rect); | 136 output->push_back(current_rect); |
| 137 current_rect.set_x(current_rect.right()); | 137 current_rect.set_x(current_rect.right()); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 gfx::Rect GetExpectedRect(const gfx::Point& origin, | 141 gfx::Rect GetExpectedRect(const gfx::Point& origin, |
| 142 const gfx::Size& size, | 142 const gfx::Size& size, |
| 143 const ui::Range& range, | 143 const gfx::Range& range, |
| 144 int line_no) { | 144 int line_no) { |
| 145 return gfx::Rect( | 145 return gfx::Rect( |
| 146 origin.x() + range.start() * size.width(), | 146 origin.x() + range.start() * size.width(), |
| 147 origin.y() + line_no * size.height(), | 147 origin.y() + line_no * size.height(), |
| 148 range.length() * size.width(), | 148 range.length() * size.width(), |
| 149 size.height()); | 149 size.height()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Returns NSScrollWheel event that mocks -phase. |mockPhaseSelector| should | 152 // Returns NSScrollWheel event that mocks -phase. |mockPhaseSelector| should |
| 153 // correspond to a method in |MockPhaseMethods| that returns the desired phase. | 153 // correspond to a method in |MockPhaseMethods| that returns the desired phase. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 cocoa_test_event_utils::KeyEventWithKeyCode( | 315 cocoa_test_event_utils::KeyEventWithKeyCode( |
| 316 53, 27, NSKeyDown, NSCommandKeyMask)]; | 316 53, 27, NSKeyDown, NSCommandKeyMask)]; |
| 317 observer.Wait(); | 317 observer.Wait(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { | 320 TEST_F(RenderWidgetHostViewMacTest, GetFirstRectForCharacterRangeCaretCase) { |
| 321 const string16 kDummyString = UTF8ToUTF16("hogehoge"); | 321 const string16 kDummyString = UTF8ToUTF16("hogehoge"); |
| 322 const size_t kDummyOffset = 0; | 322 const size_t kDummyOffset = 0; |
| 323 | 323 |
| 324 gfx::Rect caret_rect(10, 11, 0, 10); | 324 gfx::Rect caret_rect(10, 11, 0, 10); |
| 325 ui::Range caret_range(0, 0); | 325 gfx::Range caret_range(0, 0); |
| 326 ViewHostMsg_SelectionBounds_Params params; | 326 ViewHostMsg_SelectionBounds_Params params; |
| 327 | 327 |
| 328 NSRect rect; | 328 NSRect rect; |
| 329 NSRange actual_range; | 329 NSRange actual_range; |
| 330 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 330 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); |
| 331 params.anchor_rect = params.focus_rect = caret_rect; | 331 params.anchor_rect = params.focus_rect = caret_rect; |
| 332 params.anchor_dir = params.focus_dir = WebKit::WebTextDirectionLeftToRight; | 332 params.anchor_dir = params.focus_dir = WebKit::WebTextDirectionLeftToRight; |
| 333 rwhv_mac_->SelectionBoundsChanged(params); | 333 rwhv_mac_->SelectionBoundsChanged(params); |
| 334 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 334 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 335 caret_range.ToNSRange(), | 335 caret_range.ToNSRange(), |
| 336 &rect, | 336 &rect, |
| 337 &actual_range)); | 337 &actual_range)); |
| 338 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 338 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 339 EXPECT_EQ(caret_range, ui::Range(actual_range)); | 339 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 340 | 340 |
| 341 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 341 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 342 ui::Range(0, 1).ToNSRange(), | 342 gfx::Range(0, 1).ToNSRange(), |
| 343 &rect, | 343 &rect, |
| 344 &actual_range)); | 344 &actual_range)); |
| 345 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 345 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 346 ui::Range(1, 1).ToNSRange(), | 346 gfx::Range(1, 1).ToNSRange(), |
| 347 &rect, | 347 &rect, |
| 348 &actual_range)); | 348 &actual_range)); |
| 349 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 349 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 350 ui::Range(2, 3).ToNSRange(), | 350 gfx::Range(2, 3).ToNSRange(), |
| 351 &rect, | 351 &rect, |
| 352 &actual_range)); | 352 &actual_range)); |
| 353 | 353 |
| 354 // Caret moved. | 354 // Caret moved. |
| 355 caret_rect = gfx::Rect(20, 11, 0, 10); | 355 caret_rect = gfx::Rect(20, 11, 0, 10); |
| 356 caret_range = ui::Range(1, 1); | 356 caret_range = gfx::Range(1, 1); |
| 357 params.anchor_rect = params.focus_rect = caret_rect; | 357 params.anchor_rect = params.focus_rect = caret_rect; |
| 358 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 358 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); |
| 359 rwhv_mac_->SelectionBoundsChanged(params); | 359 rwhv_mac_->SelectionBoundsChanged(params); |
| 360 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 360 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 361 caret_range.ToNSRange(), | 361 caret_range.ToNSRange(), |
| 362 &rect, | 362 &rect, |
| 363 &actual_range)); | 363 &actual_range)); |
| 364 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); | 364 EXPECT_EQ(caret_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 365 EXPECT_EQ(caret_range, ui::Range(actual_range)); | 365 EXPECT_EQ(caret_range, gfx::Range(actual_range)); |
| 366 | 366 |
| 367 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 367 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 368 ui::Range(0, 0).ToNSRange(), | 368 gfx::Range(0, 0).ToNSRange(), |
| 369 &rect, | 369 &rect, |
| 370 &actual_range)); | 370 &actual_range)); |
| 371 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 371 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 372 ui::Range(1, 2).ToNSRange(), | 372 gfx::Range(1, 2).ToNSRange(), |
| 373 &rect, | 373 &rect, |
| 374 &actual_range)); | 374 &actual_range)); |
| 375 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 375 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 376 ui::Range(2, 3).ToNSRange(), | 376 gfx::Range(2, 3).ToNSRange(), |
| 377 &rect, | 377 &rect, |
| 378 &actual_range)); | 378 &actual_range)); |
| 379 | 379 |
| 380 // No caret. | 380 // No caret. |
| 381 caret_range = ui::Range(1, 2); | 381 caret_range = gfx::Range(1, 2); |
| 382 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); | 382 rwhv_mac_->SelectionChanged(kDummyString, kDummyOffset, caret_range); |
| 383 params.anchor_rect = caret_rect; | 383 params.anchor_rect = caret_rect; |
| 384 params.focus_rect = gfx::Rect(30, 11, 0, 10); | 384 params.focus_rect = gfx::Rect(30, 11, 0, 10); |
| 385 rwhv_mac_->SelectionBoundsChanged(params); | 385 rwhv_mac_->SelectionBoundsChanged(params); |
| 386 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 386 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 387 ui::Range(0, 0).ToNSRange(), | 387 gfx::Range(0, 0).ToNSRange(), |
| 388 &rect, | 388 &rect, |
| 389 &actual_range)); | 389 &actual_range)); |
| 390 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 390 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 391 ui::Range(0, 1).ToNSRange(), | 391 gfx::Range(0, 1).ToNSRange(), |
| 392 &rect, | 392 &rect, |
| 393 &actual_range)); | 393 &actual_range)); |
| 394 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 394 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 395 ui::Range(1, 1).ToNSRange(), | 395 gfx::Range(1, 1).ToNSRange(), |
| 396 &rect, | 396 &rect, |
| 397 &actual_range)); | 397 &actual_range)); |
| 398 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 398 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 399 ui::Range(1, 2).ToNSRange(), | 399 gfx::Range(1, 2).ToNSRange(), |
| 400 &rect, | 400 &rect, |
| 401 &actual_range)); | 401 &actual_range)); |
| 402 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 402 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 403 ui::Range(2, 2).ToNSRange(), | 403 gfx::Range(2, 2).ToNSRange(), |
| 404 &rect, | 404 &rect, |
| 405 &actual_range)); | 405 &actual_range)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { | 408 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionSinglelineCase) { |
| 409 const gfx::Point kOrigin(10, 11); | 409 const gfx::Point kOrigin(10, 11); |
| 410 const gfx::Size kBoundsUnit(10, 20); | 410 const gfx::Size kBoundsUnit(10, 20); |
| 411 | 411 |
| 412 NSRect rect; | 412 NSRect rect; |
| 413 // Make sure not crashing by passing NULL pointer instead of |actual_range|. | 413 // Make sure not crashing by passing NULL pointer instead of |actual_range|. |
| 414 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 414 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 415 ui::Range(0, 0).ToNSRange(), | 415 gfx::Range(0, 0).ToNSRange(), |
| 416 &rect, | 416 &rect, |
| 417 NULL)); | 417 NULL)); |
| 418 | 418 |
| 419 // If there are no update from renderer, always returned caret position. | 419 // If there are no update from renderer, always returned caret position. |
| 420 NSRange actual_range; | 420 NSRange actual_range; |
| 421 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 421 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 422 ui::Range(0, 0).ToNSRange(), | 422 gfx::Range(0, 0).ToNSRange(), |
| 423 &rect, | 423 &rect, |
| 424 &actual_range)); | 424 &actual_range)); |
| 425 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 425 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 426 ui::Range(0, 1).ToNSRange(), | 426 gfx::Range(0, 1).ToNSRange(), |
| 427 &rect, | 427 &rect, |
| 428 &actual_range)); | 428 &actual_range)); |
| 429 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 429 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 430 ui::Range(1, 0).ToNSRange(), | 430 gfx::Range(1, 0).ToNSRange(), |
| 431 &rect, | 431 &rect, |
| 432 &actual_range)); | 432 &actual_range)); |
| 433 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 433 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 434 ui::Range(1, 1).ToNSRange(), | 434 gfx::Range(1, 1).ToNSRange(), |
| 435 &rect, | 435 &rect, |
| 436 &actual_range)); | 436 &actual_range)); |
| 437 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 437 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 438 ui::Range(1, 2).ToNSRange(), | 438 gfx::Range(1, 2).ToNSRange(), |
| 439 &rect, | 439 &rect, |
| 440 &actual_range)); | 440 &actual_range)); |
| 441 | 441 |
| 442 // If the firstRectForCharacterRange is failed in renderer, empty rect vector | 442 // If the firstRectForCharacterRange is failed in renderer, empty rect vector |
| 443 // is sent. Make sure this does not crash. | 443 // is sent. Make sure this does not crash. |
| 444 rwhv_mac_->ImeCompositionRangeChanged(ui::Range(10, 12), | 444 rwhv_mac_->ImeCompositionRangeChanged(gfx::Range(10, 12), |
| 445 std::vector<gfx::Rect>()); | 445 std::vector<gfx::Rect>()); |
| 446 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 446 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 447 ui::Range(10, 11).ToNSRange(), | 447 gfx::Range(10, 11).ToNSRange(), |
| 448 &rect, | 448 &rect, |
| 449 NULL)); | 449 NULL)); |
| 450 | 450 |
| 451 const int kCompositionLength = 10; | 451 const int kCompositionLength = 10; |
| 452 std::vector<gfx::Rect> composition_bounds; | 452 std::vector<gfx::Rect> composition_bounds; |
| 453 const int kCompositionStart = 3; | 453 const int kCompositionStart = 3; |
| 454 const ui::Range kCompositionRange(kCompositionStart, | 454 const gfx::Range kCompositionRange(kCompositionStart, |
| 455 kCompositionStart + kCompositionLength); | 455 kCompositionStart + kCompositionLength); |
| 456 GenerateCompositionRectArray(kOrigin, | 456 GenerateCompositionRectArray(kOrigin, |
| 457 kBoundsUnit, | 457 kBoundsUnit, |
| 458 kCompositionLength, | 458 kCompositionLength, |
| 459 std::vector<size_t>(), | 459 std::vector<size_t>(), |
| 460 &composition_bounds); | 460 &composition_bounds); |
| 461 rwhv_mac_->ImeCompositionRangeChanged(kCompositionRange, composition_bounds); | 461 rwhv_mac_->ImeCompositionRangeChanged(kCompositionRange, composition_bounds); |
| 462 | 462 |
| 463 // Out of range requests will return caret position. | 463 // Out of range requests will return caret position. |
| 464 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 464 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 465 ui::Range(0, 0).ToNSRange(), | 465 gfx::Range(0, 0).ToNSRange(), |
| 466 &rect, | 466 &rect, |
| 467 &actual_range)); | 467 &actual_range)); |
| 468 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 468 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 469 ui::Range(1, 1).ToNSRange(), | 469 gfx::Range(1, 1).ToNSRange(), |
| 470 &rect, | 470 &rect, |
| 471 &actual_range)); | 471 &actual_range)); |
| 472 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 472 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 473 ui::Range(1, 2).ToNSRange(), | 473 gfx::Range(1, 2).ToNSRange(), |
| 474 &rect, | 474 &rect, |
| 475 &actual_range)); | 475 &actual_range)); |
| 476 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 476 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 477 ui::Range(2, 2).ToNSRange(), | 477 gfx::Range(2, 2).ToNSRange(), |
| 478 &rect, | 478 &rect, |
| 479 &actual_range)); | 479 &actual_range)); |
| 480 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 480 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 481 ui::Range(13, 14).ToNSRange(), | 481 gfx::Range(13, 14).ToNSRange(), |
| 482 &rect, | 482 &rect, |
| 483 &actual_range)); | 483 &actual_range)); |
| 484 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 484 EXPECT_FALSE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 485 ui::Range(14, 15).ToNSRange(), | 485 gfx::Range(14, 15).ToNSRange(), |
| 486 &rect, | 486 &rect, |
| 487 &actual_range)); | 487 &actual_range)); |
| 488 | 488 |
| 489 for (int i = 0; i <= kCompositionLength; ++i) { | 489 for (int i = 0; i <= kCompositionLength; ++i) { |
| 490 for (int j = 0; j <= kCompositionLength - i; ++j) { | 490 for (int j = 0; j <= kCompositionLength - i; ++j) { |
| 491 const ui::Range range(i, i + j); | 491 const gfx::Range range(i, i + j); |
| 492 const gfx::Rect expected_rect = GetExpectedRect(kOrigin, | 492 const gfx::Rect expected_rect = GetExpectedRect(kOrigin, |
| 493 kBoundsUnit, | 493 kBoundsUnit, |
| 494 range, | 494 range, |
| 495 0); | 495 0); |
| 496 const NSRange request_range = ui::Range( | 496 const NSRange request_range = gfx::Range( |
| 497 kCompositionStart + range.start(), | 497 kCompositionStart + range.start(), |
| 498 kCompositionStart + range.end()).ToNSRange(); | 498 kCompositionStart + range.end()).ToNSRange(); |
| 499 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 499 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 500 request_range, | 500 request_range, |
| 501 &rect, | 501 &rect, |
| 502 &actual_range)); | 502 &actual_range)); |
| 503 EXPECT_EQ(ui::Range(request_range), ui::Range(actual_range)); | 503 EXPECT_EQ(gfx::Range(request_range), gfx::Range(actual_range)); |
| 504 EXPECT_EQ(expected_rect, gfx::Rect(NSRectToCGRect(rect))); | 504 EXPECT_EQ(expected_rect, gfx::Rect(NSRectToCGRect(rect))); |
| 505 | 505 |
| 506 // Make sure not crashing by passing NULL pointer instead of | 506 // Make sure not crashing by passing NULL pointer instead of |
| 507 // |actual_range|. | 507 // |actual_range|. |
| 508 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( | 508 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange( |
| 509 request_range, | 509 request_range, |
| 510 &rect, | 510 &rect, |
| 511 NULL)); | 511 NULL)); |
| 512 } | 512 } |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 | 515 |
| 516 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { | 516 TEST_F(RenderWidgetHostViewMacTest, UpdateCompositionMultilineCase) { |
| 517 const gfx::Point kOrigin(10, 11); | 517 const gfx::Point kOrigin(10, 11); |
| 518 const gfx::Size kBoundsUnit(10, 20); | 518 const gfx::Size kBoundsUnit(10, 20); |
| 519 NSRect rect; | 519 NSRect rect; |
| 520 | 520 |
| 521 const int kCompositionLength = 30; | 521 const int kCompositionLength = 30; |
| 522 std::vector<gfx::Rect> composition_bounds; | 522 std::vector<gfx::Rect> composition_bounds; |
| 523 const ui::Range kCompositionRange(0, kCompositionLength); | 523 const gfx::Range kCompositionRange(0, kCompositionLength); |
| 524 // Set breaking point at 10 and 20. | 524 // Set breaking point at 10 and 20. |
| 525 std::vector<size_t> break_points; | 525 std::vector<size_t> break_points; |
| 526 break_points.push_back(10); | 526 break_points.push_back(10); |
| 527 break_points.push_back(20); | 527 break_points.push_back(20); |
| 528 GenerateCompositionRectArray(kOrigin, | 528 GenerateCompositionRectArray(kOrigin, |
| 529 kBoundsUnit, | 529 kBoundsUnit, |
| 530 kCompositionLength, | 530 kCompositionLength, |
| 531 break_points, | 531 break_points, |
| 532 &composition_bounds); | 532 &composition_bounds); |
| 533 rwhv_mac_->ImeCompositionRangeChanged(kCompositionRange, composition_bounds); | 533 rwhv_mac_->ImeCompositionRangeChanged(kCompositionRange, composition_bounds); |
| 534 | 534 |
| 535 // Range doesn't contain line breaking point. | 535 // Range doesn't contain line breaking point. |
| 536 ui::Range range; | 536 gfx::Range range; |
| 537 range = ui::Range(5, 8); | 537 range = gfx::Range(5, 8); |
| 538 NSRange actual_range; | 538 NSRange actual_range; |
| 539 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 539 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 540 &rect, | 540 &rect, |
| 541 &actual_range)); | 541 &actual_range)); |
| 542 EXPECT_EQ(range, ui::Range(actual_range)); | 542 EXPECT_EQ(range, gfx::Range(actual_range)); |
| 543 EXPECT_EQ( | 543 EXPECT_EQ( |
| 544 GetExpectedRect(kOrigin, kBoundsUnit, range, 0), | 544 GetExpectedRect(kOrigin, kBoundsUnit, range, 0), |
| 545 gfx::Rect(NSRectToCGRect(rect))); | 545 gfx::Rect(NSRectToCGRect(rect))); |
| 546 range = ui::Range(15, 18); | 546 range = gfx::Range(15, 18); |
| 547 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 547 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 548 &rect, | 548 &rect, |
| 549 &actual_range)); | 549 &actual_range)); |
| 550 EXPECT_EQ(range, ui::Range(actual_range)); | 550 EXPECT_EQ(range, gfx::Range(actual_range)); |
| 551 EXPECT_EQ( | 551 EXPECT_EQ( |
| 552 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(5, 8), 1), | 552 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(5, 8), 1), |
| 553 gfx::Rect(NSRectToCGRect(rect))); | 553 gfx::Rect(NSRectToCGRect(rect))); |
| 554 range = ui::Range(25, 28); | 554 range = gfx::Range(25, 28); |
| 555 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 555 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 556 &rect, | 556 &rect, |
| 557 &actual_range)); | 557 &actual_range)); |
| 558 EXPECT_EQ(range, ui::Range(actual_range)); | 558 EXPECT_EQ(range, gfx::Range(actual_range)); |
| 559 EXPECT_EQ( | 559 EXPECT_EQ( |
| 560 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(5, 8), 2), | 560 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(5, 8), 2), |
| 561 gfx::Rect(NSRectToCGRect(rect))); | 561 gfx::Rect(NSRectToCGRect(rect))); |
| 562 | 562 |
| 563 // Range contains line breaking point. | 563 // Range contains line breaking point. |
| 564 range = ui::Range(8, 12); | 564 range = gfx::Range(8, 12); |
| 565 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 565 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 566 &rect, | 566 &rect, |
| 567 &actual_range)); | 567 &actual_range)); |
| 568 EXPECT_EQ(ui::Range(8, 10), ui::Range(actual_range)); | 568 EXPECT_EQ(gfx::Range(8, 10), gfx::Range(actual_range)); |
| 569 EXPECT_EQ( | 569 EXPECT_EQ( |
| 570 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(8, 10), 0), | 570 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(8, 10), 0), |
| 571 gfx::Rect(NSRectToCGRect(rect))); | 571 gfx::Rect(NSRectToCGRect(rect))); |
| 572 range = ui::Range(18, 22); | 572 range = gfx::Range(18, 22); |
| 573 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 573 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 574 &rect, | 574 &rect, |
| 575 &actual_range)); | 575 &actual_range)); |
| 576 EXPECT_EQ(ui::Range(18, 20), ui::Range(actual_range)); | 576 EXPECT_EQ(gfx::Range(18, 20), gfx::Range(actual_range)); |
| 577 EXPECT_EQ( | 577 EXPECT_EQ( |
| 578 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(8, 10), 1), | 578 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(8, 10), 1), |
| 579 gfx::Rect(NSRectToCGRect(rect))); | 579 gfx::Rect(NSRectToCGRect(rect))); |
| 580 | 580 |
| 581 // Start point is line breaking point. | 581 // Start point is line breaking point. |
| 582 range = ui::Range(10, 12); | 582 range = gfx::Range(10, 12); |
| 583 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 583 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 584 &rect, | 584 &rect, |
| 585 &actual_range)); | 585 &actual_range)); |
| 586 EXPECT_EQ(ui::Range(10, 12), ui::Range(actual_range)); | 586 EXPECT_EQ(gfx::Range(10, 12), gfx::Range(actual_range)); |
| 587 EXPECT_EQ( | 587 EXPECT_EQ( |
| 588 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 2), 1), | 588 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 2), 1), |
| 589 gfx::Rect(NSRectToCGRect(rect))); | 589 gfx::Rect(NSRectToCGRect(rect))); |
| 590 range = ui::Range(20, 22); | 590 range = gfx::Range(20, 22); |
| 591 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 591 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 592 &rect, | 592 &rect, |
| 593 &actual_range)); | 593 &actual_range)); |
| 594 EXPECT_EQ(ui::Range(20, 22), ui::Range(actual_range)); | 594 EXPECT_EQ(gfx::Range(20, 22), gfx::Range(actual_range)); |
| 595 EXPECT_EQ( | 595 EXPECT_EQ( |
| 596 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 2), 2), | 596 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 2), 2), |
| 597 gfx::Rect(NSRectToCGRect(rect))); | 597 gfx::Rect(NSRectToCGRect(rect))); |
| 598 | 598 |
| 599 // End point is line breaking point. | 599 // End point is line breaking point. |
| 600 range = ui::Range(5, 10); | 600 range = gfx::Range(5, 10); |
| 601 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 601 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 602 &rect, | 602 &rect, |
| 603 &actual_range)); | 603 &actual_range)); |
| 604 EXPECT_EQ(ui::Range(5, 10), ui::Range(actual_range)); | 604 EXPECT_EQ(gfx::Range(5, 10), gfx::Range(actual_range)); |
| 605 EXPECT_EQ( | 605 EXPECT_EQ( |
| 606 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(5, 10), 0), | 606 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(5, 10), 0), |
| 607 gfx::Rect(NSRectToCGRect(rect))); | 607 gfx::Rect(NSRectToCGRect(rect))); |
| 608 range = ui::Range(15, 20); | 608 range = gfx::Range(15, 20); |
| 609 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 609 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 610 &rect, | 610 &rect, |
| 611 &actual_range)); | 611 &actual_range)); |
| 612 EXPECT_EQ(ui::Range(15, 20), ui::Range(actual_range)); | 612 EXPECT_EQ(gfx::Range(15, 20), gfx::Range(actual_range)); |
| 613 EXPECT_EQ( | 613 EXPECT_EQ( |
| 614 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(5, 10), 1), | 614 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(5, 10), 1), |
| 615 gfx::Rect(NSRectToCGRect(rect))); | 615 gfx::Rect(NSRectToCGRect(rect))); |
| 616 | 616 |
| 617 // Start and end point are same line breaking point. | 617 // Start and end point are same line breaking point. |
| 618 range = ui::Range(10, 10); | 618 range = gfx::Range(10, 10); |
| 619 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 619 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 620 &rect, | 620 &rect, |
| 621 &actual_range)); | 621 &actual_range)); |
| 622 EXPECT_EQ(ui::Range(10, 10), ui::Range(actual_range)); | 622 EXPECT_EQ(gfx::Range(10, 10), gfx::Range(actual_range)); |
| 623 EXPECT_EQ( | 623 EXPECT_EQ( |
| 624 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 0), 1), | 624 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 0), 1), |
| 625 gfx::Rect(NSRectToCGRect(rect))); | 625 gfx::Rect(NSRectToCGRect(rect))); |
| 626 range = ui::Range(20, 20); | 626 range = gfx::Range(20, 20); |
| 627 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 627 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 628 &rect, | 628 &rect, |
| 629 &actual_range)); | 629 &actual_range)); |
| 630 EXPECT_EQ(ui::Range(20, 20), ui::Range(actual_range)); | 630 EXPECT_EQ(gfx::Range(20, 20), gfx::Range(actual_range)); |
| 631 EXPECT_EQ( | 631 EXPECT_EQ( |
| 632 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 0), 2), | 632 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 0), 2), |
| 633 gfx::Rect(NSRectToCGRect(rect))); | 633 gfx::Rect(NSRectToCGRect(rect))); |
| 634 | 634 |
| 635 // Start and end point are different line breaking point. | 635 // Start and end point are different line breaking point. |
| 636 range = ui::Range(10, 20); | 636 range = gfx::Range(10, 20); |
| 637 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), | 637 EXPECT_TRUE(rwhv_mac_->GetCachedFirstRectForCharacterRange(range.ToNSRange(), |
| 638 &rect, | 638 &rect, |
| 639 &actual_range)); | 639 &actual_range)); |
| 640 EXPECT_EQ(ui::Range(10, 20), ui::Range(actual_range)); | 640 EXPECT_EQ(gfx::Range(10, 20), gfx::Range(actual_range)); |
| 641 EXPECT_EQ( | 641 EXPECT_EQ( |
| 642 GetExpectedRect(kOrigin, kBoundsUnit, ui::Range(0, 10), 1), | 642 GetExpectedRect(kOrigin, kBoundsUnit, gfx::Range(0, 10), 1), |
| 643 gfx::Rect(NSRectToCGRect(rect))); | 643 gfx::Rect(NSRectToCGRect(rect))); |
| 644 } | 644 } |
| 645 | 645 |
| 646 // Verify that |SetActive()| calls |RenderWidgetHostImpl::Blur()| and | 646 // Verify that |SetActive()| calls |RenderWidgetHostImpl::Blur()| and |
| 647 // |RenderWidgetHostImp::Focus()|. | 647 // |RenderWidgetHostImp::Focus()|. |
| 648 TEST_F(RenderWidgetHostViewMacTest, BlurAndFocusOnSetActive) { | 648 TEST_F(RenderWidgetHostViewMacTest, BlurAndFocusOnSetActive) { |
| 649 MockRenderWidgetHostDelegate delegate; | 649 MockRenderWidgetHostDelegate delegate; |
| 650 TestBrowserContext browser_context; | 650 TestBrowserContext browser_context; |
| 651 MockRenderProcessHost* process_host = | 651 MockRenderProcessHost* process_host = |
| 652 new MockRenderProcessHost(&browser_context); | 652 new MockRenderProcessHost(&browser_context); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 host->OnMessageReceived(*response2); | 776 host->OnMessageReceived(*response2); |
| 777 | 777 |
| 778 // Check that the view delegate ignored the empty unhandled wheel event. | 778 // Check that the view delegate ignored the empty unhandled wheel event. |
| 779 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); | 779 ASSERT_EQ(NO, view_delegate.get().unhandledWheelEventReceived); |
| 780 | 780 |
| 781 // Clean up. | 781 // Clean up. |
| 782 host->Shutdown(); | 782 host->Shutdown(); |
| 783 } | 783 } |
| 784 | 784 |
| 785 } // namespace content | 785 } // namespace content |
| OLD | NEW |