Implement SSLKEYLOGFILE for OpenSSL.
[chromium-blink-merge.git] / content / browser / browser_url_handler_impl_unittest.cc
blob4e8dc2115fdf3617b43feb82b1d11e991c4e44fd
1 // Copyright (c) 2011 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 "content/browser/browser_url_handler_impl.h"
6 #include "content/public/test/test_browser_context.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
10 namespace content {
12 class BrowserURLHandlerImplTest : public testing::Test {
15 // Test URL rewriter that rewrites all "foo://" URLs to "bar://bar".
16 static bool FooRewriter(GURL* url, BrowserContext* browser_context) {
17 if (url->scheme() == "foo") {
18 *url = GURL("bar://bar");
19 return true;
21 return false;
24 // Test URL rewriter that rewrites all "bar://" URLs to "foo://foo".
25 static bool BarRewriter(GURL* url, BrowserContext* browser_context) {
26 if (url->scheme() == "bar") {
27 *url = GURL("foo://foo");
28 return true;
30 return false;
33 TEST_F(BrowserURLHandlerImplTest, BasicRewriteAndReverse) {
34 TestBrowserContext browser_context;
35 BrowserURLHandlerImpl handler;
37 handler.AddHandlerPair(FooRewriter, BarRewriter);
39 GURL url("foo://bar");
40 GURL original_url(url);
41 bool reverse_on_redirect = false;
42 handler.RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect);
43 ASSERT_TRUE(reverse_on_redirect);
44 ASSERT_EQ("bar://bar", url.spec());
46 // Check that reversing the URL works.
47 GURL saved_url(url);
48 bool reversed = handler.ReverseURLRewrite(&url,
49 original_url,
50 &browser_context);
51 ASSERT_TRUE(reversed);
52 ASSERT_EQ("foo://foo", url.spec());
54 // Check that reversing the URL only works with a matching |original_url|.
55 url = saved_url;
56 original_url = GURL("bam://bam"); // Won't be matched by FooRewriter.
57 reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
58 ASSERT_FALSE(reversed);
59 ASSERT_EQ(saved_url, url);
62 TEST_F(BrowserURLHandlerImplTest, NullHandlerReverse) {
63 TestBrowserContext browser_context;
64 BrowserURLHandlerImpl handler;
66 GURL url("bar://foo");
67 GURL original_url(url);
69 handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), FooRewriter);
70 bool reversed = handler.ReverseURLRewrite(&url,
71 original_url,
72 &browser_context);
73 ASSERT_FALSE(reversed);
74 ASSERT_EQ(original_url, url);
76 handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), BarRewriter);
77 reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
78 ASSERT_TRUE(reversed);
79 ASSERT_EQ("foo://foo", url.spec());
82 } // namespace content