Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.preferences.website; | 5 package org.chromium.chrome.browser.preferences.website; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.os.Bundle; | 8 import android.os.Bundle; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 116 |
| 117 private Preferences startSiteSettingsCategory(String category) { | 117 private Preferences startSiteSettingsCategory(String category) { |
| 118 Bundle fragmentArgs = new Bundle(); | 118 Bundle fragmentArgs = new Bundle(); |
| 119 fragmentArgs.putString(SingleCategoryPreferences.EXTRA_CATEGORY, categor y); | 119 fragmentArgs.putString(SingleCategoryPreferences.EXTRA_CATEGORY, categor y); |
| 120 Intent intent = PreferencesLauncher.createIntentForSettingsPage( | 120 Intent intent = PreferencesLauncher.createIntentForSettingsPage( |
| 121 getInstrumentation().getTargetContext(), SingleCategoryPreferenc es.class.getName()); | 121 getInstrumentation().getTargetContext(), SingleCategoryPreferenc es.class.getName()); |
| 122 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ; | 122 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ; |
| 123 return (Preferences) getInstrumentation().startActivitySync(intent); | 123 return (Preferences) getInstrumentation().startActivitySync(intent); |
| 124 } | 124 } |
| 125 | 125 |
| 126 private Preferences startSingleWebsitePreferences() { | |
| 127 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsForSite ( | |
| 128 TestHttpServerClient.getUrl("")); | |
|
newt (away)
2015/12/15 00:10:01
Why not use a real page here? Seems like TestHttpS
svaldez
2015/12/15 21:45:57
Done.
| |
| 129 Intent intent = PreferencesLauncher.createIntentForSettingsPage( | |
| 130 getInstrumentation().getTargetContext(), | |
| 131 SingleWebsitePreferences.class.getName()); | |
| 132 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ; | |
| 133 return (Preferences) getInstrumentation().startActivitySync(intent); | |
| 134 } | |
| 135 | |
| 126 private void setCookiesEnabled(final Preferences preferenceActivity, final b oolean enabled) { | 136 private void setCookiesEnabled(final Preferences preferenceActivity, final b oolean enabled) { |
| 127 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 137 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 128 @Override | 138 @Override |
| 129 public void run() { | 139 public void run() { |
| 130 final SingleCategoryPreferences websitePreferences = | 140 final SingleCategoryPreferences websitePreferences = |
| 131 (SingleCategoryPreferences) preferenceActivity.getFragme ntForTest(); | 141 (SingleCategoryPreferences) preferenceActivity.getFragme ntForTest(); |
| 132 final ChromeSwitchPreference cookies = | 142 final ChromeSwitchPreference cookies = |
| 133 (ChromeSwitchPreference) websitePreferences.findPreferen ce( | 143 (ChromeSwitchPreference) websitePreferences.findPreferen ce( |
| 134 SingleCategoryPreferences.READ_WRITE_TOGGLE_KEY) ; | 144 SingleCategoryPreferences.READ_WRITE_TOGGLE_KEY) ; |
| 135 final ChromeBaseCheckBoxPreference thirdPartyCookies = | 145 final ChromeBaseCheckBoxPreference thirdPartyCookies = |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 PreferencesTest.clickPreference(languagePreferences, checkbo x); | 257 PreferencesTest.clickPreference(languagePreferences, checkbo x); |
| 248 } | 258 } |
| 249 assertEquals("Auto detect encoding should be " + (enabled ? "ena bled" : "disabled"), | 259 assertEquals("Auto detect encoding should be " + (enabled ? "ena bled" : "disabled"), |
| 250 enabled, PrefServiceBridge.getInstance().isAutoDetectEnc odingEnabled()); | 260 enabled, PrefServiceBridge.getInstance().isAutoDetectEnc odingEnabled()); |
| 251 } | 261 } |
| 252 }); | 262 }); |
| 253 | 263 |
| 254 preferenceActivity.finish(); | 264 preferenceActivity.finish(); |
| 255 } | 265 } |
| 256 | 266 |
| 267 private void setEnableKeygen(final boolean enabled) { | |
| 268 final Preferences preferenceActivity = startSingleWebsitePreferences(); | |
| 269 | |
| 270 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 271 @Override | |
| 272 public void run() { | |
| 273 SingleWebsitePreferences websitePreferences = | |
| 274 (SingleWebsitePreferences) preferenceActivity.getFragmen tForTest(); | |
| 275 ChromeSwitchPreference keygen = (ChromeSwitchPreference) | |
|
newt (away)
2015/12/15 00:10:01
Doesn't this cast fail? I thought PREF_KEYGEN_PERM
svaldez
2015/12/15 21:45:57
Done.
| |
| 276 websitePreferences.findPreference( | |
| 277 SingleWebsitePreferences.PREF_KEYGEN_PERMISSION); | |
| 278 websitePreferences.onPreferenceChange(keygen, (enabled ? "ALLOW" : "BLOCK")); | |
|
newt (away)
2015/12/15 00:10:01
I'd simulate clicking the switch, rather than call
svaldez
2015/12/15 21:45:57
Done.
| |
| 279 } | |
| 280 }); | |
| 281 preferenceActivity.finish(); | |
| 282 } | |
| 283 | |
| 257 /** | 284 /** |
| 258 * Tests that disabling cookies turns off the third-party cookie toggle. | 285 * Tests that disabling cookies turns off the third-party cookie toggle. |
| 259 * @throws Exception | 286 * @throws Exception |
| 260 */ | 287 */ |
| 261 @SmallTest | 288 @SmallTest |
| 262 @Feature({"Preferences"}) | 289 @Feature({"Preferences"}) |
| 263 public void testThirdPartyCookieToggleGetsDisabled() throws Exception { | 290 public void testThirdPartyCookieToggleGetsDisabled() throws Exception { |
| 264 Preferences preferenceActivity = | 291 Preferences preferenceActivity = |
| 265 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY); | 292 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY); |
| 266 setCookiesEnabled(preferenceActivity, true); | 293 setCookiesEnabled(preferenceActivity, true); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 setEnablePopups(true); | 371 setEnablePopups(true); |
| 345 | 372 |
| 346 // Test that a popup opens. | 373 // Test that a popup opens. |
| 347 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html ")); | 374 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html ")); |
| 348 getInstrumentation().waitForIdleSync(); | 375 getInstrumentation().waitForIdleSync(); |
| 349 | 376 |
| 350 assertEquals(2, getTabCount()); | 377 assertEquals(2, getTabCount()); |
| 351 } | 378 } |
| 352 | 379 |
| 353 /** | 380 /** |
| 381 * Sets Allow Keygen Enabled to be false and make sure it is set correctly. | |
| 382 * @throws Exception | |
| 383 */ | |
| 384 @SmallTest | |
| 385 @Feature({"Preferences"}) | |
| 386 public void testKeygenBlocked() throws Exception { | |
|
newt (away)
2015/12/15 00:10:01
Alternatively, you could just test the Preferences
svaldez
2015/12/15 21:45:57
Done.
| |
| 387 setEnableKeygen(false); | |
| 388 | |
| 389 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/keygen.htm l")); | |
| 390 assertEquals("false", runJavaScriptCodeInCurrentTab("didKeygen();")); | |
| 391 } | |
| 392 | |
| 393 /** | |
| 394 * Sets Allow Keygen Enabled to be true and make sure it is set correctly. | |
| 395 * @throws Exception | |
| 396 */ | |
| 397 @SmallTest | |
| 398 @Feature({"Preferences"}) | |
| 399 public void testKeygenNotBlocked() throws Exception { | |
| 400 setEnableKeygen(true); | |
| 401 | |
| 402 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/keygen.htm l")); | |
| 403 assertEquals("true", runJavaScriptCodeInCurrentTab("didKeygen();")); | |
| 404 } | |
| 405 | |
| 406 /** | |
| 354 * Sets Allow Camera Enabled to be false and make sure it is set correctly. | 407 * Sets Allow Camera Enabled to be false and make sure it is set correctly. |
| 355 * @throws Exception | 408 * @throws Exception |
| 356 */ | 409 */ |
| 357 @SmallTest | 410 @SmallTest |
| 358 @Feature({"Preferences"}) | 411 @Feature({"Preferences"}) |
| 359 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM) | 412 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM) |
| 360 public void testCameraBlocked() throws Exception { | 413 public void testCameraBlocked() throws Exception { |
| 361 setEnableCamera(false); | 414 setEnableCamera(false); |
| 362 | 415 |
| 363 // Test that the camera permission doesn't get requested. | 416 // Test that the camera permission doesn't get requested. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 public Integer call() throws Exception { | 513 public Integer call() throws Exception { |
| 461 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) { | 514 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) { |
| 462 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount(); | 515 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount(); |
| 463 } else { | 516 } else { |
| 464 return getActivity().getTabModelSelector().getTotalTabCount( ); | 517 return getActivity().getTabModelSelector().getTotalTabCount( ); |
| 465 } | 518 } |
| 466 } | 519 } |
| 467 }); | 520 }); |
| 468 } | 521 } |
| 469 } | 522 } |
| OLD | NEW |