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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // be configured before RenderViewImplTest::SetUp runs. Thus we make | 379 // be configured before RenderViewImplTest::SetUp runs. Thus we make |
380 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via | 380 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via |
381 // DoSetUp(), to allow tests to perform command line modifications | 381 // DoSetUp(), to allow tests to perform command line modifications |
382 // before RenderViewImplTest::SetUp is run. Each test must invoke | 382 // before RenderViewImplTest::SetUp is run. Each test must invoke |
383 // DoSetUp manually once pre-SetUp configuration is complete. | 383 // DoSetUp manually once pre-SetUp configuration is complete. |
384 void SetUp() override {} | 384 void SetUp() override {} |
385 }; | 385 }; |
386 | 386 |
387 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { | 387 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { |
388 public: | 388 public: |
389 void SetDeviceScaleFactor(float dsf) { | 389 void DoSetUp() override { |
| 390 RenderViewImplBlinkSettingsTest::DoSetUp(); |
| 391 |
390 ViewMsg_Resize_Params params; | 392 ViewMsg_Resize_Params params; |
391 params.screen_info.deviceScaleFactor = dsf; | 393 params.screen_info.deviceScaleFactor = 2.f; |
392 params.new_size = gfx::Size(100, 100); | 394 params.new_size = gfx::Size(100, 100); |
393 params.physical_backing_size = gfx::Size(200, 200); | 395 params.physical_backing_size = gfx::Size(200, 200); |
394 params.visible_viewport_size = params.new_size; | 396 params.visible_viewport_size = params.new_size; |
395 params.needs_resize_ack = false; | 397 params.needs_resize_ack = false; |
396 view()->OnResize(params); | 398 view()->OnResize(params); |
397 ASSERT_EQ(dsf, view()->device_scale_factor_); | 399 ASSERT_EQ(2.f, view()->device_scale_factor_); |
398 } | 400 } |
399 }; | 401 }; |
400 | 402 |
401 // Ensure that the main RenderFrame is deleted and cleared from the RenderView | 403 // Ensure that the main RenderFrame is deleted and cleared from the RenderView |
402 // after closing it. | 404 // after closing it. |
403 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 405 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
404 // Create a new main frame RenderFrame so that we don't interfere with the | 406 // Create a new main frame RenderFrame so that we don't interfere with the |
405 // shutdown of frame() in RenderViewTest.TearDown. | 407 // shutdown of frame() in RenderViewTest.TearDown. |
406 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 408 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
407 blink::WebView* new_web_view = view()->createView( | 409 blink::WebView* new_web_view = view()->createView( |
(...skipping 1411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1819 const base::string16 empty_string; | 1821 const base::string16 empty_string; |
1820 const std::vector<blink::WebCompositionUnderline> empty_underline; | 1822 const std::vector<blink::WebCompositionUnderline> empty_underline; |
1821 std::vector<gfx::Rect> bounds; | 1823 std::vector<gfx::Rect> bounds; |
1822 view()->OnSetFocus(true); | 1824 view()->OnSetFocus(true); |
1823 | 1825 |
1824 // ASCII composition | 1826 // ASCII composition |
1825 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); | 1827 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); |
1826 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); | 1828 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); |
1827 view()->GetCompositionCharacterBounds(&bounds); | 1829 view()->GetCompositionCharacterBounds(&bounds); |
1828 ASSERT_EQ(ascii_composition.size(), bounds.size()); | 1830 ASSERT_EQ(ascii_composition.size(), bounds.size()); |
1829 | |
1830 for (size_t i = 0; i < bounds.size(); ++i) | 1831 for (size_t i = 0; i < bounds.size(); ++i) |
1831 EXPECT_LT(0, bounds[i].width()); | 1832 EXPECT_LT(0, bounds[i].width()); |
1832 view()->OnImeConfirmComposition( | 1833 view()->OnImeConfirmComposition( |
1833 empty_string, gfx::Range::InvalidRange(), false); | 1834 empty_string, gfx::Range::InvalidRange(), false); |
1834 | 1835 |
1835 // Non surrogate pair unicode character. | 1836 // Non surrogate pair unicode character. |
1836 const base::string16 unicode_composition = base::UTF8ToUTF16( | 1837 const base::string16 unicode_composition = base::UTF8ToUTF16( |
1837 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); | 1838 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
1838 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); | 1839 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); |
1839 view()->GetCompositionCharacterBounds(&bounds); | 1840 view()->GetCompositionCharacterBounds(&bounds); |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2483 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 2484 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
2484 switches::kBlinkSettings, | 2485 switches::kBlinkSettings, |
2485 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); | 2486 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); |
2486 DoSetUp(); | 2487 DoSetUp(); |
2487 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); | 2488 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); |
2488 EXPECT_TRUE(settings()->viewportEnabled()); | 2489 EXPECT_TRUE(settings()->viewportEnabled()); |
2489 } | 2490 } |
2490 | 2491 |
2491 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { | 2492 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { |
2492 DoSetUp(); | 2493 DoSetUp(); |
2493 SetDeviceScaleFactor(2.f); | |
2494 blink::WebRect rect(20, 10, 200, 100); | 2494 blink::WebRect rect(20, 10, 200, 100); |
2495 view()->convertViewportToWindow(&rect); | 2495 view()->convertViewportToWindow(&rect); |
2496 EXPECT_EQ(20, rect.x); | 2496 EXPECT_EQ(20, rect.x); |
2497 EXPECT_EQ(10, rect.y); | 2497 EXPECT_EQ(10, rect.y); |
2498 EXPECT_EQ(200, rect.width); | 2498 EXPECT_EQ(200, rect.width); |
2499 EXPECT_EQ(100, rect.height); | 2499 EXPECT_EQ(100, rect.height); |
2500 } | 2500 } |
2501 | 2501 |
2502 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { | 2502 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { |
2503 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2503 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
2504 switches::kEnableUseZoomForDSF); | 2504 switches::kEnableUseZoomForDSF); |
2505 DoSetUp(); | 2505 DoSetUp(); |
2506 SetDeviceScaleFactor(1.f); | |
2507 { | |
2508 blink::WebRect rect(20, 10, 200, 100); | |
2509 view()->convertViewportToWindow(&rect); | |
2510 EXPECT_EQ(20, rect.x); | |
2511 EXPECT_EQ(10, rect.y); | |
2512 EXPECT_EQ(200, rect.width); | |
2513 EXPECT_EQ(100, rect.height); | |
2514 } | |
2515 | 2506 |
2516 SetDeviceScaleFactor(2.f); | 2507 blink::WebRect rect(20, 10, 200, 100); |
2517 { | 2508 view()->convertViewportToWindow(&rect); |
2518 blink::WebRect rect(20, 10, 200, 100); | 2509 EXPECT_EQ(10, rect.x); |
2519 view()->convertViewportToWindow(&rect); | 2510 EXPECT_EQ(5, rect.y); |
2520 EXPECT_EQ(10, rect.x); | 2511 EXPECT_EQ(100, rect.width); |
2521 EXPECT_EQ(5, rect.y); | 2512 EXPECT_EQ(50, rect.height); |
2522 EXPECT_EQ(100, rect.width); | |
2523 EXPECT_EQ(50, rect.height); | |
2524 } | |
2525 } | 2513 } |
2526 | 2514 |
2527 #if defined(OS_MACOSX) || defined(USE_AURA) | |
2528 TEST_F(RenderViewImplScaleFactorTest, GetCompositionCharacterBoundsTest) { | |
2529 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
2530 switches::kEnableUseZoomForDSF); | |
2531 DoSetUp(); | |
2532 SetDeviceScaleFactor(1.f); | |
2533 #if defined(OS_WIN) | |
2534 // http://crbug.com/508747 | |
2535 if (base::win::GetVersion() >= base::win::VERSION_WIN10) | |
2536 return; | |
2537 #endif | |
2538 | |
2539 LoadHTML("<textarea id=\"test\"></textarea>"); | |
2540 ExecuteJavaScriptForTests("document.getElementById('test').focus();"); | |
2541 | |
2542 const base::string16 empty_string; | |
2543 const std::vector<blink::WebCompositionUnderline> empty_underline; | |
2544 std::vector<gfx::Rect> bounds_at_1x; | |
2545 view()->OnSetFocus(true); | |
2546 | |
2547 // ASCII composition | |
2548 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); | |
2549 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); | |
2550 view()->GetCompositionCharacterBounds(&bounds_at_1x); | |
2551 ASSERT_EQ(ascii_composition.size(), bounds_at_1x.size()); | |
2552 | |
2553 SetDeviceScaleFactor(2.f); | |
2554 std::vector<gfx::Rect> bounds_at_2x; | |
2555 view()->GetCompositionCharacterBounds(&bounds_at_2x); | |
2556 ASSERT_EQ(bounds_at_1x.size(), bounds_at_2x.size()); | |
2557 for (size_t i = 0; i < bounds_at_1x.size(); i++) { | |
2558 const gfx::Rect& b1 = bounds_at_1x[i]; | |
2559 const gfx::Rect& b2 = bounds_at_2x[i]; | |
2560 gfx::Vector2d origin_diff = b1.origin() - b2.origin(); | |
2561 | |
2562 // The bounds may not be exactly same because the font metrics are different | |
2563 // at 1x and 2x. Just make sure that the difference is small. | |
2564 EXPECT_LT(origin_diff.x(), 2); | |
2565 EXPECT_LT(origin_diff.y(), 2); | |
2566 EXPECT_LT(std::abs(b1.width() - b2.width()), 2); | |
2567 EXPECT_LT(std::abs(b1.height() - b2.height()), 2); | |
2568 } | |
2569 } | |
2570 #endif | |
2571 | |
2572 #if !defined(OS_ANDROID) | |
2573 // No extensions/autoresize on Android. | |
2574 namespace { | |
2575 | |
2576 // Don't use text as it text will change the size in DIP at different | |
2577 // scale factor. | |
2578 const char kAutoResizeTestPage[] = | |
2579 "<div style='width=20px; height=20px'></div>"; | |
2580 | |
2581 } // namespace | |
2582 | |
2583 TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithZoomForDSF) { | |
2584 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
2585 switches::kEnableUseZoomForDSF); | |
2586 DoSetUp(); | |
2587 view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000)); | |
2588 LoadHTML(kAutoResizeTestPage); | |
2589 gfx::Size size_at_1x = view()->size(); | |
2590 ASSERT_FALSE(size_at_1x.IsEmpty()); | |
2591 | |
2592 SetDeviceScaleFactor(2.f); | |
2593 LoadHTML(kAutoResizeTestPage); | |
2594 gfx::Size size_at_2x = view()->size(); | |
2595 EXPECT_EQ(size_at_1x, size_at_2x); | |
2596 } | |
2597 | |
2598 TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithoutZoomForDSF) { | |
2599 DoSetUp(); | |
2600 view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000)); | |
2601 LoadHTML(kAutoResizeTestPage); | |
2602 gfx::Size size_at_1x = view()->size(); | |
2603 ASSERT_FALSE(size_at_1x.IsEmpty()); | |
2604 | |
2605 SetDeviceScaleFactor(2.f); | |
2606 LoadHTML(kAutoResizeTestPage); | |
2607 gfx::Size size_at_2x = view()->size(); | |
2608 EXPECT_EQ(size_at_1x, size_at_2x); | |
2609 } | |
2610 | |
2611 #endif | |
2612 | |
2613 TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) { | 2515 TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) { |
2614 Attach(); | 2516 Attach(); |
2615 EXPECT_FALSE(IsPaused()); | 2517 EXPECT_FALSE(IsPaused()); |
2616 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Debugger.enable\"}"); | 2518 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Debugger.enable\"}"); |
2617 | 2519 |
2618 // Executing javascript will pause the thread and create nested message loop. | 2520 // Executing javascript will pause the thread and create nested message loop. |
2619 // Posting task simulates message coming from browser. | 2521 // Posting task simulates message coming from browser. |
2620 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2522 base::ThreadTaskRunnerHandle::Get()->PostTask( |
2621 FROM_HERE, | 2523 FROM_HERE, |
2622 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2524 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2623 ExecuteJavaScriptForTests("debugger;"); | 2525 ExecuteJavaScriptForTests("debugger;"); |
2624 | 2526 |
2625 // CloseWhilePaused should resume execution and continue here. | 2527 // CloseWhilePaused should resume execution and continue here. |
2626 EXPECT_FALSE(IsPaused()); | 2528 EXPECT_FALSE(IsPaused()); |
2627 Detach(); | 2529 Detach(); |
2628 } | 2530 } |
2629 | 2531 |
2630 } // namespace content | 2532 } // namespace content |
OLD | NEW |