1 /* 2 * Copyright (C) 2017 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 17 package com.android.cts.deviceowner; 18 19 import android.content.pm.PackageManager; 20 21 import com.android.compatibility.common.util.WifiConfigCreator; 22 23 /** 24 * Tests that DeviceOwner can add WifiConfigurations containing a HttpProxy 25 */ 26 public class WifiSetHttpProxyTest extends BaseDeviceOwnerTest { 27 28 private static final String TAG = "WifiSetHttpProxyTest"; 29 private static final String TEST_PAC_URL = "http://www.example.com/proxy.pac"; 30 private static final String TEST_SSID = "SomeProxyApSsid"; 31 private static final int FAILURE_NETWORK_ID = -1; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 } 37 38 /** 39 * Test WifiManager.addNetwork() succeeds for a DeviceOwner adding a WifiConfiguraiton 40 * containing a HttpProxy. 41 * 2. Creates a new WifiConfiguration with ssid TEST_SSID 42 * 3. Adds a PAC proxy file URL to the WifiConfiguraiton 43 * 4. Adds the WifiConfiguration via WifiManager.addNetwork(), expects success 44 * 5. Verifies the added WifiConfiguration has the same proxy 45 */ 46 public void testSetHttpProxy() throws Exception { 47 PackageManager packageManager = getContext().getPackageManager(); 48 if (!packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)) { 49 // skip the test if WiFi is not supported 50 return; 51 } 52 WifiConfigCreator configCreator = new WifiConfigCreator(getContext()); 53 String retreievedPacProxyUrl = configCreator.addHttpProxyNetworkVerifyAndRemove( 54 TEST_SSID, TEST_PAC_URL); 55 assertEquals(TEST_PAC_URL, retreievedPacProxyUrl); 56 } 57 } 58