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

Side by Side Diff: ui/views/controls/webview/webview_unittest.cc

Issue 1488653002: Fix scroll restoration when exiting fullscreen mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Trying to fix test broken on Mac Created 5 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/webview/webview.h" 5 #include "ui/views/controls/webview/webview.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
9 #include "content/public/browser/web_contents_observer.h" 9 #include "content/public/browser/web_contents_observer.h"
10 #include "content/public/test/test_browser_context.h" 10 #include "content/public/test/test_browser_context.h"
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 web_view()->SetWebContents(web_contents.get()); 271 web_view()->SetWebContents(web_contents.get());
272 272
273 // Initially, the holder should fill the entire WebView. 273 // Initially, the holder should fill the entire WebView.
274 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 274 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
275 275
276 // Simulate a transition into fullscreen mode, but without screen capture 276 // Simulate a transition into fullscreen mode, but without screen capture
277 // active on the WebContents, the holder should still fill the entire 277 // active on the WebContents, the holder should still fill the entire
278 // WebView like before. 278 // WebView like before.
279 delegate.set_is_fullscreened(true); 279 delegate.set_is_fullscreened(true);
280 static_cast<content::WebContentsObserver*>(web_view())-> 280 static_cast<content::WebContentsObserver*>(web_view())->
281 DidToggleFullscreenModeForTab(true); 281 DidToggleFullscreenModeForTab(true, false);
282 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 282 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
283 283
284 // ...and transition back out of fullscreen mode. 284 // ...and transition back out of fullscreen mode.
285 delegate.set_is_fullscreened(false); 285 delegate.set_is_fullscreened(false);
286 static_cast<content::WebContentsObserver*>(web_view())-> 286 static_cast<content::WebContentsObserver*>(web_view())->
287 DidToggleFullscreenModeForTab(false); 287 DidToggleFullscreenModeForTab(false, false);
288 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 288 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
289 289
290 // Now, begin screen capture of the WebContents and then enter fullscreen 290 // Now, begin screen capture of the WebContents and then enter fullscreen
291 // mode. This time, the holder should be centered within WebView and 291 // mode. This time, the holder should be centered within WebView and
292 // sized to match the capture size. 292 // sized to match the capture size.
293 const gfx::Size capture_size(64, 48); 293 const gfx::Size capture_size(64, 48);
294 web_contents->IncrementCapturerCount(capture_size); 294 web_contents->IncrementCapturerCount(capture_size);
295 delegate.set_is_fullscreened(true); 295 delegate.set_is_fullscreened(true);
296 static_cast<content::WebContentsObserver*>(web_view())-> 296 static_cast<content::WebContentsObserver*>(web_view())->
297 DidToggleFullscreenModeForTab(true); 297 DidToggleFullscreenModeForTab(true, false);
298 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); 298 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds());
299 299
300 // Resize the WebView so that its width is smaller than the capture width. 300 // Resize the WebView so that its width is smaller than the capture width.
301 // Expect the holder to be scaled-down, letterboxed style. 301 // Expect the holder to be scaled-down, letterboxed style.
302 web_view()->SetBoundsRect(gfx::Rect(0, 0, 32, 32)); 302 web_view()->SetBoundsRect(gfx::Rect(0, 0, 32, 32));
303 EXPECT_EQ(gfx::Rect(0, 4, 32, 24), holder()->bounds()); 303 EXPECT_EQ(gfx::Rect(0, 4, 32, 24), holder()->bounds());
304 304
305 // Transition back out of fullscreen mode a final time and confirm the bounds 305 // Transition back out of fullscreen mode a final time and confirm the bounds
306 // of the holder fill the entire WebView once again. 306 // of the holder fill the entire WebView once again.
307 delegate.set_is_fullscreened(false); 307 delegate.set_is_fullscreened(false);
308 static_cast<content::WebContentsObserver*>(web_view())-> 308 static_cast<content::WebContentsObserver*>(web_view())->
309 DidToggleFullscreenModeForTab(false); 309 DidToggleFullscreenModeForTab(false, false);
310 EXPECT_EQ(gfx::Rect(0, 0, 32, 32), holder()->bounds()); 310 EXPECT_EQ(gfx::Rect(0, 0, 32, 32), holder()->bounds());
311 } 311 }
312 312
313 // Tests that a WebView correctly switches between WebContentses when one of 313 // Tests that a WebView correctly switches between WebContentses when one of
314 // them is embedding a fullscreen widget during WebContents screen capture. 314 // them is embedding a fullscreen widget during WebContents screen capture.
315 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) { 315 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) {
316 web_view()->SetEmbedFullscreenWidgetMode(true); 316 web_view()->SetEmbedFullscreenWidgetMode(true);
317 ASSERT_EQ(1, web_view()->child_count()); 317 ASSERT_EQ(1, web_view()->child_count());
318 const gfx::NativeView unset_native_view = holder()->native_view(); 318 const gfx::NativeView unset_native_view = holder()->native_view();
319 319
(...skipping 10 matching lines...) Expand all
330 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); 330 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view());
331 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 331 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
332 332
333 // Begin screen capture of the WebContents and then enter fullscreen mode. 333 // Begin screen capture of the WebContents and then enter fullscreen mode.
334 // The native view should not have changed, but the layout of its holder will 334 // The native view should not have changed, but the layout of its holder will
335 // have (indicates WebView has responded). 335 // have (indicates WebView has responded).
336 const gfx::Size capture_size(64, 48); 336 const gfx::Size capture_size(64, 48);
337 web_contents1->IncrementCapturerCount(capture_size); 337 web_contents1->IncrementCapturerCount(capture_size);
338 delegate1.set_is_fullscreened(true); 338 delegate1.set_is_fullscreened(true);
339 static_cast<content::WebContentsObserver*>(web_view())-> 339 static_cast<content::WebContentsObserver*>(web_view())->
340 DidToggleFullscreenModeForTab(true); 340 DidToggleFullscreenModeForTab(true, false);
341 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); 341 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view());
342 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); 342 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds());
343 343
344 // When setting the WebContents to nullptr, the native view should become 344 // When setting the WebContents to nullptr, the native view should become
345 // unset. 345 // unset.
346 web_view()->SetWebContents(nullptr); 346 web_view()->SetWebContents(nullptr);
347 EXPECT_EQ(unset_native_view, holder()->native_view()); 347 EXPECT_EQ(unset_native_view, holder()->native_view());
348 348
349 // ...and when setting the WebContents back to the currently-fullscreened 349 // ...and when setting the WebContents back to the currently-fullscreened
350 // instance, expect the native view and layout to reflect that. 350 // instance, expect the native view and layout to reflect that.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 web_contents->SetDelegate(&delegate); 383 web_contents->SetDelegate(&delegate);
384 web_view()->SetWebContents(web_contents.get()); 384 web_view()->SetWebContents(web_contents.get());
385 385
386 // Begin screen capture of the WebContents and then enter fullscreen mode. 386 // Begin screen capture of the WebContents and then enter fullscreen mode.
387 // The holder should be centered within WebView and sized to match the capture 387 // The holder should be centered within WebView and sized to match the capture
388 // size. 388 // size.
389 const gfx::Size capture_size(64, 48); 389 const gfx::Size capture_size(64, 48);
390 web_contents->IncrementCapturerCount(capture_size); 390 web_contents->IncrementCapturerCount(capture_size);
391 delegate.set_is_fullscreened(true); 391 delegate.set_is_fullscreened(true);
392 static_cast<content::WebContentsObserver*>(web_view())-> 392 static_cast<content::WebContentsObserver*>(web_view())->
393 DidToggleFullscreenModeForTab(true); 393 DidToggleFullscreenModeForTab(true, false);
394 EXPECT_EQ(gfx::Rect(18, 21, 64, 48), holder()->bounds()); 394 EXPECT_EQ(gfx::Rect(18, 21, 64, 48), holder()->bounds());
395 395
396 // Focus the other widget. 396 // Focus the other widget.
397 something_to_focus->RequestFocus(); 397 something_to_focus->RequestFocus();
398 EXPECT_FALSE(web_view()->HasFocus()); 398 EXPECT_FALSE(web_view()->HasFocus());
399 EXPECT_FALSE(holder()->HasFocus()); 399 EXPECT_FALSE(holder()->HasFocus());
400 EXPECT_TRUE(something_to_focus->HasFocus()); 400 EXPECT_TRUE(something_to_focus->HasFocus());
401 401
402 // Send mouse press event to WebView outside the bounds of the holder, and 402 // Send mouse press event to WebView outside the bounds of the holder, and
403 // confirm WebView took focus. 403 // confirm WebView took focus.
(...skipping 24 matching lines...) Expand all
428 gfx::Point(), // Immaterial. 428 gfx::Point(), // Immaterial.
429 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 429 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
430 EXPECT_FALSE(static_cast<views::View*>(web_view())-> 430 EXPECT_FALSE(static_cast<views::View*>(web_view())->
431 OnMousePressed(click_inside_holder)); 431 OnMousePressed(click_inside_holder));
432 EXPECT_FALSE(web_view()->HasFocus()); 432 EXPECT_FALSE(web_view()->HasFocus());
433 EXPECT_FALSE(holder()->HasFocus()); 433 EXPECT_FALSE(holder()->HasFocus());
434 EXPECT_TRUE(something_to_focus->HasFocus()); 434 EXPECT_TRUE(something_to_focus->HasFocus());
435 } 435 }
436 436
437 } // namespace views 437 } // namespace views
OLDNEW
« content/browser/frame_host/render_frame_host_impl.cc ('K') | « ui/views/controls/webview/webview.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698