Chromium Code Reviews| Index: blimp/engine/testing/app/blimp_url_rewriter_unittest.cc |
| diff --git a/blimp/engine/testing/app/blimp_url_rewriter_unittest.cc b/blimp/engine/testing/app/blimp_url_rewriter_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..69b1249d191fd5faff8c478fffd9209eefe2c459 |
| --- /dev/null |
| +++ b/blimp/engine/testing/app/blimp_url_rewriter_unittest.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright (c) 2016 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 "blimp/engine/testing/app/blimp_url_rewriter.h" |
| + |
| +#include <iostream> |
| +#include <string> |
| + |
| +#include "blimp/engine/app/blimp_content_browser_client.h" |
| +#include "blimp/engine/common/blimp_content_client.h" |
| +#include "content/browser/browser_url_handler_impl.h" |
| +#include "content/public/browser/content_browser_client.h" |
| +#include "content/public/test/test_browser_context.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| +#include "url/third_party/mozilla/url_parse.h" |
| + |
| +const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL(""); |
| + |
| +namespace blimp { |
| +namespace engine { |
| + |
| +namespace test { |
| + |
| +class BlimpUrlRewriterTest : public testing::Test { |
| + protected: |
| + void SetUp() override { |
| + g_ets_instance.reset(new net::EmbeddedTestServer()); |
| + g_ets_instance->ServeFilesFromSourceDirectory( |
| + base::FilePath(kBlimpTestRoot)); |
| + ASSERT_TRUE(g_ets_instance->Start()); |
| + |
| + content::SetContentClient(&content_client_); |
| + browser_client_.reset(new BlimpContentBrowserClient); |
|
shenghuazhang
2017/01/05 23:36:33
Failed to set up contentclient and browser causes
jbudorick at gmail
2017/01/06 16:09:37
Can you set content_client_->browser e.g. https://
shenghuazhang
2017/01/07 01:21:24
I'm afraid it's not able to do in this way, since
|
| + } |
| + |
| + void TearDown() override { |
| + if (g_ets_instance->Started()) |
| + ASSERT_TRUE(g_ets_instance->ShutdownAndWaitUntilComplete()); |
| + } |
| + |
| + private: |
| + BlimpContentClient content_client_; |
| + std::unique_ptr<BlimpContentBrowserClient> browser_client_; |
| +}; |
| + |
| +TEST_F(BlimpUrlRewriterTest, UrlRewriteMatchScheme) { |
| + // Check that rewriting the URL with a matching scheme works. |
| + content::TestBrowserContext browser_context; |
| + content::BrowserURLHandler::GetInstance()->AddHandlerPair( |
|
shenghuazhang
2017/01/05 23:36:33
Failed at GetInstance(). Due to failed to set up C
|
| + &HandleBlimpTestURL, content::BrowserURLHandler::null_handler()); |
| + |
| + GURL url("blimp-test://chrome/test/data/title2.html"); |
| + GURL original_url(url); |
| + bool reverse_on_redirect = false; |
| + content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| + &url, &browser_context, &reverse_on_redirect); |
| + ASSERT_NE(original_url, url); |
| + ASSERT_TRUE(url.is_valid()); |
| + ASSERT_TRUE(url.HostIsIPAddress()); |
| + ASSERT_LT(url::PORT_UNSPECIFIED, url.EffectiveIntPort()); |
| +} |
| + |
| +TEST_F(BlimpUrlRewriterTest, UrlRewriteHttpHttpsScheme) { |
| + // Check that rewriting the URL with a http/https url works |
| + content::TestBrowserContext browser_context; |
| + content::BrowserURLHandler::GetInstance()->AddHandlerPair( |
| + &HandleBlimpTestURL, content::BrowserURLHandler::null_handler()); |
| + |
| + GURL url = GURL("http://www.google.com"); |
| + GURL original_url = GURL(url); |
| + bool reverse_on_redirect = false; |
| + content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| + &url, &browser_context, &reverse_on_redirect); |
| + ASSERT_EQ(original_url, url); |
| + |
| + url = GURL("https://www.google.com"); |
| + original_url = GURL(url); |
| + content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| + &url, &browser_context, &reverse_on_redirect); |
| + ASSERT_EQ(original_url, url); |
| +} |
| + |
| +TEST_F(BlimpUrlRewriterTest, UrlRewriteUnmatchScheme) { |
| + // Check that rewriting the URL not works with an unmatching url. |
| + content::TestBrowserContext browser_context; |
| + content::BrowserURLHandler::GetInstance()->AddHandlerPair( |
| + &HandleBlimpTestURL, content::BrowserURLHandler::null_handler()); |
| + |
| + GURL url = GURL("foo://chrome/test/data/title2.html"); |
| + GURL original_url = GURL(url); |
| + bool reverse_on_redirect = false; |
| + content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary( |
| + &url, &browser_context, &reverse_on_redirect); |
| + ASSERT_EQ(original_url, url); |
| +} |
| + |
| +} // namespace test |
| + |
| +} // namespace engine |
| +} // namespace blimp |