blob: 8b2b69a092b50b62c64b48b32a55dd9e02addf8c [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/shell/browser/shell.h"
#include "net/http/http_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
namespace content {
namespace {
constexpr char kAsyncScriptThatAbortsOnEndPage[] =
constexpr char k400AbortOnEndUrl[] = "";
bool AbortOnEndInterceptor(URLLoaderInterceptor::RequestParams* params) {
if (params->url_request.url.spec() != k400AbortOnEndUrl)
return false;
std::string headers =
"HTTP/1.1 400 This is not OK\n"
"Content-type: text/plain\n";
net::HttpResponseInfo info;
info.headers = new net::HttpResponseHeaders(
net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.length()));
network::ResourceResponseHead response;
response.headers = info.headers;
std::string body = "some data\r\n";
uint32_t bytes_written = body.size();
mojo::DataPipe data_pipe(body.size());
data_pipe.producer_handle->WriteData(, &bytes_written, MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
return true;
} // namespace
using WebKitBrowserTest = ContentBrowserTest;
// This is a browser test because it is hard to reproduce reliably in a
// layout test without races. deals with a request
// for an async script which gets data in the response and immediately
// after aborts. This test creates that condition, and it is passed
// if chrome does not crash.
IN_PROC_BROWSER_TEST_F(WebKitBrowserTest, AbortOnEnd) {
URLLoaderInterceptor interceptor(base::BindRepeating(&AbortOnEndInterceptor));
GURL url = embedded_test_server()->GetURL(kAsyncScriptThatAbortsOnEndPage);
NavigateToURL(shell(), url);
// If you are seeing this test fail, please strongly investigate the
// possibility that and
// have reverted before
// marking this as flakey.
// This is a browser test because the test_runner framework holds
// onto a Document* reference that blocks this reproduction from
// destroying the Document, so it is not a use after free unless
// you don't have test_runner loaded.
// TODO(gavinp): remove this browser_test if we can get good LayoutTest
// coverage of the same issue.
const char kXsltBadImportPage[] = "/webkit/xslt-bad-import.html";
IN_PROC_BROWSER_TEST_F(WebKitBrowserTest, XsltBadImport) {
URLLoaderInterceptor interceptor(base::BindRepeating(&AbortOnEndInterceptor));
GURL url = embedded_test_server()->GetURL(kXsltBadImportPage);
NavigateToURL(shell(), url);
// This is a browser test because test_runner has a PrerendererClient
// implementation, and the purpose of this test is to ensure that content_shell
// does not crash when prerender elements are encountered with no Prererering
// implementation supplied to WebKit.
// TODO(gavinp,jochen): This browser_test depends on there not being a
// prerendering client and prerendering platform provided by the test_shell.
// But both will exist when we use content_shell to run layout tests. We must
// then add a mechanism to start content_shell without these, or else this
// test is not very interesting.
const char kPrerenderNoCrashPage[] = "/prerender/prerender-no-crash.html";
IN_PROC_BROWSER_TEST_F(WebKitBrowserTest, PrerenderNoCrash) {
GURL url = embedded_test_server()->GetURL(kPrerenderNoCrashPage);
NavigateToURL(shell(), url);
} // namespace content