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

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

Issue 1411123002: Fix crash in SiteEngagementServiceHelper when switching render view hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@startup_timer
Patch Set: fix compile Created 5 years, 2 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
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Set a pause timer on the input tracker for test purposes. 52 // Set a pause timer on the input tracker for test purposes.
53 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper, 53 void SetInputTrackerPauseTimer(SiteEngagementHelper* helper,
54 scoped_ptr<base::Timer> timer) { 54 scoped_ptr<base::Timer> timer) {
55 helper->input_tracker_.SetPauseTimerForTesting(timer.Pass()); 55 helper->input_tracker_.SetPauseTimerForTesting(timer.Pass());
56 } 56 }
57 57
58 bool IsTracking(SiteEngagementHelper* helper) { 58 bool IsTracking(SiteEngagementHelper* helper) {
59 return helper->input_tracker_.is_tracking(); 59 return helper->input_tracker_.is_tracking();
60 } 60 }
61
62 bool IsActive(SiteEngagementHelper* helper) {
63 return helper->input_tracker_.IsActive();
64 }
65
66 content::RenderViewHost* InputTrackerHost(SiteEngagementHelper* helper) {
67 return helper->input_tracker_.host();
68 }
61 }; 69 };
62 70
63 IN_PROC_BROWSER_TEST_F(SiteEngagementServiceBrowserTest, 71 IN_PROC_BROWSER_TEST_F(SiteEngagementServiceBrowserTest,
64 KeyPressEngagementAccumulation) { 72 KeyPressEngagementAccumulation) {
65 GURL url1("https://www.google.com/"); 73 GURL url1("https://www.google.com/");
66 GURL url2("http://www.google.com/"); 74 GURL url2("http://www.google.com/");
67 content::WebContents* web_contents = 75 content::WebContents* web_contents =
68 browser()->tab_strip_model()->GetActiveWebContents(); 76 browser()->tab_strip_model()->GetActiveWebContents();
69 77
70 scoped_ptr<SiteEngagementHelper> helper(CreateHelper(web_contents)); 78 scoped_ptr<SiteEngagementHelper> helper(CreateHelper(web_contents));
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 413
406 base::MockTimer* input_tracker_timer = new base::MockTimer(true, false); 414 base::MockTimer* input_tracker_timer = new base::MockTimer(true, false);
407 scoped_ptr<SiteEngagementHelper> helper(CreateHelper(web_contents)); 415 scoped_ptr<SiteEngagementHelper> helper(CreateHelper(web_contents));
408 SetInputTrackerPauseTimer(helper.get(), make_scoped_ptr(input_tracker_timer)); 416 SetInputTrackerPauseTimer(helper.get(), make_scoped_ptr(input_tracker_timer));
409 417
410 // Navigation starts the initial delay timer. 418 // Navigation starts the initial delay timer.
411 ui_test_utils::NavigateToURL(browser(), url1); 419 ui_test_utils::NavigateToURL(browser(), url1);
412 EXPECT_TRUE(input_tracker_timer->IsRunning()); 420 EXPECT_TRUE(input_tracker_timer->IsRunning());
413 EXPECT_FALSE(IsTracking(helper.get())); 421 EXPECT_FALSE(IsTracking(helper.get()));
414 422
415 content::RenderViewHost* rvh = web_contents->GetRenderViewHost(); 423 content::RenderViewHost* rvh1 = web_contents->GetRenderViewHost();
424
425 ui_test_utils::NavigateToURLWithDisposition(
426 browser(), url2, NEW_BACKGROUND_TAB,
427 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
428 content::RenderViewHost* rvh2 =
429 browser()->tab_strip_model()->GetWebContentsAt(1)->GetRenderViewHost();
416 430
417 // The timer should still be running after the RenderViewHost is changed. 431 // The timer should still be running after the RenderViewHost is changed.
418 helper->RenderViewHostChanged(rvh, rvh); 432 helper->RenderViewHostChanged(rvh1, rvh2);
419 EXPECT_TRUE(input_tracker_timer->IsRunning()); 433 EXPECT_TRUE(input_tracker_timer->IsRunning());
420 EXPECT_FALSE(IsTracking(helper.get())); 434 EXPECT_FALSE(IsTracking(helper.get()));
435 EXPECT_EQ(rvh2, InputTrackerHost(helper.get()));
421 436
422 // Firing the timer should add the callbacks. 437 // Firing the timer should add the callbacks.
423 input_tracker_timer->Fire(); 438 input_tracker_timer->Fire();
424 EXPECT_FALSE(input_tracker_timer->IsRunning()); 439 EXPECT_FALSE(input_tracker_timer->IsRunning());
425 EXPECT_TRUE(IsTracking(helper.get())); 440 EXPECT_TRUE(IsTracking(helper.get()));
426 441
427 // The callbacks should be on readded another RVH change since the timer has 442 // The callbacks should be on readded another RVH change since the timer has
428 // already fired. 443 // already fired.
429 helper->RenderViewHostChanged(rvh, rvh); 444 helper->RenderViewHostChanged(rvh2, rvh1);
430 EXPECT_FALSE(input_tracker_timer->IsRunning()); 445 EXPECT_FALSE(input_tracker_timer->IsRunning());
431 EXPECT_TRUE(IsTracking(helper.get())); 446 EXPECT_TRUE(IsTracking(helper.get()));
447 EXPECT_EQ(rvh1, InputTrackerHost(helper.get()));
432 448
433 // Ensure nothing bad happens with a destroyed RVH. 449 // Ensure nothing bad happens with a destroyed RVH.
434 helper->RenderViewHostChanged(nullptr, rvh); 450 helper->RenderViewHostChanged(nullptr, rvh2);
435 EXPECT_FALSE(input_tracker_timer->IsRunning()); 451 EXPECT_FALSE(input_tracker_timer->IsRunning());
436 EXPECT_TRUE(IsTracking(helper.get())); 452 EXPECT_TRUE(IsTracking(helper.get()));
453 EXPECT_EQ(rvh2, InputTrackerHost(helper.get()));
437 454
438 // Ensure nothing happens when RVH change happens for a hidden tab. 455 // Ensure nothing happens when RVH change happens for a hidden tab.
439 helper->WasHidden(); 456 helper->WasHidden();
440 EXPECT_FALSE(input_tracker_timer->IsRunning()); 457 EXPECT_FALSE(input_tracker_timer->IsRunning());
441 EXPECT_FALSE(IsTracking(helper.get())); 458 EXPECT_FALSE(IsTracking(helper.get()));
442 459
443 helper->RenderViewHostChanged(nullptr, rvh); 460 helper->RenderViewHostChanged(rvh2, rvh1);
444 EXPECT_FALSE(input_tracker_timer->IsRunning()); 461 EXPECT_FALSE(input_tracker_timer->IsRunning());
445 EXPECT_FALSE(IsTracking(helper.get())); 462 EXPECT_FALSE(IsTracking(helper.get()));
463 EXPECT_EQ(nullptr, InputTrackerHost(helper.get()));
446 } 464 }
OLDNEW
« no previous file with comments | « chrome/browser/engagement/site_engagement_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698