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

Side by Side Diff: mojo/fetcher/about_fetcher_unittest.cc

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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/fetcher/about_fetcher.cc ('k') | mojo/fetcher/data_fetcher.cc » ('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/about_fetcher.h"
6
7 #include <utility>
8
5 #include "base/at_exit.h" 9 #include "base/at_exit.h"
6 #include "base/macros.h" 10 #include "base/macros.h"
7 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h" 13 #include "base/path_service.h"
10 #include "base/run_loop.h" 14 #include "base/run_loop.h"
11 #include "mojo/application/public/cpp/application_connection.h" 15 #include "mojo/application/public/cpp/application_connection.h"
12 #include "mojo/application/public/cpp/application_delegate.h" 16 #include "mojo/application/public/cpp/application_delegate.h"
13 #include "mojo/application/public/cpp/application_impl.h" 17 #include "mojo/application/public/cpp/application_impl.h"
14 #include "mojo/application/public/cpp/interface_factory.h" 18 #include "mojo/application/public/cpp/interface_factory.h"
15 #include "mojo/application/public/interfaces/content_handler.mojom.h" 19 #include "mojo/application/public/interfaces/content_handler.mojom.h"
16 #include "mojo/common/weak_binding_set.h" 20 #include "mojo/common/weak_binding_set.h"
17 #include "mojo/fetcher/about_fetcher.h"
18 #include "mojo/package_manager/package_manager_impl.h" 21 #include "mojo/package_manager/package_manager_impl.h"
19 #include "mojo/shell/application_loader.h" 22 #include "mojo/shell/application_loader.h"
20 #include "mojo/shell/application_manager.h" 23 #include "mojo/shell/application_manager.h"
21 #include "mojo/util/filename_util.h" 24 #include "mojo/util/filename_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
23 26
24 namespace mojo { 27 namespace mojo {
25 namespace fetcher { 28 namespace fetcher {
26 namespace { 29 namespace {
27 30
(...skipping 11 matching lines...) Expand all
39 // Overridden from ApplicationDelegate: 42 // Overridden from ApplicationDelegate:
40 void Initialize(ApplicationImpl* app) override {} 43 void Initialize(ApplicationImpl* app) override {}
41 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 44 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
42 connection->AddService<ContentHandler>(this); 45 connection->AddService<ContentHandler>(this);
43 return true; 46 return true;
44 } 47 }
45 48
46 // Overridden from InterfaceFactory<ContentHandler>: 49 // Overridden from InterfaceFactory<ContentHandler>:
47 void Create(ApplicationConnection* connection, 50 void Create(ApplicationConnection* connection,
48 InterfaceRequest<ContentHandler> request) override { 51 InterfaceRequest<ContentHandler> request) override {
49 bindings_.AddBinding(this, request.Pass()); 52 bindings_.AddBinding(this, std::move(request));
50 } 53 }
51 54
52 // Overridden from ContentHandler: 55 // Overridden from ContentHandler:
53 void StartApplication( 56 void StartApplication(
54 InterfaceRequest<Application> application, 57 InterfaceRequest<Application> application,
55 URLResponsePtr response, 58 URLResponsePtr response,
56 const Callback<void()>& destruct_callback) override { 59 const Callback<void()>& destruct_callback) override {
57 response_number_++; 60 response_number_++;
58 latest_response_ = response.Pass(); 61 latest_response_ = std::move(response);
59 destruct_callback.Run(); 62 destruct_callback.Run();
60 63
61 // Drop |application| request. This results in the application manager 64 // Drop |application| request. This results in the application manager
62 // dropping the ServiceProvider interface request provided by the client 65 // dropping the ServiceProvider interface request provided by the client
63 // who made the ConnectToApplication() call. Therefore the client could 66 // who made the ConnectToApplication() call. Therefore the client could
64 // listen for connection error of the ServiceProvider interface to learn 67 // listen for connection error of the ServiceProvider interface to learn
65 // that StartApplication() has been called. 68 // that StartApplication() has been called.
66 } 69 }
67 70
68 size_t response_number_; 71 size_t response_number_;
69 URLResponsePtr latest_response_; 72 URLResponsePtr latest_response_;
70 WeakBindingSet<ContentHandler> bindings_; 73 WeakBindingSet<ContentHandler> bindings_;
71 74
72 DISALLOW_COPY_AND_ASSIGN(TestContentHandler); 75 DISALLOW_COPY_AND_ASSIGN(TestContentHandler);
73 }; 76 };
74 77
75 class TestLoader : public shell::ApplicationLoader { 78 class TestLoader : public shell::ApplicationLoader {
76 public: 79 public:
77 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {} 80 explicit TestLoader(ApplicationDelegate* delegate) : delegate_(delegate) {}
78 ~TestLoader() override {} 81 ~TestLoader() override {}
79 82
80 private: 83 private:
81 // Overridden from ApplicationLoader: 84 // Overridden from ApplicationLoader:
82 void Load(const GURL& url, InterfaceRequest<Application> request) override { 85 void Load(const GURL& url, InterfaceRequest<Application> request) override {
83 app_.reset(new ApplicationImpl(delegate_, request.Pass())); 86 app_.reset(new ApplicationImpl(delegate_, std::move(request)));
84 } 87 }
85 88
86 ApplicationDelegate* delegate_; 89 ApplicationDelegate* delegate_;
87 scoped_ptr<ApplicationImpl> app_; 90 scoped_ptr<ApplicationImpl> app_;
88 91
89 DISALLOW_COPY_AND_ASSIGN(TestLoader); 92 DISALLOW_COPY_AND_ASSIGN(TestLoader);
90 }; 93 };
91 94
92 class AboutFetcherTest : public testing::Test { 95 class AboutFetcherTest : public testing::Test {
93 public: 96 public:
(...skipping 14 matching lines...) Expand all
108 // This connection error handler will be called when: 111 // This connection error handler will be called when:
109 // - TestContentHandler::StartApplication() has been called (please see 112 // - TestContentHandler::StartApplication() has been called (please see
110 // comments in that method); or 113 // comments in that method); or
111 // - the application manager fails to fetch the requested URL. 114 // - the application manager fails to fetch the requested URL.
112 service_provider.set_connection_error_handler( 115 service_provider.set_connection_error_handler(
113 [&run_loop]() { run_loop.Quit(); }); 116 [&run_loop]() { run_loop.Quit(); });
114 117
115 scoped_ptr<shell::ConnectToApplicationParams> params( 118 scoped_ptr<shell::ConnectToApplicationParams> params(
116 new shell::ConnectToApplicationParams); 119 new shell::ConnectToApplicationParams);
117 params->SetTargetURL(GURL(url)); 120 params->SetTargetURL(GURL(url));
118 params->set_services(service_provider_request.Pass()); 121 params->set_services(std::move(service_provider_request));
119 application_manager_->ConnectToApplication(params.Pass()); 122 application_manager_->ConnectToApplication(std::move(params));
120 123
121 run_loop.Run(); 124 run_loop.Run();
122 } 125 }
123 126
124 // Overridden from testing::Test: 127 // Overridden from testing::Test:
125 void SetUp() override { 128 void SetUp() override {
126 base::FilePath shell_dir; 129 base::FilePath shell_dir;
127 PathService::Get(base::DIR_MODULE, &shell_dir); 130 PathService::Get(base::DIR_MODULE, &shell_dir);
128 scoped_ptr<package_manager::PackageManagerImpl> package_manager( 131 scoped_ptr<package_manager::PackageManagerImpl> package_manager(
129 new package_manager::PackageManagerImpl(shell_dir, nullptr)); 132 new package_manager::PackageManagerImpl(shell_dir, nullptr));
130 package_manager->RegisterContentHandler( 133 package_manager->RegisterContentHandler(
131 "text/html", GURL("test:html_content_handler")); 134 "text/html", GURL("test:html_content_handler"));
132 application_manager_.reset( 135 application_manager_.reset(
133 new shell::ApplicationManager(package_manager.Pass())); 136 new shell::ApplicationManager(std::move(package_manager)));
134 application_manager_->SetLoaderForURL( 137 application_manager_->SetLoaderForURL(
135 make_scoped_ptr(new TestLoader(&html_content_handler_)), 138 make_scoped_ptr(new TestLoader(&html_content_handler_)),
136 GURL("test:html_content_handler")); 139 GURL("test:html_content_handler"));
137 } 140 }
138 141
139 void TearDown() override { application_manager_.reset(); } 142 void TearDown() override { application_manager_.reset(); }
140 143
141 private: 144 private:
142 base::ShadowingAtExitManager at_exit_; 145 base::ShadowingAtExitManager at_exit_;
143 TestContentHandler html_content_handler_; 146 TestContentHandler html_content_handler_;
(...skipping 23 matching lines...) Expand all
167 const URLResponse* response = html_content_handler()->latest_response(); 170 const URLResponse* response = html_content_handler()->latest_response();
168 EXPECT_EQ("about:some_unrecognized_url", response->url); 171 EXPECT_EQ("about:some_unrecognized_url", response->url);
169 EXPECT_EQ(404u, response->status_code); 172 EXPECT_EQ(404u, response->status_code);
170 EXPECT_EQ("text/html", response->mime_type); 173 EXPECT_EQ("text/html", response->mime_type);
171 EXPECT_FALSE(response->body.is_valid()); 174 EXPECT_FALSE(response->body.is_valid());
172 } 175 }
173 176
174 } // namespace 177 } // namespace
175 } // namespace fetcher 178 } // namespace fetcher
176 } // namespace mojo 179 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/about_fetcher.cc ('k') | mojo/fetcher/data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698