| 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 | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "content/browser/frame_host/navigation_entry_impl.h" | 12 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_view.h" | 13 #include "content/browser/web_contents/web_contents_view.h" |
| 14 #include "content/common/frame_messages.h" | 14 #include "content/common/frame_messages.h" |
| 15 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 16 #include "content/public/browser/overscroll_configuration.h" | 16 #include "content/public/browser/overscroll_configuration.h" |
| 17 #include "content/public/common/browser_side_navigation_policy.h" | 17 #include "content/public/common/browser_side_navigation_policy.h" |
| 18 #include "content/public/test/mock_render_process_host.h" | 18 #include "content/public/test/mock_render_process_host.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 35 class OverscrollTestWebContents : public TestWebContents { | 35 class OverscrollTestWebContents : public TestWebContents { |
| 36 public: | 36 public: |
| 37 ~OverscrollTestWebContents() override {} | 37 ~OverscrollTestWebContents() override {} |
| 38 | 38 |
| 39 static OverscrollTestWebContents* Create( | 39 static OverscrollTestWebContents* Create( |
| 40 BrowserContext* browser_context, | 40 BrowserContext* browser_context, |
| 41 SiteInstance* instance, | 41 SiteInstance* instance, |
| 42 scoped_ptr<aura::Window> fake_native_view, | 42 scoped_ptr<aura::Window> fake_native_view, |
| 43 scoped_ptr<aura::Window> fake_contents_window) { | 43 scoped_ptr<aura::Window> fake_contents_window) { |
| 44 OverscrollTestWebContents* web_contents = new OverscrollTestWebContents( | 44 OverscrollTestWebContents* web_contents = new OverscrollTestWebContents( |
| 45 browser_context, fake_native_view.Pass(), fake_contents_window.Pass()); | 45 browser_context, std::move(fake_native_view), |
| 46 std::move(fake_contents_window)); |
| 46 web_contents->Init(WebContents::CreateParams(browser_context, instance)); | 47 web_contents->Init(WebContents::CreateParams(browser_context, instance)); |
| 47 return web_contents; | 48 return web_contents; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void ResetNativeView() { fake_native_view_.reset(); } | 51 void ResetNativeView() { fake_native_view_.reset(); } |
| 51 | 52 |
| 52 void ResetContentNativeView() { fake_contents_window_.reset(); } | 53 void ResetContentNativeView() { fake_contents_window_.reset(); } |
| 53 | 54 |
| 54 void set_is_being_destroyed(bool val) { is_being_destroyed_ = val; } | 55 void set_is_being_destroyed(bool val) { is_being_destroyed_ = val; } |
| 55 | 56 |
| 56 gfx::NativeView GetNativeView() override { return fake_native_view_.get(); } | 57 gfx::NativeView GetNativeView() override { return fake_native_view_.get(); } |
| 57 | 58 |
| 58 gfx::NativeView GetContentNativeView() override { | 59 gfx::NativeView GetContentNativeView() override { |
| 59 return fake_contents_window_.get(); | 60 return fake_contents_window_.get(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool IsBeingDestroyed() const override { return is_being_destroyed_; } | 63 bool IsBeingDestroyed() const override { return is_being_destroyed_; } |
| 63 | 64 |
| 64 protected: | 65 protected: |
| 65 explicit OverscrollTestWebContents( | 66 explicit OverscrollTestWebContents( |
| 66 BrowserContext* browser_context, | 67 BrowserContext* browser_context, |
| 67 scoped_ptr<aura::Window> fake_native_view, | 68 scoped_ptr<aura::Window> fake_native_view, |
| 68 scoped_ptr<aura::Window> fake_contents_window) | 69 scoped_ptr<aura::Window> fake_contents_window) |
| 69 : TestWebContents(browser_context), | 70 : TestWebContents(browser_context), |
| 70 fake_native_view_(fake_native_view.Pass()), | 71 fake_native_view_(std::move(fake_native_view)), |
| 71 fake_contents_window_(fake_contents_window.Pass()), | 72 fake_contents_window_(std::move(fake_contents_window)), |
| 72 is_being_destroyed_(false) {} | 73 is_being_destroyed_(false) {} |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 scoped_ptr<aura::Window> fake_native_view_; | 76 scoped_ptr<aura::Window> fake_native_view_; |
| 76 scoped_ptr<aura::Window> fake_contents_window_; | 77 scoped_ptr<aura::Window> fake_contents_window_; |
| 77 bool is_being_destroyed_; | 78 bool is_being_destroyed_; |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { | 81 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { |
| 81 public: | 82 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); | 114 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); |
| 114 bool window_created = window; | 115 bool window_created = window; |
| 115 // Performs BACK navigation, sets image from layer_delegate_ on | 116 // Performs BACK navigation, sets image from layer_delegate_ on |
| 116 // image_delegate_. | 117 // image_delegate_. |
| 117 GetOverlay()->OnOverscrollCompleting(); | 118 GetOverlay()->OnOverscrollCompleting(); |
| 118 if (window_created) | 119 if (window_created) |
| 119 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 120 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 120 else | 121 else |
| 121 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 122 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 122 window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 123 window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 123 GetOverlay()->OnOverscrollCompleted(window.Pass()); | 124 GetOverlay()->OnOverscrollCompleted(std::move(window)); |
| 124 if (IsBrowserSideNavigationEnabled()) | 125 if (IsBrowserSideNavigationEnabled()) |
| 125 main_test_rfh()->PrepareForCommit(); | 126 main_test_rfh()->PrepareForCommit(); |
| 126 else | 127 else |
| 127 contents()->GetPendingMainFrame()->PrepareForCommit(); | 128 contents()->GetPendingMainFrame()->PrepareForCommit(); |
| 128 if (window_created) | 129 if (window_created) |
| 129 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 130 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 130 else | 131 else |
| 131 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 132 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 132 } | 133 } |
| 133 | 134 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); | 160 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 160 | 161 |
| 161 // Set up the fake contents window. | 162 // Set up the fake contents window. |
| 162 scoped_ptr<aura::Window> fake_contents_window(new aura::Window(nullptr)); | 163 scoped_ptr<aura::Window> fake_contents_window(new aura::Window(nullptr)); |
| 163 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); | 164 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); |
| 164 root_window()->AddChild(fake_contents_window.get()); | 165 root_window()->AddChild(fake_contents_window.get()); |
| 165 fake_contents_window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 166 fake_contents_window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 166 | 167 |
| 167 // Replace the default test web contents with our custom class. | 168 // Replace the default test web contents with our custom class. |
| 168 SetContents(OverscrollTestWebContents::Create( | 169 SetContents(OverscrollTestWebContents::Create( |
| 169 browser_context(), | 170 browser_context(), SiteInstance::Create(browser_context()), |
| 170 SiteInstance::Create(browser_context()), | 171 std::move(fake_native_view), std::move(fake_contents_window))); |
| 171 fake_native_view.Pass(), | |
| 172 fake_contents_window.Pass())); | |
| 173 | 172 |
| 174 contents()->NavigateAndCommit(first()); | 173 contents()->NavigateAndCommit(first()); |
| 175 EXPECT_TRUE(controller().GetVisibleEntry()); | 174 EXPECT_TRUE(controller().GetVisibleEntry()); |
| 176 EXPECT_FALSE(controller().CanGoBack()); | 175 EXPECT_FALSE(controller().CanGoBack()); |
| 177 | 176 |
| 178 contents()->NavigateAndCommit(second()); | 177 contents()->NavigateAndCommit(second()); |
| 179 EXPECT_TRUE(controller().CanGoBack()); | 178 EXPECT_TRUE(controller().CanGoBack()); |
| 180 | 179 |
| 181 contents()->NavigateAndCommit(third()); | 180 contents()->NavigateAndCommit(third()); |
| 182 EXPECT_TRUE(controller().CanGoBack()); | 181 EXPECT_TRUE(controller().CanGoBack()); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 EXPECT_TRUE(GetOverlay()->window_.get()); | 405 EXPECT_TRUE(GetOverlay()->window_.get()); |
| 407 | 406 |
| 408 // Load the page. | 407 // Load the page. |
| 409 contents()->CommitPendingNavigation(); | 408 contents()->CommitPendingNavigation(); |
| 410 ReceivePaintUpdate(); | 409 ReceivePaintUpdate(); |
| 411 EXPECT_FALSE(GetOverlay()->window_.get()); | 410 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 412 EXPECT_EQ(contents()->GetURL(), first()); | 411 EXPECT_EQ(contents()->GetURL(), first()); |
| 413 } | 412 } |
| 414 | 413 |
| 415 } // namespace content | 414 } // namespace content |
| OLD | NEW |