Home | History | Annotate | Download | only in internet
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email.mail.internet;
     18 
     19 import android.test.AndroidTestCase;
     20 import android.test.suitebuilder.annotation.SmallTest;
     21 import android.test.suitebuilder.annotation.Suppress;
     22 
     23 /**
     24  * Tests of the Email HTML utils.
     25  *
     26  * You can run this entire test case with:
     27  *   runtest -c com.android.email.mail.internet.EmailHtmlUtilTest email
     28  */
     29 @Suppress
     30 @SmallTest
     31 public class EmailHtmlUtilTest extends AndroidTestCase {
     32 
     33     private static final String textTags = "<b>Plain</b> &";
     34     private static final String textSpaces = "3 spaces   end.";
     35     private static final String textNewlines = "ab \r\n  \n   \n\r\n";
     36 
     37     /**
     38      * Test for escapeCharacterToDisplay in plain text mode.
     39      */
     40     public void brokentestEscapeCharacterToDisplayPlainText() {
     41         String plainTags = EmailHtmlUtil.escapeCharacterToDisplay(textTags);
     42         assertEquals("plain tag", "&lt;b&gt;Plain&lt;/b&gt; &amp;", plainTags);
     43 
     44         // Successive spaces will be escaped as "&nbsp;"
     45         String plainSpaces = EmailHtmlUtil.escapeCharacterToDisplay(textSpaces);
     46         assertEquals("plain spaces", "3 spaces&nbsp;&nbsp; end.", plainSpaces);
     47 
     48         // Newlines will be escaped as "<br>"
     49         String plainNewlines = EmailHtmlUtil.escapeCharacterToDisplay(textNewlines);
     50         assertEquals("plain spaces", "ab <br>&nbsp; <br>&nbsp;&nbsp; <br><br>", plainNewlines);
     51 
     52         // All combinations.
     53         String textAll = textTags + "\n" + textSpaces + "\n" + textNewlines;
     54         String plainAll = EmailHtmlUtil.escapeCharacterToDisplay(textAll);
     55         assertEquals("plain all",
     56                 "&lt;b&gt;Plain&lt;/b&gt; &amp;<br>" +
     57                 "3 spaces&nbsp;&nbsp; end.<br>" +
     58                 "ab <br>&nbsp; <br>&nbsp;&nbsp; <br><br>",
     59                 plainAll);
     60      }
     61 }
     62