1 package android.webkit; 2 3 import android.webkit.WebSettings; 4 import android.webkit.TestWebSettings; 5 import com.xtremelabs.robolectric.Robolectric; 6 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 7 import org.junit.Before; 8 import org.junit.Test; 9 import org.junit.runner.RunWith; 10 11 import static org.hamcrest.CoreMatchers.equalTo; 12 import static org.junit.Assert.assertThat; 13 14 @RunWith(WithTestDefaultsRunner.class) 15 public class TestWebSettingsTest { 16 17 private TestWebSettings webSettings; 18 19 private boolean[] trueAndFalse = {true, false}; 20 21 @Before setUp()22 public void setUp() throws Exception { 23 webSettings = new TestWebSettings(); 24 } 25 26 @Test testDefaults()27 public void testDefaults() { 28 assertThat(webSettings.getAllowFileAccess(), equalTo(true)); 29 assertThat(webSettings.getBlockNetworkImage(), equalTo(false)); 30 assertThat(webSettings.getBlockNetworkLoads(), equalTo(false)); 31 assertThat(webSettings.getBuiltInZoomControls(), equalTo(true)); 32 assertThat(webSettings.getDatabaseEnabled(), equalTo(false)); 33 assertThat(webSettings.getDomStorageEnabled(), equalTo(false)); 34 assertThat(webSettings.getJavaScriptEnabled(), equalTo(false)); 35 assertThat(webSettings.getLightTouchEnabled(), equalTo(false)); 36 assertThat(webSettings.getLoadWithOverviewMode(), equalTo(false)); 37 assertThat(webSettings.getPluginState(), equalTo(WebSettings.PluginState.OFF)); 38 39 // deprecated methods 40 assertThat(webSettings.getPluginsEnabled(), equalTo(false)); 41 42 // obsoleted methods 43 assertThat(webSettings.getNeedInitialFocus(), equalTo(false)); 44 assertThat(webSettings.getSupportMultipleWindows(), equalTo(false)); 45 assertThat(webSettings.getSupportZoom(), equalTo(true)); 46 } 47 48 @Test testAllowFileAccess()49 public void testAllowFileAccess() { 50 for (boolean value : trueAndFalse) { 51 webSettings.setAllowFileAccess(value); 52 assertThat(webSettings.getAllowFileAccess(), equalTo(value)); 53 } 54 } 55 56 @Test testAllowFileAccessFromFileURLs()57 public void testAllowFileAccessFromFileURLs() { 58 for (boolean value : trueAndFalse) { 59 webSettings.setAllowFileAccessFromFileURLs(value); 60 assertThat(webSettings.getAllowFileAccessFromFileURLs(), equalTo(value)); 61 } 62 } 63 64 @Test testAllowUniversalAccessFromFileURLs()65 public void testAllowUniversalAccessFromFileURLs() { 66 for (boolean value : trueAndFalse) { 67 webSettings.setAllowUniversalAccessFromFileURLs(value); 68 assertThat(webSettings.getAllowUniversalAccessFromFileURLs(), equalTo(value)); 69 } 70 } 71 72 @Test testBlockNetworkImage()73 public void testBlockNetworkImage() { 74 for (boolean value : trueAndFalse) { 75 webSettings.setBlockNetworkImage(value); 76 assertThat(webSettings.getBlockNetworkImage(), equalTo(value)); 77 } 78 } 79 80 @Test testBlockNetworkLoads()81 public void testBlockNetworkLoads() { 82 for (boolean value : trueAndFalse) { 83 webSettings.setBlockNetworkLoads(value); 84 assertThat(webSettings.getBlockNetworkLoads(), equalTo(value)); 85 } 86 } 87 88 @Test testBuiltInZoomControls()89 public void testBuiltInZoomControls() { 90 for (boolean value : trueAndFalse) { 91 webSettings.setBuiltInZoomControls(value); 92 assertThat(webSettings.getBuiltInZoomControls(), equalTo(value)); 93 } 94 } 95 96 @Test testDatabaseEnabled()97 public void testDatabaseEnabled() { 98 for (boolean value : trueAndFalse) { 99 webSettings.setDatabaseEnabled(value); 100 assertThat(webSettings.getDatabaseEnabled(), equalTo(value)); 101 } 102 } 103 104 @Test testDomStorageEnabled()105 public void testDomStorageEnabled() { 106 for (boolean value : trueAndFalse) { 107 webSettings.setDomStorageEnabled(value); 108 assertThat(webSettings.getDomStorageEnabled(), equalTo(value)); 109 } 110 } 111 112 @Test testJavaScriptEnabled()113 public void testJavaScriptEnabled() { 114 for (boolean value : trueAndFalse) { 115 webSettings.setJavaScriptEnabled(value); 116 assertThat(webSettings.getJavaScriptEnabled(), equalTo(value)); 117 } 118 } 119 120 @Test testLightTouchEnabled()121 public void testLightTouchEnabled() { 122 for (boolean value : trueAndFalse) { 123 webSettings.setLightTouchEnabled(value); 124 assertThat(webSettings.getLightTouchEnabled(), equalTo(value)); 125 } 126 } 127 128 @Test testLoadWithOverviewMode()129 public void testLoadWithOverviewMode() { 130 for (boolean value : trueAndFalse) { 131 webSettings.setLoadWithOverviewMode(value); 132 assertThat(webSettings.getLoadWithOverviewMode(), equalTo(value)); 133 } 134 } 135 136 @Test testNeedInitialFocus()137 public void testNeedInitialFocus() { 138 for (boolean value : trueAndFalse) { 139 webSettings.setNeedInitialFocus(value); 140 assertThat(webSettings.getNeedInitialFocus(), equalTo(value)); 141 } 142 } 143 144 @Test testPluginsEnabled()145 public void testPluginsEnabled() { 146 for (boolean value : trueAndFalse) { 147 webSettings.setPluginsEnabled(value); 148 assertThat(webSettings.getPluginsEnabled(), equalTo(value)); 149 } 150 } 151 152 @Test testPluginState()153 public void testPluginState() { 154 WebSettings.PluginState[] states = { 155 WebSettings.PluginState.OFF, 156 WebSettings.PluginState.ON, 157 WebSettings.PluginState.ON_DEMAND 158 }; 159 160 for (WebSettings.PluginState state : states) { 161 webSettings.setPluginState(state); 162 assertThat(webSettings.getPluginState(), equalTo(state)); 163 } 164 } 165 166 @Test testSupportMultipleWindows()167 public void testSupportMultipleWindows() { 168 for (boolean value : trueAndFalse) { 169 webSettings.setSupportMultipleWindows(value); 170 assertThat(webSettings.getSupportMultipleWindows(), equalTo(value)); 171 } 172 } 173 174 @Test testSupportZoom()175 public void testSupportZoom() { 176 for (boolean value : trueAndFalse) { 177 webSettings.setSupportZoom(value); 178 assertThat(webSettings.getSupportZoom(), equalTo(value)); 179 } 180 } 181 } 182