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 #include <tuple> | 7 #include <tuple> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 ResizeParams params; | 494 ResizeParams params; |
495 params.screen_info.deviceScaleFactor = dsf; | 495 params.screen_info.deviceScaleFactor = dsf; |
496 params.new_size = gfx::Size(100, 100); | 496 params.new_size = gfx::Size(100, 100); |
497 params.physical_backing_size = gfx::Size(200, 200); | 497 params.physical_backing_size = gfx::Size(200, 200); |
498 params.visible_viewport_size = params.new_size; | 498 params.visible_viewport_size = params.new_size; |
499 params.needs_resize_ack = false; | 499 params.needs_resize_ack = false; |
500 view()->OnResize(params); | 500 view()->OnResize(params); |
501 ASSERT_EQ(dsf, view()->device_scale_factor_); | 501 ASSERT_EQ(dsf, view()->device_scale_factor_); |
502 } | 502 } |
503 | 503 |
504 void TestEmulatedSizeDprDsf(int width, int height, float dpr, | 504 void TestEmulatedSizeDprDsf(int width, |
| 505 int height, |
| 506 int visual_viewport_width, |
| 507 int visual_viewport_height, |
| 508 float dpr, |
505 float compositor_dsf) { | 509 float compositor_dsf) { |
506 static base::string16 get_width = | 510 static base::string16 get_width = base::ASCIIToUTF16( |
| 511 "Number(document.getElementById('layoutViewportDiv').clientWidth)"); |
| 512 static base::string16 get_height = base::ASCIIToUTF16( |
| 513 "Number(document.getElementById('layoutViewportDiv').clientHeight)"); |
| 514 static base::string16 get_visual_width = |
507 base::ASCIIToUTF16("Number(window.innerWidth)"); | 515 base::ASCIIToUTF16("Number(window.innerWidth)"); |
508 static base::string16 get_height = | 516 static base::string16 get_visual_height = |
509 base::ASCIIToUTF16("Number(window.innerHeight)"); | 517 base::ASCIIToUTF16("Number(window.innerHeight)"); |
510 static base::string16 get_dpr = | 518 static base::string16 get_dpr = |
511 base::ASCIIToUTF16("Number(window.devicePixelRatio * 10)"); | 519 base::ASCIIToUTF16("Number(window.devicePixelRatio * 10)"); |
512 | 520 |
513 int emulated_width, emulated_height; | 521 int emulated_width, emulated_height; |
| 522 int emulated_visual_width, emulated_visual_height; |
514 int emulated_dpr; | 523 int emulated_dpr; |
515 blink::WebDeviceEmulationParams params; | 524 blink::WebDeviceEmulationParams params; |
516 params.viewSize.width = width; | 525 params.viewSize.width = width; |
517 params.viewSize.height = height; | 526 params.viewSize.height = height; |
| 527 params.visualViewportSize.width = visual_viewport_width; |
| 528 params.visualViewportSize.height = visual_viewport_height; |
518 params.deviceScaleFactor = dpr; | 529 params.deviceScaleFactor = dpr; |
519 view()->OnEnableDeviceEmulation(params); | 530 view()->OnEnableDeviceEmulation(params); |
| 531 ProcessPendingMessages(); |
520 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width)); | 532 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width)); |
521 EXPECT_EQ(width, emulated_width); | 533 EXPECT_EQ(width, emulated_width); |
522 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, | 534 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, |
523 &emulated_height)); | 535 &emulated_height)); |
524 EXPECT_EQ(height, emulated_height); | 536 EXPECT_EQ(height, emulated_height); |
| 537 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_visual_width, |
| 538 &emulated_visual_width)); |
| 539 EXPECT_EQ(visual_viewport_width > 0 ? visual_viewport_width : width, |
| 540 emulated_visual_width); |
| 541 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_visual_height, |
| 542 &emulated_visual_height)); |
| 543 EXPECT_EQ(visual_viewport_height > 0 ? visual_viewport_height : height, |
| 544 emulated_visual_height); |
525 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr)); | 545 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr)); |
526 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr); | 546 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr); |
527 EXPECT_EQ(compositor_dsf, | 547 EXPECT_EQ(compositor_dsf, |
528 view()->compositor()->layer_tree_host()->device_scale_factor()); | 548 view()->compositor()->layer_tree_host()->device_scale_factor()); |
529 } | 549 } |
530 }; | 550 }; |
531 | 551 |
532 // Ensure that the main RenderFrame is deleted and cleared from the RenderView | 552 // Ensure that the main RenderFrame is deleted and cleared from the RenderView |
533 // after closing it. | 553 // after closing it. |
534 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 554 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2222 EXPECT_EQ(20, rect.x); | 2242 EXPECT_EQ(20, rect.x); |
2223 EXPECT_EQ(10, rect.y); | 2243 EXPECT_EQ(10, rect.y); |
2224 EXPECT_EQ(200, rect.width); | 2244 EXPECT_EQ(200, rect.width); |
2225 EXPECT_EQ(100, rect.height); | 2245 EXPECT_EQ(100, rect.height); |
2226 } | 2246 } |
2227 | 2247 |
2228 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) { | 2248 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF1) { |
2229 DoSetUp(); | 2249 DoSetUp(); |
2230 SetDeviceScaleFactor(1.f); | 2250 SetDeviceScaleFactor(1.f); |
2231 | 2251 |
2232 LoadHTML("<body style='min-height:1000px;'></body>"); | 2252 LoadHTML( |
| 2253 "<body style='min-height:1000px; overflow:hidden; margin:0px;'>" |
| 2254 "<div id='layoutViewportDiv' style='width:100%; height:100%;'></div>" |
| 2255 "</body>"); |
2233 { | 2256 { |
2234 SCOPED_TRACE("327x415 1dpr"); | 2257 SCOPED_TRACE("327x415 1dpr"); |
2235 TestEmulatedSizeDprDsf(327, 415, 1.f, 1.f); | 2258 TestEmulatedSizeDprDsf(327, 415, 0, 0, 1.f, 1.f); |
2236 } | 2259 } |
2237 { | 2260 { |
2238 SCOPED_TRACE("327x415 1.5dpr"); | 2261 SCOPED_TRACE("327x415 1.5dpr"); |
2239 TestEmulatedSizeDprDsf(327, 415, 1.5f, 1.f); | 2262 TestEmulatedSizeDprDsf(327, 415, 0, 0, 1.5f, 1.f); |
2240 } | 2263 } |
2241 { | 2264 { |
2242 SCOPED_TRACE("1005x1102 2dpr"); | 2265 SCOPED_TRACE("1005x1102 2dpr"); |
2243 TestEmulatedSizeDprDsf(1005, 1102, 2.f, 1.f); | 2266 TestEmulatedSizeDprDsf(1005, 1102, 0, 0, 2.f, 1.f); |
2244 } | 2267 } |
2245 { | 2268 { |
2246 SCOPED_TRACE("1005x1102 3dpr"); | 2269 SCOPED_TRACE("1005x1102 3dpr"); |
2247 TestEmulatedSizeDprDsf(1005, 1102, 3.f, 1.f); | 2270 TestEmulatedSizeDprDsf(1005, 1102, 0, 0, 3.f, 1.f); |
| 2271 } |
| 2272 { |
| 2273 SCOPED_TRACE("654x830 visual 327x415 1dpr"); |
| 2274 TestEmulatedSizeDprDsf(654, 830, 327, 415, 1.f, 1.f); |
| 2275 } |
| 2276 { |
| 2277 SCOPED_TRACE("654x830 visual 327x415 2dpr"); |
| 2278 TestEmulatedSizeDprDsf(654, 830, 327, 415, 2.f, 1.f); |
2248 } | 2279 } |
2249 | 2280 |
2250 view()->OnDisableDeviceEmulation(); | 2281 view()->OnDisableDeviceEmulation(); |
2251 | 2282 |
2252 blink::WebDeviceEmulationParams params; | 2283 blink::WebDeviceEmulationParams params; |
2253 view()->OnEnableDeviceEmulation(params); | 2284 view()->OnEnableDeviceEmulation(params); |
2254 // Don't disable here to test that emulation is being shutdown properly. | 2285 // Don't disable here to test that emulation is being shutdown properly. |
2255 } | 2286 } |
2256 | 2287 |
2257 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) { | 2288 TEST_F(RenderViewImplScaleFactorTest, ScreenMetricsEmulationWithOriginalDSF2) { |
2258 DoSetUp(); | 2289 DoSetUp(); |
2259 SetDeviceScaleFactor(2.f); | 2290 SetDeviceScaleFactor(2.f); |
2260 float compositor_dsf = | 2291 float compositor_dsf = |
2261 IsUseZoomForDSFEnabled() ? 1.f : 2.f; | 2292 IsUseZoomForDSFEnabled() ? 1.f : 2.f; |
2262 | 2293 |
2263 LoadHTML("<body style='min-height:1000px;'></body>"); | 2294 LoadHTML( |
| 2295 "<body style='min-height:1000px; overflow:hidden; margin:0px;'>" |
| 2296 "<div id='layoutViewportDiv' style='width:100%; height:100%;'></div>" |
| 2297 "</body>"); |
2264 { | 2298 { |
2265 SCOPED_TRACE("327x415 1dpr"); | 2299 SCOPED_TRACE("327x415 1dpr"); |
2266 TestEmulatedSizeDprDsf(327, 415, 1.f, compositor_dsf); | 2300 TestEmulatedSizeDprDsf(327, 415, 0, 0, 1.f, compositor_dsf); |
2267 } | 2301 } |
2268 { | 2302 { |
2269 SCOPED_TRACE("327x415 1.5dpr"); | 2303 SCOPED_TRACE("327x415 1.5dpr"); |
2270 TestEmulatedSizeDprDsf(327, 415, 1.5f, compositor_dsf); | 2304 TestEmulatedSizeDprDsf(327, 415, 0, 0, 1.5f, compositor_dsf); |
2271 } | 2305 } |
2272 { | 2306 { |
2273 SCOPED_TRACE("1005x1102 2dpr"); | 2307 SCOPED_TRACE("1005x1102 2dpr"); |
2274 TestEmulatedSizeDprDsf(1005, 1102, 2.f, compositor_dsf); | 2308 TestEmulatedSizeDprDsf(1005, 1102, 0, 0, 2.f, compositor_dsf); |
2275 } | 2309 } |
2276 { | 2310 { |
2277 SCOPED_TRACE("1005x1102 3dpr"); | 2311 SCOPED_TRACE("1005x1102 3dpr"); |
2278 TestEmulatedSizeDprDsf(1005, 1102, 3.f, compositor_dsf); | 2312 TestEmulatedSizeDprDsf(1005, 1102, 0, 0, 3.f, compositor_dsf); |
| 2313 } |
| 2314 { |
| 2315 SCOPED_TRACE("654x830 visual 327x415 1dpr"); |
| 2316 TestEmulatedSizeDprDsf(654, 830, 327, 415, 1.f, compositor_dsf); |
| 2317 } |
| 2318 { |
| 2319 SCOPED_TRACE("654x830 visual 327x415 2dpr"); |
| 2320 TestEmulatedSizeDprDsf(654, 830, 327, 415, 2.f, compositor_dsf); |
2279 } | 2321 } |
2280 | 2322 |
2281 view()->OnDisableDeviceEmulation(); | 2323 view()->OnDisableDeviceEmulation(); |
2282 | 2324 |
2283 blink::WebDeviceEmulationParams params; | 2325 blink::WebDeviceEmulationParams params; |
2284 view()->OnEnableDeviceEmulation(params); | 2326 view()->OnEnableDeviceEmulation(params); |
2285 // Don't disable here to test that emulation is being shutdown properly. | 2327 // Don't disable here to test that emulation is being shutdown properly. |
2286 } | 2328 } |
2287 | 2329 |
2288 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { | 2330 TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2496 ExpectPauseAndResume(3); | 2538 ExpectPauseAndResume(3); |
2497 blink::WebScriptSource source2( | 2539 blink::WebScriptSource source2( |
2498 WebString::fromUTF8("function func2() { func1(); }; func2();")); | 2540 WebString::fromUTF8("function func2() { func1(); }; func2();")); |
2499 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); | 2541 frame()->GetWebFrame()->executeScriptInIsolatedWorld(17, &source2, 1, 1); |
2500 | 2542 |
2501 EXPECT_FALSE(IsPaused()); | 2543 EXPECT_FALSE(IsPaused()); |
2502 Detach(); | 2544 Detach(); |
2503 } | 2545 } |
2504 | 2546 |
2505 } // namespace content | 2547 } // namespace content |
OLD | NEW |