Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: content/renderer/render_view_browsertest.cc

Issue 1737733002: [DevTools] Handle emulated device scale factor and original device scale factor properly. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 StartNavigationParams late_start_params; 2500 StartNavigationParams late_start_params;
2501 late_common_params.url = GURL("data:text/html,<div>Another page</div>"); 2501 late_common_params.url = GURL("data:text/html,<div>Another page</div>");
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 2651
2652 TEST_F(RenderViewImplBlinkSettingsTest, Negative) { 2652 TEST_F(RenderViewImplBlinkSettingsTest, Negative) {
2653 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2653 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2654 switches::kBlinkSettings, 2654 switches::kBlinkSettings,
2655 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); 2655 "multiTargetTapNotificationEnabled=false,viewportEnabled=true");
2656 DoSetUp(); 2656 DoSetUp();
2657 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); 2657 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled());
2658 EXPECT_TRUE(settings()->viewportEnabled()); 2658 EXPECT_TRUE(settings()->viewportEnabled());
2659 } 2659 }
2660 2660
2661 #if !defined(OS_CHROMEOS)
2662 // UseZoomForDSF is enabled on ChromeOS.
2663 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { 2661 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) {
2664 DoSetUp(); 2662 DoSetUp();
2663 if (IsUseZoomForDSFEnabled())
2664 return;
2665 SetDeviceScaleFactor(2.f); 2665 SetDeviceScaleFactor(2.f);
2666 blink::WebRect rect(20, 10, 200, 100); 2666 blink::WebRect rect(20, 10, 200, 100);
2667 view()->convertViewportToWindow(&rect); 2667 view()->convertViewportToWindow(&rect);
2668 EXPECT_EQ(20, rect.x); 2668 EXPECT_EQ(20, rect.x);
2669 EXPECT_EQ(10, rect.y); 2669 EXPECT_EQ(10, rect.y);
2670 EXPECT_EQ(200, rect.width); 2670 EXPECT_EQ(200, rect.width);
2671 EXPECT_EQ(100, rect.height); 2671 EXPECT_EQ(100, rect.height);
2672 } 2672 }
2673 #endif 2673
2674 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) {
2675 DoSetUp();
2676 SetDeviceScaleFactor(1.f);
2677
2678 LoadHTML("<body style='min-height:1000px;'></body>");
2679 {
2680 SCOPED_TRACE("327x415 1dpr");
2681 TestEmulatedSizeDprDsf(327, 415, 1.f, 1.f);
2682 }
2683 {
2684 SCOPED_TRACE("327x415 1.5dpr");
2685 TestEmulatedSizeDprDsf(327, 415, 1.5f, 1.f);
2686 }
2687 {
2688 SCOPED_TRACE("1005x1102 2dpr");
2689 TestEmulatedSizeDprDsf(1005, 1102, 2.f, 1.f);
2690 }
2691 {
2692 SCOPED_TRACE("1005x1102 3dpr");
2693 TestEmulatedSizeDprDsf(1005, 1102, 3.f, 1.f);
2694 }
2695
2696 view()->OnDisableDeviceEmulation();
2697
2698 blink::WebDeviceEmulationParams params;
2699 view()->OnEnableDeviceEmulation(params);
2700 // Don't disable here to test that emulation is being shutdown properly.
2701 }
2702
2703 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) {
2704 DoSetUp();
2705 SetDeviceScaleFactor(2.f);
2706 float compositor_dsf =
2707 IsUseZoomForDSFEnabled() ? 1.f : 2.f;
2708
2709 LoadHTML("<body style='min-height:1000px;'></body>");
2710 {
2711 SCOPED_TRACE("327x415 1dpr");
2712 TestEmulatedSizeDprDsf(327, 415, 1.f, compositor_dsf);
2713 }
2714 {
2715 SCOPED_TRACE("327x415 1.5dpr");
2716 TestEmulatedSizeDprDsf(327, 415, 1.5f, compositor_dsf);
2717 }
2718 {
2719 SCOPED_TRACE("1005x1102 2dpr");
2720 TestEmulatedSizeDprDsf(1005, 1102, 2.f, compositor_dsf);
2721 }
2722 {
2723 SCOPED_TRACE("1005x1102 3dpr");
2724 TestEmulatedSizeDprDsf(1005, 1102, 3.f, compositor_dsf);
2725 }
2726
2727 view()->OnDisableDeviceEmulation();
2728
2729 blink::WebDeviceEmulationParams params;
2730 view()->OnEnableDeviceEmulation(params);
2731 // Don't disable here to test that emulation is being shutdown properly.
2732 }
2674 2733
2675 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { 2734 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) {
2676 base::CommandLine::ForCurrentProcess()->AppendSwitch( 2735 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2677 switches::kEnableUseZoomForDSF); 2736 switches::kEnableUseZoomForDSF);
2678 DoSetUp(); 2737 DoSetUp();
2679 SetDeviceScaleFactor(1.f); 2738 SetDeviceScaleFactor(1.f);
2680 { 2739 {
2681 blink::WebRect rect(20, 10, 200, 100); 2740 blink::WebRect rect(20, 10, 200, 100);
2682 view()->convertViewportToWindow(&rect); 2741 view()->convertViewportToWindow(&rect);
2683 EXPECT_EQ(20, rect.x); 2742 EXPECT_EQ(20, rect.x);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 FROM_HERE, 2855 FROM_HERE,
2797 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2856 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2798 ExecuteJavaScriptForTests("debugger;"); 2857 ExecuteJavaScriptForTests("debugger;");
2799 2858
2800 // CloseWhilePaused should resume execution and continue here. 2859 // CloseWhilePaused should resume execution and continue here.
2801 EXPECT_FALSE(IsPaused()); 2860 EXPECT_FALSE(IsPaused());
2802 Detach(); 2861 Detach();
2803 } 2862 }
2804 2863
2805 } // namespace content 2864 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698