OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "chrome/browser/sessions/session_restore_stats_collector.h" | |
6 | |
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" | |
18 | |
19 namespace { | |
20 | |
21 using TabLoaderStats = SessionRestoreStatsCollector::TabLoaderStats; | |
22 using StatsReportingDelegate = | |
23 SessionRestoreStatsCollector::StatsReportingDelegate; | |
24 | |
25 // A mock StatsReportingDelegate. This is used by the unittests to validate the | |
26 // reporting and lifetime behaviour of the SessionRestoreStatsCollector under | |
27 // test. | |
28 class MockStatsReportingDelegate : public StatsReportingDelegate { | |
29 public: | |
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) {} | |
35 | |
36 ~MockStatsReportingDelegate() override { EnsureNoUnexpectedCalls(); } | |
37 | |
38 void ReportTabLoaderStats(const TabLoaderStats& stats) override { | |
39 report_tab_loader_stats_call_count_++; | |
40 tab_loader_stats_ = stats; | |
41 } | |
42 | |
43 void ReportTabDeferred() override { report_tab_deferred_call_count_++; } | |
44 | |
45 void ReportDeferredTabLoaded() override { | |
46 report_deferred_tab_loaded_call_count_++; | |
47 } | |
48 | |
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 | |
52 // terminates itself. | |
53 void ReportStatsCollectorDeath() { | |
54 report_stats_collector_death_call_count_++; | |
55 } | |
56 | |
57 void ExpectReportTabLoaderStatsCalled(size_t tab_count, | |
58 size_t tabs_loaded, | |
59 int foreground_tab_first_loaded_ms, | |
60 int foreground_tab_first_paint_ms, | |
61 int non_deferred_tabs_loaded_ms, | |
62 size_t parallel_tab_loads) { | |
63 EXPECT_LT(0u, report_tab_loader_stats_call_count_); | |
64 report_tab_loader_stats_call_count_--; | |
65 | |
66 EXPECT_EQ(tab_count, tab_loader_stats_.tab_count); | |
67 EXPECT_EQ(tabs_loaded, tab_loader_stats_.tabs_loaded); | |
68 EXPECT_EQ(base::TimeDelta::FromMilliseconds(foreground_tab_first_loaded_ms), | |
69 tab_loader_stats_.foreground_tab_first_loaded); | |
70 EXPECT_EQ(base::TimeDelta::FromMilliseconds(foreground_tab_first_paint_ms), | |
71 tab_loader_stats_.foreground_tab_first_paint); | |
72 EXPECT_EQ(base::TimeDelta::FromMilliseconds(non_deferred_tabs_loaded_ms), | |
73 tab_loader_stats_.non_deferred_tabs_loaded); | |
74 EXPECT_EQ(parallel_tab_loads, tab_loader_stats_.parallel_tab_loads); | |
75 } | |
76 | |
77 void ExpectReportTabDeferredCalled() { | |
78 EXPECT_LT(0u, report_tab_deferred_call_count_); | |
79 report_tab_deferred_call_count_--; | |
80 } | |
81 | |
82 void ExpectReportDeferredTabLoadedCalled() { | |
83 EXPECT_LT(0u, report_deferred_tab_loaded_call_count_); | |
84 report_deferred_tab_loaded_call_count_--; | |
85 } | |
86 | |
87 void ExpectReportStatsCollectorDeathCalled() { | |
88 EXPECT_LT(0u, report_stats_collector_death_call_count_); | |
89 report_stats_collector_death_call_count_--; | |
90 } | |
91 | |
92 void EnsureNoUnexpectedCalls() { | |
93 EXPECT_EQ(0u, report_tab_loader_stats_call_count_); | |
94 EXPECT_EQ(0u, report_tab_deferred_call_count_); | |
95 EXPECT_EQ(0u, report_deferred_tab_loaded_call_count_); | |
96 EXPECT_EQ(0u, report_stats_collector_death_call_count_); | |
97 | |
98 report_tab_loader_stats_call_count_ = 0u; | |
99 report_tab_deferred_call_count_ = 0u; | |
100 report_deferred_tab_loaded_call_count_ = 0u; | |
101 report_stats_collector_death_call_count_ = 0u; | |
102 tab_loader_stats_ = TabLoaderStats(); | |
103 } | |
104 | |
105 private: | |
106 size_t report_tab_loader_stats_call_count_; | |
107 size_t report_tab_deferred_call_count_; | |
108 size_t report_deferred_tab_loaded_call_count_; | |
109 size_t report_stats_collector_death_call_count_; | |
110 TabLoaderStats tab_loader_stats_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(MockStatsReportingDelegate); | |
113 }; | |
114 | |
115 // A pass-through stats reporting delegate. This is used to decouple the | |
116 // lifetime of the mock reporting delegate from the SessionRestoreStatsCollector | |
117 // under test. The SessionRestoreStatsCollector has ownership of this delegate, | |
118 // which will notify the mock delegate upon its death. | |
119 class PassthroughStatsReportingDelegate : public StatsReportingDelegate { | |
120 public: | |
121 PassthroughStatsReportingDelegate() : reporting_delegate_(nullptr) {} | |
122 ~PassthroughStatsReportingDelegate() override { | |
123 reporting_delegate_->ReportStatsCollectorDeath(); | |
124 } | |
125 | |
126 void set_reporting_delegate(MockStatsReportingDelegate* reporting_delegate) { | |
127 reporting_delegate_ = reporting_delegate; | |
128 } | |
129 | |
130 void ReportTabLoaderStats(const TabLoaderStats& tab_loader_stats) override { | |
131 reporting_delegate_->ReportTabLoaderStats(tab_loader_stats); | |
132 } | |
133 | |
134 void ReportTabDeferred() override { | |
135 reporting_delegate_->ReportTabDeferred(); | |
136 } | |
137 | |
138 void ReportDeferredTabLoaded() override { | |
139 reporting_delegate_->ReportDeferredTabLoaded(); | |
140 } | |
141 | |
142 private: | |
143 MockStatsReportingDelegate* reporting_delegate_; | |
144 | |
145 DISALLOW_COPY_AND_ASSIGN(PassthroughStatsReportingDelegate); | |
146 }; | |
147 | |
148 } // namespace | |
149 | |
150 class TestSessionRestoreStatsCollector : public SessionRestoreStatsCollector { | |
151 public: | |
152 using SessionRestoreStatsCollector::Observe; | |
153 | |
154 TestSessionRestoreStatsCollector( | |
155 scoped_ptr<base::TickClock> tick_clock, | |
156 scoped_ptr<StatsReportingDelegate> reporting_delegate) | |
157 : SessionRestoreStatsCollector(tick_clock->NowTicks(), | |
158 reporting_delegate.Pass()) { | |
159 set_tick_clock(tick_clock.Pass()); | |
160 } | |
161 | |
162 private: | |
163 friend class base::RefCounted<TestSessionRestoreStatsCollector>; | |
164 | |
165 ~TestSessionRestoreStatsCollector() override {} | |
166 | |
167 base::SimpleTestTickClock* test_tick_clock_; | |
168 | |
169 DISALLOW_COPY_AND_ASSIGN(TestSessionRestoreStatsCollector); | |
170 }; | |
171 | |
172 class SessionRestoreStatsCollectorTest : public testing::Test { | |
173 public: | |
174 using RestoredTab = SessionRestoreDelegate::RestoredTab; | |
175 | |
176 SessionRestoreStatsCollectorTest() | |
177 : ui_thread_(content::BrowserThread::UI, &message_loop_) {} | |
178 | |
179 void SetUp() override { | |
180 test_web_contents_factory_.reset(new content::TestWebContentsFactory); | |
181 | |
182 // Ownership of the reporting delegate is passed to the | |
183 // SessionRestoreStatsCollector, but a raw pointer is kept to it so it can | |
184 // be queried by the test. | |
185 passthrough_reporting_delegate_ = new PassthroughStatsReportingDelegate(); | |
186 | |
187 // Ownership of this clock is passed to the SessionRestoreStatsCollector. | |
188 // A raw pointer is kept to it so that it can be modified from the outside. | |
189 // The unittest must take care to access the clock only while the | |
190 // SessionRestoreStatsCollector under test is still alive. | |
191 test_tick_clock_ = new base::SimpleTestTickClock(); | |
192 | |
193 // Create a stats collector, keep a raw pointer to it, and detach from it. | |
194 // The stats collector will stay alive as long as it has not yet completed | |
195 // its job, and will clean itself up when done. | |
196 scoped_refptr<TestSessionRestoreStatsCollector> stats_collector = | |
197 new TestSessionRestoreStatsCollector( | |
198 scoped_ptr<base::TickClock>(test_tick_clock_), | |
199 scoped_ptr<StatsReportingDelegate>( | |
200 passthrough_reporting_delegate_)); | |
201 stats_collector_ = stats_collector.get(); | |
202 stats_collector = nullptr; | |
203 } | |
204 | |
205 void TearDown() override { | |
206 passthrough_reporting_delegate_ = nullptr; | |
207 test_tick_clock_ = nullptr; | |
208 stats_collector_ = nullptr; | |
209 | |
210 // Clean up any tabs that were generated by the unittest. | |
211 restored_tabs_.clear(); | |
212 test_web_contents_factory_.reset(); | |
213 } | |
214 | |
215 // Advances the test clock by 1ms. | |
216 void Tick() { | |
217 test_tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1)); | |
218 } | |
219 | |
220 void Show(size_t tab_index) { | |
221 restored_tabs_[tab_index].contents()->GetRenderWidgetHostView()->Show(); | |
222 } | |
223 | |
224 void Hide(size_t tab_index) { | |
225 restored_tabs_[tab_index].contents()->GetRenderWidgetHostView()->Hide(); | |
226 } | |
227 | |
228 // Creates a restored tab backed by dummy WebContents/NavigationController/ | |
229 // RenderWidgetHost/RenderWidgetHostView. Returns the index of the restored | |
230 // tab for future simulation of events. | |
231 void CreateRestoredTab(bool is_active) { | |
232 content::WebContents* contents = | |
233 test_web_contents_factory_->CreateWebContents(&testing_profile_); | |
234 restored_tabs_.push_back(RestoredTab(contents, is_active, false, false)); | |
235 if (is_active) | |
236 Show(restored_tabs_.size() - 1); | |
237 } | |
238 | |
239 // Helper function for various notification generation. | |
240 void GenerateControllerNotification(size_t tab_index, int type) { | |
241 content::WebContents* contents = restored_tabs_[tab_index].contents(); | |
242 content::NavigationController* controller = &contents->GetController(); | |
243 stats_collector_->Observe( | |
244 type, content::Source<content::NavigationController>(controller), | |
245 content::NotificationService::NoDetails()); | |
246 } | |
247 | |
248 // Generates a load start notification for the given tab. | |
249 void GenerateLoadStart(size_t tab_index) { | |
250 GenerateControllerNotification(tab_index, content::NOTIFICATION_LOAD_START); | |
251 } | |
252 | |
253 // Generates a load stop notification for the given tab. | |
254 void GenerateLoadStop(size_t tab_index) { | |
255 GenerateControllerNotification(tab_index, content::NOTIFICATION_LOAD_STOP); | |
256 } | |
257 | |
258 // Generates a web contents destroyed notification for the given tab. | |
259 void GenerateWebContentsDestroyed(size_t tab_index) { | |
260 content::WebContents* contents = restored_tabs_[tab_index].contents(); | |
261 stats_collector_->Observe(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
262 content::Source<content::WebContents>(contents), | |
263 content::NotificationService::NoDetails()); | |
264 } | |
265 | |
266 // Generates a paint notification for the given tab. | |
267 void GenerateRenderWidgetHostDidUpdateBackingStore(size_t tab_index) { | |
268 content::WebContents* contents = restored_tabs_[tab_index].contents(); | |
269 content::RenderWidgetHost* host = | |
270 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); | |
271 stats_collector_->Observe( | |
272 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | |
273 content::Source<content::RenderWidgetHost>(host), | |
274 content::NotificationService::NoDetails()); | |
275 } | |
276 | |
277 // Defers a tab. | |
278 void DeferTab(size_t tab_index) { | |
279 content::WebContents* contents = restored_tabs_[tab_index].contents(); | |
280 content::NavigationController* controller = &contents->GetController(); | |
281 stats_collector_->DeferTab(controller); | |
282 } | |
283 | |
284 // Inputs to the stats collector. Reset prior to each test. | |
285 base::SimpleTestTickClock* test_tick_clock_; | |
286 std::vector<RestoredTab> restored_tabs_; | |
287 | |
288 // Infrastructure needed for using the TestWebContentsFactory. These are | |
289 // initialized once by the fixture and reused across unittests. | |
290 base::MessageLoop message_loop_; | |
291 TestingProfile testing_profile_; | |
292 content::TestBrowserThread ui_thread_; | |
293 | |
294 // A new web contents factory is generated per test. This automatically cleans | |
295 // up any tabs created by previous tests. | |
296 scoped_ptr<content::TestWebContentsFactory> test_web_contents_factory_; | |
297 | |
298 // These are recreated for each test. The reporting delegate allows the test | |
299 // to observe the behaviour of the SessionRestoreStatsCollector under test. | |
300 PassthroughStatsReportingDelegate* passthrough_reporting_delegate_; | |
301 TestSessionRestoreStatsCollector* stats_collector_; | |
302 | |
303 DISALLOW_COPY_AND_ASSIGN(SessionRestoreStatsCollectorTest); | |
Alexei Svitkine (slow)
2015/06/18 17:48:48
This should actually be in the private: section.
chrisha
2015/06/18 20:09:04
Done.
| |
304 }; | |
305 | |
306 TEST_F(SessionRestoreStatsCollectorTest, SingleTabPaintBeforeLoad) { | |
307 MockStatsReportingDelegate mock_reporting_delegate; | |
308 passthrough_reporting_delegate_->set_reporting_delegate( | |
309 &mock_reporting_delegate); | |
310 | |
311 CreateRestoredTab(true); | |
312 stats_collector_->TrackTabs(restored_tabs_); | |
313 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
314 | |
315 Tick(); // 1ms. | |
316 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
317 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
318 | |
319 Tick(); // 2ms. | |
320 GenerateLoadStop(0); | |
321 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 1, 2, 1, 2, 1); | |
322 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
323 } | |
324 | |
325 TEST_F(SessionRestoreStatsCollectorTest, SingleTabPaintAfterLoad) { | |
326 MockStatsReportingDelegate mock_reporting_delegate; | |
327 passthrough_reporting_delegate_->set_reporting_delegate( | |
328 &mock_reporting_delegate); | |
329 | |
330 CreateRestoredTab(true); | |
331 stats_collector_->TrackTabs(restored_tabs_); | |
332 | |
333 Tick(); // 1ms. | |
334 GenerateLoadStop(0); | |
335 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
336 | |
337 Tick(); // 2ms. | |
338 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
339 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 1, 1, 2, 1, 1); | |
340 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
341 } | |
342 | |
343 TEST_F(SessionRestoreStatsCollectorTest, MultipleTabsLoadSerially) { | |
344 MockStatsReportingDelegate mock_reporting_delegate; | |
345 passthrough_reporting_delegate_->set_reporting_delegate( | |
346 &mock_reporting_delegate); | |
347 | |
348 CreateRestoredTab(true); | |
349 CreateRestoredTab(false); | |
350 CreateRestoredTab(false); | |
351 stats_collector_->TrackTabs(restored_tabs_); | |
352 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
353 | |
354 // Foreground tab paints then finishes loading. | |
355 Tick(); // 1ms. | |
356 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
357 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
358 Tick(); // 2ms. | |
359 GenerateLoadStop(0); | |
360 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
361 | |
362 // First background tab starts loading, paints, then finishes loading. | |
363 Tick(); // 3ms. | |
364 GenerateLoadStart(1); | |
365 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
366 Tick(); // 4ms. | |
367 GenerateRenderWidgetHostDidUpdateBackingStore(1); | |
368 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
369 Tick(); // 5ms. | |
370 GenerateLoadStop(1); | |
371 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
372 | |
373 // Second background tab starts loading, finishes loading, but never paints. | |
374 Tick(); // 6ms. | |
375 GenerateLoadStart(2); | |
376 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
377 | |
378 Tick(); // 7ms. | |
379 GenerateLoadStop(2); | |
380 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(3, 3, 2, 1, 7, 1); | |
381 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
382 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
383 } | |
384 | |
385 TEST_F(SessionRestoreStatsCollectorTest, MultipleTabsLoadSimultaneously) { | |
386 MockStatsReportingDelegate mock_reporting_delegate; | |
387 passthrough_reporting_delegate_->set_reporting_delegate( | |
388 &mock_reporting_delegate); | |
389 | |
390 CreateRestoredTab(true); | |
391 CreateRestoredTab(false); | |
392 CreateRestoredTab(false); | |
393 stats_collector_->TrackTabs(restored_tabs_); | |
394 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
395 | |
396 // Foreground tab paints then finishes loading. | |
397 Tick(); // 1ms. | |
398 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
399 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
400 Tick(); // 2ms. | |
401 GenerateLoadStop(0); | |
402 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
403 | |
404 // Both background tabs start loading at the same time. The first one paints | |
405 // before finishing loading, the second one paints after finishing loading | |
406 // (the stats collector never sees the paint event). | |
407 Tick(); // 3ms. | |
408 GenerateLoadStart(1); | |
409 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
410 GenerateLoadStart(2); | |
411 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
412 Tick(); // 4ms. | |
413 GenerateRenderWidgetHostDidUpdateBackingStore(1); | |
414 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
415 Tick(); // 5ms. | |
416 GenerateLoadStop(1); | |
417 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
418 Tick(); // 6ms. | |
419 GenerateLoadStop(2); | |
420 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(3, 3, 2, 1, 6, 2); | |
421 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
422 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
423 } | |
424 | |
425 TEST_F(SessionRestoreStatsCollectorTest, DeferredTabs) { | |
426 MockStatsReportingDelegate mock_reporting_delegate; | |
427 passthrough_reporting_delegate_->set_reporting_delegate( | |
428 &mock_reporting_delegate); | |
429 | |
430 CreateRestoredTab(true); | |
431 CreateRestoredTab(false); | |
432 stats_collector_->TrackTabs(restored_tabs_); | |
433 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
434 | |
435 // Foreground tab paints, then the background tab is deferred. | |
436 Tick(); // 1ms. | |
437 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
438 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
439 DeferTab(1); | |
440 mock_reporting_delegate.ExpectReportTabDeferredCalled(); | |
441 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
442 | |
443 // Foreground tab finishes loading and stats get reported. | |
444 Tick(); // 2ms. | |
445 GenerateLoadStop(0); | |
446 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(2, 1, 2, 1, 2, 1); | |
447 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
448 | |
449 // Background tab starts loading, paints and stops loading. This fires off a | |
450 // deferred tab loaded notification. | |
451 Tick(); // 3ms. | |
452 GenerateLoadStart(1); | |
453 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
454 Tick(); // 4ms. | |
455 GenerateRenderWidgetHostDidUpdateBackingStore(1); | |
456 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
457 Tick(); // 5ms. | |
458 GenerateLoadStop(1); | |
459 mock_reporting_delegate.ExpectReportDeferredTabLoadedCalled(); | |
460 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
461 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
462 } | |
463 | |
464 TEST_F(SessionRestoreStatsCollectorTest, FocusSwitchNoForegroundPaintOrLoad) { | |
465 MockStatsReportingDelegate mock_reporting_delegate; | |
466 passthrough_reporting_delegate_->set_reporting_delegate( | |
467 &mock_reporting_delegate); | |
468 | |
469 CreateRestoredTab(true); | |
470 stats_collector_->TrackTabs(restored_tabs_); | |
471 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
472 | |
473 // Create another tab and make it the foreground tab. This tab is not actually | |
474 // being tracked by the SessionRestoreStatsCollector, but its paint events | |
475 // will be observed. | |
476 CreateRestoredTab(false); | |
477 Hide(0); | |
478 Show(1); | |
479 | |
480 // Load and paint the restored tab (now the background tab). Don't expect | |
481 // any calls to the mock as a visible tab paint has not yet been observed. | |
482 Tick(); // 1ms. | |
483 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
484 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
485 Tick(); // 2ms. | |
486 GenerateLoadStop(0); | |
487 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
488 | |
489 // Mark the new foreground tab as having painted. This should cause the | |
490 // stats to be emitted, but with empty foreground paint and load values. | |
491 Tick(); // 3ms. | |
492 GenerateRenderWidgetHostDidUpdateBackingStore(1); | |
493 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 1, 0, 0, 2, 1); | |
494 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
495 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
496 } | |
497 | |
498 TEST_F(SessionRestoreStatsCollectorTest, FocusSwitchNoForegroundPaint) { | |
499 MockStatsReportingDelegate mock_reporting_delegate; | |
500 passthrough_reporting_delegate_->set_reporting_delegate( | |
501 &mock_reporting_delegate); | |
502 | |
503 CreateRestoredTab(true); | |
504 stats_collector_->TrackTabs(restored_tabs_); | |
505 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
506 | |
507 // Load the foreground tab. | |
508 Tick(); // 1ms. | |
509 GenerateLoadStop(0); | |
510 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
511 | |
512 // Create another tab and make it the foreground tab. This tab is not actually | |
513 // being tracked by the SessionRestoreStatsCollector, but its paint events | |
514 // will still be observed. | |
515 CreateRestoredTab(false); | |
516 Hide(0); | |
517 Show(1); | |
518 | |
519 // Load and paint the restored tab (now the background tab). Don't expect | |
520 // any calls to the mock as a visible tab paint has not yet been observed. | |
521 Tick(); // 2ms. | |
522 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
523 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
524 | |
525 // Mark the new foreground tab as having painted. This should cause the | |
526 // stats to be emitted, but with an empty foreground paint value. | |
527 Tick(); // 3ms. | |
528 GenerateRenderWidgetHostDidUpdateBackingStore(1); | |
529 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 1, 1, 0, 1, 1); | |
530 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
531 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
532 } | |
533 | |
534 TEST_F(SessionRestoreStatsCollectorTest, LoadingTabDestroyedBeforePaint) { | |
535 MockStatsReportingDelegate mock_reporting_delegate; | |
536 passthrough_reporting_delegate_->set_reporting_delegate( | |
537 &mock_reporting_delegate); | |
538 | |
539 CreateRestoredTab(true); | |
540 stats_collector_->TrackTabs(restored_tabs_); | |
541 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
542 | |
543 // Destroy the tab. Expect all timings to be zero. | |
544 GenerateWebContentsDestroyed(0); | |
545 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 0, 0, 0, 0, 1); | |
546 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
547 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
548 } | |
549 | |
550 TEST_F(SessionRestoreStatsCollectorTest, LoadingTabDestroyedAfterPaint) { | |
551 MockStatsReportingDelegate mock_reporting_delegate; | |
552 passthrough_reporting_delegate_->set_reporting_delegate( | |
553 &mock_reporting_delegate); | |
554 | |
555 CreateRestoredTab(true); | |
556 stats_collector_->TrackTabs(restored_tabs_); | |
557 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
558 | |
559 Tick(); // 1 ms. | |
560 GenerateRenderWidgetHostDidUpdateBackingStore(0); | |
561 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
562 | |
563 // Destroy the tab. Expect both load timings to be zero. | |
564 GenerateWebContentsDestroyed(0); | |
565 mock_reporting_delegate.ExpectReportTabLoaderStatsCalled(1, 0, 0, 1, 0, 1); | |
566 mock_reporting_delegate.ExpectReportStatsCollectorDeathCalled(); | |
567 mock_reporting_delegate.EnsureNoUnexpectedCalls(); | |
568 } | |
OLD | NEW |