@@ -113,15 +113,34 @@ void PrintTo(const ActivePicture& activePicture, std::ostream* os) {
113113 *os << activePicture.toString ();
114114}
115115
116- TEST_F (ActivePictureTrackerTest, notCalledWithNoProfile) {
116+ TEST_F (ActivePictureTrackerTest, whenListenerAdded_called) {
117+ ActivePictureTracker tracker;
118+ auto listener = createMockListener ();
119+ EXPECT_CALL (*listener, onActivePicturesChanged (SizeIs (0 ))).Times (1 );
120+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
121+ }
122+
123+ TEST_F (ActivePictureTrackerTest, whenListenerAdded_withListenerAlreadyAdded_notCalled) {
124+ ActivePictureTracker tracker;
125+ auto listener = createMockListener ();
126+ {
127+ EXPECT_CALL (*listener, onActivePicturesChanged (SizeIs (0 ))).Times (1 );
128+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
129+ }
130+ {
131+ EXPECT_CALL (*listener, onActivePicturesChanged (_)).Times (0 );
132+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
133+ }
134+ }
135+
136+ TEST_F (ActivePictureTrackerTest, whenListenerAdded_withUncommittedProfile_calledWithNone) {
117137 auto layer = createMockLayer (100 , 10 );
118138 TestableLayerFE layerFE;
119139
120140 ActivePictureTracker tracker;
121141 {
122142 layerFE.snapshot .pictureProfileHandle = PictureProfileHandle (1 );
123143 tracker.onLayerComposed (*layer, layerFE, layerFE.stealCompositionResult ());
124-
125144 tracker.updateAndNotifyListeners (NO_LISTENERS, NO_LISTENERS);
126145 }
127146 {
@@ -131,7 +150,27 @@ TEST_F(ActivePictureTrackerTest, notCalledWithNoProfile) {
131150 }
132151}
133152
134- TEST_F (ActivePictureTrackerTest, calledWhenLayerStartsUsingProfile) {
153+ TEST_F (ActivePictureTrackerTest, whenListenerAdded_withCommittedProfile_calledWithActivePicture) {
154+ auto layer = createMockLayer (100 , 10 );
155+ TestableLayerFE layerFE;
156+
157+ ActivePictureTracker tracker;
158+ {
159+ layerFE.snapshot .pictureProfileHandle = PictureProfileHandle (1 );
160+ layerFE.onPictureProfileCommitted ();
161+ tracker.onLayerComposed (*layer, layerFE, layerFE.stealCompositionResult ());
162+
163+ auto listener = createMockListener ();
164+ EXPECT_CALL (*listener, onActivePicturesChanged (_))
165+ .WillOnce ([](const std::vector<gui::ActivePicture>& activePictures) {
166+ EXPECT_THAT (activePictures, UnorderedElementsAre ({{100 , 10 , 1 }}));
167+ return binder::Status::ok ();
168+ });
169+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
170+ }
171+ }
172+
173+ TEST_F (ActivePictureTrackerTest, whenProfileAdded_calledWithActivePicture) {
135174 auto layer = createMockLayer (100 , 10 );
136175 TestableLayerFE layerFE;
137176
@@ -157,7 +196,7 @@ TEST_F(ActivePictureTrackerTest, calledWhenLayerStartsUsingProfile) {
157196 }
158197}
159198
160- TEST_F (ActivePictureTrackerTest, notCalledWhenLayerContinuesUsingProfile ) {
199+ TEST_F (ActivePictureTrackerTest, whenContinuesUsingProfile_notCalled ) {
161200 auto layer = createMockLayer (100 , 10 );
162201 TestableLayerFE layerFE;
163202
@@ -181,7 +220,7 @@ TEST_F(ActivePictureTrackerTest, notCalledWhenLayerContinuesUsingProfile) {
181220 }
182221}
183222
184- TEST_F (ActivePictureTrackerTest, calledWhenLayerStopsUsingProfile ) {
223+ TEST_F (ActivePictureTrackerTest, whenProfileIsRemoved_calledWithNoActivePictures ) {
185224 auto layer = createMockLayer (100 , 10 );
186225 TestableLayerFE layerFE;
187226
@@ -204,7 +243,30 @@ TEST_F(ActivePictureTrackerTest, calledWhenLayerStopsUsingProfile) {
204243 }
205244}
206245
207- TEST_F (ActivePictureTrackerTest, calledWhenLayerChangesProfile) {
246+ TEST_F (ActivePictureTrackerTest, whenProfileIsNotCommitted_calledWithNoActivePictures) {
247+ auto layer = createMockLayer (100 , 10 );
248+ TestableLayerFE layerFE;
249+
250+ ActivePictureTracker tracker;
251+ auto listener = createMockListener ();
252+ {
253+ layerFE.snapshot .pictureProfileHandle = PictureProfileHandle (1 );
254+ layerFE.onPictureProfileCommitted ();
255+ tracker.onLayerComposed (*layer, layerFE, layerFE.stealCompositionResult ());
256+
257+ EXPECT_CALL (*listener, onActivePicturesChanged (SizeIs (1 ))).Times (1 );
258+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
259+ }
260+ {
261+ layerFE.snapshot .pictureProfileHandle = PictureProfileHandle (1 );
262+ tracker.onLayerComposed (*layer, layerFE, layerFE.stealCompositionResult ());
263+
264+ EXPECT_CALL (*listener, onActivePicturesChanged (SizeIs (0 ))).Times (1 );
265+ tracker.updateAndNotifyListeners (NO_LISTENERS, NO_LISTENERS);
266+ }
267+ }
268+
269+ TEST_F (ActivePictureTrackerTest, whenProfileChanges_calledWithDifferentProfile) {
208270 auto layer = createMockLayer (100 , 10 );
209271 TestableLayerFE layerFE;
210272
@@ -236,7 +298,34 @@ TEST_F(ActivePictureTrackerTest, calledWhenLayerChangesProfile) {
236298 }
237299}
238300
239- TEST_F (ActivePictureTrackerTest, notCalledWhenUncommittedLayerChangesProfile) {
301+ TEST_F (ActivePictureTrackerTest, whenMultipleCommittedProfiles_calledWithMultipleActivePictures) {
302+ auto layer1 = createMockLayer (100 , 10 );
303+ TestableLayerFE layerFE1;
304+
305+ auto layer2 = createMockLayer (200 , 20 );
306+ TestableLayerFE layerFE2;
307+
308+ ActivePictureTracker tracker;
309+ auto listener = createMockListener ();
310+ {
311+ layerFE1.snapshot .pictureProfileHandle = PictureProfileHandle (1 );
312+ layerFE1.onPictureProfileCommitted ();
313+ tracker.onLayerComposed (*layer1, layerFE1, layerFE1.stealCompositionResult ());
314+
315+ layerFE2.snapshot .pictureProfileHandle = PictureProfileHandle (2 );
316+ layerFE2.onPictureProfileCommitted ();
317+ tracker.onLayerComposed (*layer2, layerFE2, layerFE2.stealCompositionResult ());
318+
319+ EXPECT_CALL (*listener, onActivePicturesChanged (SizeIs (2 )))
320+ .WillOnce ([](const std::vector<gui::ActivePicture>& activePictures) {
321+ EXPECT_THAT (activePictures, UnorderedElementsAre ({{100 , 10 , 1 }, {200 , 20 , 2 }}));
322+ return binder::Status::ok ();
323+ });
324+ tracker.updateAndNotifyListeners (*listener, NO_LISTENERS);
325+ }
326+ }
327+
328+ TEST_F (ActivePictureTrackerTest, whenNonCommittedProfileChanges_notCalled) {
240329 auto layer1 = createMockLayer (100 , 10 );
241330 TestableLayerFE layerFE1;
242331
@@ -269,7 +358,7 @@ TEST_F(ActivePictureTrackerTest, notCalledWhenUncommittedLayerChangesProfile) {
269358 }
270359}
271360
272- TEST_F (ActivePictureTrackerTest, calledWhenDifferentLayerUsesSameProfile ) {
361+ TEST_F (ActivePictureTrackerTest, whenDifferentLayerUsesSameProfile_called ) {
273362 auto layer1 = createMockLayer (100 , 10 );
274363 TestableLayerFE layerFE1;
275364
@@ -312,7 +401,7 @@ TEST_F(ActivePictureTrackerTest, calledWhenDifferentLayerUsesSameProfile) {
312401 }
313402}
314403
315- TEST_F (ActivePictureTrackerTest, calledWhenSameUidUsesSameProfile ) {
404+ TEST_F (ActivePictureTrackerTest, whenSameUidDifferentLayerUsesSameProfile_called ) {
316405 auto layer1 = createMockLayer (100 , 10 );
317406 TestableLayerFE layerFE1;
318407
@@ -355,7 +444,7 @@ TEST_F(ActivePictureTrackerTest, calledWhenSameUidUsesSameProfile) {
355444 }
356445}
357446
358- TEST_F (ActivePictureTrackerTest, calledWhenNewLayerUsesSameProfile ) {
447+ TEST_F (ActivePictureTrackerTest, whenNewLayerUsesSameProfile_called ) {
359448 auto layer1 = createMockLayer (100 , 10 );
360449 TestableLayerFE layerFE1;
361450
0 commit comments