MockDataDispatcher mockDispatcher = new MockDataDispatcher();
dispatchTestUiEvents(mockDispatcher);
// Test aggregating with window bounds around the entire data set.
ReportDataCollector dataCollector = new ReportDataCollector(mockDispatcher);
ReportData data = dataCollector.gatherDataWithinWindow(0, 22);
JsIntegerDoubleMap typeDurations = data.getAggregatedTypeDurations();
// Available time should be 4ms;
assertEquals(4.0, typeDurations.get(-1), ERROR_MARGIN);
assertEquals(6.0, typeDurations.get(4), ERROR_MARGIN);
assertEquals(3.0, typeDurations.get(3), ERROR_MARGIN);
assertEquals(6.0, typeDurations.get(2), ERROR_MARGIN);
assertEquals(3.0, typeDurations.get(1), ERROR_MARGIN);
// Tests that aggregating works even when events fall on both window
// boundaries.
data = dataCollector.gatherDataWithinWindow(1.5, 20.7);
typeDurations = data.getAggregatedTypeDurations();
// Available time should still be 4ms;
assertEquals(4.0, typeDurations.get(-1), ERROR_MARGIN);
assertEquals(4.7, typeDurations.get(4), ERROR_MARGIN);
assertEquals(2.5, typeDurations.get(3), ERROR_MARGIN);
assertEquals(5.0, typeDurations.get(2), ERROR_MARGIN);
assertEquals(3.0, typeDurations.get(1), ERROR_MARGIN);
// Tests gathering data with a window completely to the right of everything.
data = dataCollector.gatherDataWithinWindow(100, 120);
typeDurations = data.getAggregatedTypeDurations();
assertEquals(20.0, typeDurations.get(-1), ERROR_MARGIN);
}