OLD | NEW |
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 "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/aura_extra/image_window_delegate.h" | 24 #include "ui/aura_extra/image_window_delegate.h" |
25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
26 #include "ui/compositor/scoped_layer_animation_settings.h" | 26 #include "ui/compositor/scoped_layer_animation_settings.h" |
27 #include "ui/compositor/test/layer_animator_test_controller.h" | 27 #include "ui/compositor/test/layer_animator_test_controller.h" |
28 #include "ui/events/gesture_detection/gesture_configuration.h" | 28 #include "ui/events/gesture_detection/gesture_configuration.h" |
29 #include "ui/events/test/event_generator.h" | 29 #include "ui/events/test/event_generator.h" |
30 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
| 34 // Forces web contents to complete web page load as soon as navigation starts. |
| 35 class ImmediateLoadObserver : WebContentsObserver { |
| 36 public: |
| 37 explicit ImmediateLoadObserver(TestWebContents* contents) |
| 38 : contents_(contents) { |
| 39 Observe(contents); |
| 40 } |
| 41 ~ImmediateLoadObserver() override {} |
| 42 |
| 43 void DidStartNavigationToPendingEntry( |
| 44 const GURL& url, |
| 45 NavigationController::ReloadType reload_type) override { |
| 46 // Simulate immediate web page load. |
| 47 contents_->TestSetIsLoading(false); |
| 48 Observe(nullptr); |
| 49 } |
| 50 |
| 51 private: |
| 52 TestWebContents* contents_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(ImmediateLoadObserver); |
| 55 }; |
| 56 |
34 // A subclass of TestWebContents that offers a fake content window. | 57 // A subclass of TestWebContents that offers a fake content window. |
35 class OverscrollTestWebContents : public TestWebContents { | 58 class OverscrollTestWebContents : public TestWebContents { |
36 public: | 59 public: |
37 ~OverscrollTestWebContents() override {} | 60 ~OverscrollTestWebContents() override {} |
38 | 61 |
39 static OverscrollTestWebContents* Create( | 62 static OverscrollTestWebContents* Create( |
40 BrowserContext* browser_context, | 63 BrowserContext* browser_context, |
41 scoped_refptr<SiteInstance> instance, | 64 scoped_refptr<SiteInstance> instance, |
42 std::unique_ptr<aura::Window> fake_native_view, | 65 std::unique_ptr<aura::Window> fake_native_view, |
43 std::unique_ptr<aura::Window> fake_contents_window) { | 66 std::unique_ptr<aura::Window> fake_contents_window) { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); | 347 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
325 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 348 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
326 OverscrollTestWebContents* test_web_contents = | 349 OverscrollTestWebContents* test_web_contents = |
327 static_cast<OverscrollTestWebContents*>(web_contents()); | 350 static_cast<OverscrollTestWebContents*>(web_contents()); |
328 test_web_contents->set_is_being_destroyed(true); | 351 test_web_contents->set_is_being_destroyed(true); |
329 test_web_contents->ResetContentNativeView(); | 352 test_web_contents->ResetContentNativeView(); |
330 test_web_contents->ResetNativeView(); | 353 test_web_contents->ResetNativeView(); |
331 // Ensure a clean close. | 354 // Ensure a clean close. |
332 } | 355 } |
333 | 356 |
| 357 // Tests that we can handle the case when the load completes as soon as the |
| 358 // navigation is started. |
| 359 TEST_F(OverscrollNavigationOverlayTest, ImmediateLoadOnNavigate) { |
| 360 PerformBackNavigationViaSliderCallbacks(); |
| 361 // This observer will force the page load to complete as soon as the |
| 362 // navigation starts. |
| 363 ImmediateLoadObserver immediate_nav(contents()); |
| 364 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST); |
| 365 // This will start and immediately complete the navigation. |
| 366 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
| 367 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 368 } |
334 | 369 |
335 // Tests that swapping the overlay window at the end of a gesture caused by the | 370 // Tests that swapping the overlay window at the end of a gesture caused by the |
336 // start of a new overscroll does not crash and the events still reach the new | 371 // start of a new overscroll does not crash and the events still reach the new |
337 // overlay window. | 372 // overlay window. |
338 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { | 373 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { |
339 PerformBackNavigationViaSliderCallbacks(); | 374 PerformBackNavigationViaSliderCallbacks(); |
340 aura::Window* first_overlay_window = GetOverlay()->window_.get(); | 375 aura::Window* first_overlay_window = GetOverlay()->window_.get(); |
341 EXPECT_TRUE(GetOverlay()->web_contents()); | 376 EXPECT_TRUE(GetOverlay()->web_contents()); |
342 EXPECT_TRUE(first_overlay_window); | 377 EXPECT_TRUE(first_overlay_window); |
343 | 378 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 EXPECT_TRUE(GetOverlay()->window_.get()); | 441 EXPECT_TRUE(GetOverlay()->window_.get()); |
407 | 442 |
408 // Load the page. | 443 // Load the page. |
409 contents()->CommitPendingNavigation(); | 444 contents()->CommitPendingNavigation(); |
410 ReceivePaintUpdate(); | 445 ReceivePaintUpdate(); |
411 EXPECT_FALSE(GetOverlay()->window_.get()); | 446 EXPECT_FALSE(GetOverlay()->window_.get()); |
412 EXPECT_EQ(contents()->GetURL(), first()); | 447 EXPECT_EQ(contents()->GetURL(), first()); |
413 } | 448 } |
414 | 449 |
415 } // namespace content | 450 } // namespace content |
OLD | NEW |