11b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent/* 21b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * Copyright (C) 2017 The Android Open Source Project 31b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * 41b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * Licensed under the Apache License, Version 2.0 (the "License"); 51b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * you may not use this file except in compliance with the License. 61b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * You may obtain a copy of the License at 71b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * 81b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * http://www.apache.org/licenses/LICENSE-2.0 91b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * 101b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * Unless required by applicable law or agreed to in writing, software 111b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * distributed under the License is distributed on an "AS IS" BASIS, 121b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * See the License for the specific language governing permissions and 141b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent * limitations under the License. 151b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent */ 161b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 171b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentpackage com.android.settings.bluetooth; 181b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 191b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport static org.mockito.Mockito.when; 201b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 211b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.app.Instrumentation; 221b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.content.Context; 231b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.content.Intent; 241b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.os.Bundle; 251b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.os.RemoteException; 261b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.support.test.InstrumentationRegistry; 271b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.support.test.filters.SmallTest; 281b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.support.test.runner.AndroidJUnit4; 291b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport android.support.test.uiautomator.UiDevice; 301b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 311b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport com.android.settings.SettingsActivity; 321b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport com.android.settingslib.bluetooth.CachedBluetoothDevice; 331b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport com.android.settingslib.bluetooth.LocalBluetoothManager; 341b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 351b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.junit.Before; 361b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.junit.Test; 371b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.junit.runner.RunWith; 381b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.mockito.Answers; 391b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.mockito.Mock; 401b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentimport org.mockito.MockitoAnnotations; 411b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 421b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent@RunWith(AndroidJUnit4.class) 431b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent@SmallTest 441b6e7d76edd992715e87767199991f92d8f3a084Antony Sargentpublic class BluetoothDeviceDetailsRotationTest { 451b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private Context mContext; 461b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private UiDevice mUiDevice; 471b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private Instrumentation mInstrumentation; 481b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 491b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Mock(answer = Answers.RETURNS_DEEP_STUBS) 501b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private CachedBluetoothDevice mCachedDevice; 511b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 521b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Mock(answer = Answers.RETURNS_DEEP_STUBS) 531b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private LocalBluetoothManager mBluetoothManager; 541b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 551b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent private String mDeviceAddress; 561b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 571b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Before 581b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent public void setUp() throws Exception { 591b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent MockitoAnnotations.initMocks(this); 601b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mContext = InstrumentationRegistry.getTargetContext(); 611b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); 621b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mInstrumentation = InstrumentationRegistry.getInstrumentation(); 631b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 641b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mDeviceAddress = "AA:BB:CC:DD:EE:FF"; 651b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent when(mCachedDevice.getAddress()).thenReturn(mDeviceAddress); 661b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent when(mCachedDevice.getName()).thenReturn("Mock Device"); 671b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 681b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent BluetoothDeviceDetailsFragment.sTestDataFactory = 691b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent new BluetoothDeviceDetailsFragment.TestDataFactory() { 701b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Override 711b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent public CachedBluetoothDevice getDevice(String deviceAddress) { 721b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent return mCachedDevice; 731b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } 741b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 751b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Override 761b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent public LocalBluetoothManager getManager(Context context) { 771b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent return mBluetoothManager; 781b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } 791b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent }; 801b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } 811b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 821b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent @Test 831b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent public void rotation() { 841b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS"); 851b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent); 861b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent Bundle args = new Bundle(1); 871b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, mDeviceAddress); 881b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent activity.startPreferencePanel(null, BluetoothDeviceDetailsFragment.class.getName(), args, 891b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent 0, null, null, 0); 901b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent try { 911b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mUiDevice.setOrientationLeft(); 921b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mUiDevice.setOrientationNatural(); 931b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mUiDevice.setOrientationRight(); 941b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent mUiDevice.setOrientationNatural(); 951b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } catch (RemoteException e) { 961b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent throw new RuntimeException(e); 971b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } 981b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent } 991b6e7d76edd992715e87767199991f92d8f3a084Antony Sargent} 100