/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 *
 * 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.google.jenkins.plugins.storage;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
 * Tests for {@link HttpHeaders}.
 */

public class HttpHeadersTest {
  @Test
  public void testGetContentDisposition_ascii() {
    assertEquals(
        "attachment; filename=\"myapp.war\"; filename*=UTF-8''myapp.war",
        HttpHeaders.getContentDisposition("myapp.war"));

    assertEquals(
        "attachment; filename=\"contains space.txt2\"; "
            + "filename*=UTF-8''contains%20space.txt2",
        HttpHeaders.getContentDisposition("contains space.txt2"));
  }

  @Test
  public void testGetContentDisposition_unicodeBmp() {
    assertEquals(
        "attachment; filename=\"snowman _.txt2\"; "
            + "filename*=UTF-8''snowman%20%E2%98%83.txt2",
        HttpHeaders.getContentDisposition("snowman ☃.txt2"));
  }

  @Test
  public void testGetContentDisposition_unicodeNonBmp() {
    assertEquals(
        "attachment; filename=\"_.zip\"; filename*=UTF-8''%F0%9D%92%9E.zip",
        HttpHeaders.getContentDisposition("𝒞.zip"));
  }

  @Test
  public void testGetContentDisposition_rfc2616Escapes() {
    assertEquals(
        "attachment; filename=\"-\\\\-\\\"-\"; filename*=UTF-8''-%5C-%22-",
        HttpHeaders.getContentDisposition("-\\-\"-"));
  }

  @Test
  public void testGetContentDisposition_rfc5987IdentitySymbols() {
    assertEquals(
        "attachment; filename=\"!#$&+-.^_`|~\"; filename*=UTF-8''!#$&+-.^_`|~",
        HttpHeaders.getContentDisposition("!#$&+-.^_`|~"));
  }

  @Test
  public void testGetContentDisposition_rfc5987PercentEncodedSymbols() {
    assertEquals(
        "attachment; filename=\"@%*()=[]{}\\\\:;\\\"'<>,/?\"; "
            + "filename*=UTF-8''%40%25%2A%28%29%3D%5B%5D%7B%7D%5C%3A%3B%22%27"
            + "%3C%3E%2C%2F%3F",
        HttpHeaders.getContentDisposition("@%*()=[]{}\\:;\"'<>,/?"));
  }
    @Test
    public void testGetContentDisposition_emptyForViewableFiles(){
        String[] viewableExtentions =
                {"avi","css","gif",
                        "Html","htm","jpeg",
                        "jpg","MP3","mpeg",
                        "mpg","mov","qt",
                        "pdf","png",
                        "tiff","TXT","wav"};
        for(String ex: viewableExtentions)
            assertEquals("",HttpHeaders.getContentDisposition("someFile." + ex));
    }
}

@@ -2813,16 +2813,22 @@
 %22,%22png%22,
+%22XML%22,
 %0A       
@@ -2862,16 +2862,22 @@
 T%22,%22wav%22
+,%22log%22
 %7D;%0A     

Update HttpHeadersTest.java