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 
     22 /**
     23  * Tests of the Email HTML utils.
     24  *
     25  * You can run this entire test case with:
     26  *   runtest -c com.android.email.mail.internet.EmailHtmlUtilTest email
     27  */
     28 @SmallTest
     29 public class EmailHtmlUtilTest extends AndroidTestCase {
     30 
     31     private static final String textTags = "<b>Plain</b> &";
     32     private static final String textSpaces = "3 spaces   end.";
     33     private static final String textNewlines = "ab \r\n  \n   \n\r\n";
     34 
     35     /**
     36      * Test for escapeCharacterToDisplay in plain text mode.
     37      */
     38     public void testEscapeCharacterToDisplayPlainText() {
     39         String plainTags = EmailHtmlUtil.escapeCharacterToDisplay(textTags);
     40         assertEquals("plain tag", "&lt;b&gt;Plain&lt;/b&gt; &amp;", plainTags);
     41 
     42         // Successive spaces will be escaped as "&nbsp;"
     43         String plainSpaces = EmailHtmlUtil.escapeCharacterToDisplay(textSpaces);
     44         assertEquals("plain spaces", "3 spaces&nbsp;&nbsp; end.", plainSpaces);
     45 
     46         // Newlines will be escaped as "<br>"
     47         String plainNewlines = EmailHtmlUtil.escapeCharacterToDisplay(textNewlines);
     48         assertEquals("plain spaces", "ab <br>&nbsp; <br>&nbsp;&nbsp; <br><br>", plainNewlines);
     49 
     50         // All combinations.
     51         String textAll = textTags + "\n" + textSpaces + "\n" + textNewlines;
     52         String plainAll = EmailHtmlUtil.escapeCharacterToDisplay(textAll);
     53         assertEquals("plain all",
     54                 "&lt;b&gt;Plain&lt;/b&gt; &amp;<br>" +
     55                 "3 spaces&nbsp;&nbsp; end.<br>" +
     56                 "ab <br>&nbsp; <br>&nbsp;&nbsp; <br><br>",
     57                 plainAll);
     58      }
     59 }
     60