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

Side by Side Diff: chrome/browser/engagement/site_engagement_helper_unittest.cc

Issue 1478643002: Refactor media out of WebContentsImpl to MediaWebContentsObserver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix namespace for cast. Created 5 years 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 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/test/histogram_tester.h" 6 #include "base/test/histogram_tester.h"
7 #include "base/timer/mock_timer.h" 7 #include "base/timer/mock_timer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/engagement/site_engagement_helper.h" 9 #include "chrome/browser/engagement/site_engagement_helper.h"
10 #include "chrome/browser/engagement/site_engagement_service.h" 10 #include "chrome/browser/engagement/site_engagement_service.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 blink::WebInputEvent::Type type) { 46 blink::WebInputEvent::Type type) {
47 helper->input_tracker_.DidGetUserInteraction(type); 47 helper->input_tracker_.DidGetUserInteraction(type);
48 helper->input_tracker_.TrackingStarted(); 48 helper->input_tracker_.TrackingStarted();
49 } 49 }
50 50
51 void HandleMediaPlaying(SiteEngagementHelper* helper, bool is_hidden) { 51 void HandleMediaPlaying(SiteEngagementHelper* helper, bool is_hidden) {
52 helper->RecordMediaPlaying(is_hidden); 52 helper->RecordMediaPlaying(is_hidden);
53 } 53 }
54 54
55 void MediaStartedPlaying(SiteEngagementHelper* helper) { 55 void MediaStartedPlaying(SiteEngagementHelper* helper) {
56 helper->media_tracker_.MediaStartedPlaying(); 56 helper->media_tracker_.MediaStartedPlaying(
57 content::WebContentsObserver::MediaPlayerId(nullptr, 1));
57 } 58 }
58 59
59 void MediaPaused(SiteEngagementHelper* helper) { 60 void MediaStoppedPlaying(SiteEngagementHelper* helper) {
60 helper->media_tracker_.MediaPaused(); 61 helper->media_tracker_.MediaStoppedPlaying(
62 content::WebContentsObserver::MediaPlayerId(nullptr, 1));
61 } 63 }
62 64
63 // Set a pause timer on the input tracker for test purposes. 65 // Set a pause timer on the input tracker for test purposes.
64 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper, 66 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper,
65 scoped_ptr<base::Timer> timer) { 67 scoped_ptr<base::Timer> timer) {
66 helper->input_tracker_.SetPauseTimerForTesting(timer.Pass()); 68 helper->input_tracker_.SetPauseTimerForTesting(timer.Pass());
67 } 69 }
68 70
69 // Set a pause timer on the input tracker for test purposes. 71 // Set a pause timer on the input tracker for test purposes.
70 void SetMediaTrackerPauseTimer(SiteEngagementHelper* helper, 72 void SetMediaTrackerPauseTimer(SiteEngagementHelper* helper,
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 EXPECT_DOUBLE_EQ(0.52, service->GetScore(url1)); 230 EXPECT_DOUBLE_EQ(0.52, service->GetScore(url1));
229 EXPECT_EQ(0, service->GetScore(url2)); 231 EXPECT_EQ(0, service->GetScore(url2));
230 EXPECT_TRUE(media_tracker_timer->IsRunning()); 232 EXPECT_TRUE(media_tracker_timer->IsRunning());
231 233
232 web_contents->WasHidden(); 234 web_contents->WasHidden();
233 media_tracker_timer->Fire(); 235 media_tracker_timer->Fire();
234 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1)); 236 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1));
235 EXPECT_EQ(0, service->GetScore(url2)); 237 EXPECT_EQ(0, service->GetScore(url2));
236 EXPECT_TRUE(media_tracker_timer->IsRunning()); 238 EXPECT_TRUE(media_tracker_timer->IsRunning());
237 239
238 MediaPaused(helper.get()); 240 MediaStoppedPlaying(helper.get());
239 media_tracker_timer->Fire(); 241 media_tracker_timer->Fire();
240 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1)); 242 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1));
241 EXPECT_EQ(0, service->GetScore(url2)); 243 EXPECT_EQ(0, service->GetScore(url2));
242 EXPECT_TRUE(media_tracker_timer->IsRunning()); 244 EXPECT_TRUE(media_tracker_timer->IsRunning());
243 245
244 web_contents->WasShown(); 246 web_contents->WasShown();
245 media_tracker_timer->Fire(); 247 media_tracker_timer->Fire();
246 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1)); 248 EXPECT_DOUBLE_EQ(0.53, service->GetScore(url1));
247 EXPECT_EQ(0, service->GetScore(url2)); 249 EXPECT_EQ(0, service->GetScore(url2));
248 EXPECT_TRUE(media_tracker_timer->IsRunning()); 250 EXPECT_TRUE(media_tracker_timer->IsRunning());
(...skipping 14 matching lines...) Expand all
263 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1)); 265 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1));
264 EXPECT_EQ(0.52, service->GetScore(url2)); 266 EXPECT_EQ(0.52, service->GetScore(url2));
265 EXPECT_TRUE(media_tracker_timer->IsRunning()); 267 EXPECT_TRUE(media_tracker_timer->IsRunning());
266 268
267 web_contents->WasHidden(); 269 web_contents->WasHidden();
268 media_tracker_timer->Fire(); 270 media_tracker_timer->Fire();
269 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1)); 271 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1));
270 EXPECT_EQ(0.53, service->GetScore(url2)); 272 EXPECT_EQ(0.53, service->GetScore(url2));
271 EXPECT_TRUE(media_tracker_timer->IsRunning()); 273 EXPECT_TRUE(media_tracker_timer->IsRunning());
272 274
273 MediaPaused(helper.get()); 275 MediaStoppedPlaying(helper.get());
274 web_contents->WasShown(); 276 web_contents->WasShown();
275 media_tracker_timer->Fire(); 277 media_tracker_timer->Fire();
276 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1)); 278 EXPECT_DOUBLE_EQ(0.55, service->GetScore(url1));
277 EXPECT_EQ(0.53, service->GetScore(url2)); 279 EXPECT_EQ(0.53, service->GetScore(url2));
278 EXPECT_TRUE(media_tracker_timer->IsRunning()); 280 EXPECT_TRUE(media_tracker_timer->IsRunning());
279 } 281 }
280 282
281 TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) { 283 TEST_F(SiteEngagementHelperTest, MixedInputEngagementAccumulation) {
282 AddTab(browser(), GURL("about:blank")); 284 AddTab(browser(), GURL("about:blank"));
283 GURL url1("https://www.google.com/"); 285 GURL url1("https://www.google.com/");
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 // When the timer fires, callbacks are added. 574 // When the timer fires, callbacks are added.
573 input_tracker_timer->Fire(); 575 input_tracker_timer->Fire();
574 EXPECT_FALSE(input_tracker_timer->IsRunning()); 576 EXPECT_FALSE(input_tracker_timer->IsRunning());
575 EXPECT_TRUE(IsTrackingInput(helper.get())); 577 EXPECT_TRUE(IsTrackingInput(helper.get()));
576 578
577 // Navigation should start the initial delay timer again. 579 // Navigation should start the initial delay timer again.
578 NavigateWithDisposition(url1, CURRENT_TAB); 580 NavigateWithDisposition(url1, CURRENT_TAB);
579 EXPECT_TRUE(input_tracker_timer->IsRunning()); 581 EXPECT_TRUE(input_tracker_timer->IsRunning());
580 EXPECT_FALSE(IsTrackingInput(helper.get())); 582 EXPECT_FALSE(IsTrackingInput(helper.get()));
581 } 583 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.cc ('k') | chromecast/browser/cast_content_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698