Skip to content

Commit

Permalink
Set content type in UnsupportedBrowserHandler (#8803)
Browse files Browse the repository at this point in the history
Fixes #7936
  • Loading branch information
Denis authored Aug 4, 2020
1 parent dfc70df commit 6fe6905
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.io.IOException;
import java.io.Writer;

import com.vaadin.flow.shared.ApplicationConstants;

/**
* A {@link RequestHandler} that presents an informative page if the browser in
* use is unsupported.
Expand Down Expand Up @@ -104,6 +106,9 @@ protected void writeBrowserTooOldPage(VaadinRequest request,
Writer page = response.getWriter();
WebBrowser browser = VaadinSession.getCurrent().getBrowser();

response.setContentType(
ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);

// @formatter:off
page.write(
"<html>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import com.vaadin.flow.shared.ApplicationConstants;
import com.vaadin.tests.util.MockDeploymentConfiguration;

public class UnsupportedBrowserHandlerTest {
Expand Down Expand Up @@ -72,6 +73,9 @@ public void testUnsupportedBrowserHandler_tooOldBrowser_returnsUnsupportedBrowse
Assert.assertTrue("Unsupported browser page not used",
pageCapture.getValue().contains(
"I'm sorry, but your browser is not supported"));

Mockito.verify(response).setContentType(
ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
}

@Test
Expand All @@ -94,6 +98,15 @@ public void testUnsupportedBrowserHandler_validBrowserWithForceReloadCookie_does
Mockito.verify(writer, Mockito.never()).write(Mockito.anyString());
}

@Test
public void writeBrowserTooOldPage_setContentType() throws IOException {
initMocks(true, true);
handler.writeBrowserTooOldPage(request, response);

Mockito.verify(response).setContentType(
ApplicationConstants.CONTENT_TYPE_TEXT_HTML_UTF_8);
}

@After
public void tearDown() {
VaadinSession.setCurrent(null);
Expand Down

0 comments on commit 6fe6905

Please sign in to comment.