Refactor add network page
WifiDialog.java can be launched as "full screen mode" in some use cases. However the way it's done is that it uses theme to fake the full screen appearance. It just feels hacky to use a dialog for full screen UI. So, we created an "AddNetworkFragment" to make this page can look like a normal fragment. Also, clean up some useless code about "full screen mode" of WifiDialog. Change-Id: Iedd04c6a8e403cbceb872313314e1cba0d514246 Fixes: 111875856 Test: robo test, manual test
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||
import com.android.settingslib.testutils.FragmentTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowConnectivityManager.class)
|
||||
public class AddNetworkFragmentTest {
|
||||
|
||||
private AddNetworkFragment mAddNetworkFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mAddNetworkFragment = spy(new AddNetworkFragment());
|
||||
FragmentTestUtils.startFragment(mAddNetworkFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_shouldReturnAddNetwork() {
|
||||
assertThat(mAddNetworkFragment.getMetricsCategory()).isEqualTo(
|
||||
MetricsEvent.SETTINGS_WIFI_ADD_NETWORK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMode_shouldBeModeConnected() {
|
||||
assertThat(mAddNetworkFragment.getMode()).isEqualTo(WifiConfigUiBase.MODE_CONNECT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchFragment_shouldShowSubmitButton() {
|
||||
assertThat(mAddNetworkFragment.getSubmitButton()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchFragment_shouldShowCancelButton() {
|
||||
assertThat(mAddNetworkFragment.getCancelButton()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickSubmitButton_shouldHandleSubmitAction() {
|
||||
View submitButton = mAddNetworkFragment.getView().findViewById(
|
||||
AddNetworkFragment.SUBMIT_BUTTON_ID);
|
||||
|
||||
mAddNetworkFragment.onClick(submitButton);
|
||||
|
||||
verify(mAddNetworkFragment).handleSubmitAction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClickCancelButton_shouldHandleCancelAction() {
|
||||
View cancelButton = mAddNetworkFragment.getView().findViewById(
|
||||
AddNetworkFragment.CANCEL_BUTTON_ID);
|
||||
|
||||
mAddNetworkFragment.onClick(cancelButton);
|
||||
|
||||
verify(mAddNetworkFragment).handleCancelAction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dispatchSubmit_shouldHandleSubmitAction() {
|
||||
mAddNetworkFragment.dispatchSubmit();
|
||||
|
||||
verify(mAddNetworkFragment).handleSubmitAction();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.wifi.WifiDialog.WifiDialogListener;
|
||||
@@ -32,14 +31,6 @@ public class WifiDialogTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFullscreen_setsFullscreenTheme() {
|
||||
WifiDialog fullscreen = WifiDialog.createFullscreen(mContext, mListener, mockAccessPoint,
|
||||
WifiConfigUiBase.MODE_CONNECT);
|
||||
assertThat(fullscreen.getContext().getThemeResId())
|
||||
.isEqualTo(R.style.Theme_Settings_WifiDialogFullScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createModal_usesDefaultTheme() {
|
||||
WifiDialog modal = WifiDialog
|
||||
|
||||
@@ -16,9 +16,17 @@
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -60,4 +68,15 @@ public class WifiSettingsTest {
|
||||
|
||||
assertThat(indexRes).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNetworkFragmentSendResult_onActivityResult_shouldHandleEvent() {
|
||||
final WifiSettings wifiSettings = spy(new WifiSettings());
|
||||
final Intent intent = new Intent();
|
||||
doNothing().when(wifiSettings).handleAddNetworkRequest(anyInt(), any(Intent.class));
|
||||
|
||||
wifiSettings.onActivityResult(WifiSettings.ADD_NETWORK_REQUEST, Activity.RESULT_OK, intent);
|
||||
|
||||
verify(wifiSettings).handleAddNetworkRequest(anyInt(), any(Intent.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user