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

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, float compositor _dsf) {
440 static base::string16 get_width = base::ASCIIToUTF16("Number(window.innerWid th)");
441 static base::string16 get_height = base::ASCIIToUTF16("Number(window.innerHe ight)");
442 static base::string16 get_dpr = base::ASCIIToUTF16("Number(window.devicePixe lRatio * 10)");
443
444 int emulated_width, emulated_height;
445 int emulated_dpr;
446 blink::WebDeviceEmulationParams params;
447 params.viewSize.width = width;
448 params.viewSize.height = height;
449 params.deviceScaleFactor = dpr;
450 view()->OnEnableDeviceEmulation(params);
451 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width));
452 EXPECT_EQ(width, emulated_width);
453 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, &emulated_height) );
454 EXPECT_EQ(height, emulated_height);
455 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr));
456 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr);
457 EXPECT_EQ(compositor_dsf,
458 view()->compositor()->layer_tree_host()->device_scale_factor());
459 }
435 }; 460 };
436 461
437 // Ensure that the main RenderFrame is deleted and cleared from the RenderView 462 // Ensure that the main RenderFrame is deleted and cleared from the RenderView
438 // after closing it. 463 // after closing it.
439 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { 464 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) {
440 // Create a new main frame RenderFrame so that we don't interfere with the 465 // Create a new main frame RenderFrame so that we don't interfere with the
441 // shutdown of frame() in RenderViewTest.TearDown. 466 // shutdown of frame() in RenderViewTest.TearDown.
442 blink::WebURLRequest popup_request(GURL("http://foo.com")); 467 blink::WebURLRequest popup_request(GURL("http://foo.com"));
443 blink::WebView* new_web_view = view()->createView( 468 blink::WebView* new_web_view = view()->createView(
444 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo", 469 GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo",
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 2477
2453 frame()->SetAccessibilityMode(AccessibilityModeOff); 2478 frame()->SetAccessibilityMode(AccessibilityModeOff);
2454 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode()); 2479 ASSERT_EQ(AccessibilityModeOff, frame()->accessibility_mode());
2455 ASSERT_EQ((RendererAccessibility*) NULL, frame()->renderer_accessibility()); 2480 ASSERT_EQ((RendererAccessibility*) NULL, frame()->renderer_accessibility());
2456 2481
2457 frame()->SetAccessibilityMode(AccessibilityModeComplete); 2482 frame()->SetAccessibilityMode(AccessibilityModeComplete);
2458 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode()); 2483 ASSERT_EQ(AccessibilityModeComplete, frame()->accessibility_mode());
2459 ASSERT_NE((RendererAccessibility*) NULL, frame()->renderer_accessibility()); 2484 ASSERT_NE((RendererAccessibility*) NULL, frame()->renderer_accessibility());
2460 } 2485 }
2461 2486
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 2487 // Sanity check for the Navigation Timing API |navigationStart| override. We
2493 // are asserting only most basic constraints, as TimeTicks (passed as the 2488 // 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). 2489 // override) are not comparable with the wall time (returned by the Blink API).
2495 TEST_F(RenderViewImplTest, NavigationStartOverride) { 2490 TEST_F(RenderViewImplTest, NavigationStartOverride) {
2496 // Verify that a navigation that claims to have started in the future - 42 2491 // 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 2492 // days from now is *not* reported as one that starts in the future; as we
2498 // sanitize the override allowing a maximum of ::Now(). 2493 // sanitize the override allowing a maximum of ::Now().
2499 CommonNavigationParams late_common_params; 2494 CommonNavigationParams late_common_params;
2500 StartNavigationParams late_start_params; 2495 StartNavigationParams late_start_params;
2501 late_common_params.url = GURL("data:text/html,<div>Another page</div>"); 2496 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 2646
2652 TEST_F(RenderViewImplBlinkSettingsTest, Negative) { 2647 TEST_F(RenderViewImplBlinkSettingsTest, Negative) {
2653 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 2648 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
2654 switches::kBlinkSettings, 2649 switches::kBlinkSettings,
2655 "multiTargetTapNotificationEnabled=false,viewportEnabled=true"); 2650 "multiTargetTapNotificationEnabled=false,viewportEnabled=true");
2656 DoSetUp(); 2651 DoSetUp();
2657 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled()); 2652 EXPECT_FALSE(settings()->multiTargetTapNotificationEnabled());
2658 EXPECT_TRUE(settings()->viewportEnabled()); 2653 EXPECT_TRUE(settings()->viewportEnabled());
2659 } 2654 }
2660 2655
2661 #if !defined(OS_CHROMEOS)
2662 // UseZoomForDSF is enabled on ChromeOS.
2663 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) { 2656 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) {
2657 if (IsUseZoomForDSFEnabled())
2658 return;
2664 DoSetUp(); 2659 DoSetUp();
2665 SetDeviceScaleFactor(2.f); 2660 SetDeviceScaleFactor(2.f);
2666 blink::WebRect rect(20, 10, 200, 100); 2661 blink::WebRect rect(20, 10, 200, 100);
2667 view()->convertViewportToWindow(&rect); 2662 view()->convertViewportToWindow(&rect);
2668 EXPECT_EQ(20, rect.x); 2663 EXPECT_EQ(20, rect.x);
2669 EXPECT_EQ(10, rect.y); 2664 EXPECT_EQ(10, rect.y);
2670 EXPECT_EQ(200, rect.width); 2665 EXPECT_EQ(200, rect.width);
2671 EXPECT_EQ(100, rect.height); 2666 EXPECT_EQ(100, rect.height);
2672 } 2667 }
2673 #endif 2668
2669 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) {
2670 DoSetUp();
2671 SetDeviceScaleFactor(1.f);
2672
2673 LoadHTML("<body style='min-height:1000px;'></body>");
2674 {
2675 SCOPED_TRACE("327x415 1dpr");
2676 TestEmulatedSizeDprDsf(327, 415, 1.f, 1.f);
2677 }
2678 {
2679 SCOPED_TRACE("1005x1102 2dpr");
2680 TestEmulatedSizeDprDsf(1005, 1102, 2.f, 1.f);
2681 }
2682 {
2683 SCOPED_TRACE("1005x1102 3dpr");
2684 TestEmulatedSizeDprDsf(1005, 1102, 3.f, 1.f);
2685 }
2686
2687 view()->OnDisableDeviceEmulation();
2688
2689 blink::WebDeviceEmulationParams params;
2690 view()->OnEnableDeviceEmulation(params);
2691 // Don't disable here to test that emulation is being shutdown properly.
2692 }
2693
2694 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) {
2695 DoSetUp();
2696 SetDeviceScaleFactor(2.f);
2697 float compositor_dsf =
2698 IsUseZoomForDSFEnabled() ? 1.f : 2.f;
2699
2700 LoadHTML("<body style='min-height:1000px;'></body>");
2701 {
2702 SCOPED_TRACE("327x415 1dpr");
2703 TestEmulatedSizeDprDsf(327, 415, 1.f, compositor_dsf);
2704 }
2705 {
2706 SCOPED_TRACE("1005x1102 2dpr");
2707 TestEmulatedSizeDprDsf(1005, 1102, 2.f, compositor_dsf);
2708 }
2709 {
2710 SCOPED_TRACE("1005x1102 3dpr");
2711 TestEmulatedSizeDprDsf(1005, 1102, 3.f, compositor_dsf);
2712 }
2713
2714 view()->OnDisableDeviceEmulation();
2715
2716 blink::WebDeviceEmulationParams params;
2717 view()->OnEnableDeviceEmulation(params);
2718 // Don't disable here to test that emulation is being shutdown properly.
2719 }
2674 2720
2675 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { 2721 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) {
2676 base::CommandLine::ForCurrentProcess()->AppendSwitch( 2722 base::CommandLine::ForCurrentProcess()->AppendSwitch(
2677 switches::kEnableUseZoomForDSF); 2723 switches::kEnableUseZoomForDSF);
2678 DoSetUp(); 2724 DoSetUp();
2679 SetDeviceScaleFactor(1.f); 2725 SetDeviceScaleFactor(1.f);
2680 { 2726 {
2681 blink::WebRect rect(20, 10, 200, 100); 2727 blink::WebRect rect(20, 10, 200, 100);
2682 view()->convertViewportToWindow(&rect); 2728 view()->convertViewportToWindow(&rect);
2683 EXPECT_EQ(20, rect.x); 2729 EXPECT_EQ(20, rect.x);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 FROM_HERE, 2842 FROM_HERE,
2797 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this))); 2843 base::Bind(&DevToolsAgentTest::CloseWhilePaused, base::Unretained(this)));
2798 ExecuteJavaScriptForTests("debugger;"); 2844 ExecuteJavaScriptForTests("debugger;");
2799 2845
2800 // CloseWhilePaused should resume execution and continue here. 2846 // CloseWhilePaused should resume execution and continue here.
2801 EXPECT_FALSE(IsPaused()); 2847 EXPECT_FALSE(IsPaused());
2802 Detach(); 2848 Detach();
2803 } 2849 }
2804 2850
2805 } // namespace content 2851 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698