Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: content/browser/web_contents/aura/overscroll_navigation_overlay_unittest.cc

Issue 2986483002: Adding metrics logging for Simplified Gesture Navigation. (Closed)
Patch Set: Rebase Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 12 #include "base/test/histogram_tester.h"
13 #include "base/test/user_action_tester.h" 13 #include "base/test/user_action_tester.h"
14 #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" 15 #include "content/browser/web_contents/aura/types.h"
16 #include "content/browser/web_contents/web_contents_view.h" 16 #include "content/browser/web_contents/web_contents_view.h"
17 #include "content/common/frame_messages.h" 17 #include "content/common/frame_messages.h"
18 #include "content/common/view_messages.h" 18 #include "content/common/view_messages.h"
19 #include "content/public/browser/overscroll_configuration.h" 19 #include "content/public/browser/overscroll_configuration.h"
20 #include "content/public/common/browser_side_navigation_policy.h" 20 #include "content/public/common/browser_side_navigation_policy.h"
21 #include "content/public/test/mock_render_process_host.h" 21 #include "content/public/test/mock_render_process_host.h"
22 #include "content/test/test_render_frame_host.h" 22 #include "content/test/test_render_frame_host.h"
23 #include "content/test/test_render_view_host.h" 23 #include "content/test/test_render_view_host.h"
24 #include "content/test/test_web_contents.h" 24 #include "content/test/test_web_contents.h"
25 #include "ui/aura/test/test_windows.h" 25 #include "ui/aura/test/test_windows.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 GetOverlay()->owa_->SetOverscrollSourceForTesting(source); 150 GetOverlay()->owa_->SetOverscrollSourceForTesting(source);
151 std::unique_ptr<aura::Window> window( 151 std::unique_ptr<aura::Window> window(
152 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds())); 152 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()));
153 bool window_created = !!window; 153 bool window_created = !!window;
154 if (window_created) { 154 if (window_created) {
155 histogram_tester()->ExpectTotalCount(kUmaStarted, 1); 155 histogram_tester()->ExpectTotalCount(kUmaStarted, 1);
156 histogram_tester()->ExpectBucketCount( 156 histogram_tester()->ExpectBucketCount(
157 kUmaStarted, source == OverscrollSource::TOUCHPAD ? BACK_TOUCHPAD 157 kUmaStarted, source == OverscrollSource::TOUCHPAD ? BACK_TOUCHPAD
158 : BACK_TOUCHSCREEN, 158 : BACK_TOUCHSCREEN,
159 1); 159 1);
160 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); 160 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::BACK);
161 // Performs BACK navigation, sets image from layer_delegate_ on 161 // Performs BACK navigation, sets image from layer_delegate_ on
162 // image_delegate_. 162 // image_delegate_.
163 GetOverlay()->OnOverscrollCompleting(); 163 GetOverlay()->OnOverscrollCompleting();
164 window->SetBounds(gfx::Rect(root_window()->bounds().size())); 164 window->SetBounds(gfx::Rect(root_window()->bounds().size()));
165 165
166 histogram_tester()->ExpectTotalCount(kUmaNavigated, 0); 166 histogram_tester()->ExpectTotalCount(kUmaNavigated, 0);
167 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedBack)); 167 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedBack));
168 168
169 GetOverlay()->OnOverscrollCompleted(std::move(window)); 169 GetOverlay()->OnOverscrollCompleted(std::move(window));
170 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); 170 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1);
171 histogram_tester()->ExpectBucketCount(kUmaNavigated, 171 histogram_tester()->ExpectBucketCount(kUmaNavigated,
172 source == OverscrollSource::TOUCHPAD 172 source == OverscrollSource::TOUCHPAD
173 ? BACK_TOUCHPAD 173 ? BACK_TOUCHPAD
174 : BACK_TOUCHSCREEN, 174 : BACK_TOUCHSCREEN,
175 1); 175 1);
176 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); 176 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack));
177 } else { 177 } else {
178 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); 178 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::NONE);
179 histogram_tester()->ExpectTotalCount(kUmaStarted, 0); 179 histogram_tester()->ExpectTotalCount(kUmaStarted, 0);
180 } 180 }
181 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::NONE); 181 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::NONE);
182 if (IsBrowserSideNavigationEnabled()) 182 if (IsBrowserSideNavigationEnabled())
183 main_test_rfh()->PrepareForCommit(); 183 main_test_rfh()->PrepareForCommit();
184 else 184 else
185 contents()->GetPendingMainFrame()->PrepareForCommit(); 185 contents()->GetPendingMainFrame()->PrepareForCommit();
186 if (window_created) 186 if (window_created)
187 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 187 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
188 else 188 else
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 nullptr); 313 nullptr);
314 } 314 }
315 315
316 // Tests that if a navigation is cancelled, no navigation is performed and the 316 // Tests that if a navigation is cancelled, no navigation is performed and the
317 // state is restored. 317 // state is restored.
318 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) { 318 TEST_F(OverscrollNavigationOverlayTest, CancelNavigation) {
319 GetOverlay()->owa_->SetOverscrollSourceForTesting( 319 GetOverlay()->owa_->SetOverscrollSourceForTesting(
320 OverscrollSource::TOUCHSCREEN); 320 OverscrollSource::TOUCHSCREEN);
321 std::unique_ptr<aura::Window> window = 321 std::unique_ptr<aura::Window> window =
322 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); 322 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds());
323 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); 323 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::BACK);
324 324
325 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); 325 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0);
326 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledBack)); 326 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledBack));
327 327
328 GetOverlay()->OnOverscrollCancelled(); 328 GetOverlay()->OnOverscrollCancelled();
329 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); 329 EXPECT_FALSE(contents()->CrossProcessNavigationPending());
330 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); 330 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::NONE);
331 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); 331 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1);
332 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHSCREEN, 1); 332 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHSCREEN, 1);
333 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); 333 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack));
334 } 334 }
335 335
336 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigation) { 336 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigation) {
337 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); 337 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD);
338 338
339 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD); 339 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD);
340 std::unique_ptr<aura::Window> window = 340 std::unique_ptr<aura::Window> window =
341 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); 341 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds());
342 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); 342 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::FORWARD);
343 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); 343 histogram_tester()->ExpectTotalCount(kUmaStarted, 2);
344 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHPAD, 1); 344 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHPAD, 1);
345 345
346 GetOverlay()->OnOverscrollCompleting(); 346 GetOverlay()->OnOverscrollCompleting();
347 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); 347 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1);
348 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedForward)); 348 EXPECT_EQ(0, action_tester()->GetActionCount(kActionNavigatedForward));
349 349
350 GetOverlay()->OnOverscrollCompleted(std::move(window)); 350 GetOverlay()->OnOverscrollCompleted(std::move(window));
351 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2); 351 histogram_tester()->ExpectTotalCount(kUmaNavigated, 2);
352 histogram_tester()->ExpectBucketCount(kUmaNavigated, FORWARD_TOUCHPAD, 1); 352 histogram_tester()->ExpectBucketCount(kUmaNavigated, FORWARD_TOUCHPAD, 1);
353 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedForward)); 353 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedForward));
354 354
355 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 355 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
356 } 356 }
357 357
358 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigationCancelled) { 358 TEST_F(OverscrollNavigationOverlayTest, ForwardNavigationCancelled) {
359 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); 359 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD);
360 360
361 GetOverlay()->owa_->SetOverscrollSourceForTesting( 361 GetOverlay()->owa_->SetOverscrollSourceForTesting(
362 OverscrollSource::TOUCHSCREEN); 362 OverscrollSource::TOUCHSCREEN);
363 std::unique_ptr<aura::Window> window = 363 std::unique_ptr<aura::Window> window =
364 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds()); 364 GetOverlay()->CreateFrontWindow(GetBackSlideWindowBounds());
365 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::FORWARD); 365 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::FORWARD);
366 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); 366 histogram_tester()->ExpectTotalCount(kUmaStarted, 2);
367 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHSCREEN, 1); 367 histogram_tester()->ExpectBucketCount(kUmaStarted, FORWARD_TOUCHSCREEN, 1);
368 368
369 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0); 369 histogram_tester()->ExpectTotalCount(kUmaCancelled, 0);
370 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledForward)); 370 EXPECT_EQ(0, action_tester()->GetActionCount(kActionCancelledForward));
371 371
372 GetOverlay()->OnOverscrollCancelled(); 372 GetOverlay()->OnOverscrollCancelled();
373 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); 373 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::NONE);
374 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); 374 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1);
375 histogram_tester()->ExpectBucketCount(kUmaCancelled, FORWARD_TOUCHSCREEN, 1); 375 histogram_tester()->ExpectBucketCount(kUmaCancelled, FORWARD_TOUCHSCREEN, 1);
376 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledForward)); 376 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledForward));
377 } 377 }
378 378
379 // Performs two navigations. The second navigation is cancelled, tests that the 379 // Performs two navigations. The second navigation is cancelled, tests that the
380 // first one worked correctly. 380 // first one worked correctly.
381 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) { 381 TEST_F(OverscrollNavigationOverlayTest, CancelAfterSuccessfulNavigation) {
382 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD); 382 PerformBackNavigationViaSliderCallbacks(OverscrollSource::TOUCHPAD);
383 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD); 383 GetOverlay()->owa_->SetOverscrollSourceForTesting(OverscrollSource::TOUCHPAD);
384 std::unique_ptr<aura::Window> wrapper = 384 std::unique_ptr<aura::Window> wrapper =
385 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds()); 385 GetOverlay()->CreateBackWindow(GetBackSlideWindowBounds());
386 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); 386 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::BACK);
387 histogram_tester()->ExpectTotalCount(kUmaStarted, 2); 387 histogram_tester()->ExpectTotalCount(kUmaStarted, 2);
388 histogram_tester()->ExpectBucketCount(kUmaStarted, BACK_TOUCHPAD, 2); 388 histogram_tester()->ExpectBucketCount(kUmaStarted, BACK_TOUCHPAD, 2);
389 389
390 GetOverlay()->OnOverscrollCancelled(); 390 GetOverlay()->OnOverscrollCancelled();
391 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::NONE); 391 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::NONE);
392 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1); 392 histogram_tester()->ExpectTotalCount(kUmaCancelled, 1);
393 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHPAD, 1); 393 histogram_tester()->ExpectBucketCount(kUmaCancelled, BACK_TOUCHPAD, 1);
394 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack)); 394 EXPECT_EQ(1, action_tester()->GetActionCount(kActionCancelledBack));
395 // Navigation metrics shouldn't change. 395 // Navigation metrics shouldn't change.
396 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1); 396 histogram_tester()->ExpectTotalCount(kUmaNavigated, 1);
397 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack)); 397 EXPECT_EQ(1, action_tester()->GetActionCount(kActionNavigatedBack));
398 398
399 EXPECT_TRUE(contents()->CrossProcessNavigationPending()); 399 EXPECT_TRUE(contents()->CrossProcessNavigationPending());
400 NavigationEntry* pending = contents()->GetController().GetPendingEntry(); 400 NavigationEntry* pending = contents()->GetController().GetPendingEntry();
401 contents()->GetPendingMainFrame()->SendNavigateWithTransition( 401 contents()->GetPendingMainFrame()->SendNavigateWithTransition(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 pending->GetUniqueID(), false, pending->GetURL()); 443 pending->GetUniqueID(), false, pending->GetURL());
444 EXPECT_EQ(contents()->GetURL(), third()); 444 EXPECT_EQ(contents()->GetURL(), third());
445 } 445 }
446 446
447 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) { 447 TEST_F(OverscrollNavigationOverlayTest, CloseDuringAnimation) {
448 ui::ScopedAnimationDurationScaleMode normal_duration_( 448 ui::ScopedAnimationDurationScaleMode normal_duration_(
449 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 449 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
450 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST, 450 GetOverlay()->owa_->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST,
451 OverscrollSource::TOUCHSCREEN); 451 OverscrollSource::TOUCHSCREEN);
452 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST); 452 GetOverlay()->owa_->OnOverscrollComplete(OVERSCROLL_EAST);
453 EXPECT_EQ(GetOverlay()->direction_, OverscrollNavigationOverlay::BACK); 453 EXPECT_EQ(GetOverlay()->direction_, NavigationDirection::BACK);
454 OverscrollTestWebContents* test_web_contents = 454 OverscrollTestWebContents* test_web_contents =
455 static_cast<OverscrollTestWebContents*>(web_contents()); 455 static_cast<OverscrollTestWebContents*>(web_contents());
456 test_web_contents->set_is_being_destroyed(true); 456 test_web_contents->set_is_being_destroyed(true);
457 test_web_contents->ResetContentNativeView(); 457 test_web_contents->ResetContentNativeView();
458 test_web_contents->ResetNativeView(); 458 test_web_contents->ResetNativeView();
459 // Ensure a clean close. 459 // Ensure a clean close.
460 } 460 }
461 461
462 // Tests that we can handle the case when the load completes as soon as the 462 // Tests that we can handle the case when the load completes as soon as the
463 // navigation is started. 463 // navigation is started.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 EXPECT_TRUE(GetOverlay()->window_.get()); 550 EXPECT_TRUE(GetOverlay()->window_.get());
551 551
552 // Load the page. 552 // Load the page.
553 contents()->CommitPendingNavigation(); 553 contents()->CommitPendingNavigation();
554 ReceivePaintUpdate(); 554 ReceivePaintUpdate();
555 EXPECT_FALSE(GetOverlay()->window_.get()); 555 EXPECT_FALSE(GetOverlay()->window_.get());
556 EXPECT_EQ(contents()->GetURL(), first()); 556 EXPECT_EQ(contents()->GetURL(), first());
557 } 557 }
558 558
559 } // namespace content 559 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/aura/overscroll_navigation_overlay.cc ('k') | content/browser/web_contents/aura/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698