| 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 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/test/histogram_tester.h" |
| 13 #include "base/test/user_action_tester.h" |
| 12 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/web_contents/aura/uma_navigation_type.h" |
| 13 #include "content/browser/web_contents/web_contents_view.h" | 16 #include "content/browser/web_contents/web_contents_view.h" |
| 14 #include "content/common/frame_messages.h" | 17 #include "content/common/frame_messages.h" |
| 15 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
| 16 #include "content/public/browser/overscroll_configuration.h" | 19 #include "content/public/browser/overscroll_configuration.h" |
| 17 #include "content/public/common/browser_side_navigation_policy.h" | 20 #include "content/public/common/browser_side_navigation_policy.h" |
| 18 #include "content/public/test/mock_render_process_host.h" | 21 #include "content/public/test/mock_render_process_host.h" |
| 19 #include "content/test/test_render_frame_host.h" | 22 #include "content/test/test_render_frame_host.h" |
| 20 #include "content/test/test_render_view_host.h" | 23 #include "content/test/test_render_view_host.h" |
| 21 #include "content/test/test_web_contents.h" | 24 #include "content/test/test_web_contents.h" |
| 22 #include "ui/aura/test/test_windows.h" | 25 #include "ui/aura/test/test_windows.h" |
| 23 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 24 #include "ui/aura_extra/image_window_delegate.h" | 27 #include "ui/aura_extra/image_window_delegate.h" |
| 25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 26 #include "ui/compositor/scoped_layer_animation_settings.h" | 29 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 27 #include "ui/compositor/test/layer_animator_test_controller.h" | 30 #include "ui/compositor/test/layer_animator_test_controller.h" |
| 28 #include "ui/events/gesture_detection/gesture_configuration.h" | 31 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 29 #include "ui/events/test/event_generator.h" | 32 #include "ui/events/test/event_generator.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 33 #include "ui/gfx/codec/png_codec.h" |
| 31 | 34 |
| 32 namespace content { | 35 namespace content { |
| 36 namespace { |
| 37 |
| 38 const char kUmaStarted[] = "Overscroll.Started3"; |
| 39 const char kUmaCancelled[] = "Overscroll.Cancelled3"; |
| 40 const char kUmaNavigated[] = "Overscroll.Navigated3"; |
| 41 |
| 42 const char kActionCancelledBack[] = "Overscroll_Cancelled.Back"; |
| 43 const char kActionCancelledForward[] = "Overscroll_Cancelled.Forward"; |
| 44 const char kActionNavigatedBack[] = "Overscroll_Navigated.Back"; |
| 45 const char kActionNavigatedForward[] = "Overscroll_Navigated.Forward"; |
| 46 |
| 47 } // namespace |
| 33 | 48 |
| 34 // Forces web contents to complete web page load as soon as navigation starts. | 49 // Forces web contents to complete web page load as soon as navigation starts. |
| 35 class ImmediateLoadObserver : WebContentsObserver { | 50 class ImmediateLoadObserver : WebContentsObserver { |
| 36 public: | 51 public: |
| 37 explicit ImmediateLoadObserver(TestWebContents* contents) | 52 explicit ImmediateLoadObserver(TestWebContents* contents) |
| 38 : contents_(contents) { | 53 : contents_(contents) { |
| 39 Observe(contents); | 54 Observe(contents); |
| 40 } | 55 } |
| 41 ~ImmediateLoadObserver() override {} | 56 ~ImmediateLoadObserver() override {} |
| 42 | 57 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 NavigationEntryImpl* entry_impl = | 148 NavigationEntryImpl* entry_impl = |
| 134 NavigationEntryImpl::FromNavigationEntry(entry); | 149 NavigationEntryImpl::FromNavigationEntry(entry); |
| 135 entry_impl->SetScreenshotPNGData(png_bytes); | 150 entry_impl->SetScreenshotPNGData(png_bytes); |
| 136 } | 151 } |
| 137 | 152 |
| 138 void ReceivePaintUpdate() { | 153 void ReceivePaintUpdate() { |
| 139 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg(test_rvh()->GetRoutingID()); | 154 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg(test_rvh()->GetRoutingID()); |
| 140 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); | 155 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); |
| 141 } | 156 } |
| 142 | 157 |
| 143 void PerformBackNavigationViaSliderCallbacks() { | 158 void PerformBackNavigationViaSliderCallbacks(OverscrollSource source) { |
| 144 // Sets slide direction to BACK, sets screenshot from NavEntry at | 159 // Sets slide direction to BACK, sets screenshot from NavEntry at |
| 145 // offset -1 on layer_delegate_. | 160 // offset -1 on layer_delegate_. |
| 161 GetOverlay()->owa_->SetOverscrollSourceForTesting(source); |
| 146 std::unique_ptr<aura::Window> window( | 162 std::unique_ptr<aura::Window> window( |
| 147 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); | 163 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); |
| 148 bool window_created = !!window; | 164 bool window_created = !!window; |
| 149 // Performs BACK navigation, sets image from layer_delegate_ on | 165 if (window_created) { |
| 150 // image_delegate_. | 166 histogram_tester()->ExpectTotalCount(kUmaStarted, 1); |
| 151 GetOverlay()->OnOverscrollCompleting(); | 167 histogram_tester()->ExpectBucketCount( |
| 152 if (window_created) | 168 kUmaStarted, source == OverscrollSource::TOUCHPAD ? BACK_TOUCHPAD |
| 169 : BACK_TOUCHSCREEN, |
| 170 1); |
| 153 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 171 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 154 else | 172 // Performs BACK navigation, sets image from layer_delegate_ on |
| 173 // image_delegate_. |
| 174 GetOverlay()->OnOverscrollCompleting(); |
| 175 window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 176 |
| 177 histogram_tester()->ExpectTotalCount(kUmaNavigated, 0); |
| 178 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 179 |
| 180 GetOverlay()->OnOverscrollCompleted(std::move(window)); |
| 181 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 182 histogram_tester()->ExpectBucketCount(kUmaNavigated, |
| 183 source == OverscrollSource::TOUCHPAD |
| 184 ? BACK_TOUCHPAD |
| 185 : BACK_TOUCHSCREEN, |
| 186 1); |
| 187 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 188 } else { |
| 155 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 189 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 156 window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 190 histogram_tester()->ExpectTotalCount(kUmaStarted, 0); |
| 157 GetOverlay()->OnOverscrollCompleted(std::move(window)); | 191 } |
| 192 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::NONE); |
| 158 if (IsBrowserSideNavigationEnabled()) | 193 if (IsBrowserSideNavigationEnabled()) |
| 159 main_test_rfh()->PrepareForCommit(); | 194 main_test_rfh()->PrepareForCommit(); |
| 160 else | 195 else |
| 161 contents()->GetPendingMainFrame()->PrepareForCommit(); | 196 contents()->GetPendingMainFrame()->PrepareForCommit(); |
| 162 if (window_created) | 197 if (window_created) |
| 163 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 198 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 164 else | 199 else |
| 165 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 200 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 166 } | 201 } |
| 167 | 202 |
| 168 gfx::Rect GetFrontSlideWindowBounds() { | 203 gfx::Rect GetFrontSlideWindowBounds() { |
| 169 gfx::Rect bounds = gfx::Rect(root_window()->bounds().size()); | 204 gfx::Rect bounds = gfx::Rect(root_window()->bounds().size()); |
| 170 bounds.Offset(root_window()->bounds().size().width(), 0); | 205 bounds.Offset(root_window()->bounds().size().width(), 0); |
| 171 return bounds; | 206 return bounds; |
| 172 } | 207 } |
| 173 | 208 |
| 174 gfx::Rect GetBackSlideWindowBounds() { | 209 gfx::Rect GetBackSlideWindowBounds() { |
| 175 return gfx::Rect(root_window()->bounds().size()); | 210 return gfx::Rect(root_window()->bounds().size()); |
| 176 } | 211 } |
| 177 | 212 |
| 178 // Const accessors. | 213 // Const accessors. |
| 179 const GURL first() { return first_; } | 214 const GURL first() { return first_; } |
| 180 const GURL second() { return second_; } | 215 const GURL second() { return second_; } |
| 181 const GURL third() { return third_; } | 216 const GURL third() { return third_; } |
| 182 const GURL fourth() { return fourth_; } | 217 const GURL fourth() { return fourth_; } |
| 183 | 218 |
| 219 base::HistogramTester* histogram_tester() { return histogram_tester_.get(); } |
| 220 base::UserActionTester* action_tester() { return action_tester_.get(); } |
| 221 |
| 184 protected: | 222 protected: |
| 185 // RenderViewHostImplTestHarness: | 223 // RenderViewHostImplTestHarness: |
| 186 void SetUp() override { | 224 void SetUp() override { |
| 187 RenderViewHostImplTestHarness::SetUp(); | 225 RenderViewHostImplTestHarness::SetUp(); |
| 188 | 226 |
| 227 histogram_tester_.reset(new base::HistogramTester); |
| 228 action_tester_.reset(new base::UserActionTester); |
| 229 |
| 189 // Set up the fake web contents native view. | 230 // Set up the fake web contents native view. |
| 190 std::unique_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); | 231 std::unique_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); |
| 191 fake_native_view->Init(ui::LAYER_SOLID_COLOR); | 232 fake_native_view->Init(ui::LAYER_SOLID_COLOR); |
| 192 root_window()->AddChild(fake_native_view.get()); | 233 root_window()->AddChild(fake_native_view.get()); |
| 193 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); | 234 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 194 | 235 |
| 195 // Set up the fake contents window. | 236 // Set up the fake contents window. |
| 196 std::unique_ptr<aura::Window> fake_contents_window( | 237 std::unique_ptr<aura::Window> fake_contents_window( |
| 197 new aura::Window(nullptr)); | 238 new aura::Window(nullptr)); |
| 198 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); | 239 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return overlay_.get(); | 283 return overlay_.get(); |
| 243 } | 284 } |
| 244 | 285 |
| 245 private: | 286 private: |
| 246 // Tests URLs. | 287 // Tests URLs. |
| 247 const GURL first_; | 288 const GURL first_; |
| 248 const GURL second_; | 289 const GURL second_; |
| 249 const GURL third_; | 290 const GURL third_; |
| 250 const GURL fourth_; | 291 const GURL fourth_; |
| 251 | 292 |
| 293 std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 294 std::unique_ptr<base::UserActionTester> action_tester_; |
| 295 |
| 252 std::unique_ptr<OverscrollNavigationOverlay> overlay_; | 296 std::unique_ptr<OverscrollNavigationOverlay> overlay_; |
| 253 | 297 |
| 254 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 298 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
| 255 }; | 299 }; |
| 256 | 300 |
| 257 // Tests that if a screenshot is available, it is set in the overlay window | 301 // Tests that if a screenshot is available, it is set in the overlay window |
| 258 // delegate. | 302 // delegate. |
| 259 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { | 303 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { |
| 260 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 304 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
| 261 PerformBackNavigationViaSliderCallbacks(); | 305 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 262 // Screenshot was set on NavEntry at offset -1. | 306 // Screenshot was set on NavEntry at offset -1. |
| 263 EXPECT_TRUE(static_cast<aura_extra::ImageWindowDelegate*>( | 307 EXPECT_TRUE(static_cast<aura_extra::ImageWindowDelegate*>( |
| 264 GetOverlay()->window_->delegate())->has_image()); | 308 GetOverlay()->window_->delegate())->has_image()); |
| 265 } | 309 } |
| 266 | 310 |
| 267 // Tests that if a screenshot is not available, no image is set in the overlay | 311 // Tests that if a screenshot is not available, no image is set in the overlay |
| 268 // window delegate. | 312 // window delegate. |
| 269 TEST_F(OverscrollNavigationOverlayTest, WithoutScreenshot) { | 313 TEST_F(OverscrollNavigationOverlayTest, WithoutScreenshot) { |
| 270 PerformBackNavigationViaSliderCallbacks(); | 314 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHSCREEN); |
| 271 // No screenshot was set on NavEntry at offset -1. | 315 // No screenshot was set on NavEntry at offset -1. |
| 272 EXPECT_FALSE(static_cast<aura_extra::ImageWindowDelegate*>( | 316 EXPECT_FALSE(static_cast<aura_extra::ImageWindowDelegate*>( |
| 273 GetOverlay()->window_->delegate())->has_image()); | 317 GetOverlay()->window_->delegate())->has_image()); |
| 274 } | 318 } |
| 275 | 319 |
| 276 // Tests that if a navigation is attempted but there is nothing to navigate to, | 320 // Tests that if a navigation is attempted but there is nothing to navigate to, |
| 277 // we return a null window. | 321 // we return a null window. |
| 278 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { | 322 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { |
| 279 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), | 323 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), |
| 280 nullptr); | 324 nullptr); |
| 281 } | 325 } |
| 282 | 326 |
| 283 // Tests that if a navigation is cancelled, no navigation is performed and the | 327 // Tests that if a navigation is cancelled, no navigation is performed and the |
| 284 // state is restored. | 328 // state is restored. |
| 285 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { | 329 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { |
| 330 GetOverlay()->owa_->SetOverscrollSourceForTesting( |
| 331 OverscrollSource::TOUCHSCREEN); |
| 286 std::unique_ptr<aura::Window> window = | 332 std::unique_ptr<aura::Window> window = |
| 287 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 333 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 288 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 334 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 289 | 335 |
| 336 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); |
| 337 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledBack)); |
| 338 |
| 290 GetOverlay()->OnOverscrollCancelled(); | 339 GetOverlay()->OnOverscrollCancelled(); |
| 291 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 340 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 292 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 341 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 342 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 343 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHSCREEN, 1); |
| 344 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); |
| 345 } |
| 346 |
| 347 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigation) { |
| 348 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 349 |
| 350 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD); |
| 351 std::unique_ptr<aura::Window> window = |
| 352 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); |
| 353 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); |
| 354 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 355 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHPAD, 1); |
| 356 |
| 357 GetOverlay()->OnOverscrollCompleting(); |
| 358 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 359 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedForward)); |
| 360 |
| 361 GetOverlay()->OnOverscrollCompleted(std::move(window)); |
| 362 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2); |
| 363 histogram_tester()->ExpectBucketCount(kUmaNavigated, FORWARD_TOUCHPAD, 1); |
| 364 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedForward)); |
| 365 |
| 366 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 367 } |
| 368 |
| 369 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigationCancelled) { |
| 370 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 371 |
| 372 GetOverlay()->owa_->SetOverscrollSourceForTesting( |
| 373 OverscrollSource::TOUCHSCREEN); |
| 374 std::unique_ptr<aura::Window> window = |
| 375 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); |
| 376 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); |
| 377 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 378 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHSCREEN, 1); |
| 379 |
| 380 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); |
| 381 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledForward)); |
| 382 |
| 383 GetOverlay()->OnOverscrollCancelled(); |
| 384 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 385 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 386 histogram_tester()->ExpectBucketCount(kUmaCancelled, FORWARD_TOUCHSCREEN, 1); |
| 387 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledForward)); |
| 293 } | 388 } |
| 294 | 389 |
| 295 // Performs two navigations. The second navigation is cancelled, tests that the | 390 // Performs two navigations. The second navigation is cancelled, tests that the |
| 296 // first one worked correctly. | 391 // first one worked correctly. |
| 297 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { | 392 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { |
| 298 PerformBackNavigationViaSliderCallbacks(); | 393 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 394 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD); |
| 299 std::unique_ptr<aura::Window> wrapper = | 395 std::unique_ptr<aura::Window> wrapper = |
| 300 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 396 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 301 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 397 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 398 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 399 histogram_tester()->ExpectBucketCount(kUmaStarted, BACK_TOUCHPAD, 2); |
| 302 | 400 |
| 303 GetOverlay()->OnOverscrollCancelled(); | 401 GetOverlay()->OnOverscrollCancelled(); |
| 304 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 402 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 403 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 404 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHPAD, 1); |
| 405 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); |
| 406 // Navigation metrics shouldn't change. |
| 407 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 408 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 305 | 409 |
| 306 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 410 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 307 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 411 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 308 contents()->GetPendingMainFrame()->SendNavigate( | 412 contents()->GetPendingMainFrame()->SendNavigate( |
| 309 pending->GetUniqueID(), false, pending->GetURL()); | 413 pending->GetUniqueID(), false, pending->GetURL()); |
| 310 EXPECT_EQ(contents()->GetURL(), third()); | 414 EXPECT_EQ(contents()->GetURL(), third()); |
| 311 } | 415 } |
| 312 | 416 |
| 313 // Tests that an overscroll navigation that receives a paint update actually | 417 // Tests that an overscroll navigation that receives a paint update actually |
| 314 // stops observing. | 418 // stops observing. |
| 315 TEST_F(OverscrollNavigationOverlayTest, Navigation_PaintUpdate) { | 419 TEST_F(OverscrollNavigationOverlayTest, Navigation_PaintUpdate) { |
| 316 PerformBackNavigationViaSliderCallbacks(); | 420 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHSCREEN); |
| 317 ReceivePaintUpdate(); | 421 ReceivePaintUpdate(); |
| 318 | 422 |
| 319 // Paint updates until the navigation is committed typically represent updates | 423 // Paint updates until the navigation is committed typically represent updates |
| 320 // for the previous page, so we should still be observing. | 424 // for the previous page, so we should still be observing. |
| 321 EXPECT_TRUE(GetOverlay()->web_contents()); | 425 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 322 | 426 |
| 323 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 427 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 324 contents()->GetPendingMainFrame()->SendNavigate( | 428 contents()->GetPendingMainFrame()->SendNavigate( |
| 325 pending->GetUniqueID(), false, pending->GetURL()); | 429 pending->GetUniqueID(), false, pending->GetURL()); |
| 326 ReceivePaintUpdate(); | 430 ReceivePaintUpdate(); |
| 327 | 431 |
| 328 // Navigation was committed and the paint update was received - we should no | 432 // Navigation was committed and the paint update was received - we should no |
| 329 // longer be observing. | 433 // longer be observing. |
| 330 EXPECT_FALSE(GetOverlay()->web_contents()); | 434 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 331 EXPECT_EQ(contents()->GetURL(), third()); | 435 EXPECT_EQ(contents()->GetURL(), third()); |
| 332 } | 436 } |
| 333 | 437 |
| 334 // Tests that an overscroll navigation that receives a loading update actually | 438 // Tests that an overscroll navigation that receives a loading update actually |
| 335 // stops observing. | 439 // stops observing. |
| 336 TEST_F(OverscrollNavigationOverlayTest, Navigation_LoadingUpdate) { | 440 TEST_F(OverscrollNavigationOverlayTest, Navigation_LoadingUpdate) { |
| 337 PerformBackNavigationViaSliderCallbacks(); | 441 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 338 EXPECT_TRUE(GetOverlay()->web_contents()); | 442 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 339 // DidStopLoading for any navigation should always reset the load flag and | 443 // DidStopLoading for any navigation should always reset the load flag and |
| 340 // dismiss the overlay even if the pending navigation wasn't committed - | 444 // dismiss the overlay even if the pending navigation wasn't committed - |
| 341 // this is a "safety net" in case we mis-identify the destination webpage | 445 // this is a "safety net" in case we mis-identify the destination webpage |
| 342 // (which can happen if a new navigation is performed while while a GestureNav | 446 // (which can happen if a new navigation is performed while while a GestureNav |
| 343 // navigation is in progress). | 447 // navigation is in progress). |
| 344 contents()->TestSetIsLoading(false); | 448 contents()->TestSetIsLoading(false); |
| 345 EXPECT_FALSE(GetOverlay()->web_contents()); | 449 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 346 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 450 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 347 contents()->GetPendingMainFrame()->SendNavigate( | 451 contents()->GetPendingMainFrame()->SendNavigate( |
| 348 pending->GetUniqueID(), false, pending->GetURL()); | 452 pending->GetUniqueID(), false, pending->GetURL()); |
| 349 EXPECT_EQ(contents()->GetURL(), third()); | 453 EXPECT_EQ(contents()->GetURL(), third()); |
| 350 } | 454 } |
| 351 | 455 |
| 352 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) { | 456 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) { |
| 353 ui::ScopedAnimationDurationScaleMode normal_duration_( | 457 ui::ScopedAnimationDurationScaleMode normal_duration_( |
| 354 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 458 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
| 355 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST); | 459 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST, |
| 460 OverscrollSource::TOUCHSCREEN); |
| 356 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); | 461 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
| 357 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 462 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 358 OverscrollTestWebContents* test_web_contents = | 463 OverscrollTestWebContents* test_web_contents = |
| 359 static_cast<OverscrollTestWebContents*>(web_contents()); | 464 static_cast<OverscrollTestWebContents*>(web_contents()); |
| 360 test_web_contents->set_is_being_destroyed(true); | 465 test_web_contents->set_is_being_destroyed(true); |
| 361 test_web_contents->ResetContentNativeView(); | 466 test_web_contents->ResetContentNativeView(); |
| 362 test_web_contents->ResetNativeView(); | 467 test_web_contents->ResetNativeView(); |
| 363 // Ensure a clean close. | 468 // Ensure a clean close. |
| 364 } | 469 } |
| 365 | 470 |
| 366 // Tests that we can handle the case when the load completes as soon as the | 471 // Tests that we can handle the case when the load completes as soon as the |
| 367 // navigation is started. | 472 // navigation is started. |
| 368 TEST_F(OverscrollNavigationOverlayTest, ImmediateLoadOnNavigate) { | 473 TEST_F(OverscrollNavigationOverlayTest, ImmediateLoadOnNavigate) { |
| 369 PerformBackNavigationViaSliderCallbacks(); | 474 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 370 // This observer will force the page load to complete as soon as the | 475 // This observer will force the page load to complete as soon as the |
| 371 // navigation starts. | 476 // navigation starts. |
| 372 ImmediateLoadObserver immediate_nav(contents()); | 477 ImmediateLoadObserver immediate_nav(contents()); |
| 373 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST); | 478 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST, |
| 479 OverscrollSource::TOUCHPAD); |
| 374 // This will start and immediately complete the navigation. | 480 // This will start and immediately complete the navigation. |
| 375 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); | 481 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
| 376 EXPECT_FALSE(GetOverlay()->window_.get()); | 482 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 483 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2); |
| 484 histogram_tester()->ExpectBucketCount(kUmaNavigated, BACK_TOUCHPAD, 2); |
| 485 EXPECT_EQ(2, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 377 } | 486 } |
| 378 | 487 |
| 379 // Tests that swapping the overlay window at the end of a gesture caused by the | 488 // Tests that swapping the overlay window at the end of a gesture caused by the |
| 380 // start of a new overscroll does not crash and the events still reach the new | 489 // start of a new overscroll does not crash and the events still reach the new |
| 381 // overlay window. | 490 // overlay window. |
| 382 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { | 491 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { |
| 383 PerformBackNavigationViaSliderCallbacks(); | 492 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); |
| 384 aura::Window* first_overlay_window = GetOverlay()->window_.get(); | 493 aura::Window* first_overlay_window = GetOverlay()->window_.get(); |
| 385 EXPECT_TRUE(GetOverlay()->web_contents()); | 494 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 386 EXPECT_TRUE(first_overlay_window); | 495 EXPECT_TRUE(first_overlay_window); |
| 387 | 496 |
| 388 // At this stage, the overlay window is covering the web contents. Configure | 497 // At this stage, the overlay window is covering the web contents. Configure |
| 389 // the animator of the overlay window for the test. | 498 // the animator of the overlay window for the test. |
| 390 ui::ScopedAnimationDurationScaleMode normal_duration( | 499 ui::ScopedAnimationDurationScaleMode normal_duration( |
| 391 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 500 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
| 392 ui::LayerAnimator* animator = GetOverlay()->window_->layer()->GetAnimator(); | 501 ui::LayerAnimator* animator = GetOverlay()->window_->layer()->GetAnimator(); |
| 393 animator->set_disable_timer_for_test(true); | 502 animator->set_disable_timer_for_test(true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 EXPECT_TRUE(GetOverlay()->window_.get()); | 559 EXPECT_TRUE(GetOverlay()->window_.get()); |
| 451 | 560 |
| 452 // Load the page. | 561 // Load the page. |
| 453 contents()->CommitPendingNavigation(); | 562 contents()->CommitPendingNavigation(); |
| 454 ReceivePaintUpdate(); | 563 ReceivePaintUpdate(); |
| 455 EXPECT_FALSE(GetOverlay()->window_.get()); | 564 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 456 EXPECT_EQ(contents()->GetURL(), first()); | 565 EXPECT_EQ(contents()->GetURL(), first()); |
| 457 } | 566 } |
| 458 | 567 |
| 459 } // namespace content | 568 } // namespace content |
| OLD | NEW |