blob: 4162bc1da479d3adcae68658a4440e8de71a6475 [file] [log] [blame]
Selim Cinekfc9af342017-05-05 14:45:11 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package com.android.systemui.settings;
18
19import android.content.Intent;
Brett Chabot84151d92019-02-27 15:37:59 -080020
21import androidx.test.filters.SmallTest;
Selim Cinekfc9af342017-05-05 14:45:11 -070022
23import com.android.systemui.SysuiTestCase;
24
25import org.junit.Before;
26import org.junit.Test;
27
28/**
29 * Testing functionality of the current user tracker
30 */
Jason Monkfba8faf2017-05-23 10:42:59 -040031@SmallTest
Selim Cinekfc9af342017-05-05 14:45:11 -070032public class CurrentUserTrackerTest extends SysuiTestCase {
33
34 private CurrentUserTracker mTracker;
35 private CurrentUserTracker.UserReceiver mReceiver;
36
37 @Before
38 public void setUp() {
39 mReceiver = new CurrentUserTracker.UserReceiver(getContext());
40 mTracker = new CurrentUserTracker(mReceiver) {
41 @Override
42 public void onUserSwitched(int newUserId) {
43 stopTracking();
44 }
45 };
46 }
47
48 @Test
49 public void testBroadCastDoesntCrashOnConcurrentModification() {
50 mTracker.startTracking();
51 CurrentUserTracker secondTracker = new CurrentUserTracker(mReceiver) {
52 @Override
53 public void onUserSwitched(int newUserId) {
54 stopTracking();
55 }
56 };
57 secondTracker.startTracking();
58 triggerUserSwitch();
59 }
60 /**
61 * Simulates a user switch event.
62 */
63 private void triggerUserSwitch() {
64 Intent intent = new Intent(Intent.ACTION_USER_SWITCHED);
65 intent.putExtra(Intent.EXTRA_USER_HANDLE, 1);
66 mReceiver.onReceive(getContext(), intent);
67 }
68}