Merge "Refactor add network page"

This commit is contained in:
TreeHugger Robot
2018-08-21 00:21:07 +00:00
committed by Android (Google) Code Review
9 changed files with 402 additions and 53 deletions

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<!-- Since Robolectric can't inflate @*android:layout/alert_dialog_button_bar_material in
../res/layout/wifi_add_network_view.xml, so this Layout overrides button bar part. -->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="@layout/wifi_dialog"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@android:id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@android:id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -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));
}
}