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

Side by Side Diff: blimp/engine/testing/app/blimp_url_rewriter_unittest.cc

Issue 2572563006: [Blimp] Refactor Blimp test engine with embedded test server and URL rewriting (Closed)
Patch Set: Function works. Needs to refactor blimp_url_rewriter_unittest.cc 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 unified diff | Download patch
OLDNEW
(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 <iostream>
8 #include <string>
9
10 #include "blimp/engine/app/blimp_content_browser_client.h"
11 #include "blimp/engine/common/blimp_content_client.h"
12 #include "content/browser/browser_url_handler_impl.h"
13 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/test/test_browser_context.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
18 #include "url/third_party/mozilla/url_parse.h"
19
20 const base::FilePath::CharType kBlimpTestRoot[] = FILE_PATH_LITERAL("");
21
22 namespace blimp {
23 namespace engine {
24
25 namespace test {
26
27 class BlimpUrlRewriterTest : public testing::Test {
28 protected:
29 void SetUp() override {
30 g_ets_instance.reset(new net::EmbeddedTestServer());
31 g_ets_instance->ServeFilesFromSourceDirectory(
32 base::FilePath(kBlimpTestRoot));
33 ASSERT_TRUE(g_ets_instance->Start());
34
35 content::SetContentClient(&content_client_);
36 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
37 }
38
39 void TearDown() override {
40 if (g_ets_instance->Started())
41 ASSERT_TRUE(g_ets_instance->ShutdownAndWaitUntilComplete());
42 }
43
44 private:
45 BlimpContentClient content_client_;
46 std::unique_ptr<BlimpContentBrowserClient> browser_client_;
47 };
48
49 TEST_F(BlimpUrlRewriterTest, UrlRewriteMatchScheme) {
50 // Check that rewriting the URL with a matching scheme works.
51 content::TestBrowserContext browser_context;
52 content::BrowserURLHandler::GetInstance()->AddHandlerPair(
shenghuazhang 2017/01/05 23:36:33 Failed at GetInstance(). Due to failed to set up C
53 &HandleBlimpTestURL, content::BrowserURLHandler::null_handler());
54
55 GURL url("blimp-test://chrome/test/data/title2.html");
56 GURL original_url(url);
57 bool reverse_on_redirect = false;
58 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
59 &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::GetInstance()->AddHandlerPair(
70 &HandleBlimpTestURL, content::BrowserURLHandler::null_handler());
71
72 GURL url = GURL("http://www.google.com");
73 GURL original_url = GURL(url);
74 bool reverse_on_redirect = false;
75 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
76 &url, &browser_context, &reverse_on_redirect);
77 ASSERT_EQ(original_url, url);
78
79 url = GURL("https://www.google.com");
80 original_url = GURL(url);
81 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
82 &url, &browser_context, &reverse_on_redirect);
83 ASSERT_EQ(original_url, url);
84 }
85
86 TEST_F(BlimpUrlRewriterTest, UrlRewriteUnmatchScheme) {
87 // Check that rewriting the URL not works with an unmatching url.
88 content::TestBrowserContext browser_context;
89 content::BrowserURLHandler::GetInstance()->AddHandlerPair(
90 &HandleBlimpTestURL, content::BrowserURLHandler::null_handler());
91
92 GURL url = GURL("foo://chrome/test/data/title2.html");
93 GURL original_url = GURL(url);
94 bool reverse_on_redirect = false;
95 content::BrowserURLHandler::GetInstance()->RewriteURLIfNecessary(
96 &url, &browser_context, &reverse_on_redirect);
97 ASSERT_EQ(original_url, url);
98 }
99
100 } // namespace test
101
102 } // namespace engine
103 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698