blob: eaafa258f6fef41c24fa7d54b6b6617887e31f25 [file] [log] [blame]
Girish Moturu7e48b432019-07-11 14:52:13 -07001#
2# Copyright 2019 - 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
16import time
17
18from acts import asserts
19from acts import base_test
Girish Moturu7e48b432019-07-11 14:52:13 -070020from acts.test_decorators import test_tracker_info
Xianyuan Jia63751fb2020-11-17 00:07:40 +000021from acts_contrib.test_utils.net import connectivity_const as cconst
22from acts_contrib.test_utils.net import connectivity_test_utils as cutils
23from acts_contrib.test_utils.net import ui_utils as uutils
24from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
25from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
Girish Moturu7e48b432019-07-11 14:52:13 -070026
27WifiEnums = wutils.WifiEnums
28IFACE = "InterfaceName"
29TIME_OUT = 20
30WLAN = "wlan0"
Girish Moturu267f71e2020-05-16 22:51:03 -070031ACCEPT_CONTINUE = "Accept and Continue"
Girish Moturu572d5212021-01-08 10:48:17 -080032CONNECTED = "Connected"
33SIGN_IN_NOTIFICATION = "Sign in to network"
Girish Moturu7e48b432019-07-11 14:52:13 -070034
35
36class CaptivePortalTest(base_test.BaseTestClass):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080037 """Tests for Captive portal."""
Girish Moturu7e48b432019-07-11 14:52:13 -070038
39 def setup_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080040 """Setup devices for tests and unpack params.
Girish Moturu7e48b432019-07-11 14:52:13 -070041
42 Required params:
43 1. rk_captive_portal: SSID of ruckus captive portal network in dict
44 2. gg_captive_portal: SSID of guestgate network in dict
45 3. uicd_workflows: uicd workflow that specify click actions to accept
46 a captive portal connection. Ex: Click on SignIn, Accept & Continue
47 //wireless/android/platform/testing/wifi/configs/uicd/
48 4. uic_zip: Zip file location of UICD application
49 """
50 self.dut = self.android_devices[0]
Girish Moturu267f71e2020-05-16 22:51:03 -070051 req_params = ["rk_captive_portal", "gg_captive_portal"]
Girish Moturu7e48b432019-07-11 14:52:13 -070052 self.unpack_userparams(req_param_names=req_params,)
Girish Moturu267f71e2020-05-16 22:51:03 -070053 wutils.wifi_test_device_init(self.dut)
Girish Moturu7e48b432019-07-11 14:52:13 -070054
55 def teardown_class(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080056 """Reset devices."""
Girish Moturu7e48b432019-07-11 14:52:13 -070057 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
Girish Moturu267f71e2020-05-16 22:51:03 -070058 wutils.reset_wifi(self.dut)
59 self.dut.droid.telephonyToggleDataConnection(True)
Girish Moturu7e48b432019-07-11 14:52:13 -070060
61 def setup_test(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080062 """Setup device."""
Girish Moturu7e48b432019-07-11 14:52:13 -070063 wutils.reset_wifi(self.dut)
Girish Moturu267f71e2020-05-16 22:51:03 -070064 self.dut.unlock_screen()
65 self._go_to_wifi_settings()
Girish Moturu7e48b432019-07-11 14:52:13 -070066
67 def on_fail(self, test_name, begin_time):
68 self.dut.take_bug_report(test_name, begin_time)
69
70 ### Helper methods ###
71
Girish Moturu267f71e2020-05-16 22:51:03 -070072 def _go_to_wifi_settings(self):
73 """Go to wifi settings to perform UI actions for Captive portal."""
74 self.dut.adb.shell("am start -a android.settings.SETTINGS")
75 asserts.assert_true(
76 uutils.has_element(self.dut, text="Network & internet"),
77 "Failed to find 'Network & internet' icon")
78 uutils.wait_and_click(self.dut, text="Network & internet")
79 uutils.wait_and_click(self.dut, text="Not connected")
80
Girish Moturu572d5212021-01-08 10:48:17 -080081 def _verify_sign_in_notification(self):
82 """Verify sign in notification shows for captive portal."""
83 curr_time = time.time()
84 while time.time() < curr_time + TIME_OUT:
Girish Moturue648b6a2021-03-04 13:52:15 -080085 time.sleep(3) # wait for sometime before checking the notification
Girish Moturu572d5212021-01-08 10:48:17 -080086 screen_dump = uutils.get_screen_dump_xml(self.dut)
87 nodes = screen_dump.getElementsByTagName('node')
88 for node in nodes:
89 if SIGN_IN_NOTIFICATION in node.getAttribute(
90 'text') or CONNECTED in node.getAttribute('text'):
91 return
Girish Moturu572d5212021-01-08 10:48:17 -080092 asserts.fail("Failed to get sign in notification")
93
Girish Moturu267f71e2020-05-16 22:51:03 -070094 def _verify_captive_portal(self, network, click_accept=ACCEPT_CONTINUE):
Girish Moturu3a8de0d2019-12-06 13:00:33 -080095 """Connect to captive portal network using uicd workflow.
Girish Moturu7e48b432019-07-11 14:52:13 -070096
97 Steps:
98 1. Connect to captive portal network
99 2. Run uicd workflow to accept connection
100 3. Verify internet connectivity
101
102 Args:
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800103 network: captive portal network to connect to
Girish Moturu267f71e2020-05-16 22:51:03 -0700104 click_accept: Notification to select to accept captive portal
Girish Moturu7e48b432019-07-11 14:52:13 -0700105 """
106 # connect to captive portal wifi network
Girish Moturu267f71e2020-05-16 22:51:03 -0700107 wutils.connect_to_wifi_network(
108 self.dut, network, check_connectivity=False)
Girish Moturu7e48b432019-07-11 14:52:13 -0700109
Girish Moturu267f71e2020-05-16 22:51:03 -0700110 # run ui automator
Girish Moturu572d5212021-01-08 10:48:17 -0800111 self._verify_sign_in_notification()
Girish Moturu267f71e2020-05-16 22:51:03 -0700112 uutils.wait_and_click(self.dut, text="%s" % network["SSID"])
113 if uutils.has_element(self.dut, text="%s" % click_accept):
114 uutils.wait_and_click(self.dut, text="%s" % click_accept)
Girish Moturu7e48b432019-07-11 14:52:13 -0700115
116 # wait for sometime for captive portal connection to go through
117 curr_time = time.time()
118 while time.time() < curr_time + TIME_OUT:
Girish Moturue648b6a2021-03-04 13:52:15 -0800119 time.sleep(3) # wait for sometime for AP to send DHCP info
Girish Moturu7e48b432019-07-11 14:52:13 -0700120 link_prop = self.dut.droid.connectivityGetActiveLinkProperties()
121 self.log.debug("Link properties %s" % link_prop)
122 if link_prop and link_prop[IFACE] == WLAN:
123 break
Girish Moturu7e48b432019-07-11 14:52:13 -0700124
125 # verify connectivity
Girish Moturu267f71e2020-05-16 22:51:03 -0700126 asserts.assert_true(
127 wutils.validate_connection(self.dut, ping_gateway=False),
128 "Failed to connect to internet. Captive portal test failed")
Girish Moturu7e48b432019-07-11 14:52:13 -0700129
130 ### Test Cases ###
131
132 @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800133 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700134 def test_ruckus_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800135 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700136
137 Steps:
138 1. Set default private dns mode
139 2. Connect to ruckus captive portal network
140 3. Verify connectivity
141 """
142 # set private dns to opportunistic
143 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
144
145 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700146 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700147
148 @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800149 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700150 def test_ruckus_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800151 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700152
153 Steps:
154 1. Turn off private dns mode
155 2. Connect to ruckus captive portal network
156 3. Verify connectivity
157 """
158 # turn off private dns
159 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
160
161 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700162 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700163
164 @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4")
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800165 @WifiBaseTest.wifi_test_wrap
Girish Moturu7e48b432019-07-11 14:52:13 -0700166 def test_ruckus_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800167 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700168
169 Steps:
170 1. Set strict private dns mode
171 2. Connect to ruckus captive portal network
172 3. Verify connectivity
173 """
174 # set private dns to strict mode
175 cutils.set_private_dns(self.dut,
176 cconst.PRIVATE_DNS_MODE_STRICT,
177 cconst.DNS_GOOGLE)
178
179 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700180 self._verify_captive_portal(self.rk_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700181
182 @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a")
183 def test_guestgate_captive_portal_default(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800184 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700185
186 Steps:
187 1. Set default private dns mode
188 2. Connect to guestgate captive portal network
189 3. Verify connectivity
190 """
191 # set private dns to opportunistic
192 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC)
193
194 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700195 self._verify_captive_portal(self.gg_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700196
197 @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc")
198 def test_guestgate_captive_portal_private_dns_off(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800199 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700200
201 Steps:
202 1. Turn off private dns mode
203 2. Connect to guestgate captive portal network
204 3. Verify connectivity
205 """
206 # turn off private dns
207 cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF)
208
209 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700210 self._verify_captive_portal(self.gg_captive_portal)
Girish Moturu7e48b432019-07-11 14:52:13 -0700211
212 @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a")
213 def test_guestgate_captive_portal_private_dns_strict(self):
Girish Moturu3a8de0d2019-12-06 13:00:33 -0800214 """Verify captive portal network.
Girish Moturu7e48b432019-07-11 14:52:13 -0700215
216 Steps:
217 1. Set strict private dns mode
218 2. Connect to guestgate captive portal network
219 3. Verify connectivity
220 """
221 # set private dns to strict mode
222 cutils.set_private_dns(self.dut,
223 cconst.PRIVATE_DNS_MODE_STRICT,
224 cconst.DNS_GOOGLE)
225
226 # verify connection to captive portal network
Girish Moturu267f71e2020-05-16 22:51:03 -0700227 self._verify_captive_portal(self.gg_captive_portal)