Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/website/SiteSettingsPreferencesTest.java

Issue 1432573002: Adding <keygen> Content Setting (Android UI) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@keygen_ui
Patch Set: Trying tested code. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.test.util.CommandLineFlags; 12 import org.chromium.base.test.util.CommandLineFlags;
13 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
14 import org.chromium.chrome.browser.ChromeActivity; 14 import org.chromium.chrome.browser.ChromeActivity;
15 import org.chromium.chrome.browser.ChromeApplication; 15 import org.chromium.chrome.browser.ChromeApplication;
16 import org.chromium.chrome.browser.ChromeSwitches; 16 import org.chromium.chrome.browser.ChromeSwitches;
17 import org.chromium.chrome.browser.infobar.InfoBarContainer; 17 import org.chromium.chrome.browser.infobar.InfoBarContainer;
18 import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference; 18 import org.chromium.chrome.browser.preferences.ChromeBaseCheckBoxPreference;
19 import org.chromium.chrome.browser.preferences.ChromeBaseListPreference;
19 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference; 20 import org.chromium.chrome.browser.preferences.ChromeSwitchPreference;
20 import org.chromium.chrome.browser.preferences.LocationSettings; 21 import org.chromium.chrome.browser.preferences.LocationSettings;
21 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 22 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
22 import org.chromium.chrome.browser.preferences.Preferences; 23 import org.chromium.chrome.browser.preferences.Preferences;
23 import org.chromium.chrome.browser.preferences.PreferencesLauncher; 24 import org.chromium.chrome.browser.preferences.PreferencesLauncher;
24 import org.chromium.chrome.browser.preferences.PreferencesTest; 25 import org.chromium.chrome.browser.preferences.PreferencesTest;
25 import org.chromium.chrome.browser.util.FeatureUtilities; 26 import org.chromium.chrome.browser.util.FeatureUtilities;
26 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 27 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
27 import org.chromium.chrome.test.util.ChromeTabUtils; 28 import org.chromium.chrome.test.util.ChromeTabUtils;
28 import org.chromium.chrome.test.util.InfoBarTestAnimationListener; 29 import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 117
117 private Preferences startSiteSettingsCategory(String category) { 118 private Preferences startSiteSettingsCategory(String category) {
118 Bundle fragmentArgs = new Bundle(); 119 Bundle fragmentArgs = new Bundle();
119 fragmentArgs.putString(SingleCategoryPreferences.EXTRA_CATEGORY, categor y); 120 fragmentArgs.putString(SingleCategoryPreferences.EXTRA_CATEGORY, categor y);
120 Intent intent = PreferencesLauncher.createIntentForSettingsPage( 121 Intent intent = PreferencesLauncher.createIntentForSettingsPage(
121 getInstrumentation().getTargetContext(), SingleCategoryPreferenc es.class.getName()); 122 getInstrumentation().getTargetContext(), SingleCategoryPreferenc es.class.getName());
122 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ; 123 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ;
123 return (Preferences) getInstrumentation().startActivitySync(intent); 124 return (Preferences) getInstrumentation().startActivitySync(intent);
124 } 125 }
125 126
127 private Preferences startSingleWebsitePreferences(Website site) {
128 Bundle fragmentArgs = new Bundle();
129 fragmentArgs.putSerializable(SingleWebsitePreferences.EXTRA_SITE, site);
130 Intent intent = PreferencesLauncher.createIntentForSettingsPage(
131 getInstrumentation().getTargetContext(), SingleWebsitePreference s.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
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 String origin, final boolean enabled) {
268 Website website = new Website(WebsiteAddress.create(origin));
269 website.setKeygenInfo(new KeygenInfo(origin, origin, false));
270 final Preferences preferenceActivity = startSingleWebsitePreferences(web site);
271
272 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
273 @Override
274 public void run() {
275 SingleWebsitePreferences websitePreferences =
276 (SingleWebsitePreferences) preferenceActivity.getFragmen tForTest();
277 ChromeBaseListPreference keygen =
278 (ChromeBaseListPreference) websitePreferences.findPrefer ence(
279 SingleWebsitePreferences.PREF_KEYGEN_PERMISSION) ;
280 websitePreferences.onPreferenceChange(keygen, enabled
281 ? ContentSetting.ALLOW.toString()
282 : ContentSetting.BLOCK.toString());
283 }
284 });
285 preferenceActivity.finish();
286 }
287
257 /** 288 /**
258 * Tests that disabling cookies turns off the third-party cookie toggle. 289 * Tests that disabling cookies turns off the third-party cookie toggle.
259 * @throws Exception 290 * @throws Exception
260 */ 291 */
261 @SmallTest 292 @SmallTest
262 @Feature({"Preferences"}) 293 @Feature({"Preferences"})
263 public void testThirdPartyCookieToggleGetsDisabled() throws Exception { 294 public void testThirdPartyCookieToggleGetsDisabled() throws Exception {
264 Preferences preferenceActivity = 295 Preferences preferenceActivity =
265 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY); 296 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY);
266 setCookiesEnabled(preferenceActivity, true); 297 setCookiesEnabled(preferenceActivity, true);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 setEnablePopups(true); 375 setEnablePopups(true);
345 376
346 // Test that a popup opens. 377 // Test that a popup opens.
347 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html ")); 378 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html "));
348 getInstrumentation().waitForIdleSync(); 379 getInstrumentation().waitForIdleSync();
349 380
350 assertEquals(2, getTabCount()); 381 assertEquals(2, getTabCount());
351 } 382 }
352 383
353 /** 384 /**
385 * Sets Allow Keygen Enabled to be false and make sure it is set correctly.
386 * @throws Exception
387 */
388 @SmallTest
389 @Feature({"Preferences"})
390 public void testKeygenBlocked() throws Exception {
391 final String origin = "http://example.com/";
392 setEnableKeygen(origin, false);
393
394 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
395 @Override
396 public void run() {
397 Website site = new Website(WebsiteAddress.create(origin));
398 site.setKeygenInfo(new KeygenInfo(origin, origin, false));
399 assertEquals(site.getKeygenPermission(), ContentSetting.BLOCK);
400 }
401 });
402 }
403
404 /**
405 * Sets Allow Keygen Enabled to be true and make sure it is set correctly.
406 * @throws Exception
407 */
408 @SmallTest
409 @Feature({"Preferences"})
410 public void testKeygenNotBlocked() throws Exception {
411 final String origin = "http://example.com/";
412 setEnableKeygen(origin, true);
413
414 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
415 @Override
416 public void run() {
417 Website site = new Website(WebsiteAddress.create(origin));
418 site.setKeygenInfo(new KeygenInfo(origin, origin, false));
419 assertEquals(site.getKeygenPermission(), ContentSetting.ALLOW);
420 }
421 });
422 }
423
424 /**
354 * Sets Allow Camera Enabled to be false and make sure it is set correctly. 425 * Sets Allow Camera Enabled to be false and make sure it is set correctly.
355 * @throws Exception 426 * @throws Exception
356 */ 427 */
357 @SmallTest 428 @SmallTest
358 @Feature({"Preferences"}) 429 @Feature({"Preferences"})
359 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM) 430 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM)
360 public void testCameraBlocked() throws Exception { 431 public void testCameraBlocked() throws Exception {
361 setEnableCamera(false); 432 setEnableCamera(false);
362 433
363 // Test that the camera permission doesn't get requested. 434 // Test that the camera permission doesn't get requested.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 public Integer call() throws Exception { 531 public Integer call() throws Exception {
461 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) { 532 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) {
462 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount(); 533 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount();
463 } else { 534 } else {
464 return getActivity().getTabModelSelector().getTotalTabCount( ); 535 return getActivity().getTabModelSelector().getTotalTabCount( );
465 } 536 }
466 } 537 }
467 }); 538 });
468 } 539 }
469 } 540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698