Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3552)

Unified Diff: blimp/engine/testing/app/blimp_url_rewriter.cc

Issue 2572563006: [Blimp] Refactor Blimp test engine with embedded test server and URL rewriting (Closed)
Patch Set: nit change Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/engine/testing/app/blimp_url_rewriter.cc
diff --git a/blimp/engine/testing/app/blimp_url_rewriter.cc b/blimp/engine/testing/app/blimp_url_rewriter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bbf1b48d262150641f3e9b92e00a0974ecd29cc
--- /dev/null
+++ b/blimp/engine/testing/app/blimp_url_rewriter.cc
@@ -0,0 +1,49 @@
+// 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 "content/public/test/test_browser_context.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "url/gurl.h"
+
+namespace content {
+const char kBlimpTestScheme[] = "blimp-test";
+} // namespace content
+
+namespace blimp {
+namespace engine {
+
+namespace test {
+
+// Embedded Test Server instance. This should be available globally and should
+// be long lived.
+std::unique_ptr<net::EmbeddedTestServer> g_ets_instance;
+
+bool HandleBlimpTestURL(GURL* url, content::BrowserContext* browser_context) {
+ // Handles rewriting request URLs to be what the engine will actually load
+ // URL with scheme 'blimp-test', i.e.,
+ // 'blimp-test://chrome/test/data/simple.html'. It works together with
+ // EmbeddedTestServer to handle getting full url, which strips the url
+ // content first and calls the GetURL function. The result URL would be like
+ // 'http://127.0.0.1:12345/chrome/test/data/simple.html'
+ if (url->SchemeIs(content::kBlimpTestScheme)) {
+ // Load the URL content which is everything after the scheme.
+ // URL = "blimp-test://chrome/test/data/page.html"
+ // URL->GetContent() = "//chrome/test/data/page.html"
+ std::string url_content = url->GetContent();
+ url_content.erase(url_content.begin());
+ GURL rewritten_url = g_ets_instance->GetURL(url_content);
+
+ DCHECK(rewritten_url.is_valid());
+ *url = rewritten_url;
+ return true;
+ }
+ return false;
+}
+
+} // namespace test
+
+} // namespace engine
+} // namespace blimp
« no previous file with comments | « blimp/engine/testing/app/blimp_url_rewriter.h ('k') | blimp/engine/testing/app/blimp_url_rewriter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698