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

Side by Side Diff: net/proxy/network_delegate_error_observer_unittest.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « net/proxy/network_delegate_error_observer.cc ('k') | net/proxy/polling_proxy_config_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "net/proxy/network_delegate_error_observer.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/threading/thread.h"
11 #include "net/base/net_errors.h"
12 #include "net/base/network_delegate_impl.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace net {
16
17 namespace {
18
19 class TestNetworkDelegate : public net::NetworkDelegateImpl {
20 public:
21 TestNetworkDelegate() : got_pac_error_(false) {}
22 ~TestNetworkDelegate() override {}
23
24 bool got_pac_error() const { return got_pac_error_; }
25
26 private:
27 // net::NetworkDelegate implementation.
28 int OnBeforeURLRequest(URLRequest* request,
29 const CompletionCallback& callback,
30 GURL* new_url) override {
31 return OK;
32 }
33 int OnBeforeSendHeaders(URLRequest* request,
34 const CompletionCallback& callback,
35 HttpRequestHeaders* headers) override {
36 return OK;
37 }
38 void OnSendHeaders(URLRequest* request,
39 const HttpRequestHeaders& headers) override {}
40 int OnHeadersReceived(
41 URLRequest* request,
42 const CompletionCallback& callback,
43 const HttpResponseHeaders* original_response_headers,
44 scoped_refptr<HttpResponseHeaders>* override_response_headers,
45 GURL* allowed_unsafe_redirect_url) override {
46 return net::OK;
47 }
48 void OnBeforeRedirect(URLRequest* request,
49 const GURL& new_location) override {}
50 void OnResponseStarted(URLRequest* request) override {}
51 void OnRawBytesRead(const URLRequest& request, int bytes_read) override {}
52 void OnCompleted(URLRequest* request, bool started) override {}
53 void OnURLRequestDestroyed(URLRequest* request) override {}
54
55 void OnPACScriptError(int line_number, const base::string16& error) override {
56 got_pac_error_ = true;
57 }
58 AuthRequiredResponse OnAuthRequired(URLRequest* request,
59 const AuthChallengeInfo& auth_info,
60 const AuthCallback& callback,
61 AuthCredentials* credentials) override {
62 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
63 }
64 bool OnCanGetCookies(const URLRequest& request,
65 const CookieList& cookie_list) override {
66 return true;
67 }
68 bool OnCanSetCookie(const URLRequest& request,
69 const std::string& cookie_line,
70 CookieOptions* options) override {
71 return true;
72 }
73 bool OnCanAccessFile(const net::URLRequest& request,
74 const base::FilePath& path) const override {
75 return true;
76 }
77 bool OnCanThrottleRequest(const URLRequest& request) const override {
78 return false;
79 }
80
81 bool got_pac_error_;
82 };
83
84 } // namespace
85
86 // Check that the OnPACScriptError method can be called from an arbitrary
87 // thread.
88 TEST(NetworkDelegateErrorObserverTest, CallOnThread) {
89 base::Thread thread("test_thread");
90 thread.Start();
91 TestNetworkDelegate network_delegate;
92 NetworkDelegateErrorObserver observer(
93 &network_delegate, base::MessageLoopProxy::current().get());
94 thread.message_loop()
95 ->PostTask(FROM_HERE,
96 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError,
97 base::Unretained(&observer),
98 42,
99 base::string16()));
100 thread.Stop();
101 base::MessageLoop::current()->RunUntilIdle();
102 ASSERT_TRUE(network_delegate.got_pac_error());
103 }
104
105 // Check that passing a NULL network delegate works.
106 TEST(NetworkDelegateErrorObserverTest, NoDelegate) {
107 base::Thread thread("test_thread");
108 thread.Start();
109 NetworkDelegateErrorObserver observer(
110 NULL, base::MessageLoopProxy::current().get());
111 thread.message_loop()
112 ->PostTask(FROM_HERE,
113 base::Bind(&NetworkDelegateErrorObserver::OnPACScriptError,
114 base::Unretained(&observer),
115 42,
116 base::string16()));
117 thread.Stop();
118 base::MessageLoop::current()->RunUntilIdle();
119 // Shouldn't have crashed until here...
120 }
121
122 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/network_delegate_error_observer.cc ('k') | net/proxy/polling_proxy_config_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698