Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / extensions / background_xhr_browsertest.cc
blob6ff6debbb2a33c7660794e10f00be576667f663d
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_io_data.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/test/result_catcher.h"
16 #include "net/base/escape.h"
17 #include "net/base/url_util.h"
18 #include "net/ssl/client_cert_store.h"
19 #include "net/test/spawned_test_server/spawned_test_server.h"
20 #include "url/gurl.h"
22 namespace {
24 scoped_ptr<net::ClientCertStore> CreateNullCertStore() {
25 return nullptr;
28 void InstallNullCertStoreFactoryOnIOThread(
29 content::ResourceContext* resource_context) {
30 ProfileIOData::FromResourceContext(resource_context)
31 ->set_client_cert_store_factory_for_testing(
32 base::Bind(&CreateNullCertStore));
35 } // namespace
37 class BackgroundXhrTest : public ExtensionBrowserTest {
38 protected:
39 void RunTest(const std::string& path, const GURL& url) {
40 const extensions::Extension* extension =
41 LoadExtension(test_data_dir_.AppendASCII("background_xhr"));
42 ASSERT_TRUE(extension);
44 extensions::ResultCatcher catcher;
45 GURL test_url = net::AppendQueryParameter(extension->GetResourceURL(path),
46 "url", url.spec());
47 ui_test_utils::NavigateToURL(browser(), test_url);
48 ASSERT_TRUE(catcher.GetNextResult());
52 // Test that fetching a URL using TLS client auth doesn't crash, hang, or
53 // prompt.
54 IN_PROC_BROWSER_TEST_F(BackgroundXhrTest, TlsClientAuth) {
55 // Install a null ClientCertStore so the client auth prompt isn't bypassed due
56 // to the system certificate store returning no certificates.
57 base::RunLoop loop;
58 content::BrowserThread::PostTaskAndReply(
59 content::BrowserThread::IO, FROM_HERE,
60 base::Bind(&InstallNullCertStoreFactoryOnIOThread,
61 browser()->profile()->GetResourceContext()),
62 loop.QuitClosure());
63 loop.Run();
65 // Launch HTTPS server.
66 net::SpawnedTestServer::SSLOptions ssl_options;
67 ssl_options.request_client_certificate = true;
68 net::SpawnedTestServer https_server(
69 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
70 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
71 ASSERT_TRUE(https_server.Start());
73 ASSERT_NO_FATAL_FAILURE(
74 RunTest("test_tls_client_auth.html", https_server.GetURL("")));
77 // Test that fetching a URL using HTTP auth doesn't crash, hang, or prompt.
78 IN_PROC_BROWSER_TEST_F(BackgroundXhrTest, HttpAuth) {
79 ASSERT_TRUE(test_server()->Start());
80 ASSERT_NO_FATAL_FAILURE(
81 RunTest("test_http_auth.html", test_server()->GetURL("auth-basic")));