blob: 9e15a054d22fc74ddc1d1dd154714f26fc900c86 [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;
20
21import com.android.systemui.SysuiTestCase;
22
23import org.junit.Before;
24import org.junit.Test;
25
26/**
27 * Testing functionality of the current user tracker
28 */
29public class CurrentUserTrackerTest extends SysuiTestCase {
30
31 private CurrentUserTracker mTracker;
32 private CurrentUserTracker.UserReceiver mReceiver;
33
34 @Before
35 public void setUp() {
36 mReceiver = new CurrentUserTracker.UserReceiver(getContext());
37 mTracker = new CurrentUserTracker(mReceiver) {
38 @Override
39 public void onUserSwitched(int newUserId) {
40 stopTracking();
41 }
42 };
43 }
44
45 @Test
46 public void testBroadCastDoesntCrashOnConcurrentModification() {
47 mTracker.startTracking();
48 CurrentUserTracker secondTracker = new CurrentUserTracker(mReceiver) {
49 @Override
50 public void onUserSwitched(int newUserId) {
51 stopTracking();
52 }
53 };
54 secondTracker.startTracking();
55 triggerUserSwitch();
56 }
57 /**
58 * Simulates a user switch event.
59 */
60 private void triggerUserSwitch() {
61 Intent intent = new Intent(Intent.ACTION_USER_SWITCHED);
62 intent.putExtra(Intent.EXTRA_USER_HANDLE, 1);
63 mReceiver.onReceive(getContext(), intent);
64 }
65}