When does Contrastive Learning Preserve Adversarial Robustness from Pretraining to Finetuning?