Chromium Code Reviews| 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 <string> | |
| 6 | |
| 7 #include "blimp/engine/testing/app/blimp_url_rewriter.h" | |
| 8 #include "content/public/test/test_browser_context.h" | |
| 9 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 10 #include "url/gurl.h" | |
| 11 | |
| 12 namespace content { | |
| 13 const char kBlimpTestScheme[] = "blimp-test"; | |
| 14 } // namespace content | |
| 15 | |
| 16 namespace blimp { | |
| 17 namespace engine { | |
| 18 | |
| 19 namespace test { | |
| 20 | |
| 21 // Embedded Test Server instance. This should be available globally and should | |
| 22 // be long lived. | |
| 23 std::unique_ptr<net::EmbeddedTestServer> g_ets_instance; | |
| 24 | |
| 25 bool HandleBlimpTestURL(GURL* url, content::BrowserContext* browser_context) { | |
|
Kevin M
2017/01/09 20:17:18
browser_context is never referenced, so can we rem
shenghuazhang
2017/01/10 23:20:50
I think it needs the content::BrowserContext inclu
| |
| 26 // Handles rewriting request URLs to be what the engine will actually load | |
| 27 // URL with scheme 'blimp-test', i.e., | |
| 28 // 'blimp-test://chrome/test/data/simple.html'. It works together with | |
| 29 // EmbeddedTestServer to handle getting full url, which strips the url | |
| 30 // content first and calls the GetURL function. The result URL would be like | |
| 31 // 'http://127.0.0.1:12345/chrome/test/data/simple.html' | |
| 32 if (url->is_valid() && url->SchemeIsHTTPOrHTTPS()) | |
|
Kevin M
2017/01/09 20:17:18
What about non-HTTP urls? Can you fall back to a d
shenghuazhang
2017/01/10 23:20:50
Got it.
Return false for all conditions except for
| |
| 33 return true; | |
| 34 | |
| 35 if (url->SchemeIs(content::kBlimpTestScheme)) { | |
| 36 // Load the URL content which is everything after the scheme. | |
| 37 // URL = "blimp-test://chrome/test/data/page.html" | |
| 38 // URL->GetContent() = "//chrome/test/data/page.html" | |
| 39 std::string url_content = url->GetContent(); | |
| 40 url_content.erase(url_content.begin()); | |
| 41 GURL rewritten_url = g_ets_instance->GetURL(url_content); | |
| 42 | |
| 43 if (rewritten_url.is_valid()) { | |
|
Kevin M
2017/01/09 20:17:18
Assuming our code isn't broken, should this ever f
shenghuazhang
2017/01/10 23:20:50
That makes sense. Would use DCHECK thing instead.
| |
| 44 *url = rewritten_url; | |
| 45 return true; | |
| 46 } | |
| 47 } | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 } // namespace test | |
| 52 | |
| 53 } // namespace engine | |
| 54 } // namespace blimp | |
| OLD | NEW |