| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016 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. |
| 4 |
| 5 #include "blimp/engine/testing/app/blimp_url_rewriter.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "content/browser/browser_url_handler_impl.h" |
| 10 #include "content/public/browser/content_browser_client.h" |
| 11 #include "content/public/test/test_browser_context.h" |
| 12 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "url/gurl.h" |
| 15 #include "url/third_party/mozilla/url_parse.h" |
| 16 |
| 17 const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL(""); |
| 18 |
| 19 namespace blimp { |
| 20 namespace engine { |
| 21 |
| 22 namespace test { |
| 23 |
| 24 class BlimpUrlRewriterTest : public testing::Test { |
| 25 protected: |
| 26 void SetUp() override { |
| 27 g_ets_instance.reset(new net::EmbeddedTestServer()); |
| 28 g_ets_instance->ServeFilesFromSourceDirectory( |
| 29 base::FilePath(kBlimpTestRoot)); |
| 30 ASSERT_TRUE(g_ets_instance->Start()); |
| 31 |
| 32 content_client_.reset(new content::ContentClient()); |
| 33 // browser_content_client_.reset(new content::BrowserClient()); |
| 34 // SetBrowserClientForTesting(browser_content_client_.get()); |
| 35 } |
| 36 |
| 37 void TearDown() override { |
| 38 if (g_ets_instance->Started()) |
| 39 ASSERT_TRUE(g_ets_instance->ShutdownAndWaitUntilComplete()); |
| 40 } |
| 41 |
| 42 private: |
| 43 std::unique_ptr<content::ContentClient> content_client_; |
| 44 // std::unique_ptr<content::ContentBrowserClient> browser_content_client_; |
| 45 }; |
| 46 |
| 47 TEST_F(BlimpUrlRewriterTest, UrlRewriteMatchScheme) { |
| 48 // Check that rewriting the URL with a matching scheme works. |
| 49 content::TestBrowserContext browser_context; |
| 50 content::BrowserURLHandler* handler = |
| 51 content::BrowserURLHandler::GetInstance(); |
| 52 |
| 53 handler->AddHandlerPair(&HandleBlimpTestURL, |
| 54 content::BrowserURLHandler::null_handler()); |
| 55 |
| 56 GURL url("blimp-test://chrome/test/data/simple.html"); |
| 57 GURL original_url(url); |
| 58 bool reverse_on_redirect = false; |
| 59 handler->RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect); |
| 60 ASSERT_NE(original_url, url); |
| 61 ASSERT_TRUE(url.is_valid()); |
| 62 ASSERT_TRUE(url.HostIsIPAddress()); |
| 63 ASSERT_LT(url::PORT_UNSPECIFIED, url.EffectiveIntPort()); |
| 64 } |
| 65 |
| 66 TEST_F(BlimpUrlRewriterTest, UrlRewriteHttpHttpsScheme) { |
| 67 // Check that rewriting the URL with a http/https url works |
| 68 content::TestBrowserContext browser_context; |
| 69 content::BrowserURLHandler* handler = |
| 70 content::BrowserURLHandler::GetInstance(); |
| 71 |
| 72 handler->AddHandlerPair(&HandleBlimpTestURL, |
| 73 content::BrowserURLHandler::null_handler()); |
| 74 |
| 75 GURL url = GURL("http://www.google.com"); |
| 76 GURL original_url = GURL(url); |
| 77 bool reverse_on_redirect = false; |
| 78 handler->RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect); |
| 79 ASSERT_EQ(original_url, url); |
| 80 |
| 81 url = GURL("https://www.google.com"); |
| 82 original_url = GURL(url); |
| 83 handler->RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect); |
| 84 ASSERT_EQ(original_url, url); |
| 85 } |
| 86 |
| 87 TEST_F(BlimpUrlRewriterTest, UrlRewriteUnmatchScheme) { |
| 88 // Check that rewriting the URL not works with an unmatching url. |
| 89 content::TestBrowserContext browser_context; |
| 90 content::BrowserURLHandler* handler = |
| 91 content::BrowserURLHandler::GetInstance(); |
| 92 |
| 93 handler->AddHandlerPair(&HandleBlimpTestURL, |
| 94 content::BrowserURLHandler::null_handler()); |
| 95 |
| 96 GURL url = GURL("foo://chrome/test/data/simple.html"); |
| 97 GURL original_url = GURL(url); |
| 98 bool reverse_on_redirect = false; |
| 99 handler->RewriteURLIfNecessary(&url, &browser_context, &reverse_on_redirect); |
| 100 ASSERT_EQ(original_url, url); |
| 101 } |
| 102 |
| 103 } // namespace test |
| 104 |
| 105 } // namespace engine |
| 106 } // namespace blimp |
| OLD | NEW |