| 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 ResizeParams params; | 493 ResizeParams params; |
| 494 params.screen_info.deviceScaleFactor = dsf; | 494 params.screen_info.deviceScaleFactor = dsf; |
| 495 params.new_size = gfx::Size(100, 100); | 495 params.new_size = gfx::Size(100, 100); |
| 496 params.physical_backing_size = gfx::Size(200, 200); | 496 params.physical_backing_size = gfx::Size(200, 200); |
| 497 params.visible_viewport_size = params.new_size; | 497 params.visible_viewport_size = params.new_size; |
| 498 params.needs_resize_ack = false; | 498 params.needs_resize_ack = false; |
| 499 view()->OnResize(params); | 499 view()->OnResize(params); |
| 500 ASSERT_EQ(dsf, view()->device_scale_factor_); | 500 ASSERT_EQ(dsf, view()->device_scale_factor_); |
| 501 } | 501 } |
| 502 | 502 |
| 503 void TestEmulatedSizeDprDsf(int width, int height, float dpr, | 503 void TestEmulatedSizeDprDsf(int width, |
| 504 int height, |
| 505 int visual_viewport_width, |
| 506 int visual_viewport_height, |
| 507 float dpr, |
| 504 float compositor_dsf) { | 508 float compositor_dsf) { |
| 505 static base::string16 get_width = | 509 static base::string16 get_width = base::ASCIIToUTF16( |
| 510 "Number(document.getElementById('layoutViewportDiv').clientWidth)"); |
| 511 static base::string16 get_height = base::ASCIIToUTF16( |
| 512 "Number(document.getElementById('layoutViewportDiv').clientHeight)"); |
| 513 static base::string16 get_visual_width = |
| 506 base::ASCIIToUTF16("Number(window.innerWidth)"); | 514 base::ASCIIToUTF16("Number(window.innerWidth)"); |
| 507 static base::string16 get_height = | 515 static base::string16 get_visual_height = |
| 508 base::ASCIIToUTF16("Number(window.innerHeight)"); | 516 base::ASCIIToUTF16("Number(window.innerHeight)"); |
| 509 static base::string16 get_dpr = | 517 static base::string16 get_dpr = |
| 510 base::ASCIIToUTF16("Number(window.devicePixelRatio * 10)"); | 518 base::ASCIIToUTF16("Number(window.devicePixelRatio * 10)"); |
| 511 | 519 |
| 512 int emulated_width, emulated_height; | 520 int emulated_width, emulated_height; |
| 521 int emulated_visual_width, emulated_visual_height; |
| 513 int emulated_dpr; | 522 int emulated_dpr; |
| 514 blink::WebDeviceEmulationParams params; | 523 blink::WebDeviceEmulationParams params; |
| 515 params.viewSize.width = width; | 524 params.viewSize.width = width; |
| 516 params.viewSize.height = height; | 525 params.viewSize.height = height; |
| 526 params.visualViewportSize.width = visual_viewport_width; |
| 527 params.visualViewportSize.height = visual_viewport_height; |
| 517 params.deviceScaleFactor = dpr; | 528 params.deviceScaleFactor = dpr; |
| 518 view()->OnEnableDeviceEmulation(params); | 529 view()->OnEnableDeviceEmulation(params); |
| 530 ProcessPendingMessages(); |
| 519 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width)); | 531 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_width, &emulated_width)); |
| 520 EXPECT_EQ(width, emulated_width); | 532 EXPECT_EQ(width, emulated_width); |
| 521 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, | 533 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_height, |
| 522 &emulated_height)); | 534 &emulated_height)); |
| 523 EXPECT_EQ(height, emulated_height); | 535 EXPECT_EQ(height, emulated_height); |
| 536 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_visual_width, |
| 537 &emulated_visual_width)); |
| 538 EXPECT_EQ(visual_viewport_width > 0 ? visual_viewport_width : width, |
| 539 emulated_visual_width); |
| 540 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_visual_height, |
| 541 &emulated_visual_height)); |
| 542 EXPECT_EQ(visual_viewport_height > 0 ? visual_viewport_height : height, |
| 543 emulated_visual_height); |
| 524 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr)); | 544 EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(get_dpr, &emulated_dpr)); |
| 525 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr); | 545 EXPECT_EQ(static_cast<int>(dpr * 10), emulated_dpr); |
| 526 EXPECT_EQ(compositor_dsf, | 546 EXPECT_EQ(compositor_dsf, |
| 527 view()->compositor()->layer_tree_host()->device_scale_factor()); | 547 view()->compositor()->layer_tree_host()->device_scale_factor()); |
| 528 } | 548 } |
| 529 }; | 549 }; |
| 530 | 550 |
| 531 // Ensure that the main RenderFrame is deleted and cleared from the RenderView | 551 // Ensure that the main RenderFrame is deleted and cleared from the RenderView |
| 532 // after closing it. | 552 // after closing it. |
| 533 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { | 553 TEST_F(RenderViewImplTest, RenderFrameClearedAfterClose) { |
| (...skipping 1688 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 |