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

Side by Side Diff: mojo/shell/fetcher/network_fetcher_unittest.cc

Issue 1563413002: Move fetchers into mojo/shell/fetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « mojo/shell/fetcher/network_fetcher.cc ('k') | mojo/shell/fetcher/switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/fetcher/network_fetcher.h" 5 #include "mojo/shell/fetcher/network_fetcher.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/at_exit.h" 11 #include "base/at_exit.h"
12 #include "base/auto_reset.h" 12 #include "base/auto_reset.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "mojo/public/cpp/bindings/strong_binding.h" 19 #include "mojo/public/cpp/bindings/strong_binding.h"
20 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" 20 #include "mojo/services/network/public/interfaces/url_loader.mojom.h"
21 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" 21 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 namespace mojo { 24 namespace mojo {
25 namespace fetcher { 25 namespace shell {
26 namespace { 26 namespace {
27 27
28 const char k200Request[] = "http://request_expect_200"; 28 const char k200Request[] = "http://request_expect_200";
29 const char k404Request[] = "http://request_expect_404"; 29 const char k404Request[] = "http://request_expect_404";
30 const char k504Request[] = "http://request_expect_504"; 30 const char k504Request[] = "http://request_expect_504";
31 const char kErrorRequest[] = "http://request_expect_error"; 31 const char kErrorRequest[] = "http://request_expect_error";
32 32
33 class TestURLLoaderImpl : public URLLoader { 33 class TestURLLoaderImpl : public URLLoader {
34 public: 34 public:
35 explicit TestURLLoaderImpl(InterfaceRequest<URLLoader> request) 35 explicit TestURLLoaderImpl(InterfaceRequest<URLLoader> request)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 StrongBinding<URLLoaderFactory> binding_; 84 StrongBinding<URLLoaderFactory> binding_;
85 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactoryImpl); 85 DISALLOW_COPY_AND_ASSIGN(TestURLLoaderFactoryImpl);
86 }; 86 };
87 87
88 class FetchCallbackHelper { 88 class FetchCallbackHelper {
89 public: 89 public:
90 FetchCallbackHelper() : run_loop_(nullptr) {} 90 FetchCallbackHelper() : run_loop_(nullptr) {}
91 ~FetchCallbackHelper() {} 91 ~FetchCallbackHelper() {}
92 92
93 shell::Fetcher::FetchCallback GetCallback() { 93 Fetcher::FetchCallback GetCallback() {
94 return base::Bind(&FetchCallbackHelper::CallbackHandler, 94 return base::Bind(&FetchCallbackHelper::CallbackHandler,
95 base::Unretained(this)); 95 base::Unretained(this));
96 } 96 }
97 97
98 void WaitForCallback() { 98 void WaitForCallback() {
99 base::RunLoop run_loop; 99 base::RunLoop run_loop;
100 base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop); 100 base::AutoReset<base::RunLoop*> auto_reset(&run_loop_, &run_loop);
101 run_loop.Run(); 101 run_loop.Run();
102 } 102 }
103 103
104 shell::Fetcher* fetcher() const { return fetcher_.get(); } 104 Fetcher* fetcher() const { return fetcher_.get(); }
105 105
106 private: 106 private:
107 void CallbackHandler(scoped_ptr<shell::Fetcher> fetcher) { 107 void CallbackHandler(scoped_ptr<Fetcher> fetcher) {
108 fetcher_ = std::move(fetcher); 108 fetcher_ = std::move(fetcher);
109 if (run_loop_) 109 if (run_loop_)
110 run_loop_->Quit(); 110 run_loop_->Quit();
111 } 111 }
112 112
113 // If it is not null, it points to a stack-allocated base::RunLoop instance in 113 // If it is not null, it points to a stack-allocated base::RunLoop instance in
114 // WaitForCallback(). 114 // WaitForCallback().
115 base::RunLoop* run_loop_; 115 base::RunLoop* run_loop_;
116 scoped_ptr<shell::Fetcher> fetcher_; 116 scoped_ptr<Fetcher> fetcher_;
117 DISALLOW_COPY_AND_ASSIGN(FetchCallbackHelper); 117 DISALLOW_COPY_AND_ASSIGN(FetchCallbackHelper);
118 }; 118 };
119 119
120 class NetworkFetcherTest : public testing::Test { 120 class NetworkFetcherTest : public testing::Test {
121 public: 121 public:
122 NetworkFetcherTest() {} 122 NetworkFetcherTest() {}
123 ~NetworkFetcherTest() override {} 123 ~NetworkFetcherTest() override {}
124 124
125 protected: 125 protected:
126 // Overridden from testing::Test: 126 // Overridden from testing::Test:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 TEST_F(NetworkFetcherTest, FetchSucceeded504) { 171 TEST_F(NetworkFetcherTest, FetchSucceeded504) {
172 TestFetchURL(k504Request, true, 504u); 172 TestFetchURL(k504Request, true, 504u);
173 } 173 }
174 174
175 TEST_F(NetworkFetcherTest, FetchFailed) { 175 TEST_F(NetworkFetcherTest, FetchFailed) {
176 TestFetchURL(kErrorRequest, false, 0u); 176 TestFetchURL(kErrorRequest, false, 0u);
177 } 177 }
178 178
179 } // namespace 179 } // namespace
180 } // namespace fetcher 180 } // namespace shell
181 } // namespace mojo 181 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/fetcher/network_fetcher.cc ('k') | mojo/shell/fetcher/switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698