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

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: Simplify fragmentArgs. Created 5 years 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(),
132 SingleWebsitePreferences.class.getName());
133 intent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArgs) ;
134 return (Preferences) getInstrumentation().startActivitySync(intent);
135 }
136
126 private void setCookiesEnabled(final Preferences preferenceActivity, final b oolean enabled) { 137 private void setCookiesEnabled(final Preferences preferenceActivity, final b oolean enabled) {
127 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 138 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
128 @Override 139 @Override
129 public void run() { 140 public void run() {
130 final SingleCategoryPreferences websitePreferences = 141 final SingleCategoryPreferences websitePreferences =
131 (SingleCategoryPreferences) preferenceActivity.getFragme ntForTest(); 142 (SingleCategoryPreferences) preferenceActivity.getFragme ntForTest();
132 final ChromeSwitchPreference cookies = 143 final ChromeSwitchPreference cookies =
133 (ChromeSwitchPreference) websitePreferences.findPreferen ce( 144 (ChromeSwitchPreference) websitePreferences.findPreferen ce(
134 SingleCategoryPreferences.READ_WRITE_TOGGLE_KEY) ; 145 SingleCategoryPreferences.READ_WRITE_TOGGLE_KEY) ;
135 final ChromeBaseCheckBoxPreference thirdPartyCookies = 146 final ChromeBaseCheckBoxPreference thirdPartyCookies =
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 PreferencesTest.clickPreference(languagePreferences, checkbo x); 258 PreferencesTest.clickPreference(languagePreferences, checkbo x);
248 } 259 }
249 assertEquals("Auto detect encoding should be " + (enabled ? "ena bled" : "disabled"), 260 assertEquals("Auto detect encoding should be " + (enabled ? "ena bled" : "disabled"),
250 enabled, PrefServiceBridge.getInstance().isAutoDetectEnc odingEnabled()); 261 enabled, PrefServiceBridge.getInstance().isAutoDetectEnc odingEnabled());
251 } 262 }
252 }); 263 });
253 264
254 preferenceActivity.finish(); 265 preferenceActivity.finish();
255 } 266 }
256 267
268 private void setEnableKeygen(String origin, final boolean enabled) {
269 Website website = new Website(WebsiteAddress.create(origin));
270 website.setKeygenInfo(new KeygenInfo(origin, origin, false));
newt (away) 2015/12/17 21:00:27 Should you be setting the embedder here, or just t
271 final Preferences preferenceActivity = startSingleWebsitePreferences(web site);
272
273 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
274 @Override
275 public void run() {
276 SingleWebsitePreferences websitePreferences =
277 (SingleWebsitePreferences) preferenceActivity.getFragmen tForTest();
278 ChromeBaseListPreference keygen = (ChromeBaseListPreference)
279 websitePreferences.findPreference(
280 SingleWebsitePreferences.PREF_KEYGEN_PERMISSION);
281 keygen.setValue(enabled ? "ALLOW" : "BLOCK");
282 }
283 });
284 preferenceActivity.finish();
285 }
286
257 /** 287 /**
258 * Tests that disabling cookies turns off the third-party cookie toggle. 288 * Tests that disabling cookies turns off the third-party cookie toggle.
259 * @throws Exception 289 * @throws Exception
260 */ 290 */
261 @SmallTest 291 @SmallTest
262 @Feature({"Preferences"}) 292 @Feature({"Preferences"})
263 public void testThirdPartyCookieToggleGetsDisabled() throws Exception { 293 public void testThirdPartyCookieToggleGetsDisabled() throws Exception {
264 Preferences preferenceActivity = 294 Preferences preferenceActivity =
265 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY); 295 startSiteSettingsCategory(SiteSettingsPreferences.COOKIES_KEY);
266 setCookiesEnabled(preferenceActivity, true); 296 setCookiesEnabled(preferenceActivity, true);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 setEnablePopups(true); 374 setEnablePopups(true);
345 375
346 // Test that a popup opens. 376 // Test that a popup opens.
347 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html ")); 377 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/popup.html "));
348 getInstrumentation().waitForIdleSync(); 378 getInstrumentation().waitForIdleSync();
349 379
350 assertEquals(2, getTabCount()); 380 assertEquals(2, getTabCount());
351 } 381 }
352 382
353 /** 383 /**
384 * Sets Allow Keygen Enabled to be false and make sure it is set correctly.
385 * @throws Exception
386 */
387 @SmallTest
388 @Feature({"Preferences"})
389 public void testKeygenBlocked() throws Exception {
390 String origin = "http://example.com/";
391 setEnableKeygen(origin, false);
392 int setting = WebsitePreferenceBridge.nativeGetKeygenSettingForOrigin(
393 origin, origin, false);
394 assertEquals(ContentSetting.fromInt(setting), ContentSetting.BLOCK);
395 }
396
397 /**
398 * Sets Allow Keygen Enabled to be true and make sure it is set correctly.
399 * @throws Exception
400 */
401 @SmallTest
402 @Feature({"Preferences"})
403 public void testKeygenNotBlocked() throws Exception {
404 String origin = "http://example.com/";
405 setEnableKeygen(origin, true);
406 int setting = WebsitePreferenceBridge.nativeGetKeygenSettingForOrigin(
407 origin, origin, false);
408 assertEquals(ContentSetting.fromInt(setting), ContentSetting.ALLOW);
409 }
410
411 /**
354 * Sets Allow Camera Enabled to be false and make sure it is set correctly. 412 * Sets Allow Camera Enabled to be false and make sure it is set correctly.
355 * @throws Exception 413 * @throws Exception
356 */ 414 */
357 @SmallTest 415 @SmallTest
358 @Feature({"Preferences"}) 416 @Feature({"Preferences"})
359 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM) 417 @CommandLineFlags.Add(ChromeSwitches.USE_FAKE_DEVICE_FOR_MEDIA_STREAM)
360 public void testCameraBlocked() throws Exception { 418 public void testCameraBlocked() throws Exception {
361 setEnableCamera(false); 419 setEnableCamera(false);
362 420
363 // Test that the camera permission doesn't get requested. 421 // 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 { 518 public Integer call() throws Exception {
461 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) { 519 if (FeatureUtilities.isDocumentMode(getInstrumentation().getTarg etContext())) {
462 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount(); 520 return ChromeApplication.getDocumentTabModelSelector().getTo talTabCount();
463 } else { 521 } else {
464 return getActivity().getTabModelSelector().getTotalTabCount( ); 522 return getActivity().getTabModelSelector().getTotalTabCount( );
465 } 523 }
466 } 524 }
467 }); 525 });
468 } 526 }
469 } 527 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698