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

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: Accidentally made will_cause_resize always false in previous cleanup. Fixed Created 4 years, 10 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
« no previous file with comments | « ui/views/controls/webview/webview.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 web_view()->SetWebContents(web_contents.get()); 274 web_view()->SetWebContents(web_contents.get());
275 275
276 // Initially, the holder should fill the entire WebView. 276 // Initially, the holder should fill the entire WebView.
277 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 277 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
278 278
279 // Simulate a transition into fullscreen mode, but without screen capture 279 // Simulate a transition into fullscreen mode, but without screen capture
280 // active on the WebContents, the holder should still fill the entire 280 // active on the WebContents, the holder should still fill the entire
281 // WebView like before. 281 // WebView like before.
282 delegate.set_is_fullscreened(true); 282 delegate.set_is_fullscreened(true);
283 static_cast<content::WebContentsObserver*>(web_view())-> 283 static_cast<content::WebContentsObserver*>(web_view())->
284 DidToggleFullscreenModeForTab(true); 284 DidToggleFullscreenModeForTab(true, false);
285 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 285 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
286 286
287 // ...and transition back out of fullscreen mode. 287 // ...and transition back out of fullscreen mode.
288 delegate.set_is_fullscreened(false); 288 delegate.set_is_fullscreened(false);
289 static_cast<content::WebContentsObserver*>(web_view())-> 289 static_cast<content::WebContentsObserver*>(web_view())->
290 DidToggleFullscreenModeForTab(false); 290 DidToggleFullscreenModeForTab(false, false);
291 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 291 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
292 292
293 // Now, begin screen capture of the WebContents and then enter fullscreen 293 // Now, begin screen capture of the WebContents and then enter fullscreen
294 // mode. This time, the holder should be centered within WebView and 294 // mode. This time, the holder should be centered within WebView and
295 // sized to match the capture size. 295 // sized to match the capture size.
296 const gfx::Size capture_size(64, 48); 296 const gfx::Size capture_size(64, 48);
297 web_contents->IncrementCapturerCount(capture_size); 297 web_contents->IncrementCapturerCount(capture_size);
298 delegate.set_is_fullscreened(true); 298 delegate.set_is_fullscreened(true);
299 static_cast<content::WebContentsObserver*>(web_view())-> 299 static_cast<content::WebContentsObserver*>(web_view())->
300 DidToggleFullscreenModeForTab(true); 300 DidToggleFullscreenModeForTab(true, false);
301 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); 301 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds());
302 302
303 // Resize the WebView so that its width is smaller than the capture width. 303 // Resize the WebView so that its width is smaller than the capture width.
304 // Expect the holder to be scaled-down, letterboxed style. 304 // Expect the holder to be scaled-down, letterboxed style.
305 web_view()->SetBoundsRect(gfx::Rect(0, 0, 32, 32)); 305 web_view()->SetBoundsRect(gfx::Rect(0, 0, 32, 32));
306 EXPECT_EQ(gfx::Rect(0, 4, 32, 24), holder()->bounds()); 306 EXPECT_EQ(gfx::Rect(0, 4, 32, 24), holder()->bounds());
307 307
308 // Transition back out of fullscreen mode a final time and confirm the bounds 308 // Transition back out of fullscreen mode a final time and confirm the bounds
309 // of the holder fill the entire WebView once again. 309 // of the holder fill the entire WebView once again.
310 delegate.set_is_fullscreened(false); 310 delegate.set_is_fullscreened(false);
311 static_cast<content::WebContentsObserver*>(web_view())-> 311 static_cast<content::WebContentsObserver*>(web_view())->
312 DidToggleFullscreenModeForTab(false); 312 DidToggleFullscreenModeForTab(false, false);
313 EXPECT_EQ(gfx::Rect(0, 0, 32, 32), holder()->bounds()); 313 EXPECT_EQ(gfx::Rect(0, 0, 32, 32), holder()->bounds());
314 } 314 }
315 315
316 // Tests that a WebView correctly switches between WebContentses when one of 316 // Tests that a WebView correctly switches between WebContentses when one of
317 // them is embedding a fullscreen widget during WebContents screen capture. 317 // them is embedding a fullscreen widget during WebContents screen capture.
318 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) { 318 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) {
319 web_view()->SetEmbedFullscreenWidgetMode(true); 319 web_view()->SetEmbedFullscreenWidgetMode(true);
320 ASSERT_EQ(1, web_view()->child_count()); 320 ASSERT_EQ(1, web_view()->child_count());
321 const gfx::NativeView unset_native_view = holder()->native_view(); 321 const gfx::NativeView unset_native_view = holder()->native_view();
322 322
(...skipping 10 matching lines...) Expand all
333 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); 333 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view());
334 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 334 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
335 335
336 // Begin screen capture of the WebContents and then enter fullscreen mode. 336 // Begin screen capture of the WebContents and then enter fullscreen mode.
337 // The native view should not have changed, but the layout of its holder will 337 // The native view should not have changed, but the layout of its holder will
338 // have (indicates WebView has responded). 338 // have (indicates WebView has responded).
339 const gfx::Size capture_size(64, 48); 339 const gfx::Size capture_size(64, 48);
340 web_contents1->IncrementCapturerCount(capture_size); 340 web_contents1->IncrementCapturerCount(capture_size);
341 delegate1.set_is_fullscreened(true); 341 delegate1.set_is_fullscreened(true);
342 static_cast<content::WebContentsObserver*>(web_view())-> 342 static_cast<content::WebContentsObserver*>(web_view())->
343 DidToggleFullscreenModeForTab(true); 343 DidToggleFullscreenModeForTab(true, false);
344 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); 344 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view());
345 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); 345 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds());
346 346
347 // When setting the WebContents to nullptr, the native view should become 347 // When setting the WebContents to nullptr, the native view should become
348 // unset. 348 // unset.
349 web_view()->SetWebContents(nullptr); 349 web_view()->SetWebContents(nullptr);
350 EXPECT_EQ(unset_native_view, holder()->native_view()); 350 EXPECT_EQ(unset_native_view, holder()->native_view());
351 351
352 // ...and when setting the WebContents back to the currently-fullscreened 352 // ...and when setting the WebContents back to the currently-fullscreened
353 // instance, expect the native view and layout to reflect that. 353 // instance, expect the native view and layout to reflect that.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 web_contents->SetDelegate(&delegate); 386 web_contents->SetDelegate(&delegate);
387 web_view()->SetWebContents(web_contents.get()); 387 web_view()->SetWebContents(web_contents.get());
388 388
389 // Begin screen capture of the WebContents and then enter fullscreen mode. 389 // Begin screen capture of the WebContents and then enter fullscreen mode.
390 // The holder should be centered within WebView and sized to match the capture 390 // The holder should be centered within WebView and sized to match the capture
391 // size. 391 // size.
392 const gfx::Size capture_size(64, 48); 392 const gfx::Size capture_size(64, 48);
393 web_contents->IncrementCapturerCount(capture_size); 393 web_contents->IncrementCapturerCount(capture_size);
394 delegate.set_is_fullscreened(true); 394 delegate.set_is_fullscreened(true);
395 static_cast<content::WebContentsObserver*>(web_view())-> 395 static_cast<content::WebContentsObserver*>(web_view())->
396 DidToggleFullscreenModeForTab(true); 396 DidToggleFullscreenModeForTab(true, false);
397 EXPECT_EQ(gfx::Rect(18, 21, 64, 48), holder()->bounds()); 397 EXPECT_EQ(gfx::Rect(18, 21, 64, 48), holder()->bounds());
398 398
399 // Focus the other widget. 399 // Focus the other widget.
400 something_to_focus->RequestFocus(); 400 something_to_focus->RequestFocus();
401 EXPECT_FALSE(web_view()->HasFocus()); 401 EXPECT_FALSE(web_view()->HasFocus());
402 EXPECT_FALSE(holder()->HasFocus()); 402 EXPECT_FALSE(holder()->HasFocus());
403 EXPECT_TRUE(something_to_focus->HasFocus()); 403 EXPECT_TRUE(something_to_focus->HasFocus());
404 404
405 // Send mouse press event to WebView outside the bounds of the holder, and 405 // Send mouse press event to WebView outside the bounds of the holder, and
406 // confirm WebView took focus. 406 // confirm WebView took focus.
(...skipping 24 matching lines...) Expand all
431 gfx::Point(), // Immaterial. 431 gfx::Point(), // Immaterial.
432 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); 432 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
433 EXPECT_FALSE(static_cast<views::View*>(web_view())-> 433 EXPECT_FALSE(static_cast<views::View*>(web_view())->
434 OnMousePressed(click_inside_holder)); 434 OnMousePressed(click_inside_holder));
435 EXPECT_FALSE(web_view()->HasFocus()); 435 EXPECT_FALSE(web_view()->HasFocus());
436 EXPECT_FALSE(holder()->HasFocus()); 436 EXPECT_FALSE(holder()->HasFocus());
437 EXPECT_TRUE(something_to_focus->HasFocus()); 437 EXPECT_TRUE(something_to_focus->HasFocus());
438 } 438 }
439 439
440 } // namespace views 440 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/webview/webview.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698