| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/engagement/site_engagement_helper.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 5 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 6 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| 7 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
| 8 #include "base/values.h" | 12 #include "base/values.h" |
| 9 #include "chrome/browser/engagement/site_engagement_helper.h" | |
| 10 #include "chrome/browser/engagement/site_engagement_service.h" | 13 #include "chrome/browser/engagement/site_engagement_service.h" |
| 11 #include "chrome/browser/engagement/site_engagement_service_factory.h" | 14 #include "chrome/browser/engagement/site_engagement_service_factory.h" |
| 12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
| 16 #include "content/public/browser/page_navigator.h" | 19 #include "content/public/browser/page_navigator.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 21 |
| 19 class SiteEngagementHelperTest : public BrowserWithTestWindowTest { | 22 class SiteEngagementHelperTest : public BrowserWithTestWindowTest { |
| 20 public: | 23 public: |
| 21 // Create a SiteEngagementHelper. Called here as friend class methods cannot | 24 // Create a SiteEngagementHelper. Called here as friend class methods cannot |
| 22 // be called in tests. | 25 // be called in tests. |
| 23 scoped_ptr<SiteEngagementHelper> CreateHelper( | 26 scoped_ptr<SiteEngagementHelper> CreateHelper( |
| 24 content::WebContents* web_contents) { | 27 content::WebContents* web_contents) { |
| 25 scoped_ptr<SiteEngagementHelper> helper( | 28 scoped_ptr<SiteEngagementHelper> helper( |
| 26 new SiteEngagementHelper(web_contents)); | 29 new SiteEngagementHelper(web_contents)); |
| 27 DCHECK(helper.get()); | 30 DCHECK(helper.get()); |
| 28 | 31 |
| 29 return helper.Pass(); | 32 return helper; |
| 30 } | 33 } |
| 31 | 34 |
| 32 void TrackingStarted(SiteEngagementHelper* helper) { | 35 void TrackingStarted(SiteEngagementHelper* helper) { |
| 33 helper->input_tracker_.TrackingStarted(); | 36 helper->input_tracker_.TrackingStarted(); |
| 34 helper->media_tracker_.TrackingStarted(); | 37 helper->media_tracker_.TrackingStarted(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 // Simulate a user interaction event and handle it. | 40 // Simulate a user interaction event and handle it. |
| 38 void HandleUserInput(SiteEngagementHelper* helper, | 41 void HandleUserInput(SiteEngagementHelper* helper, |
| 39 blink::WebInputEvent::Type type) { | 42 blink::WebInputEvent::Type type) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 } | 61 } |
| 59 | 62 |
| 60 void MediaStoppedPlaying(SiteEngagementHelper* helper) { | 63 void MediaStoppedPlaying(SiteEngagementHelper* helper) { |
| 61 helper->media_tracker_.MediaStoppedPlaying( | 64 helper->media_tracker_.MediaStoppedPlaying( |
| 62 content::WebContentsObserver::MediaPlayerId(nullptr, 1)); | 65 content::WebContentsObserver::MediaPlayerId(nullptr, 1)); |
| 63 } | 66 } |
| 64 | 67 |
| 65 // Set a pause timer on the input tracker for test purposes. | 68 // Set a pause timer on the input tracker for test purposes. |
| 66 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper, | 69 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper, |
| 67 scoped_ptr<base::Timer> timer) { | 70 scoped_ptr<base::Timer> timer) { |
| 68 helper->input_tracker_.SetPauseTimerForTesting(timer.Pass()); | 71 helper->input_tracker_.SetPauseTimerForTesting(std::move(timer)); |
| 69 } | 72 } |
| 70 | 73 |
| 71 // Set a pause timer on the input tracker for test purposes. | 74 // Set a pause timer on the input tracker for test purposes. |
| 72 void SetMediaTrackerPauseTimer(SiteEngagementHelper* helper, | 75 void SetMediaTrackerPauseTimer(SiteEngagementHelper* helper, |
| 73 scoped_ptr<base::Timer> timer) { | 76 scoped_ptr<base::Timer> timer) { |
| 74 helper->media_tracker_.SetPauseTimerForTesting(timer.Pass()); | 77 helper->media_tracker_.SetPauseTimerForTesting(std::move(timer)); |
| 75 } | 78 } |
| 76 | 79 |
| 77 bool IsTrackingInput(SiteEngagementHelper* helper) { | 80 bool IsTrackingInput(SiteEngagementHelper* helper) { |
| 78 return helper->input_tracker_.is_tracking(); | 81 return helper->input_tracker_.is_tracking(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 void NavigateWithDisposition(GURL& url, WindowOpenDisposition disposition) { | 84 void NavigateWithDisposition(GURL& url, WindowOpenDisposition disposition) { |
| 82 content::NavigationController* controller = | 85 content::NavigationController* controller = |
| 83 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); | 86 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); |
| 84 browser()->OpenURL( | 87 browser()->OpenURL( |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // When the timer fires, callbacks are added. | 577 // When the timer fires, callbacks are added. |
| 575 input_tracker_timer->Fire(); | 578 input_tracker_timer->Fire(); |
| 576 EXPECT_FALSE(input_tracker_timer->IsRunning()); | 579 EXPECT_FALSE(input_tracker_timer->IsRunning()); |
| 577 EXPECT_TRUE(IsTrackingInput(helper.get())); | 580 EXPECT_TRUE(IsTrackingInput(helper.get())); |
| 578 | 581 |
| 579 // Navigation should start the initial delay timer again. | 582 // Navigation should start the initial delay timer again. |
| 580 NavigateWithDisposition(url1, CURRENT_TAB); | 583 NavigateWithDisposition(url1, CURRENT_TAB); |
| 581 EXPECT_TRUE(input_tracker_timer->IsRunning()); | 584 EXPECT_TRUE(input_tracker_timer->IsRunning()); |
| 582 EXPECT_FALSE(IsTrackingInput(helper.get())); | 585 EXPECT_FALSE(IsTrackingInput(helper.get())); |
| 583 } | 586 } |
| OLD | NEW |