@SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationEnabledByAutofillSyncCheckbox() throws Exception {
    setUpTestAccountAndSignIn();

    setPaymentsIntegrationEnabled(false);

    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    assertDefaultSyncOnState(fragment);
    SwitchPreference syncEverything = getSyncEverything(fragment);
    togglePreference(syncEverything);

    CheckBoxPreference syncAutofill =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_SYNC_AUTOFILL);
    togglePreference(syncAutofill); // Disable autofill sync.
    togglePreference(syncAutofill); // Re-enable autofill sync again.

    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);
    assertTrue(paymentsIntegration.isEnabled());
    assertTrue(paymentsIntegration.isChecked());

    closeFragment(fragment);
    assertPaymentsIntegrationEnabled(true);
  }
  @SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationCheckboxClearsServerAutofillCreditCards() throws Exception {
    setUpTestAccountAndSignIn();

    setPaymentsIntegrationEnabled(true);

    assertFalse("There should be no server cards", hasServerAutofillCreditCards());
    addServerAutofillCreditCard();
    assertTrue("There should be server cards", hasServerAutofillCreditCards());

    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    assertDefaultSyncOnState(fragment);
    SwitchPreference syncEverything = getSyncEverything(fragment);
    togglePreference(syncEverything);

    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);
    togglePreference(paymentsIntegration);

    closeFragment(fragment);
    assertPaymentsIntegrationEnabled(false);

    assertFalse("There should be no server cards remaining", hasServerAutofillCreditCards());
  }
  @SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationChecked() throws Exception {
    setUpTestAccountAndSignIn();

    setPaymentsIntegrationEnabled(true);

    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    assertDefaultSyncOnState(fragment);

    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);

    assertFalse(paymentsIntegration.isEnabled());
    assertTrue(paymentsIntegration.isChecked());
  }
 private Map<Integer, CheckBoxPreference> getDataTypes(SyncCustomizationFragment fragment) {
   Map<Integer, CheckBoxPreference> dataTypes = new HashMap<Integer, CheckBoxPreference>();
   for (Map.Entry<Integer, String> uiDataType : UI_DATATYPES.entrySet()) {
     Integer modelType = uiDataType.getKey();
     String prefId = uiDataType.getValue();
     dataTypes.put(modelType, (CheckBoxPreference) fragment.findPreference(prefId));
   }
   return dataTypes;
 }
  @SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationCheckboxEnablesPaymentsIntegration() throws Exception {
    setUpTestAccountAndSignIn();

    setPaymentsIntegrationEnabled(false);

    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    assertDefaultSyncOnState(fragment);
    SwitchPreference syncEverything = getSyncEverything(fragment);
    togglePreference(syncEverything);

    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);
    togglePreference(paymentsIntegration);

    closeFragment(fragment);
    assertPaymentsIntegrationEnabled(true);
  }
  @SmallTest
  @Feature({"Sync"})
  public void testPaymentsIntegrationEnabledBySyncEverything() throws Exception {
    setUpTestAccountAndSignIn();
    setPaymentsIntegrationEnabled(false);
    disableDataType(ModelType.AUTOFILL);

    // Get the UI elements.
    SyncCustomizationFragment fragment = startSyncCustomizationFragment();
    SwitchPreference syncEverything = getSyncEverything(fragment);
    CheckBoxPreference syncAutofill =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_SYNC_AUTOFILL);
    CheckBoxPreference paymentsIntegration =
        (CheckBoxPreference)
            fragment.findPreference(SyncCustomizationFragment.PREFERENCE_PAYMENTS_INTEGRATION);

    // All three are unchecked and payments is disabled.
    assertFalse(syncEverything.isChecked());
    assertFalse(syncAutofill.isChecked());
    assertTrue(syncAutofill.isEnabled());
    assertFalse(paymentsIntegration.isChecked());
    assertFalse(paymentsIntegration.isEnabled());

    // All three are checked after toggling sync everything.
    togglePreference(syncEverything);
    assertTrue(syncEverything.isChecked());
    assertTrue(syncAutofill.isChecked());
    assertFalse(syncAutofill.isEnabled());
    assertTrue(paymentsIntegration.isChecked());
    assertFalse(paymentsIntegration.isEnabled());

    // Closing the fragment enabled payments integration.
    closeFragment(fragment);
    assertPaymentsIntegrationEnabled(true);
  }
 private Preference getManageData(SyncCustomizationFragment fragment) {
   return (Preference)
       fragment.findPreference(SyncCustomizationFragment.PREFERENCE_SYNC_MANAGE_DATA);
 }
 private Preference getEncryption(SyncCustomizationFragment fragment) {
   return (Preference) fragment.findPreference(SyncCustomizationFragment.PREFERENCE_ENCRYPTION);
 }
 private SwitchPreference getSyncEverything(SyncCustomizationFragment fragment) {
   return (SwitchPreference)
       fragment.findPreference(SyncCustomizationFragment.PREFERENCE_SYNC_EVERYTHING);
 }
 private SwitchPreference getSyncSwitch(SyncCustomizationFragment fragment) {
   return (SwitchPreference) fragment.findPreference(SyncCustomizationFragment.PREF_SYNC_SWITCH);
 }