1308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki/* 2308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * Copyright (C) 2011 The Android Open Source Project 3308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * 4308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * Licensed under the Apache License, Version 2.0 (the "License"); 5308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * you may not use this file except in compliance with the License. 6308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * You may obtain a copy of the License at 7308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * 8308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * http://www.apache.org/licenses/LICENSE-2.0 9308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * 10308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * Unless required by applicable law or agreed to in writing, software 11308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * distributed under the License is distributed on an "AS IS" BASIS, 12308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * See the License for the specific language governing permissions and 14308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki * limitations under the License. 15308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki */ 16308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 17308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onukipackage com.android.email.activity; 18308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 190e6a521747970d5427f10c25cdc070d2341dc93aBen Komaloimport com.android.emailcommon.utility.IntentUtilities; 20308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 21308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onukiimport android.content.Intent; 22308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onukiimport android.net.Uri; 23308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onukiimport android.test.AndroidTestCase; 243555dc03bf2243dc275c9c832702abbee3b64387Jerry Xieimport android.test.suitebuilder.annotation.SmallTest; 25308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 263555dc03bf2243dc275c9c832702abbee3b64387Jerry Xie@SmallTest 27308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onukipublic class IntentUtilitiesTests extends AndroidTestCase { 287037a0bd3d8e925a9115f475f5c0d05ddae2eeeeJerry Xie public void brokentestSimple() { 29308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki final Uri.Builder b = IntentUtilities.createActivityIntentUrlBuilder("/abc"); 30308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki IntentUtilities.setAccountId(b, 10); 31308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki IntentUtilities.setMailboxId(b, 20); 32308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki IntentUtilities.setMessageId(b, 30); 330b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki IntentUtilities.setAccountUuid(b, "*uuid*"); 34308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 35308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki final Uri u = b.build(); 36308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals("content", u.getScheme()); 37308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals("ui.email.android.com", u.getAuthority()); 38308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals("/abc", u.getPath()); 39308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 40308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki final Intent i = new Intent(Intent.ACTION_MAIN, u); 41308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(10, IntentUtilities.getAccountIdFromIntent(i)); 42308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(20, IntentUtilities.getMailboxIdFromIntent(i)); 43308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(30, IntentUtilities.getMessageIdFromIntent(i)); 440b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki assertEquals("*uuid*", IntentUtilities.getAccountUuidFromIntent(i)); 45308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki } 46308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 477037a0bd3d8e925a9115f475f5c0d05ddae2eeeeJerry Xie public void brokentestGetIdFromIntent() { 48308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki Intent i; 49308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 50308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // No URL in intent 51308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki i = new Intent(getContext(), getClass()); 52308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(-1, IntentUtilities.getAccountIdFromIntent(i)); 53308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(-1, IntentUtilities.getMailboxIdFromIntent(i)); 54308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(-1, IntentUtilities.getMessageIdFromIntent(i)); 55308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 56308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // No param 57308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki checkGetIdFromIntent("content://s/", -1); 58308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 59308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // No value 60308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki checkGetIdFromIntent("content://s/?ID=", -1); 61308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 62308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // Value not integer 63308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki checkGetIdFromIntent("content://s/?ID=x", -1); 64308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 65308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // Negative value 66308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki checkGetIdFromIntent("content://s/?ID=-100", -100); 67308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 68308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // Normal value 69308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki checkGetIdFromIntent("content://s/?ID=200", 200); 70308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 71308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki // With all 3 params 72308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse( 73308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki "content://s/?ACCOUNT_ID=5&MAILBOX_ID=6&MESSAGE_ID=7")); 74308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(5, IntentUtilities.getAccountIdFromIntent(i)); 75308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(6, IntentUtilities.getMailboxIdFromIntent(i)); 76308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(7, IntentUtilities.getMessageIdFromIntent(i)); 77308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki } 78308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 79308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki public void checkGetIdFromIntent(String uri, long expected) { 80308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri.replace("ID", "ACCOUNT_ID"))); 81308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(expected, IntentUtilities.getAccountIdFromIntent(i)); 82308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 83308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri.replace("ID", "MAILBOX_ID"))); 84308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(expected, IntentUtilities.getMailboxIdFromIntent(i)); 85308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki 86308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri.replace("ID", "MESSAGE_ID"))); 87308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki assertEquals(expected, IntentUtilities.getMessageIdFromIntent(i)); 88308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki } 890b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki 907037a0bd3d8e925a9115f475f5c0d05ddae2eeeeJerry Xie public void brokentestGetAccountUuidFromIntent() { 910b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki Intent i; 920b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki 930b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki // No URL in intent 940b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki i = new Intent(getContext(), getClass()); 950b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki assertEquals(null, IntentUtilities.getAccountUuidFromIntent(i)); 960b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki 970b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki // No param 980b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://s/")); 990b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki assertEquals(null, IntentUtilities.getAccountUuidFromIntent(i)); 1000b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki 1010b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki // No value 1020b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://s/?ACCOUNT_UUID=")); 1030b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki assertEquals(null, IntentUtilities.getAccountUuidFromIntent(i)); 1040b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki 1050b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki // With valid UUID 1060b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki i = new Intent(Intent.ACTION_VIEW, Uri.parse("content://s/?ACCOUNT_UUID=xyz")); 1070b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki assertEquals("xyz", IntentUtilities.getAccountUuidFromIntent(i)); 1080b6cb1c3307b10929fca7dc09125a128fc330a19Makoto Onuki } 109308ce9284793b597797994dfb1fb25155cbe0b20Makoto Onuki} 110