This source file includes following definitions.
- FooRewriter
- BarRewriter
- TEST_F
- TEST_F
#include "content/browser/browser_url_handler_impl.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
namespace content {
class BrowserURLHandlerImplTest : public testing::Test {
};
static bool FooRewriter(GURL* url, BrowserContext* browser_context) {
if (url->scheme() == "foo") {
*url = GURL("bar://bar");
return true;
}
return false;
}
static bool BarRewriter(GURL* url, BrowserContext* browser_context) {
if (url->scheme() == "bar") {
*url = GURL("foo://foo");
return true;
}
return false;
}
TEST_F(BrowserURLHandlerImplTest, BasicRewriteAndReverse) {
TestBrowserContext browser_context;
BrowserURLHandlerImpl handler;
handler.AddHandlerPair(FooRewriter, BarRewriter);
GURL url("foo://bar");
GURL original_url(url);
bool reverse_on_redirect = false;
handler.RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect);
ASSERT_TRUE(reverse_on_redirect);
ASSERT_EQ("bar://bar", url.spec());
GURL saved_url(url);
bool reversed = handler.ReverseURLRewrite(&url,
original_url,
&browser_context);
ASSERT_TRUE(reversed);
ASSERT_EQ("foo://foo", url.spec());
url = saved_url;
original_url = GURL("bam://bam");
reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
ASSERT_FALSE(reversed);
ASSERT_EQ(saved_url, url);
}
TEST_F(BrowserURLHandlerImplTest, NullHandlerReverse) {
TestBrowserContext browser_context;
BrowserURLHandlerImpl handler;
GURL url("bar://foo");
GURL original_url(url);
handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), FooRewriter);
bool reversed = handler.ReverseURLRewrite(&url,
original_url,
&browser_context);
ASSERT_FALSE(reversed);
ASSERT_EQ(original_url, url);
handler.AddHandlerPair(BrowserURLHandlerImpl::null_handler(), BarRewriter);
reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
ASSERT_TRUE(reversed);
ASSERT_EQ("foo://foo", url.spec());
}
}