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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // be configured before RenderViewImplTest::SetUp runs. Thus we make | 381 // be configured before RenderViewImplTest::SetUp runs. Thus we make |
382 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via | 382 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via |
383 // DoSetUp(), to allow tests to perform command line modifications | 383 // DoSetUp(), to allow tests to perform command line modifications |
384 // before RenderViewImplTest::SetUp is run. Each test must invoke | 384 // before RenderViewImplTest::SetUp is run. Each test must invoke |
385 // DoSetUp manually once pre-SetUp configuration is complete. | 385 // DoSetUp manually once pre-SetUp configuration is complete. |
386 void SetUp() override {} | 386 void SetUp() override {} |
387 }; | 387 }; |
388 | 388 |
389 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { | 389 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { |
390 public: | 390 public: |
391 void DoSetUp() override { | 391 void SetDeviceScaleFactor(float dsf) { |
392 RenderViewImplBlinkSettingsTest::DoSetUp(); | |
393 | |
394 ViewMsg_Resize_Params params; | 392 ViewMsg_Resize_Params params; |
395 params.screen_info.deviceScaleFactor = 2.f; | 393 params.screen_info.deviceScaleFactor = dsf; |
396 params.new_size = gfx::Size(100, 100); | 394 params.new_size = gfx::Size(100, 100); |
397 params.physical_backing_size = gfx::Size(200, 200); | 395 params.physical_backing_size = gfx::Size(200, 200); |
398 params.visible_viewport_size = params.new_size; | 396 params.visible_viewport_size = params.new_size; |
399 params.needs_resize_ack = false; | 397 params.needs_resize_ack = false; |
400 view()->OnResize(params); | 398 view()->OnResize(params); |
401 ASSERT_EQ(2.f, view()->device_scale_factor_); | 399 ASSERT_EQ(dsf, view()->device_scale_factor_); |
402 } | 400 } |
403 }; | 401 }; |
404 | 402 |
405 // 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 |
406 // after closing it. | 404 // after closing it. |
407 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 405 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
408 // 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 |
409 // shutdown of frame() in RenderViewTest.TearDown. | 407 // shutdown of frame() in RenderViewTest.TearDown. |
410 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 408 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
411 blink::WebView* new_web_view = view()->createView( | 409 blink::WebView* new_web_view = view()->createView( |
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 const base::string16 empty_string; | 1878 const base::string16 empty_string; |
1881 const std::vector<blink::WebCompositionUnderline> empty_underline; | 1879 const std::vector<blink::WebCompositionUnderline> empty_underline; |
1882 std::vector<gfx::Rect> bounds; | 1880 std::vector<gfx::Rect> bounds; |
1883 view()->OnSetFocus(true); | 1881 view()->OnSetFocus(true); |
1884 | 1882 |
1885 // ASCII composition | 1883 // ASCII composition |
1886 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); | 1884 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); |
1887 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); | 1885 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); |
1888 view()->GetCompositionCharacterBounds(&bounds); | 1886 view()->GetCompositionCharacterBounds(&bounds); |
1889 ASSERT_EQ(ascii_composition.size(), bounds.size()); | 1887 ASSERT_EQ(ascii_composition.size(), bounds.size()); |
| 1888 |
1890 for (size_t i = 0; i < bounds.size(); ++i) | 1889 for (size_t i = 0; i < bounds.size(); ++i) |
1891 EXPECT_LT(0, bounds[i].width()); | 1890 EXPECT_LT(0, bounds[i].width()); |
1892 view()->OnImeConfirmComposition( | 1891 view()->OnImeConfirmComposition( |
1893 empty_string, gfx::Range::InvalidRange(), false); | 1892 empty_string, gfx::Range::InvalidRange(), false); |
1894 | 1893 |
1895 // Non surrogate pair unicode character. | 1894 // Non surrogate pair unicode character. |
1896 const base::string16 unicode_composition = base::UTF8ToUTF16( | 1895 const base::string16 unicode_composition = base::UTF8ToUTF16( |
1897 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); | 1896 "\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A"); |
1898 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); | 1897 view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0); |
1899 view()->GetCompositionCharacterBounds(&bounds); | 1898 view()->GetCompositionCharacterBounds(&bounds); |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 2542 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
2544 switches::kBlinkSettings, | 2543 switches::kBlinkSettings, |
2545 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); | 2544 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); |
2546 DoSetUp(); | 2545 DoSetUp(); |
2547 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); | 2546 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); |
2548 EXPECT_TRUE(settings()->viewportEnabled()); | 2547 EXPECT_TRUE(settings()->viewportEnabled()); |
2549 } | 2548 } |
2550 | 2549 |
2551 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { | 2550 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { |
2552 DoSetUp(); | 2551 DoSetUp(); |
| 2552 SetDeviceScaleFactor(2.f); |
2553 blink::WebRect rect(20, 10, 200, 100); | 2553 blink::WebRect rect(20, 10, 200, 100); |
2554 view()->convertViewportToWindow(&rect); | 2554 view()->convertViewportToWindow(&rect); |
2555 EXPECT_EQ(20, rect.x); | 2555 EXPECT_EQ(20, rect.x); |
2556 EXPECT_EQ(10, rect.y); | 2556 EXPECT_EQ(10, rect.y); |
2557 EXPECT_EQ(200, rect.width); | 2557 EXPECT_EQ(200, rect.width); |
2558 EXPECT_EQ(100, rect.height); | 2558 EXPECT_EQ(100, rect.height); |
2559 } | 2559 } |
2560 | 2560 |
2561 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { | 2561 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { |
2562 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2562 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
2563 switches::kEnableUseZoomForDSF); | 2563 switches::kEnableUseZoomForDSF); |
2564 DoSetUp(); | 2564 DoSetUp(); |
| 2565 SetDeviceScaleFactor(1.f); |
| 2566 { |
| 2567 blink::WebRect rect(20, 10, 200, 100); |
| 2568 view()->convertViewportToWindow(&rect); |
| 2569 EXPECT_EQ(20, rect.x); |
| 2570 EXPECT_EQ(10, rect.y); |
| 2571 EXPECT_EQ(200, rect.width); |
| 2572 EXPECT_EQ(100, rect.height); |
| 2573 } |
2565 | 2574 |
2566 blink::WebRect rect(20, 10, 200, 100); | 2575 SetDeviceScaleFactor(2.f); |
2567 view()->convertViewportToWindow(&rect); | 2576 { |
2568 EXPECT_EQ(10, rect.x); | 2577 blink::WebRect rect(20, 10, 200, 100); |
2569 EXPECT_EQ(5, rect.y); | 2578 view()->convertViewportToWindow(&rect); |
2570 EXPECT_EQ(100, rect.width); | 2579 EXPECT_EQ(10, rect.x); |
2571 EXPECT_EQ(50, rect.height); | 2580 EXPECT_EQ(5, rect.y); |
| 2581 EXPECT_EQ(100, rect.width); |
| 2582 EXPECT_EQ(50, rect.height); |
| 2583 } |
2572 } | 2584 } |
2573 | 2585 |
| 2586 #if defined(OS_MACOSX) || defined(USE_AURA) |
| 2587 TEST_F(RenderViewImplScaleFactorTest, GetCompositionCharacterBoundsTest) { |
| 2588 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2589 switches::kEnableUseZoomForDSF); |
| 2590 DoSetUp(); |
| 2591 SetDeviceScaleFactor(1.f); |
| 2592 #if defined(OS_WIN) |
| 2593 // http://crbug.com/508747 |
| 2594 if (base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 2595 return; |
| 2596 #endif |
| 2597 |
| 2598 LoadHTML("<textarea id=\"test\"></textarea>"); |
| 2599 ExecuteJavaScriptForTests("document.getElementById('test').focus();"); |
| 2600 |
| 2601 const base::string16 empty_string; |
| 2602 const std::vector<blink::WebCompositionUnderline> empty_underline; |
| 2603 std::vector<gfx::Rect> bounds_at_1x; |
| 2604 view()->OnSetFocus(true); |
| 2605 |
| 2606 // ASCII composition |
| 2607 const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo"); |
| 2608 view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0); |
| 2609 view()->GetCompositionCharacterBounds(&bounds_at_1x); |
| 2610 ASSERT_EQ(ascii_composition.size(), bounds_at_1x.size()); |
| 2611 |
| 2612 SetDeviceScaleFactor(2.f); |
| 2613 std::vector<gfx::Rect> bounds_at_2x; |
| 2614 view()->GetCompositionCharacterBounds(&bounds_at_2x); |
| 2615 ASSERT_EQ(bounds_at_1x.size(), bounds_at_2x.size()); |
| 2616 for (size_t i = 0; i < bounds_at_1x.size(); i++) { |
| 2617 const gfx::Rect& b1 = bounds_at_1x[i]; |
| 2618 const gfx::Rect& b2 = bounds_at_2x[i]; |
| 2619 gfx::Vector2d origin_diff = b1.origin() - b2.origin(); |
| 2620 |
| 2621 // The bounds may not be exactly same because the font metrics are different |
| 2622 // at 1x and 2x. Just make sure that the difference is small. |
| 2623 EXPECT_LT(origin_diff.x(), 2); |
| 2624 EXPECT_LT(origin_diff.y(), 2); |
| 2625 EXPECT_LT(std::abs(b1.width() - b2.width()), 3); |
| 2626 EXPECT_LT(std::abs(b1.height() - b2.height()), 2); |
| 2627 } |
| 2628 } |
| 2629 #endif |
| 2630 |
| 2631 #if !defined(OS_ANDROID) |
| 2632 // No extensions/autoresize on Android. |
| 2633 namespace { |
| 2634 |
| 2635 // Don't use text as it text will change the size in DIP at different |
| 2636 // scale factor. |
| 2637 const char kAutoResizeTestPage[] = |
| 2638 "<div style='width=20px; height=20px'></div>"; |
| 2639 |
| 2640 } // namespace |
| 2641 |
| 2642 TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithZoomForDSF) { |
| 2643 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 2644 switches::kEnableUseZoomForDSF); |
| 2645 DoSetUp(); |
| 2646 view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000)); |
| 2647 LoadHTML(kAutoResizeTestPage); |
| 2648 gfx::Size size_at_1x = view()->size(); |
| 2649 ASSERT_FALSE(size_at_1x.IsEmpty()); |
| 2650 |
| 2651 SetDeviceScaleFactor(2.f); |
| 2652 LoadHTML(kAutoResizeTestPage); |
| 2653 gfx::Size size_at_2x = view()->size(); |
| 2654 EXPECT_EQ(size_at_1x, size_at_2x); |
| 2655 } |
| 2656 |
| 2657 TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithoutZoomForDSF) { |
| 2658 DoSetUp(); |
| 2659 view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000)); |
| 2660 LoadHTML(kAutoResizeTestPage); |
| 2661 gfx::Size size_at_1x = view()->size(); |
| 2662 ASSERT_FALSE(size_at_1x.IsEmpty()); |
| 2663 |
| 2664 SetDeviceScaleFactor(2.f); |
| 2665 LoadHTML(kAutoResizeTestPage); |
| 2666 gfx::Size size_at_2x = view()->size(); |
| 2667 EXPECT_EQ(size_at_1x, size_at_2x); |
| 2668 } |
| 2669 |
| 2670 #endif |
| 2671 |
2574 TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) { | 2672 TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) { |
2575 Attach(); | 2673 Attach(); |
2576 EXPECT_FALSE(IsPaused()); | 2674 EXPECT_FALSE(IsPaused()); |
2577 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Debugger.enable\"}"); | 2675 DispatchDevToolsMessage("{\"id\":1,\"method\":\"Debugger.enable\"}"); |
2578 | 2676 |
2579 // Executing javascript will pause the thread and create nested message loop. | 2677 // Executing javascript will pause the thread and create nested message loop. |
2580 // Posting task simulates message coming from browser. | 2678 // Posting task simulates message coming from browser. |
2581 base::ThreadTaskRunnerHandle::Get()->PostTask( | 2679 base::ThreadTaskRunnerHandle::Get()->PostTask( |
2582 FROM_HERE, | 2680 FROM_HERE, |
2583 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2681 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2584 ExecuteJavaScriptForTests("debugger;"); | 2682 ExecuteJavaScriptForTests("debugger;"); |
2585 | 2683 |
2586 // CloseWhilePaused should resume execution and continue here. | 2684 // CloseWhilePaused should resume execution and continue here. |
2587 EXPECT_FALSE(IsPaused()); | 2685 EXPECT_FALSE(IsPaused()); |
2588 Detach(); | 2686 Detach(); |
2589 } | 2687 } |
2590 | 2688 |
2591 } // namespace content | 2689 } // namespace content |
OLD | NEW |