| 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, |
| 169 source == OVERSCROLL_TOUCHPAD ? BACK_TOUCHPAD : BACK_TOUCHSCREEN, 1); |
| 153 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 170 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 154 else | 171 // Performs BACK navigation, sets image from layer_delegate_ on |
| 172 // image_delegate_. |
| 173 GetOverlay()->OnOverscrollCompleting(); |
| 174 window->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 175 |
| 176 histogram_tester()->ExpectTotalCount(kUmaNavigated, 0); |
| 177 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 178 |
| 179 GetOverlay()->OnOverscrollCompleted(std::move(window)); |
| 180 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 181 histogram_tester()->ExpectBucketCount( |
| 182 kUmaNavigated, |
| 183 source == OVERSCROLL_TOUCHPAD ? BACK_TOUCHPAD : BACK_TOUCHSCREEN, 1); |
| 184 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 185 } else { |
| 155 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 186 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 156 window->SetBounds(gfx::Rect(root_window()->bounds().size())); | 187 histogram_tester()->ExpectTotalCount(kUmaStarted, 0); |
| 157 GetOverlay()->OnOverscrollCompleted(std::move(window)); | 188 } |
| 189 GetOverlay()->owa_->SetOverscrollSourceForTesting(OVERSCROLL_SOURCE_NONE); |
| 158 if (IsBrowserSideNavigationEnabled()) | 190 if (IsBrowserSideNavigationEnabled()) |
| 159 main_test_rfh()->PrepareForCommit(); | 191 main_test_rfh()->PrepareForCommit(); |
| 160 else | 192 else |
| 161 contents()->GetPendingMainFrame()->PrepareForCommit(); | 193 contents()->GetPendingMainFrame()->PrepareForCommit(); |
| 162 if (window_created) | 194 if (window_created) |
| 163 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 195 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 164 else | 196 else |
| 165 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 197 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 166 } | 198 } |
| 167 | 199 |
| 168 gfx::Rect GetFrontSlideWindowBounds() { | 200 gfx::Rect GetFrontSlideWindowBounds() { |
| 169 gfx::Rect bounds = gfx::Rect(root_window()->bounds().size()); | 201 gfx::Rect bounds = gfx::Rect(root_window()->bounds().size()); |
| 170 bounds.Offset(root_window()->bounds().size().width(), 0); | 202 bounds.Offset(root_window()->bounds().size().width(), 0); |
| 171 return bounds; | 203 return bounds; |
| 172 } | 204 } |
| 173 | 205 |
| 174 gfx::Rect GetBackSlideWindowBounds() { | 206 gfx::Rect GetBackSlideWindowBounds() { |
| 175 return gfx::Rect(root_window()->bounds().size()); | 207 return gfx::Rect(root_window()->bounds().size()); |
| 176 } | 208 } |
| 177 | 209 |
| 178 // Const accessors. | 210 // Const accessors. |
| 179 const GURL first() { return first_; } | 211 const GURL first() { return first_; } |
| 180 const GURL second() { return second_; } | 212 const GURL second() { return second_; } |
| 181 const GURL third() { return third_; } | 213 const GURL third() { return third_; } |
| 182 const GURL fourth() { return fourth_; } | 214 const GURL fourth() { return fourth_; } |
| 183 | 215 |
| 216 base::HistogramTester* histogram_tester() { return histogram_tester_.get(); } |
| 217 base::UserActionTester* action_tester() { return action_tester_.get(); } |
| 218 |
| 184 protected: | 219 protected: |
| 185 // RenderViewHostImplTestHarness: | 220 // RenderViewHostImplTestHarness: |
| 186 void SetUp() override { | 221 void SetUp() override { |
| 187 RenderViewHostImplTestHarness::SetUp(); | 222 RenderViewHostImplTestHarness::SetUp(); |
| 188 | 223 |
| 224 histogram_tester_.reset(new base::HistogramTester); |
| 225 action_tester_.reset(new base::UserActionTester); |
| 226 |
| 189 // Set up the fake web contents native view. | 227 // Set up the fake web contents native view. |
| 190 std::unique_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); | 228 std::unique_ptr<aura::Window> fake_native_view(new aura::Window(nullptr)); |
| 191 fake_native_view->Init(ui::LAYER_SOLID_COLOR); | 229 fake_native_view->Init(ui::LAYER_SOLID_COLOR); |
| 192 root_window()->AddChild(fake_native_view.get()); | 230 root_window()->AddChild(fake_native_view.get()); |
| 193 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); | 231 fake_native_view->SetBounds(gfx::Rect(root_window()->bounds().size())); |
| 194 | 232 |
| 195 // Set up the fake contents window. | 233 // Set up the fake contents window. |
| 196 std::unique_ptr<aura::Window> fake_contents_window( | 234 std::unique_ptr<aura::Window> fake_contents_window( |
| 197 new aura::Window(nullptr)); | 235 new aura::Window(nullptr)); |
| 198 fake_contents_window->Init(ui::LAYER_SOLID_COLOR); | 236 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(); | 280 return overlay_.get(); |
| 243 } | 281 } |
| 244 | 282 |
| 245 private: | 283 private: |
| 246 // Tests URLs. | 284 // Tests URLs. |
| 247 const GURL first_; | 285 const GURL first_; |
| 248 const GURL second_; | 286 const GURL second_; |
| 249 const GURL third_; | 287 const GURL third_; |
| 250 const GURL fourth_; | 288 const GURL fourth_; |
| 251 | 289 |
| 290 std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 291 std::unique_ptr<base::UserActionTester> action_tester_; |
| 292 |
| 252 std::unique_ptr<OverscrollNavigationOverlay> overlay_; | 293 std::unique_ptr<OverscrollNavigationOverlay> overlay_; |
| 253 | 294 |
| 254 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 295 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
| 255 }; | 296 }; |
| 256 | 297 |
| 257 // Tests that if a screenshot is available, it is set in the overlay window | 298 // Tests that if a screenshot is available, it is set in the overlay window |
| 258 // delegate. | 299 // delegate. |
| 259 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { | 300 TEST_F(OverscrollNavigationOverlayTest, WithScreenshot) { |
| 260 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 301 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
| 261 PerformBackNavigationViaSliderCallbacks(); | 302 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 262 // Screenshot was set on NavEntry at offset -1. | 303 // Screenshot was set on NavEntry at offset -1. |
| 263 EXPECT_TRUE(static_cast<aura_extra::ImageWindowDelegate*>( | 304 EXPECT_TRUE(static_cast<aura_extra::ImageWindowDelegate*>( |
| 264 GetOverlay()->window_->delegate())->has_image()); | 305 GetOverlay()->window_->delegate())->has_image()); |
| 265 } | 306 } |
| 266 | 307 |
| 267 // Tests that if a screenshot is not available, no image is set in the overlay | 308 // Tests that if a screenshot is not available, no image is set in the overlay |
| 268 // window delegate. | 309 // window delegate. |
| 269 TEST_F(OverscrollNavigationOverlayTest, WithoutScreenshot) { | 310 TEST_F(OverscrollNavigationOverlayTest, WithoutScreenshot) { |
| 270 PerformBackNavigationViaSliderCallbacks(); | 311 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHSCREEN); |
| 271 // No screenshot was set on NavEntry at offset -1. | 312 // No screenshot was set on NavEntry at offset -1. |
| 272 EXPECT_FALSE(static_cast<aura_extra::ImageWindowDelegate*>( | 313 EXPECT_FALSE(static_cast<aura_extra::ImageWindowDelegate*>( |
| 273 GetOverlay()->window_->delegate())->has_image()); | 314 GetOverlay()->window_->delegate())->has_image()); |
| 274 } | 315 } |
| 275 | 316 |
| 276 // Tests that if a navigation is attempted but there is nothing to navigate to, | 317 // Tests that if a navigation is attempted but there is nothing to navigate to, |
| 277 // we return a null window. | 318 // we return a null window. |
| 278 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { | 319 TEST_F(OverscrollNavigationOverlayTest, CannotNavigate) { |
| 279 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), | 320 EXPECT_EQ(GetOverlay()->CreateFrontWindow(GetFrontSlideWindowBounds()), |
| 280 nullptr); | 321 nullptr); |
| 281 } | 322 } |
| 282 | 323 |
| 283 // Tests that if a navigation is cancelled, no navigation is performed and the | 324 // Tests that if a navigation is cancelled, no navigation is performed and the |
| 284 // state is restored. | 325 // state is restored. |
| 285 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { | 326 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { |
| 327 GetOverlay()->owa_->SetOverscrollSourceForTesting(OVERSCROLL_TOUCHSCREEN); |
| 286 std::unique_ptr<aura::Window> window = | 328 std::unique_ptr<aura::Window> window = |
| 287 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 329 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 288 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 330 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 289 | 331 |
| 332 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); |
| 333 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledBack)); |
| 334 |
| 290 GetOverlay()->OnOverscrollCancelled(); | 335 GetOverlay()->OnOverscrollCancelled(); |
| 291 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 336 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
| 292 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 337 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 338 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 339 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHSCREEN, 1); |
| 340 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); |
| 341 } |
| 342 |
| 343 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigation) { |
| 344 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 345 |
| 346 GetOverlay()->owa_->SetOverscrollSourceForTesting(OVERSCROLL_TOUCHPAD); |
| 347 std::unique_ptr<aura::Window> window = |
| 348 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); |
| 349 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); |
| 350 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 351 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHPAD, 1); |
| 352 |
| 353 GetOverlay()->OnOverscrollCompleting(); |
| 354 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 355 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedForward)); |
| 356 |
| 357 GetOverlay()->OnOverscrollCompleted(std::move(window)); |
| 358 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2); |
| 359 histogram_tester()->ExpectBucketCount(kUmaNavigated, FORWARD_TOUCHPAD, 1); |
| 360 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedForward)); |
| 361 |
| 362 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 363 } |
| 364 |
| 365 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigationCancelled) { |
| 366 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 367 |
| 368 GetOverlay()->owa_->SetOverscrollSourceForTesting(OVERSCROLL_TOUCHSCREEN); |
| 369 std::unique_ptr<aura::Window> window = |
| 370 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); |
| 371 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); |
| 372 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 373 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHSCREEN, 1); |
| 374 |
| 375 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); |
| 376 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledForward)); |
| 377 |
| 378 GetOverlay()->OnOverscrollCancelled(); |
| 379 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 380 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 381 histogram_tester()->ExpectBucketCount(kUmaCancelled, FORWARD_TOUCHSCREEN, 1); |
| 382 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledForward)); |
| 293 } | 383 } |
| 294 | 384 |
| 295 // Performs two navigations. The second navigation is cancelled, tests that the | 385 // Performs two navigations. The second navigation is cancelled, tests that the |
| 296 // first one worked correctly. | 386 // first one worked correctly. |
| 297 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { | 387 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { |
| 298 PerformBackNavigationViaSliderCallbacks(); | 388 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 389 GetOverlay()->owa_->SetOverscrollSourceForTesting(OVERSCROLL_TOUCHPAD); |
| 299 std::unique_ptr<aura::Window> wrapper = | 390 std::unique_ptr<aura::Window> wrapper = |
| 300 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); | 391 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); |
| 301 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 392 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 393 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); |
| 394 histogram_tester()->ExpectBucketCount(kUmaStarted, BACK_TOUCHPAD, 2); |
| 302 | 395 |
| 303 GetOverlay()->OnOverscrollCancelled(); | 396 GetOverlay()->OnOverscrollCancelled(); |
| 304 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); | 397 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); |
| 398 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); |
| 399 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHPAD, 1); |
| 400 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); |
| 401 // Navigation metrics shouldn't change. |
| 402 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); |
| 403 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 305 | 404 |
| 306 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); | 405 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); |
| 307 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 406 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 308 contents()->GetPendingMainFrame()->SendNavigate( | 407 contents()->GetPendingMainFrame()->SendNavigate( |
| 309 pending->GetUniqueID(), false, pending->GetURL()); | 408 pending->GetUniqueID(), false, pending->GetURL()); |
| 310 EXPECT_EQ(contents()->GetURL(), third()); | 409 EXPECT_EQ(contents()->GetURL(), third()); |
| 311 } | 410 } |
| 312 | 411 |
| 313 // Tests that an overscroll navigation that receives a paint update actually | 412 // Tests that an overscroll navigation that receives a paint update actually |
| 314 // stops observing. | 413 // stops observing. |
| 315 TEST_F(OverscrollNavigationOverlayTest, Navigation_PaintUpdate) { | 414 TEST_F(OverscrollNavigationOverlayTest, Navigation_PaintUpdate) { |
| 316 PerformBackNavigationViaSliderCallbacks(); | 415 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHSCREEN); |
| 317 ReceivePaintUpdate(); | 416 ReceivePaintUpdate(); |
| 318 | 417 |
| 319 // Paint updates until the navigation is committed typically represent updates | 418 // Paint updates until the navigation is committed typically represent updates |
| 320 // for the previous page, so we should still be observing. | 419 // for the previous page, so we should still be observing. |
| 321 EXPECT_TRUE(GetOverlay()->web_contents()); | 420 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 322 | 421 |
| 323 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 422 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 324 contents()->GetPendingMainFrame()->SendNavigate( | 423 contents()->GetPendingMainFrame()->SendNavigate( |
| 325 pending->GetUniqueID(), false, pending->GetURL()); | 424 pending->GetUniqueID(), false, pending->GetURL()); |
| 326 ReceivePaintUpdate(); | 425 ReceivePaintUpdate(); |
| 327 | 426 |
| 328 // Navigation was committed and the paint update was received - we should no | 427 // Navigation was committed and the paint update was received - we should no |
| 329 // longer be observing. | 428 // longer be observing. |
| 330 EXPECT_FALSE(GetOverlay()->web_contents()); | 429 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 331 EXPECT_EQ(contents()->GetURL(), third()); | 430 EXPECT_EQ(contents()->GetURL(), third()); |
| 332 } | 431 } |
| 333 | 432 |
| 334 // Tests that an overscroll navigation that receives a loading update actually | 433 // Tests that an overscroll navigation that receives a loading update actually |
| 335 // stops observing. | 434 // stops observing. |
| 336 TEST_F(OverscrollNavigationOverlayTest, Navigation_LoadingUpdate) { | 435 TEST_F(OverscrollNavigationOverlayTest, Navigation_LoadingUpdate) { |
| 337 PerformBackNavigationViaSliderCallbacks(); | 436 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 338 EXPECT_TRUE(GetOverlay()->web_contents()); | 437 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 339 // DidStopLoading for any navigation should always reset the load flag and | 438 // DidStopLoading for any navigation should always reset the load flag and |
| 340 // dismiss the overlay even if the pending navigation wasn't committed - | 439 // 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 | 440 // 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 | 441 // (which can happen if a new navigation is performed while while a GestureNav |
| 343 // navigation is in progress). | 442 // navigation is in progress). |
| 344 contents()->TestSetIsLoading(false); | 443 contents()->TestSetIsLoading(false); |
| 345 EXPECT_FALSE(GetOverlay()->web_contents()); | 444 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 346 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); | 445 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); |
| 347 contents()->GetPendingMainFrame()->SendNavigate( | 446 contents()->GetPendingMainFrame()->SendNavigate( |
| 348 pending->GetUniqueID(), false, pending->GetURL()); | 447 pending->GetUniqueID(), false, pending->GetURL()); |
| 349 EXPECT_EQ(contents()->GetURL(), third()); | 448 EXPECT_EQ(contents()->GetURL(), third()); |
| 350 } | 449 } |
| 351 | 450 |
| 352 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) { | 451 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) { |
| 353 ui::ScopedAnimationDurationScaleMode normal_duration_( | 452 ui::ScopedAnimationDurationScaleMode normal_duration_( |
| 354 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 453 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
| 355 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST); | 454 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST, |
| 455 OVERSCROLL_TOUCHSCREEN); |
| 356 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); | 456 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
| 357 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); | 457 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); |
| 358 OverscrollTestWebContents* test_web_contents = | 458 OverscrollTestWebContents* test_web_contents = |
| 359 static_cast<OverscrollTestWebContents*>(web_contents()); | 459 static_cast<OverscrollTestWebContents*>(web_contents()); |
| 360 test_web_contents->set_is_being_destroyed(true); | 460 test_web_contents->set_is_being_destroyed(true); |
| 361 test_web_contents->ResetContentNativeView(); | 461 test_web_contents->ResetContentNativeView(); |
| 362 test_web_contents->ResetNativeView(); | 462 test_web_contents->ResetNativeView(); |
| 363 // Ensure a clean close. | 463 // Ensure a clean close. |
| 364 } | 464 } |
| 365 | 465 |
| 366 // Tests that we can handle the case when the load completes as soon as the | 466 // Tests that we can handle the case when the load completes as soon as the |
| 367 // navigation is started. | 467 // navigation is started. |
| 368 TEST_F(OverscrollNavigationOverlayTest, ImmediateLoadOnNavigate) { | 468 TEST_F(OverscrollNavigationOverlayTest, ImmediateLoadOnNavigate) { |
| 369 PerformBackNavigationViaSliderCallbacks(); | 469 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 370 // This observer will force the page load to complete as soon as the | 470 // This observer will force the page load to complete as soon as the |
| 371 // navigation starts. | 471 // navigation starts. |
| 372 ImmediateLoadObserver immediate_nav(contents()); | 472 ImmediateLoadObserver immediate_nav(contents()); |
| 373 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST); | 473 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST, |
| 474 OVERSCROLL_TOUCHPAD); |
| 374 // This will start and immediately complete the navigation. | 475 // This will start and immediately complete the navigation. |
| 375 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); | 476 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); |
| 376 EXPECT_FALSE(GetOverlay()->window_.get()); | 477 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 478 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2); |
| 479 histogram_tester()->ExpectBucketCount(kUmaNavigated, BACK_TOUCHPAD, 2); |
| 480 EXPECT_EQ(2, action_tester()->GetActionCount(kActionNavigatedBack)); |
| 377 } | 481 } |
| 378 | 482 |
| 379 // Tests that swapping the overlay window at the end of a gesture caused by the | 483 // 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 | 484 // start of a new overscroll does not crash and the events still reach the new |
| 381 // overlay window. | 485 // overlay window. |
| 382 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { | 486 TEST_F(OverscrollNavigationOverlayTest, OverlayWindowSwap) { |
| 383 PerformBackNavigationViaSliderCallbacks(); | 487 PerformBackNavigationViaSliderCallbacks(OVERSCROLL_TOUCHPAD); |
| 384 aura::Window* first_overlay_window = GetOverlay()->window_.get(); | 488 aura::Window* first_overlay_window = GetOverlay()->window_.get(); |
| 385 EXPECT_TRUE(GetOverlay()->web_contents()); | 489 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 386 EXPECT_TRUE(first_overlay_window); | 490 EXPECT_TRUE(first_overlay_window); |
| 387 | 491 |
| 388 // At this stage, the overlay window is covering the web contents. Configure | 492 // At this stage, the overlay window is covering the web contents. Configure |
| 389 // the animator of the overlay window for the test. | 493 // the animator of the overlay window for the test. |
| 390 ui::ScopedAnimationDurationScaleMode normal_duration( | 494 ui::ScopedAnimationDurationScaleMode normal_duration( |
| 391 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 495 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
| 392 ui::LayerAnimator* animator = GetOverlay()->window_->layer()->GetAnimator(); | 496 ui::LayerAnimator* animator = GetOverlay()->window_->layer()->GetAnimator(); |
| 393 animator->set_disable_timer_for_test(true); | 497 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()); | 554 EXPECT_TRUE(GetOverlay()->window_.get()); |
| 451 | 555 |
| 452 // Load the page. | 556 // Load the page. |
| 453 contents()->CommitPendingNavigation(); | 557 contents()->CommitPendingNavigation(); |
| 454 ReceivePaintUpdate(); | 558 ReceivePaintUpdate(); |
| 455 EXPECT_FALSE(GetOverlay()->window_.get()); | 559 EXPECT_FALSE(GetOverlay()->window_.get()); |
| 456 EXPECT_EQ(contents()->GetURL(), first()); | 560 EXPECT_EQ(contents()->GetURL(), first()); |
| 457 } | 561 } |
| 458 | 562 |
| 459 } // namespace content | 563 } // namespace content |
| OLD | NEW |