| 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 21 matching lines...) Expand all Loading... |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 // A subclass of TestWebContents that offers a fake content window. | 34 // A subclass of TestWebContents that offers a fake content window. |
| 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 scoped_refptr<SiteInstance> instance, | 41 scoped_refptr<SiteInstance> instance, |
| 42 scoped_ptr<aura::Window> fake_native_view, | 42 std::unique_ptr<aura::Window> fake_native_view, |
| 43 scoped_ptr<aura::Window> fake_contents_window) { | 43 std::unique_ptr<aura::Window> fake_contents_window) { |
| 44 OverscrollTestWebContents* web_contents = new OverscrollTestWebContents( | 44 OverscrollTestWebContents* web_contents = new OverscrollTestWebContents( |
| 45 browser_context, std::move(fake_native_view), | 45 browser_context, std::move(fake_native_view), |
| 46 std::move(fake_contents_window)); | 46 std::move(fake_contents_window)); |
| 47 web_contents->Init( | 47 web_contents->Init( |
| 48 WebContents::CreateParams(browser_context, std::move(instance))); | 48 WebContents::CreateParams(browser_context, std::move(instance))); |
| 49 return web_contents; | 49 return web_contents; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void ResetNativeView() { fake_native_view_.reset(); } | 52 void ResetNativeView() { fake_native_view_.reset(); } |
| 53 | 53 |
| 54 void ResetContentNativeView() { fake_contents_window_.reset(); } | 54 void ResetContentNativeView() { fake_contents_window_.reset(); } |
| 55 | 55 |
| 56 void set_is_being_destroyed(bool val) { is_being_destroyed_ = val; } | 56 void set_is_being_destroyed(bool val) { is_being_destroyed_ = val; } |
| 57 | 57 |
| 58 gfx::NativeView GetNativeView() override { return fake_native_view_.get(); } | 58 gfx::NativeView GetNativeView() override { return fake_native_view_.get(); } |
| 59 | 59 |
| 60 gfx::NativeView GetContentNativeView() override { | 60 gfx::NativeView GetContentNativeView() override { |
| 61 return fake_contents_window_.get(); | 61 return fake_contents_window_.get(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool IsBeingDestroyed() const override { return is_being_destroyed_; } | 64 bool IsBeingDestroyed() const override { return is_being_destroyed_; } |
| 65 | 65 |
| 66 protected: | 66 protected: |
| 67 explicit OverscrollTestWebContents( | 67 explicit OverscrollTestWebContents( |
| 68 BrowserContext* browser_context, | 68 BrowserContext* browser_context, |
| 69 scoped_ptr<aura::Window> fake_native_view, | 69 std::unique_ptr<aura::Window> fake_native_view, |
| 70 scoped_ptr<aura::Window> fake_contents_window) | 70 std::unique_ptr<aura::Window> fake_contents_window) |
| 71 : TestWebContents(browser_context), | 71 : TestWebContents(browser_context), |
| 72 fake_native_view_(std::move(fake_native_view)), | 72 fake_native_view_(std::move(fake_native_view)), |
| 73 fake_contents_window_(std::move(fake_contents_window)), | 73 fake_contents_window_(std::move(fake_contents_window)), |
| 74 is_being_destroyed_(false) {} | 74 is_being_destroyed_(false) {} |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 scoped_ptr<aura::Window> fake_native_view_; | 77 std::unique_ptr<aura::Window> fake_native_view_; |
| 78 scoped_ptr<aura::Window> fake_contents_window_; | 78 std::unique_ptr<aura::Window> fake_contents_window_; |
| 79 bool is_being_destroyed_; | 79 bool is_being_destroyed_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { | 82 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { |
| 83 public: | 83 public: |
| 84 OverscrollNavigationOverlayTest() | 84 OverscrollNavigationOverlayTest() |
| 85 : first_("https://www.google.com"), | 85 : first_("https://www.google.com"), |
| 86 second_("http://www.chromium.org"), | 86 second_("http://www.chromium.org"), |
| 87 third_("https://www.kernel.org/"), | 87 third_("https://www.kernel.org/"), |
| 88 fourth_("https://github.com/") {} | 88 fourth_("https://github.com/") {} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 | 104 |
| 105 void ReceivePaintUpdate() { | 105 void ReceivePaintUpdate() { |
| 106 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg( | 106 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg( |
| 107 main_test_rfh()->GetRoutingID()); | 107 main_test_rfh()->GetRoutingID()); |
| 108 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); | 108 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void PerformBackNavigationViaSliderCallbacks() { | 111 void PerformBackNavigationViaSliderCallbacks() { |
| 112 // Sets slide direction to BACK, sets screenshot from NavEntry at | 112 // Sets slide direction to BACK, sets screenshot from NavEntry at |
| 113 // offset -1 on layer_delegate_. | 113 // offset -1 on layer_delegate_. |
| 114 scoped_ptr<aura::Window> window( | 114 std::unique_ptr<aura::Window> window( |
| 115 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); | 115 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); |
| 116 bool window_created = !!window; | 116 bool window_created = !!window; |
| 117 // Performs BACK navigation, sets image from layer_delegate_ on | 117 // Performs BACK navigation, sets image from layer_delegate_ on |
| 118 // image_delegate_. | 118 // image_delegate_. |
| 119 GetOverlay()->OnOverscrollCompleting(); | 119 GetOverlay()->OnOverscrollCompleting(); |
| 120 if (window_created) | 120 if (window_created) |
| 121 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 121 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 122 else | 122 else |
| 123 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 123 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 124 window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 124 window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 148 const GURL second() { return second_; } | 148 const GURL second() { return second_; } |
| 149 const GURL third() { return third_; } | 149 const GURL third() { return third_; } |
| 150 const GURL fourth() { return fourth_; } | 150 const GURL fourth() { return fourth_; } |
| 151 | 151 |
| 152 protected: | 152 protected: |
| 153 // RenderViewHostImplTestHarness: | 153 // RenderViewHostImplTestHarness: |
| 154 void SetUp() override { | 154 void SetUp() override { |
| 155 RenderViewHostImplTestHarness::SetUp(); | 155 RenderViewHostImplTestHarness::SetUp(); |
| 156 | 156 |
| 157 // Set up the fake web contents native view. | 157 // Set up the fake web contents native view. |
| 158 scoped_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); | 158 std::unique_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); |
| 159 fake_native_view->Init(ui::LAYER_SOLID_COLOR); | 159 fake_native_view->Init(ui::LAYER_SOLID_COLOR); |
| 160 root_window()->AddChild(fake_native_view.get()); | 160 root_window()->AddChild(fake_native_view.get()); |
| 161 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); | 161 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 162 | 162 |
| 163 // Set up the fake contents window. | 163 // Set up the fake contents window. |
| 164 scoped_ptr<aura::Window> fake_contents_window(new aura::Window(nullptr)); | 164 std::unique_ptr<aura::Window> fake_contents_window( |
| 165 new aura::Window(nullptr)); |
| 165 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); | 166 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); |
| 166 root_window()->AddChild(fake_contents_window.get()); | 167 root_window()->AddChild(fake_contents_window.get()); |
| 167 fake_contents_window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 168 fake_contents_window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 168 | 169 |
| 169 // Replace the default test web contents with our custom class. | 170 // Replace the default test web contents with our custom class. |
| 170 SetContents(OverscrollTestWebContents::Create( | 171 SetContents(OverscrollTestWebContents::Create( |
| 171 browser_context(), SiteInstance::Create(browser_context()), | 172 browser_context(), SiteInstance::Create(browser_context()), |
| 172 std::move(fake_native_view), std::move(fake_contents_window))); | 173 std::move(fake_native_view), std::move(fake_contents_window))); |
| 173 | 174 |
| 174 contents()->NavigateAndCommit(first()); | 175 contents()->NavigateAndCommit(first()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return overlay_.get(); | 210 return overlay_.get(); |
| 210 } | 211 } |
| 211 | 212 |
| 212 private: | 213 private: |
| 213 // Tests URLs. | 214 // Tests URLs. |
| 214 const GURL first_; | 215 const GURL first_; |
| 215 const GURL second_; | 216 const GURL second_; |
| 216 const GURL third_; | 217 const GURL third_; |
| 217 const GURL fourth_; | 218 const GURL fourth_; |
| 218 | 219 |
| 219 scoped_ptr<OverscrollNavigationOverlay> overlay_; | 220 std::unique_ptr<OverscrollNavigationOverlay> overlay_; |
| 220 | 221 |
| 221 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 222 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
| 222 }; | 223 }; |
| 223 | 224 |
| 224 // Tests that if a screenshot is available, it is set in the overlay window | 225 // Tests that if a screenshot is available, it is set in the overlay window |
| 225 // delegate. | 226 // delegate. |
| 226 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { | 227 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { |
| 227 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 228 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
| 228 PerformBackNavigationViaSliderCallbacks(); | 229 PerformBackNavigationViaSliderCallbacks(); |
| 229 // Screenshot was set on NavEntry at offset -1. | 230 // Screenshot was set on NavEntry at offset -1. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 243 // Tests that if a navigation is attempted but there is nothing to navigate to, | 244 // Tests that if a navigation is attempted but there is nothing to navigate to, |
| 244 // we return a null window. | 245 // we return a null window. |
| 245 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { | 246 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { |
| 246 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), | 247 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), |
| 247 nullptr); | 248 nullptr); |
| 248 } | 249 } |
| 249 | 250 |
| 250 // Tests that if a navigation is cancelled, no navigation is performed and the | 251 // Tests that if a navigation is cancelled, no navigation is performed and the |
| 251 // state is restored. | 252 // state is restored. |
| 252 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { | 253 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { |
| 253 scoped_ptr<aura::Window> window = | 254 std::unique_ptr<aura::Window> window = |
| 254 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 255 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 255 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 256 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 256 | 257 |
| 257 GetOverlay()->OnOverscrollCancelled(); | 258 GetOverlay()->OnOverscrollCancelled(); |
| 258 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 259 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 259 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 260 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 260 } | 261 } |
| 261 | 262 |
| 262 // Performs two navigations. The second navigation is cancelled, tests that the | 263 // Performs two navigations. The second navigation is cancelled, tests that the |
| 263 // first one worked correctly. | 264 // first one worked correctly. |
| 264 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { | 265 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { |
| 265 PerformBackNavigationViaSliderCallbacks(); | 266 PerformBackNavigationViaSliderCallbacks(); |
| 266 scoped_ptr<aura::Window> wrapper = | 267 std::unique_ptr<aura::Window> wrapper = |
| 267 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 268 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 268 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 269 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 269 | 270 |
| 270 GetOverlay()->OnOverscrollCancelled(); | 271 GetOverlay()->OnOverscrollCancelled(); |
| 271 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 272 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 272 | 273 |
| 273 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 274 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 274 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 275 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 275 contents()->GetPendingMainFrame()->SendNavigate( | 276 contents()->GetPendingMainFrame()->SendNavigate( |
| 276 pending->GetPageID(), pending->GetUniqueID(), false, pending->GetURL()); | 277 pending->GetPageID(), pending->GetUniqueID(), false, pending->GetURL()); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 EXPECT_TRUE(GetOverlay()->window_.get()); | 406 EXPECT_TRUE(GetOverlay()->window_.get()); |
| 406 | 407 |
| 407 // Load the page. | 408 // Load the page. |
| 408 contents()->CommitPendingNavigation(); | 409 contents()->CommitPendingNavigation(); |
| 409 ReceivePaintUpdate(); | 410 ReceivePaintUpdate(); |
| 410 EXPECT_FALSE(GetOverlay()->window_.get()); | 411 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 411 EXPECT_EQ(contents()->GetURL(), first()); | 412 EXPECT_EQ(contents()->GetURL(), first()); |
| 412 } | 413 } |
| 413 | 414 |
| 414 } // namespace content | 415 } // namespace content |
| OLD | NEW |