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

Unified Diff: net/proxy/proxy_service_mojo_unittest.cc

Issue 910343003: Create an in-process v8 proxy resolver using Mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8-pac-complete-patch
Patch Set: Remove extra space. Created 5 years, 9 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
« no previous file with comments | « net/proxy/proxy_service_mojo.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_service_mojo_unittest.cc
diff --git a/net/proxy/proxy_service_mojo_unittest.cc b/net/proxy/proxy_service_mojo_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4f9491f1a803f315164b5cd65496ec9c8762192c
--- /dev/null
+++ b/net/proxy/proxy_service_mojo_unittest.cc
@@ -0,0 +1,95 @@
+// Copyright 2015 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 "net/proxy/proxy_service_mojo.h"
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/load_flags.h"
+#include "net/base/net_log.h"
+#include "net/base/test_completion_callback.h"
+#include "net/dns/mock_host_resolver.h"
+#include "net/proxy/dhcp_proxy_script_fetcher.h"
+#include "net/proxy/mock_proxy_script_fetcher.h"
+#include "net/proxy/proxy_config_service_fixed.h"
+#include "net/proxy/proxy_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace net {
+
+namespace {
+
+const char kPacUrl[] = "http://example.com/proxy.pac";
+const char kSimplePacScript[] =
+ "function FindProxyForURL(url, host) {\n"
+ " return 'PROXY foo:1234';\n"
+ "}";
+const char kDnsResolvePacScript[] =
+ "function FindProxyForURL(url, host) {\n"
+ " if (dnsResolveEx('example.com') != '1.2.3.4')\n"
+ " return 'DIRECT';\n"
+ " return 'QUIC bar:4321';\n"
+ "}";
+
+} // namespace
+
+class ProxyServiceMojoTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ mock_host_resolver_.rules()->AddRule("example.com", "1.2.3.4");
+
+ fetcher_ = new MockProxyScriptFetcher;
+ proxy_service_.reset(CreateProxyServiceUsingMojoInProcess(
+ new ProxyConfigServiceFixed(
+ ProxyConfig::CreateFromCustomPacURL(GURL(kPacUrl))),
+ fetcher_, new DoNothingDhcpProxyScriptFetcher(), &mock_host_resolver_,
+ nullptr /* NetLog* */, nullptr /* NetworkDelegate* */));
+ }
+
+ MockHostResolver mock_host_resolver_;
+ MockProxyScriptFetcher* fetcher_; // Owned by |proxy_service_|.
+ scoped_ptr<ProxyService> proxy_service_;
+};
+
+TEST_F(ProxyServiceMojoTest, Basic) {
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info,
+ callback.callback(), nullptr, nullptr,
+ BoundNetLog()));
+
+ // Proxy script fetcher should have a fetch triggered by the first
+ // |ResolveProxy()| request.
+ EXPECT_TRUE(fetcher_->has_pending_request());
+ EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
+ fetcher_->NotifyFetchCompletion(OK, kSimplePacScript);
+
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ("PROXY foo:1234", info.ToPacString());
+ EXPECT_EQ(0u, mock_host_resolver_.num_resolve());
+}
+
+TEST_F(ProxyServiceMojoTest, DnsResolution) {
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ EXPECT_EQ(ERR_IO_PENDING,
+ proxy_service_->ResolveProxy(GURL("http://foo"), LOAD_NORMAL, &info,
+ callback.callback(), nullptr, nullptr,
+ BoundNetLog()));
+
+ // Proxy script fetcher should have a fetch triggered by the first
+ // |ResolveProxy()| request.
+ EXPECT_TRUE(fetcher_->has_pending_request());
+ EXPECT_EQ(GURL(kPacUrl), fetcher_->pending_request_url());
+ fetcher_->NotifyFetchCompletion(OK, kDnsResolvePacScript);
+
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ("QUIC bar:4321", info.ToPacString());
+ EXPECT_EQ(1u, mock_host_resolver_.num_resolve());
+}
+
+} // namespace net
« no previous file with comments | « net/proxy/proxy_service_mojo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698