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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "cc/trees/layer_tree_host.h" | |
20 #include "content/child/request_extra_data.h" | 21 #include "content/child/request_extra_data.h" |
21 #include "content/child/service_worker/service_worker_network_provider.h" | 22 #include "content/child/service_worker/service_worker_network_provider.h" |
23 #include "content/common/content_switches_internal.h" | |
22 #include "content/common/frame_messages.h" | 24 #include "content/common/frame_messages.h" |
23 #include "content/common/frame_replication_state.h" | 25 #include "content/common/frame_replication_state.h" |
24 #include "content/common/site_isolation_policy.h" | 26 #include "content/common/site_isolation_policy.h" |
25 #include "content/common/ssl_status_serialization.h" | 27 #include "content/common/ssl_status_serialization.h" |
26 #include "content/common/view_messages.h" | 28 #include "content/common/view_messages.h" |
27 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
28 #include "content/public/browser/native_web_keyboard_event.h" | 30 #include "content/public/browser/native_web_keyboard_event.h" |
29 #include "content/public/browser/web_ui_controller_factory.h" | 31 #include "content/public/browser/web_ui_controller_factory.h" |
30 #include "content/public/common/bindings_policy.h" | 32 #include "content/public/common/bindings_policy.h" |
31 #include "content/public/common/browser_side_navigation_policy.h" | 33 #include "content/public/common/browser_side_navigation_policy.h" |
32 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/page_zoom.h" | 35 #include "content/public/common/page_zoom.h" |
34 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
35 #include "content/public/common/url_utils.h" | 37 #include "content/public/common/url_utils.h" |
36 #include "content/public/renderer/content_renderer_client.h" | 38 #include "content/public/renderer/content_renderer_client.h" |
37 #include "content/public/renderer/document_state.h" | 39 #include "content/public/renderer/document_state.h" |
38 #include "content/public/renderer/navigation_state.h" | 40 #include "content/public/renderer/navigation_state.h" |
39 #include "content/public/test/browser_test_utils.h" | 41 #include "content/public/test/browser_test_utils.h" |
40 #include "content/public/test/frame_load_waiter.h" | 42 #include "content/public/test/frame_load_waiter.h" |
41 #include "content/public/test/render_view_test.h" | 43 #include "content/public/test/render_view_test.h" |
42 #include "content/public/test/test_utils.h" | 44 #include "content/public/test/test_utils.h" |
43 #include "content/renderer/accessibility/renderer_accessibility.h" | 45 #include "content/renderer/accessibility/renderer_accessibility.h" |
44 #include "content/renderer/devtools/devtools_agent.h" | 46 #include "content/renderer/devtools/devtools_agent.h" |
47 #include "content/renderer/gpu/render_widget_compositor.h" | |
45 #include "content/renderer/history_controller.h" | 48 #include "content/renderer/history_controller.h" |
46 #include "content/renderer/history_serialization.h" | 49 #include "content/renderer/history_serialization.h" |
47 #include "content/renderer/navigation_state_impl.h" | 50 #include "content/renderer/navigation_state_impl.h" |
48 #include "content/renderer/render_process.h" | 51 #include "content/renderer/render_process.h" |
49 #include "content/renderer/render_view_impl.h" | 52 #include "content/renderer/render_view_impl.h" |
50 #include "content/shell/browser/shell.h" | 53 #include "content/shell/browser/shell.h" |
51 #include "content/shell/browser/shell_browser_context.h" | 54 #include "content/shell/browser/shell_browser_context.h" |
52 #include "content/test/mock_keyboard.h" | 55 #include "content/test/mock_keyboard.h" |
53 #include "content/test/test_render_frame.h" | 56 #include "content/test/test_render_frame.h" |
54 #include "net/base/net_errors.h" | 57 #include "net/base/net_errors.h" |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 // Blink settings may be specified on the command line, which must | 417 // Blink settings may be specified on the command line, which must |
415 // be configured before RenderViewImplTest::SetUp runs. Thus we make | 418 // be configured before RenderViewImplTest::SetUp runs. Thus we make |
416 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via | 419 // SetUp() a no-op, and expose RenderViewImplTest::SetUp() via |
417 // DoSetUp(), to allow tests to perform command line modifications | 420 // DoSetUp(), to allow tests to perform command line modifications |
418 // before RenderViewImplTest::SetUp is run. Each test must invoke | 421 // before RenderViewImplTest::SetUp is run. Each test must invoke |
419 // DoSetUp manually once pre-SetUp configuration is complete. | 422 // DoSetUp manually once pre-SetUp configuration is complete. |
420 void SetUp() override {} | 423 void SetUp() override {} |
421 }; | 424 }; |
422 | 425 |
423 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { | 426 class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest { |
424 public: | 427 protected: |
425 void SetDeviceScaleFactor(float dsf) { | 428 void SetDeviceScaleFactor(float dsf) { |
426 ResizeParams params; | 429 ResizeParams params; |
427 params.screen_info.deviceScaleFactor = dsf; | 430 params.screen_info.deviceScaleFactor = dsf; |
428 params.new_size = gfx::Size(100, 100); | 431 params.new_size = gfx::Size(100, 100); |
429 params.physical_backing_size = gfx::Size(200, 200); | 432 params.physical_backing_size = gfx::Size(200, 200); |
430 params.visible_viewport_size = params.new_size; | 433 params.visible_viewport_size = params.new_size; |
431 params.needs_resize_ack = false; | 434 params.needs_resize_ack = false; |
432 view()->OnResize(params); | 435 view()->OnResize(params); |
433 ASSERT_EQ(dsf, view()->device_scale_factor_); | 436 ASSERT_EQ(dsf, view()->device_scale_factor_); |
434 } | 437 } |
438 | |
439 void TestEmulatedSizeDprDsf(int width, int height, float dpr, | |
440 float compositor_dsf) { | |
441 static base::string16 get_width = | |
442 base::ASCIIToUTF16("Number(window.innerWidth)"); | |
443 static base::string16 get_height = | |
444 base::ASCIIToUTF16("Number(window.innerHeight)"); | |
445 static base::string16 get_dpr = | |
446 base::ASCIIToUTF16("Number(window.devicePixelRatio * 10)"); | |
447 | |
448 int emulated_width, emulated_height; | |
449 int emulated_dpr; | |
450 blink::WebDeviceEmulationParams params; | |
451 params.viewSize.width = width; | |
452 params.viewSize.height = height; | |
453 params.deviceScaleFactor = dpr; | |
454 view()->OnEnableDeviceEmulation(params); | |
455 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width)); | |
456 EXPECT_EQ(width, emulated_width); | |
457 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, | |
458 &emulated_height)); | |
459 EXPECT_EQ(height, emulated_height); | |
460 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr)); | |
461 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr); | |
462 EXPECT_EQ(compositor_dsf, | |
463 view()->compositor()->layer_tree_host()->device_scale_factor()); | |
464 } | |
435 }; | 465 }; |
436 | 466 |
437 // Ensure that the main RenderFrame is deleted and cleared from the RenderView | 467 // Ensure that the main RenderFrame is deleted and cleared from the RenderView |
438 // after closing it. | 468 // after closing it. |
439 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 469 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
440 // Create a new main frame RenderFrame so that we don't interfere with the | 470 // Create a new main frame RenderFrame so that we don't interfere with the |
441 // shutdown of frame() in RenderViewTest.TearDown. | 471 // shutdown of frame() in RenderViewTest.TearDown. |
442 blink::WebURLRequest popup_request(GURL("http://foo.com")); | 472 blink::WebURLRequest popup_request(GURL("http://foo.com")); |
443 blink::WebView* new_web_view = view()->createView( | 473 blink::WebView* new_web_view = view()->createView( |
444 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", | 474 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", |
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2452 | 2482 |
2453 frame()->SetAccessibilityMode(AccessibilityModeOff); | 2483 frame()->SetAccessibilityMode(AccessibilityModeOff); |
2454 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); | 2484 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); |
2455 ASSERT_EQ((RendererAccessibility*) NULL, frame()->renderer_accessibility()); | 2485 ASSERT_EQ((RendererAccessibility*) NULL, frame()->renderer_accessibility()); |
2456 | 2486 |
2457 frame()->SetAccessibilityMode(AccessibilityModeComplete); | 2487 frame()->SetAccessibilityMode(AccessibilityModeComplete); |
2458 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); | 2488 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); |
2459 ASSERT_NE((RendererAccessibility*) NULL, frame()->renderer_accessibility()); | 2489 ASSERT_NE((RendererAccessibility*) NULL, frame()->renderer_accessibility()); |
2460 } | 2490 } |
2461 | 2491 |
2462 TEST_F(RenderViewImplTest, ScreenMetricsEmulation) { | |
2463 LoadHTML("<body style='min-height:1000px;'></body>"); | |
2464 | |
2465 blink::WebDeviceEmulationParams params; | |
2466 base::string16 get_width = base::ASCIIToUTF16("Number(window.innerWidth)"); | |
2467 base::string16 get_height = base::ASCIIToUTF16("Number(window.innerHeight)"); | |
2468 int width, height; | |
2469 | |
2470 params.viewSize.width = 327; | |
2471 params.viewSize.height = 415; | |
2472 view()->OnEnableDeviceEmulation(params); | |
2473 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &width)); | |
2474 EXPECT_EQ(params.viewSize.width, width); | |
2475 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, &height)); | |
2476 EXPECT_EQ(params.viewSize.height, height); | |
2477 | |
2478 params.viewSize.width = 1005; | |
2479 params.viewSize.height = 1102; | |
2480 view()->OnEnableDeviceEmulation(params); | |
2481 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &width)); | |
2482 EXPECT_EQ(params.viewSize.width, width); | |
2483 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, &height)); | |
2484 EXPECT_EQ(params.viewSize.height, height); | |
2485 | |
2486 view()->OnDisableDeviceEmulation(); | |
2487 | |
2488 view()->OnEnableDeviceEmulation(params); | |
2489 // Don't disable here to test that emulation is being shutdown properly. | |
2490 } | |
2491 | |
2492 // Sanity check for the Navigation Timing API |navigationStart| override. We | 2492 // Sanity check for the Navigation Timing API |navigationStart| override. We |
2493 // are asserting only most basic constraints, as TimeTicks (passed as the | 2493 // are asserting only most basic constraints, as TimeTicks (passed as the |
2494 // override) are not comparable with the wall time (returned by the Blink API). | 2494 // override) are not comparable with the wall time (returned by the Blink API). |
2495 TEST_F(RenderViewImplTest, NavigationStartOverride) { | 2495 TEST_F(RenderViewImplTest, NavigationStartOverride) { |
2496 // Verify that a navigation that claims to have started in the future - 42 | 2496 // Verify that a navigation that claims to have started in the future - 42 |
2497 // days from now is *not* reported as one that starts in the future; as we | 2497 // days from now is *not* reported as one that starts in the future; as we |
2498 // sanitize the override allowing a maximum of ::Now(). | 2498 // sanitize the override allowing a maximum of ::Now(). |
2499 CommonNavigationParams late_common_params; | 2499 CommonNavigationParams late_common_params; |
2500 late_common_params.url = GURL("data:text/html,<div>Another page</div>"); | 2500 late_common_params.url = GURL("data:text/html,<div>Another page</div>"); |
2501 late_common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; | 2501 late_common_params.navigation_type = FrameMsg_Navigate_Type::NORMAL; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2650 | 2650 |
2651 TEST_F(RenderViewImplBlinkSettingsTest, Negative) { | 2651 TEST_F(RenderViewImplBlinkSettingsTest, Negative) { |
2652 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 2652 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
2653 switches::kBlinkSettings, | 2653 switches::kBlinkSettings, |
2654 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); | 2654 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); |
2655 DoSetUp(); | 2655 DoSetUp(); |
2656 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); | 2656 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); |
2657 EXPECT_TRUE(settings()->viewportEnabled()); | 2657 EXPECT_TRUE(settings()->viewportEnabled()); |
2658 } | 2658 } |
2659 | 2659 |
2660 #if !defined(OS_CHROMEOS) | |
2661 // UseZoomForDSF is enabled on ChromeOS. | |
2662 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { | 2660 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { |
2663 DoSetUp(); | 2661 DoSetUp(); |
2662 if (IsUseZoomForDSFEnabled()) | |
2663 return; | |
2664 SetDeviceScaleFactor(2.f); | 2664 SetDeviceScaleFactor(2.f); |
2665 blink::WebRect rect(20, 10, 200, 100); | 2665 blink::WebRect rect(20, 10, 200, 100); |
2666 view()->convertViewportToWindow(&rect); | 2666 view()->convertViewportToWindow(&rect); |
2667 EXPECT_EQ(20, rect.x); | 2667 EXPECT_EQ(20, rect.x); |
2668 EXPECT_EQ(10, rect.y); | 2668 EXPECT_EQ(10, rect.y); |
2669 EXPECT_EQ(200, rect.width); | 2669 EXPECT_EQ(200, rect.width); |
2670 EXPECT_EQ(100, rect.height); | 2670 EXPECT_EQ(100, rect.height); |
2671 } | 2671 } |
2672 #endif | 2672 |
2673 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) { | |
kinuko
2016/03/03 08:29:08
DSF1 / DSF2 comes from SetDeviceScaleFactor 1.f an
| |
2674 DoSetUp(); | |
2675 SetDeviceScaleFactor(1.f); | |
2676 | |
2677 LoadHTML("<body style='min-height:1000px;'></body>"); | |
2678 { | |
2679 SCOPED_TRACE("327x415 1dpr"); | |
2680 TestEmulatedSizeDprDsf(327, 415, 1.f, 1.f); | |
2681 } | |
2682 { | |
2683 SCOPED_TRACE("327x415 1.5dpr"); | |
2684 TestEmulatedSizeDprDsf(327, 415, 1.5f, 1.f); | |
2685 } | |
2686 { | |
2687 SCOPED_TRACE("1005x1102 2dpr"); | |
2688 TestEmulatedSizeDprDsf(1005, 1102, 2.f, 1.f); | |
2689 } | |
2690 { | |
2691 SCOPED_TRACE("1005x1102 3dpr"); | |
2692 TestEmulatedSizeDprDsf(1005, 1102, 3.f, 1.f); | |
2693 } | |
2694 | |
2695 view()->OnDisableDeviceEmulation(); | |
2696 | |
2697 blink::WebDeviceEmulationParams params; | |
2698 view()->OnEnableDeviceEmulation(params); | |
2699 // Don't disable here to test that emulation is being shutdown properly. | |
2700 } | |
2701 | |
2702 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) { | |
2703 DoSetUp(); | |
2704 SetDeviceScaleFactor(2.f); | |
2705 float compositor_dsf = | |
2706 IsUseZoomForDSFEnabled() ? 1.f : 2.f; | |
2707 | |
2708 LoadHTML("<body style='min-height:1000px;'></body>"); | |
2709 { | |
2710 SCOPED_TRACE("327x415 1dpr"); | |
2711 TestEmulatedSizeDprDsf(327, 415, 1.f, compositor_dsf); | |
2712 } | |
2713 { | |
2714 SCOPED_TRACE("327x415 1.5dpr"); | |
2715 TestEmulatedSizeDprDsf(327, 415, 1.5f, compositor_dsf); | |
2716 } | |
2717 { | |
2718 SCOPED_TRACE("1005x1102 2dpr"); | |
2719 TestEmulatedSizeDprDsf(1005, 1102, 2.f, compositor_dsf); | |
2720 } | |
2721 { | |
2722 SCOPED_TRACE("1005x1102 3dpr"); | |
2723 TestEmulatedSizeDprDsf(1005, 1102, 3.f, compositor_dsf); | |
2724 } | |
2725 | |
2726 view()->OnDisableDeviceEmulation(); | |
2727 | |
2728 blink::WebDeviceEmulationParams params; | |
2729 view()->OnEnableDeviceEmulation(params); | |
2730 // Don't disable here to test that emulation is being shutdown properly. | |
2731 } | |
2673 | 2732 |
2674 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { | 2733 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { |
2675 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 2734 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
2676 switches::kEnableUseZoomForDSF); | 2735 switches::kEnableUseZoomForDSF); |
2677 DoSetUp(); | 2736 DoSetUp(); |
2678 SetDeviceScaleFactor(1.f); | 2737 SetDeviceScaleFactor(1.f); |
2679 { | 2738 { |
2680 blink::WebRect rect(20, 10, 200, 100); | 2739 blink::WebRect rect(20, 10, 200, 100); |
2681 view()->convertViewportToWindow(&rect); | 2740 view()->convertViewportToWindow(&rect); |
2682 EXPECT_EQ(20, rect.x); | 2741 EXPECT_EQ(20, rect.x); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2795 FROM_HERE, | 2854 FROM_HERE, |
2796 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); | 2855 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); |
2797 ExecuteJavaScriptForTests("debugger;"); | 2856 ExecuteJavaScriptForTests("debugger;"); |
2798 | 2857 |
2799 // CloseWhilePaused should resume execution and continue here. | 2858 // CloseWhilePaused should resume execution and continue here. |
2800 EXPECT_FALSE(IsPaused()); | 2859 EXPECT_FALSE(IsPaused()); |
2801 Detach(); | 2860 Detach(); |
2802 } | 2861 } |
2803 | 2862 |
2804 } // namespace content | 2863 } // namespace content |
OLD | NEW |