/* * Copyright (C) 2012 Google Inc. * Licensed to The Android Open Source Project. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.mail.ui; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import com.android.mail.ui.HtmlConversationTemplates; import junit.framework.ComparisonFailure; public class ImgSrcReplacementTest extends AndroidTestCase { private static void replace(final String input, final String expectedOutput) { assertEquals(expectedOutput, HtmlConversationTemplates.replaceAbsoluteImgUrls(input)); } @SmallTest public void testSimple() { replace( "", "" ); } @SmallTest public void testSimpleSingleQuotes() { replace( "", "" ); } @SmallTest public void testSimpleNoQuotes() { replace( "", "" ); } @SmallTest public void testWithElementId() { replace( "", "" ); } @SmallTest public void testWithElementIdAndAltAttr() { replace( "foo", "foo" ); } @SmallTest public void testHttps() { replace( "", "" ); } @SmallTest public void testRelativeUrl() { // should not modify replace( "", "" ); } @SmallTest public void testNoSrcAttr() { // should not modify replace( "foo", "foo" ); } @SmallTest public void testSrcElsewhere() { replace( "foo src=httplawl", "foo src=httplawl" ); } @SmallTest public void testWithInnerWhitespace() { replace( "< img src = \"http://google.com/favicon.ico\" >", "< img src='data:' blocked-src = \"http://google.com/favicon.ico\" >" ); } @SmallTest public void testValueWithTheWordSrc() { replace( "", "" ); } @SmallTest public void testWithOtherAttrsAndValueWithTheWordSrc() { replace( "", "" ); } public void testValueWithTheWordSrcAndASpace() { // Doesn't work, but this is not likely to be common. // For a regex to handle this properly, it would have to avoid matching on attribute values, // maybe by counting quotes. try { replace( "", "" ); } catch (ComparisonFailure fail) { System.out.println("passing known broken case"); } } }