1 package com.android.documentsui.files; 2 3 import static junit.framework.Assert.assertEquals; 4 import static junit.framework.Assert.assertTrue; 5 6 import android.content.Intent; 7 import android.content.QuickViewConstants; 8 import android.content.pm.PackageManager; 9 import android.support.test.filters.SmallTest; 10 import android.support.test.runner.AndroidJUnit4; 11 12 import com.android.documentsui.testing.TestEnv; 13 import com.android.documentsui.testing.TestPackageManager; 14 import com.android.documentsui.testing.TestResources; 15 16 import org.junit.Before; 17 import org.junit.Test; 18 import org.junit.runner.RunWith; 19 20 import java.util.Arrays; 21 import java.util.HashSet; 22 import java.util.Set; 23 24 @SmallTest 25 @RunWith(AndroidJUnit4.class) 26 public class QuickViewIntentBuilderTest { 27 28 private PackageManager mPm; 29 private TestEnv mEnv; 30 private TestResources mRes; 31 32 @Before setUp()33 public void setUp() { 34 mPm = TestPackageManager.create(); 35 mEnv = TestEnv.create(); 36 mRes = TestResources.create(); 37 38 mRes.setQuickViewerPackage("com.android.documentsui"); 39 } 40 41 @Test testSetsNoFeatures_InArchiveDocument()42 public void testSetsNoFeatures_InArchiveDocument() { 43 QuickViewIntentBuilder builder = 44 new QuickViewIntentBuilder(mPm, mRes, TestEnv.FILE_IN_ARCHIVE, mEnv.archiveModel); 45 46 Intent intent = builder.build(); 47 48 String[] features = intent.getStringArrayExtra(Intent.EXTRA_QUICK_VIEW_FEATURES); 49 assertEquals(0, features.length); 50 } 51 52 @Test testSetsFullFeatures_RegularDocument()53 public void testSetsFullFeatures_RegularDocument() { 54 QuickViewIntentBuilder builder = 55 new QuickViewIntentBuilder(mPm, mRes, TestEnv.FILE_JPG, mEnv.model); 56 57 Intent intent = builder.build(); 58 59 Set<String> features = new HashSet<>( 60 Arrays.asList(intent.getStringArrayExtra(Intent.EXTRA_QUICK_VIEW_FEATURES))); 61 62 assertEquals("Unexpected features set: " + features, 5, features.size()); 63 assertTrue(features.contains(QuickViewConstants.FEATURE_VIEW)); 64 assertTrue(features.contains(QuickViewConstants.FEATURE_EDIT)); 65 assertTrue(features.contains(QuickViewConstants.FEATURE_SEND)); 66 assertTrue(features.contains(QuickViewConstants.FEATURE_DOWNLOAD)); 67 assertTrue(features.contains(QuickViewConstants.FEATURE_PRINT)); 68 } 69 } 70