Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 1 | # |
| 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 | |
| 16 | import time |
| 17 | |
| 18 | from acts import asserts |
| 19 | from acts import base_test |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 20 | from acts.test_decorators import test_tracker_info |
Xianyuan Jia | 63751fb | 2020-11-17 00:07:40 +0000 | [diff] [blame^] | 21 | from acts_contrib.test_utils.net import connectivity_const as cconst |
| 22 | from acts_contrib.test_utils.net import connectivity_test_utils as cutils |
| 23 | from acts_contrib.test_utils.net import ui_utils as uutils |
| 24 | from acts_contrib.test_utils.wifi import wifi_test_utils as wutils |
| 25 | from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 26 | |
| 27 | WifiEnums = wutils.WifiEnums |
| 28 | IFACE = "InterfaceName" |
| 29 | TIME_OUT = 20 |
| 30 | WLAN = "wlan0" |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 31 | ACCEPT_CONTINUE = "Accept and Continue" |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 32 | |
| 33 | |
| 34 | class CaptivePortalTest(base_test.BaseTestClass): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 35 | """Tests for Captive portal.""" |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 36 | |
| 37 | def setup_class(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 38 | """Setup devices for tests and unpack params. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 39 | |
| 40 | Required params: |
| 41 | 1. rk_captive_portal: SSID of ruckus captive portal network in dict |
| 42 | 2. gg_captive_portal: SSID of guestgate network in dict |
| 43 | 3. uicd_workflows: uicd workflow that specify click actions to accept |
| 44 | a captive portal connection. Ex: Click on SignIn, Accept & Continue |
| 45 | //wireless/android/platform/testing/wifi/configs/uicd/ |
| 46 | 4. uic_zip: Zip file location of UICD application |
| 47 | """ |
| 48 | self.dut = self.android_devices[0] |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 49 | req_params = ["rk_captive_portal", "gg_captive_portal"] |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 50 | self.unpack_userparams(req_param_names=req_params,) |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 51 | wutils.wifi_test_device_init(self.dut) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 52 | |
| 53 | def teardown_class(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 54 | """Reset devices.""" |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 55 | cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC) |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 56 | wutils.reset_wifi(self.dut) |
| 57 | self.dut.droid.telephonyToggleDataConnection(True) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 58 | |
| 59 | def setup_test(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 60 | """Setup device.""" |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 61 | wutils.reset_wifi(self.dut) |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 62 | self.dut.unlock_screen() |
| 63 | self._go_to_wifi_settings() |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 64 | |
| 65 | def on_fail(self, test_name, begin_time): |
| 66 | self.dut.take_bug_report(test_name, begin_time) |
| 67 | |
| 68 | ### Helper methods ### |
| 69 | |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 70 | def _go_to_wifi_settings(self): |
| 71 | """Go to wifi settings to perform UI actions for Captive portal.""" |
| 72 | self.dut.adb.shell("am start -a android.settings.SETTINGS") |
| 73 | asserts.assert_true( |
| 74 | uutils.has_element(self.dut, text="Network & internet"), |
| 75 | "Failed to find 'Network & internet' icon") |
| 76 | uutils.wait_and_click(self.dut, text="Network & internet") |
| 77 | uutils.wait_and_click(self.dut, text="Not connected") |
| 78 | |
| 79 | def _verify_captive_portal(self, network, click_accept=ACCEPT_CONTINUE): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 80 | """Connect to captive portal network using uicd workflow. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 81 | |
| 82 | Steps: |
| 83 | 1. Connect to captive portal network |
| 84 | 2. Run uicd workflow to accept connection |
| 85 | 3. Verify internet connectivity |
| 86 | |
| 87 | Args: |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 88 | network: captive portal network to connect to |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 89 | click_accept: Notification to select to accept captive portal |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 90 | """ |
| 91 | # connect to captive portal wifi network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 92 | wutils.connect_to_wifi_network( |
| 93 | self.dut, network, check_connectivity=False) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 94 | |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 95 | # run ui automator |
| 96 | uutils.wait_and_click(self.dut, text="%s" % network["SSID"]) |
| 97 | if uutils.has_element(self.dut, text="%s" % click_accept): |
| 98 | uutils.wait_and_click(self.dut, text="%s" % click_accept) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 99 | |
| 100 | # wait for sometime for captive portal connection to go through |
| 101 | curr_time = time.time() |
| 102 | while time.time() < curr_time + TIME_OUT: |
| 103 | link_prop = self.dut.droid.connectivityGetActiveLinkProperties() |
| 104 | self.log.debug("Link properties %s" % link_prop) |
| 105 | if link_prop and link_prop[IFACE] == WLAN: |
| 106 | break |
| 107 | time.sleep(2) |
| 108 | |
| 109 | # verify connectivity |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 110 | asserts.assert_true( |
| 111 | wutils.validate_connection(self.dut, ping_gateway=False), |
| 112 | "Failed to connect to internet. Captive portal test failed") |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 113 | |
| 114 | ### Test Cases ### |
| 115 | |
| 116 | @test_tracker_info(uuid="b035b4f9-40f7-42f6-9941-ec27afe15040") |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 117 | @WifiBaseTest.wifi_test_wrap |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 118 | def test_ruckus_captive_portal_default(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 119 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 120 | |
| 121 | Steps: |
| 122 | 1. Set default private dns mode |
| 123 | 2. Connect to ruckus captive portal network |
| 124 | 3. Verify connectivity |
| 125 | """ |
| 126 | # set private dns to opportunistic |
| 127 | cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC) |
| 128 | |
| 129 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 130 | self._verify_captive_portal(self.rk_captive_portal) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 131 | |
| 132 | @test_tracker_info(uuid="8ea18d80-0170-41b1-8945-fe14bcd4feab") |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 133 | @WifiBaseTest.wifi_test_wrap |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 134 | def test_ruckus_captive_portal_private_dns_off(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 135 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 136 | |
| 137 | Steps: |
| 138 | 1. Turn off private dns mode |
| 139 | 2. Connect to ruckus captive portal network |
| 140 | 3. Verify connectivity |
| 141 | """ |
| 142 | # turn off private dns |
| 143 | cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF) |
| 144 | |
| 145 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 146 | self._verify_captive_portal(self.rk_captive_portal) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 147 | |
| 148 | @test_tracker_info(uuid="e8e05907-55f7-40e5-850c-b3111ceb31a4") |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 149 | @WifiBaseTest.wifi_test_wrap |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 150 | def test_ruckus_captive_portal_private_dns_strict(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 151 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 152 | |
| 153 | Steps: |
| 154 | 1. Set strict private dns mode |
| 155 | 2. Connect to ruckus captive portal network |
| 156 | 3. Verify connectivity |
| 157 | """ |
| 158 | # set private dns to strict mode |
| 159 | cutils.set_private_dns(self.dut, |
| 160 | cconst.PRIVATE_DNS_MODE_STRICT, |
| 161 | cconst.DNS_GOOGLE) |
| 162 | |
| 163 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 164 | self._verify_captive_portal(self.rk_captive_portal) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 165 | |
| 166 | @test_tracker_info(uuid="76e49800-f141-4fd2-9969-562585eb1e7a") |
| 167 | def test_guestgate_captive_portal_default(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 168 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 169 | |
| 170 | Steps: |
| 171 | 1. Set default private dns mode |
| 172 | 2. Connect to guestgate captive portal network |
| 173 | 3. Verify connectivity |
| 174 | """ |
| 175 | # set private dns to opportunistic |
| 176 | cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OPPORTUNISTIC) |
| 177 | |
| 178 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 179 | self._verify_captive_portal(self.gg_captive_portal) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 180 | |
| 181 | @test_tracker_info(uuid="0aea0cac-0f42-406b-84ba-62c1ef74adfc") |
| 182 | def test_guestgate_captive_portal_private_dns_off(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 183 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 184 | |
| 185 | Steps: |
| 186 | 1. Turn off private dns mode |
| 187 | 2. Connect to guestgate captive portal network |
| 188 | 3. Verify connectivity |
| 189 | """ |
| 190 | # turn off private dns |
| 191 | cutils.set_private_dns(self.dut, cconst.PRIVATE_DNS_MODE_OFF) |
| 192 | |
| 193 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 194 | self._verify_captive_portal(self.gg_captive_portal) |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 195 | |
| 196 | @test_tracker_info(uuid="39124dcc-2fd3-4d33-b129-a1c8150b7f2a") |
| 197 | def test_guestgate_captive_portal_private_dns_strict(self): |
Girish Moturu | 3a8de0d | 2019-12-06 13:00:33 -0800 | [diff] [blame] | 198 | """Verify captive portal network. |
Girish Moturu | 7e48b43 | 2019-07-11 14:52:13 -0700 | [diff] [blame] | 199 | |
| 200 | Steps: |
| 201 | 1. Set strict private dns mode |
| 202 | 2. Connect to guestgate captive portal network |
| 203 | 3. Verify connectivity |
| 204 | """ |
| 205 | # set private dns to strict mode |
| 206 | cutils.set_private_dns(self.dut, |
| 207 | cconst.PRIVATE_DNS_MODE_STRICT, |
| 208 | cconst.DNS_GOOGLE) |
| 209 | |
| 210 | # verify connection to captive portal network |
Girish Moturu | 267f71e | 2020-05-16 22:51:03 -0700 | [diff] [blame] | 211 | self._verify_captive_portal(self.gg_captive_portal) |