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