0
Files
src/content/browser/browser_url_handler_impl_unittest.cc
Gabriel Charette c710874894 Reland "[TaskEnvironment] Complete migration with header rename"
This is a reland of 18947083c7

The move_source_file.py script's formatting rules incorrectly
formatted services/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc
after all. But we also can't rely 100% on git cl format (crbug.com/997063)
so I ended up performing a git cl format && git add -up
(+interactive addition of missing blank line after foo.h when included
from top of foo.cc)

Also added
$ tools/git/move_source_file.py net/test/test_with_scoped_task_environment.h net/test/test_with_task_environment.h

Original change's description:
> [TaskEnvironment] Complete migration with header rename
>
> This is merely:
>
> $ tools/git/move_source_file.py base/test/scoped_task_environment.h base/test/task_environment.h
> $ tools/git/move_source_file.py base/test/scoped_task_environment.cc base/test/task_environment.cc
> $ tools/git/move_source_file.py base/test/scoped_task_environment_unittest.cc base/test/task_environment_unittest.cc
> $ tools/git/move_source_file.py content/public/test/test_browser_thread_bundle.h content/public/test/browser_task_environment.h
> $ tools/git/move_source_file.py content/public/test/test_browser_thread_bundle.cc content/public/test/browser_task_environment.cc
> $ tools/git/move_source_file.py content/public/test/test_browser_thread_bundle_unittest.cc content/public/test/browser_task_environment_unittest.cc
> $ tools/git/move_source_file.py ios/web/public/test/test_web_thread_bundle.h ios/web/public/test/web_task_environment.h
> $ tools/git/move_source_file.py ios/web/test/test_web_thread_bundle.cc ios/web/test/web_task_environment.cc
>
> and a few manual renames in DEPS files missed by the script
>
> This CL uses --bypass-hooks to avoid having to git cl format because
> many headers are being reordered by git cl format and it's too many to
> figure out in a no-op CL which ones are okay with it.
> windows.h for one should typically be first and another one of the
> reorderings in PS3 even caused a compile failure:
> https://chromium-review.googlesource.com/c/chromium/src/+/1764962/3/components/services/font/font_loader_unittest.cc
>
> TBR=dcheng@chromium.org
>
> Bug: 992483
> Change-Id: I32a4afd43ef779393c95d9873c157be2d3da1dd1
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764962
> Reviewed-by: Gabriel Charette <gab@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#689778}

TBR=dcheng@chromium.org

Bug: 992483
Change-Id: I6179dd1329a4d30bf5c65450ea893537f31e6f85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767658
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689794}
2019-08-23 03:31:40 +00:00

102 lines
3.3 KiB
C++

// Copyright (c) 2011 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/browser_url_handler_impl.h"
#include "content/public/test/browser_task_environment.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 {
};
// Test URL rewriter that rewrites all "foo://" URLs to "bar://bar".
static bool FooRewriter(GURL* url, BrowserContext* browser_context) {
if (url->scheme() == "foo") {
*url = GURL("bar://bar");
return true;
}
return false;
}
// Test URL rewriter that rewrites all "bar://" URLs to "foo://foo".
static bool BarRewriter(GURL* url, BrowserContext* browser_context) {
if (url->scheme() == "bar") {
*url = GURL("foo://foo");
return true;
}
return false;
}
TEST_F(BrowserURLHandlerImplTest, BasicRewriteAndReverse) {
BrowserTaskEnvironment task_environment;
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());
// Check that reversing the URL works.
GURL saved_url(url);
bool reversed = handler.ReverseURLRewrite(&url,
original_url,
&browser_context);
ASSERT_TRUE(reversed);
ASSERT_EQ("foo://foo", url.spec());
// Check that reversing the URL only works with a matching |original_url|.
url = saved_url;
original_url = GURL("bam://bam"); // Won't be matched by FooRewriter.
reversed = handler.ReverseURLRewrite(&url, original_url, &browser_context);
ASSERT_FALSE(reversed);
ASSERT_EQ(saved_url, url);
}
TEST_F(BrowserURLHandlerImplTest, NullHandlerReverse) {
BrowserTaskEnvironment task_environment;
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());
}
// Verify that the reverse handler for view-source does not duplicate query
// parameters.
TEST_F(BrowserURLHandlerImplTest, ViewSourceReverse) {
BrowserTaskEnvironment task_environment;
TestBrowserContext browser_context;
BrowserURLHandlerImpl handler;
GURL url("http://foo/?a=1");
GURL original_url("view-source:http://some_url");
bool reversed = handler.ReverseURLRewrite(&url,
original_url,
&browser_context);
ASSERT_TRUE(reversed);
ASSERT_EQ("view-source:http://foo/?a=1", url.spec());
}
} // namespace content