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
3 // found in the LICENSE file.
5 #include "chrome/browser/sessions/session_restore_stats_collector.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/test/simple_test_tick_clock.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/notification_types.h"
12 #include "content/public/browser/render_widget_host.h"
13 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/test_browser_thread.h"
16 #include "content/public/test/test_web_contents_factory.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 using TabLoaderStats
= SessionRestoreStatsCollector::TabLoaderStats
;
22 using StatsReportingDelegate
=
23 SessionRestoreStatsCollector::StatsReportingDelegate
;
25 // A mock StatsReportingDelegate. This is used by the unittests to validate the
26 // reporting and lifetime behaviour of the SessionRestoreStatsCollector under
28 class MockStatsReportingDelegate
: public StatsReportingDelegate
{
30 MockStatsReportingDelegate()
31 : report_tab_loader_stats_call_count_(0u),
32 report_tab_deferred_call_count_(0u),
33 report_deferred_tab_loaded_call_count_(0u),
34 report_stats_collector_death_call_count_(0u) {}
36 ~MockStatsReportingDelegate() override
{ EnsureNoUnexpectedCalls(); }
38 void ReportTabLoaderStats(const TabLoaderStats
& stats
) override
{
39 report_tab_loader_stats_call_count_
++;
40 tab_loader_stats_
= stats
;
43 void ReportTabDeferred() override
{ report_tab_deferred_call_count_
++; }
45 void ReportDeferredTabLoaded() override
{
46 report_deferred_tab_loaded_call_count_
++;
49 // This is not part of the StatsReportingDelegate, but an added function that
50 // is invoked by the PassthroughStatsReportingDelegate when it dies. This
51 // allows the tests to be notified the moment the underlying stats collector
53 void ReportStatsCollectorDeath() {
54 report_stats_collector_death_call_count_
++;
57 void ExpectReportTabLoaderStatsCalled(size_t tab_count
,
59 size_t tabs_load_started
,
61 int foreground_tab_first_loaded_ms
,
62 int foreground_tab_first_paint_ms
,
63 int non_deferred_tabs_loaded_ms
,
64 size_t parallel_tab_loads
) {
65 EXPECT_LT(0u, report_tab_loader_stats_call_count_
);
66 report_tab_loader_stats_call_count_
--;
68 EXPECT_EQ(tab_count
, tab_loader_stats_
.tab_count
);
69 EXPECT_EQ(tabs_deferred
, tab_loader_stats_
.tabs_deferred
);
70 EXPECT_EQ(tabs_load_started
, tab_loader_stats_
.tabs_load_started
);
71 EXPECT_EQ(tabs_loaded
, tab_loader_stats_
.tabs_loaded
);
72 EXPECT_EQ(base::TimeDelta::FromMilliseconds(foreground_tab_first_loaded_ms
),
73 tab_loader_stats_
.foreground_tab_first_loaded
);
74 EXPECT_EQ(base::TimeDelta::FromMilliseconds(foreground_tab_first_paint_ms
),
75 tab_loader_stats_
.foreground_tab_first_paint
);
76 EXPECT_EQ(base::TimeDelta::FromMilliseconds(non_deferred_tabs_loaded_ms
),
77 tab_loader_stats_
.non_deferred_tabs_loaded
);
78 EXPECT_EQ(parallel_tab_loads
, tab_loader_stats_
.parallel_tab_loads
);
81 void ExpectReportTabDeferredCalled() {
82 EXPECT_LT(0u, report_tab_deferred_call_count_
);
83 report_tab_deferred_call_count_
--;
86 void ExpectReportDeferredTabLoadedCalled() {
87 EXPECT_LT(0u, report_deferred_tab_loaded_call_count_
);
88 report_deferred_tab_loaded_call_count_
--;
91 void ExpectReportStatsCollectorDeathCalled() {
92 EXPECT_LT(0u, report_stats_collector_death_call_count_
);
93 report_stats_collector_death_call_count_
--;
96 void EnsureNoUnexpectedCalls() {
97 EXPECT_EQ(0u, report_tab_loader_stats_call_count_
);
98 EXPECT_EQ(0u, report_tab_deferred_call_count_
);
99 EXPECT_EQ(0u, report_deferred_tab_loaded_call_count_
);
100 EXPECT_EQ(0u, report_stats_collector_death_call_count_
);
102 report_tab_loader_stats_call_count_
= 0u;
103 report_tab_deferred_call_count_
= 0u;
104 report_deferred_tab_loaded_call_count_
= 0u;
105 report_stats_collector_death_call_count_
= 0u;
106 tab_loader_stats_
= TabLoaderStats();
110 size_t report_tab_loader_stats_call_count_
;
111 size_t report_tab_deferred_call_count_
;
112 size_t report_deferred_tab_loaded_call_count_
;
113 size_t report_stats_collector_death_call_count_
;
114 TabLoaderStats tab_loader_stats_
;
116 DISALLOW_COPY_AND_ASSIGN(MockStatsReportingDelegate
);
119 // A pass-through stats reporting delegate. This is used to decouple the
120 // lifetime of the mock reporting delegate from the SessionRestoreStatsCollector
121 // under test. The SessionRestoreStatsCollector has ownership of this delegate,
122 // which will notify the mock delegate upon its death.
123 class PassthroughStatsReportingDelegate
: public StatsReportingDelegate
{
125 PassthroughStatsReportingDelegate() : reporting_delegate_(nullptr) {}
126 ~PassthroughStatsReportingDelegate() override
{
127 reporting_delegate_
->ReportStatsCollectorDeath();
130 void set_reporting_delegate(MockStatsReportingDelegate
* reporting_delegate
) {
131 reporting_delegate_
= reporting_delegate
;
134 void ReportTabLoaderStats(const TabLoaderStats
& tab_loader_stats
) override
{
135 reporting_delegate_
->ReportTabLoaderStats(tab_loader_stats
);
138 void ReportTabDeferred() override
{
139 reporting_delegate_
->ReportTabDeferred();
142 void ReportDeferredTabLoaded() override
{
143 reporting_delegate_
->ReportDeferredTabLoaded();
147 MockStatsReportingDelegate
* reporting_delegate_
;
149 DISALLOW_COPY_AND_ASSIGN(PassthroughStatsReportingDelegate
);
154 class TestSessionRestoreStatsCollector
: public SessionRestoreStatsCollector
{
156 using SessionRestoreStatsCollector::Observe
;
158 TestSessionRestoreStatsCollector(
159 scoped_ptr
<base::TickClock
> tick_clock
,
160 scoped_ptr
<StatsReportingDelegate
> reporting_delegate
)
161 : SessionRestoreStatsCollector(tick_clock
->NowTicks(),
162 reporting_delegate
.Pass()) {
163 set_tick_clock(tick_clock
.Pass());
167 friend class base::RefCounted
<TestSessionRestoreStatsCollector
>;
169 ~TestSessionRestoreStatsCollector() override
{}
171 base::SimpleTestTickClock
* test_tick_clock_
;
173 DISALLOW_COPY_AND_ASSIGN(TestSessionRestoreStatsCollector
);
176 class SessionRestoreStatsCollectorTest
: public testing::Test
{
178 using RestoredTab
= SessionRestoreDelegate::RestoredTab
;
180 SessionRestoreStatsCollectorTest()
181 : ui_thread_(content::BrowserThread::UI
, &message_loop_
) {}
183 void SetUp() override
{
184 test_web_contents_factory_
.reset(new content::TestWebContentsFactory
);
186 // Ownership of the reporting delegate is passed to the
187 // SessionRestoreStatsCollector, but a raw pointer is kept to it so it can
188 // be queried by the test.
189 passthrough_reporting_delegate_
= new PassthroughStatsReportingDelegate();
191 // Ownership of this clock is passed to the SessionRestoreStatsCollector.
192 // A raw pointer is kept to it so that it can be modified from the outside.
193 // The unittest must take care to access the clock only while the
194 // SessionRestoreStatsCollector under test is still alive.
195 test_tick_clock_
= new base::SimpleTestTickClock();
197 // Create a stats collector, keep a raw pointer to it, and detach from it.
198 // The stats collector will stay alive as long as it has not yet completed
199 // its job, and will clean itself up when done.
200 scoped_refptr
<TestSessionRestoreStatsCollector
> stats_collector
=
201 new TestSessionRestoreStatsCollector(
202 scoped_ptr
<base::TickClock
>(test_tick_clock_
),
203 scoped_ptr
<StatsReportingDelegate
>(
204 passthrough_reporting_delegate_
));
205 stats_collector_
= stats_collector
.get();
206 stats_collector
= nullptr;
209 void TearDown() override
{
210 passthrough_reporting_delegate_
= nullptr;
211 test_tick_clock_
= nullptr;
212 stats_collector_
= nullptr;
214 // Clean up any tabs that were generated by the unittest.
215 restored_tabs_
.clear();
216 test_web_contents_factory_
.reset();
219 // Advances the test clock by 1ms.
221 test_tick_clock_
->Advance(base::TimeDelta::FromMilliseconds(1));
224 void Show(size_t tab_index
) {
225 restored_tabs_
[tab_index
].contents()->GetRenderWidgetHostView()->Show();
228 void Hide(size_t tab_index
) {
229 restored_tabs_
[tab_index
].contents()->GetRenderWidgetHostView()->Hide();
232 // Creates a restored tab backed by dummy WebContents/NavigationController/
233 // RenderWidgetHost/RenderWidgetHostView. Returns the index of the restored
234 // tab for future simulation of events.
235 void CreateRestoredTab(bool is_active
) {
236 content::WebContents
* contents
=
237 test_web_contents_factory_
->CreateWebContents(&testing_profile_
);
238 restored_tabs_
.push_back(RestoredTab(contents
, is_active
, false, false));
240 Show(restored_tabs_
.size() - 1);
243 // Helper function for various notification generation.
244 void GenerateControllerNotification(size_t tab_index
, int type
) {
245 content::WebContents
* contents
= restored_tabs_
[tab_index
].contents();
246 content::NavigationController
* controller
= &contents
->GetController();
247 stats_collector_
->Observe(
248 type
, content::Source
<content::NavigationController
>(controller
),
249 content::NotificationService::NoDetails());
252 // Generates a load start notification for the given tab.
253 void GenerateLoadStart(size_t tab_index
) {
254 GenerateControllerNotification(tab_index
, content::NOTIFICATION_LOAD_START
);
257 // Generates a load stop notification for the given tab.
258 void GenerateLoadStop(size_t tab_index
) {
259 GenerateControllerNotification(tab_index
, content::NOTIFICATION_LOAD_STOP
);
262 // Generates a web contents destroyed notification for the given tab.
263 void GenerateWebContentsDestroyed(size_t tab_index
) {
264 content::WebContents
* contents
= restored_tabs_
[tab_index
].contents();
265 stats_collector_
->Observe(content::NOTIFICATION_WEB_CONTENTS_DESTROYED
,
266 content::Source
<content::WebContents
>(contents
),
267 content::NotificationService::NoDetails());
270 // Generates a paint notification for the given tab.
271 void GenerateRenderWidgetHostDidUpdateBackingStore(size_t tab_index
) {
272 content::WebContents
* contents
= restored_tabs_
[tab_index
].contents();
273 content::RenderWidgetHost
* host
=
274 contents
->GetRenderWidgetHostView()->GetRenderWidgetHost();
275 stats_collector_
->Observe(
276 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE
,
277 content::Source
<content::RenderWidgetHost
>(host
),
278 content::NotificationService::NoDetails());
282 void DeferTab(size_t tab_index
) {
283 content::WebContents
* contents
= restored_tabs_
[tab_index
].contents();
284 content::NavigationController
* controller
= &contents
->GetController();
285 stats_collector_
->DeferTab(controller
);
288 // Inputs to the stats collector. Reset prior to each test.
289 base::SimpleTestTickClock
* test_tick_clock_
;
290 std::vector
<RestoredTab
> restored_tabs_
;
292 // Infrastructure needed for using the TestWebContentsFactory. These are
293 // initialized once by the fixture and reused across unittests.
294 base::MessageLoop message_loop_
;
295 TestingProfile testing_profile_
;
296 content::TestBrowserThread ui_thread_
;
298 // A new web contents factory is generated per test. This automatically cleans
299 // up any tabs created by previous tests.
300 scoped_ptr
<content::TestWebContentsFactory
> test_web_contents_factory_
;
302 // These are recreated for each test. The reporting delegate allows the test
303 // to observe the behaviour of the SessionRestoreStatsCollector under test.
304 PassthroughStatsReportingDelegate
* passthrough_reporting_delegate_
;
305 TestSessionRestoreStatsCollector
* stats_collector_
;
308 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollectorTest
);
311 TEST_F(SessionRestoreStatsCollectorTest
, SingleTabPaintBeforeLoad
) {
312 MockStatsReportingDelegate mock_reporting_delegate
;
313 passthrough_reporting_delegate_
->set_reporting_delegate(
314 &mock_reporting_delegate
);
316 CreateRestoredTab(true);
317 stats_collector_
->TrackTabs(restored_tabs_
);
318 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
321 GenerateRenderWidgetHostDidUpdateBackingStore(0);
322 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
326 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 1, 2, 1, 2,
328 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
331 TEST_F(SessionRestoreStatsCollectorTest
, SingleTabPaintAfterLoad
) {
332 MockStatsReportingDelegate mock_reporting_delegate
;
333 passthrough_reporting_delegate_
->set_reporting_delegate(
334 &mock_reporting_delegate
);
336 CreateRestoredTab(true);
337 stats_collector_
->TrackTabs(restored_tabs_
);
341 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
344 GenerateRenderWidgetHostDidUpdateBackingStore(0);
345 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 1, 1, 2, 1,
347 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
350 TEST_F(SessionRestoreStatsCollectorTest
, MultipleTabsLoadSerially
) {
351 MockStatsReportingDelegate mock_reporting_delegate
;
352 passthrough_reporting_delegate_
->set_reporting_delegate(
353 &mock_reporting_delegate
);
355 CreateRestoredTab(true);
356 CreateRestoredTab(false);
357 CreateRestoredTab(false);
358 stats_collector_
->TrackTabs(restored_tabs_
);
359 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
361 // Foreground tab paints then finishes loading.
363 GenerateRenderWidgetHostDidUpdateBackingStore(0);
364 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
367 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
369 // First background tab starts loading, paints, then finishes loading.
371 GenerateLoadStart(1);
372 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
374 GenerateRenderWidgetHostDidUpdateBackingStore(1);
375 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
378 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
380 // Second background tab starts loading, finishes loading, but never paints.
382 GenerateLoadStart(2);
383 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
387 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(3, 0, 3, 3, 2, 1, 7,
389 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
390 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
393 TEST_F(SessionRestoreStatsCollectorTest
, MultipleTabsLoadSimultaneously
) {
394 MockStatsReportingDelegate mock_reporting_delegate
;
395 passthrough_reporting_delegate_
->set_reporting_delegate(
396 &mock_reporting_delegate
);
398 CreateRestoredTab(true);
399 CreateRestoredTab(false);
400 CreateRestoredTab(false);
401 stats_collector_
->TrackTabs(restored_tabs_
);
402 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
404 // Foreground tab paints then finishes loading.
406 GenerateRenderWidgetHostDidUpdateBackingStore(0);
407 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
410 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
412 // Both background tabs start loading at the same time. The first one paints
413 // before finishing loading, the second one paints after finishing loading
414 // (the stats collector never sees the paint event).
416 GenerateLoadStart(1);
417 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
418 GenerateLoadStart(2);
419 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
421 GenerateRenderWidgetHostDidUpdateBackingStore(1);
422 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
425 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
428 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(3, 0, 3, 3, 2, 1, 6,
430 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
431 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
434 TEST_F(SessionRestoreStatsCollectorTest
, DeferredTabs
) {
435 MockStatsReportingDelegate mock_reporting_delegate
;
436 passthrough_reporting_delegate_
->set_reporting_delegate(
437 &mock_reporting_delegate
);
439 CreateRestoredTab(true);
440 CreateRestoredTab(false);
441 stats_collector_
->TrackTabs(restored_tabs_
);
442 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
444 // Foreground tab paints, then the background tab is deferred.
446 GenerateRenderWidgetHostDidUpdateBackingStore(0);
447 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
449 mock_reporting_delegate
.ExpectReportTabDeferredCalled();
450 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
452 // Foreground tab finishes loading and stats get reported.
455 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(2, 1, 1, 1, 2, 1, 2,
457 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
459 // Background tab starts loading, paints and stops loading. This fires off a
460 // deferred tab loaded notification.
462 GenerateLoadStart(1);
463 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
465 GenerateRenderWidgetHostDidUpdateBackingStore(1);
466 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
469 mock_reporting_delegate
.ExpectReportDeferredTabLoadedCalled();
470 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
471 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
474 TEST_F(SessionRestoreStatsCollectorTest
, FocusSwitchNoForegroundPaintOrLoad
) {
475 MockStatsReportingDelegate mock_reporting_delegate
;
476 passthrough_reporting_delegate_
->set_reporting_delegate(
477 &mock_reporting_delegate
);
479 CreateRestoredTab(true);
480 stats_collector_
->TrackTabs(restored_tabs_
);
481 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
483 // Create another tab and make it the foreground tab. This tab is not actually
484 // being tracked by the SessionRestoreStatsCollector, but its paint events
486 CreateRestoredTab(false);
490 // Load and paint the restored tab (now the background tab). Don't expect
491 // any calls to the mock as a visible tab paint has not yet been observed.
493 GenerateRenderWidgetHostDidUpdateBackingStore(0);
494 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
497 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
499 // Mark the new foreground tab as having painted. This should cause the
500 // stats to be emitted, but with empty foreground paint and load values.
502 GenerateRenderWidgetHostDidUpdateBackingStore(1);
503 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 1, 0, 0, 2,
505 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
506 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
509 TEST_F(SessionRestoreStatsCollectorTest
, FocusSwitchNoForegroundPaint
) {
510 MockStatsReportingDelegate mock_reporting_delegate
;
511 passthrough_reporting_delegate_
->set_reporting_delegate(
512 &mock_reporting_delegate
);
514 CreateRestoredTab(true);
515 stats_collector_
->TrackTabs(restored_tabs_
);
516 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
518 // Load the foreground tab.
521 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
523 // Create another tab and make it the foreground tab. This tab is not actually
524 // being tracked by the SessionRestoreStatsCollector, but its paint events
525 // will still be observed.
526 CreateRestoredTab(false);
530 // Load and paint the restored tab (now the background tab). Don't expect
531 // any calls to the mock as a visible tab paint has not yet been observed.
533 GenerateRenderWidgetHostDidUpdateBackingStore(0);
534 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
536 // Mark the new foreground tab as having painted. This should cause the
537 // stats to be emitted, but with an empty foreground paint value.
539 GenerateRenderWidgetHostDidUpdateBackingStore(1);
540 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 1, 1, 0, 1,
542 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
543 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
546 TEST_F(SessionRestoreStatsCollectorTest
, LoadingTabDestroyedBeforePaint
) {
547 MockStatsReportingDelegate mock_reporting_delegate
;
548 passthrough_reporting_delegate_
->set_reporting_delegate(
549 &mock_reporting_delegate
);
551 CreateRestoredTab(true);
552 stats_collector_
->TrackTabs(restored_tabs_
);
553 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
555 // Destroy the tab. Expect all timings to be zero.
556 GenerateWebContentsDestroyed(0);
557 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 0, 0, 0, 0,
559 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
560 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
563 TEST_F(SessionRestoreStatsCollectorTest
, LoadingTabDestroyedAfterPaint
) {
564 MockStatsReportingDelegate mock_reporting_delegate
;
565 passthrough_reporting_delegate_
->set_reporting_delegate(
566 &mock_reporting_delegate
);
568 CreateRestoredTab(true);
569 stats_collector_
->TrackTabs(restored_tabs_
);
570 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
573 GenerateRenderWidgetHostDidUpdateBackingStore(0);
574 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
576 // Destroy the tab. Expect both load timings to be zero.
577 GenerateWebContentsDestroyed(0);
578 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 0, 0, 1, 0,
580 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
581 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
584 TEST_F(SessionRestoreStatsCollectorTest
, BrowseAwayBeforePaint
) {
585 MockStatsReportingDelegate mock_reporting_delegate
;
586 passthrough_reporting_delegate_
->set_reporting_delegate(
587 &mock_reporting_delegate
);
589 CreateRestoredTab(true);
590 stats_collector_
->TrackTabs(restored_tabs_
);
591 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
596 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
598 // Reload the tab. Expect the paint timing to be zero.
600 GenerateLoadStart(0);
601 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(1, 0, 1, 1, 1, 0, 1,
603 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
604 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
607 TEST_F(SessionRestoreStatsCollectorTest
, DiscardDeferredTabs
) {
608 MockStatsReportingDelegate mock_reporting_delegate
;
609 passthrough_reporting_delegate_
->set_reporting_delegate(
610 &mock_reporting_delegate
);
612 CreateRestoredTab(true);
613 CreateRestoredTab(false);
614 stats_collector_
->TrackTabs(restored_tabs_
);
615 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
617 // Defer the background tab.
620 mock_reporting_delegate
.ExpectReportTabDeferredCalled();
621 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
623 // Discard the foreground tab. The stats tab loader stats should be reported
624 // with all zero timings.
626 GenerateWebContentsDestroyed(0);
627 mock_reporting_delegate
.ExpectReportTabLoaderStatsCalled(2, 1, 1, 0, 0, 0, 0,
629 mock_reporting_delegate
.EnsureNoUnexpectedCalls();
631 // Destroy the background tab. The collector should release itself.
633 GenerateWebContentsDestroyed(1);
634 mock_reporting_delegate
.ExpectReportStatsCollectorDeathCalled();
635 mock_reporting_delegate
.EnsureNoUnexpectedCalls();