| 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 "content/public/test/test_browser_context.h" |
| 8 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 namespace content { |
| 12 const char kBlimpTestScheme[] = "blimp-test"; |
| 13 } // namespace content |
| 14 |
| 15 namespace blimp { |
| 16 namespace engine { |
| 17 |
| 18 namespace test { |
| 19 |
| 20 // Embedded Test Server instance. This should be available globally and should |
| 21 // be long lived. |
| 22 std::unique_ptr<net::EmbeddedTestServer> g_ets_instance; |
| 23 |
| 24 bool HandleBlimpTestURL(GURL* url, content::BrowserContext* browser_context) { |
| 25 // Handles rewriting request URLs to be what the engine will actually load |
| 26 // URL with scheme 'blimp-test', i.e., |
| 27 // 'blimp-test://chrome/test/data/simple.html'. It works together with |
| 28 // EmbeddedTestServer to handle getting full url, which strips the url |
| 29 // content first and calls the GetURL function. The result URL would be like |
| 30 // 'http://127.0.0.1:12345/chrome/test/data/simple.html' |
| 31 if (url->SchemeIs(content::kBlimpTestScheme)) { |
| 32 // Load the URL content which is everything after the scheme. |
| 33 // URL = "blimp-test://chrome/test/data/page.html" |
| 34 // URL->GetContent() = "//chrome/test/data/page.html" |
| 35 std::string url_content = url->GetContent(); |
| 36 url_content.erase(url_content.begin()); |
| 37 GURL rewritten_url = g_ets_instance->GetURL(url_content); |
| 38 |
| 39 DCHECK(rewritten_url.is_valid()); |
| 40 *url = rewritten_url; |
| 41 return true; |
| 42 } |
| 43 return false; |
| 44 } |
| 45 |
| 46 } // namespace test |
| 47 |
| 48 } // namespace engine |
| 49 } // namespace blimp |
| OLD | NEW |