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

Side by Side Diff: mojo/shell/application_manager_unittest.cc

Issue 1675153002: ApplicationImpl->ShellConnection, mojom::Application->mojom::ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ci2
Patch Set: . Created 4 years, 10 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/application_manager.cc ('k') | mojo/shell/application_package_apptest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shell/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 15 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "mojo/shell/application_loader.h" 16 #include "mojo/shell/application_loader.h"
17 #include "mojo/shell/connect_util.h" 17 #include "mojo/shell/connect_util.h"
18 #include "mojo/shell/fetcher.h" 18 #include "mojo/shell/fetcher.h"
19 #include "mojo/shell/package_manager.h" 19 #include "mojo/shell/package_manager.h"
20 #include "mojo/shell/public/cpp/application_impl.h"
21 #include "mojo/shell/public/cpp/interface_factory.h" 20 #include "mojo/shell/public/cpp/interface_factory.h"
22 #include "mojo/shell/public/cpp/shell_client.h" 21 #include "mojo/shell/public/cpp/shell_client.h"
22 #include "mojo/shell/public/cpp/shell_connection.h"
23 #include "mojo/shell/public/interfaces/service_provider.mojom.h" 23 #include "mojo/shell/public/interfaces/service_provider.mojom.h"
24 #include "mojo/shell/test.mojom.h" 24 #include "mojo/shell/test.mojom.h"
25 #include "mojo/shell/test_package_manager.h" 25 #include "mojo/shell/test_package_manager.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 namespace mojo { 28 namespace mojo {
29 namespace shell { 29 namespace shell {
30 namespace test { 30 namespace test {
31 31
32 const char kTestURLString[] = "test:testService"; 32 const char kTestURLString[] = "test:testService";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 class TestApplicationLoader : public ApplicationLoader, 96 class TestApplicationLoader : public ApplicationLoader,
97 public ShellClient, 97 public ShellClient,
98 public InterfaceFactory<TestService> { 98 public InterfaceFactory<TestService> {
99 public: 99 public:
100 TestApplicationLoader() 100 TestApplicationLoader()
101 : context_(nullptr), num_loads_(0) {} 101 : context_(nullptr), num_loads_(0) {}
102 102
103 ~TestApplicationLoader() override { 103 ~TestApplicationLoader() override {
104 if (context_) 104 if (context_)
105 ++context_->num_loader_deletes; 105 ++context_->num_loader_deletes;
106 test_app_.reset(); 106 shell_connection_.reset();
107 } 107 }
108 108
109 void set_context(TestContext* context) { context_ = context; } 109 void set_context(TestContext* context) { context_ = context; }
110 int num_loads() const { return num_loads_; } 110 int num_loads() const { return num_loads_; }
111 const GURL& last_requestor_url() const { return last_requestor_url_; } 111 const GURL& last_requestor_url() const { return last_requestor_url_; }
112 112
113 private: 113 private:
114 // ApplicationLoader implementation. 114 // ApplicationLoader implementation.
115 void Load(const GURL& url, 115 void Load(const GURL& url,
116 InterfaceRequest<mojom::Application> application_request) override { 116 InterfaceRequest<mojom::ShellClient> request) override {
117 ++num_loads_; 117 ++num_loads_;
118 test_app_.reset(new ApplicationImpl(this, std::move(application_request))); 118 shell_connection_.reset(new ShellConnection(this, std::move(request)));
119 } 119 }
120 120
121 // mojo::ShellClient implementation. 121 // mojo::ShellClient implementation.
122 bool AcceptConnection(Connection* connection) override { 122 bool AcceptConnection(Connection* connection) override {
123 connection->AddService<TestService>(this); 123 connection->AddService<TestService>(this);
124 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL()); 124 last_requestor_url_ = GURL(connection->GetRemoteApplicationURL());
125 return true; 125 return true;
126 } 126 }
127 127
128 // InterfaceFactory<TestService> implementation. 128 // InterfaceFactory<TestService> implementation.
129 void Create(Connection* connection, 129 void Create(Connection* connection,
130 InterfaceRequest<TestService> request) override { 130 InterfaceRequest<TestService> request) override {
131 new TestServiceImpl(context_, std::move(request)); 131 new TestServiceImpl(context_, std::move(request));
132 } 132 }
133 133
134 scoped_ptr<ApplicationImpl> test_app_; 134 scoped_ptr<ShellConnection> shell_connection_;
135 TestContext* context_; 135 TestContext* context_;
136 int num_loads_; 136 int num_loads_;
137 GURL last_requestor_url_; 137 GURL last_requestor_url_;
138 138
139 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader); 139 DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
140 }; 140 };
141 141
142 class ClosingApplicationLoader : public ApplicationLoader { 142 class ClosingApplicationLoader : public ApplicationLoader {
143 private: 143 private:
144 // ApplicationLoader implementation. 144 // ApplicationLoader implementation.
145 void Load(const GURL& url, 145 void Load(const GURL& url,
146 InterfaceRequest<mojom::Application> application_request) override { 146 InterfaceRequest<mojom::ShellClient> request) override {
147 } 147 }
148 }; 148 };
149 149
150 class TesterContext { 150 class TesterContext {
151 public: 151 public:
152 explicit TesterContext(base::MessageLoop* loop) 152 explicit TesterContext(base::MessageLoop* loop)
153 : num_b_calls_(0), 153 : num_b_calls_(0),
154 num_c_calls_(0), 154 num_c_calls_(0),
155 num_a_deletes_(0), 155 num_a_deletes_(0),
156 num_b_deletes_(0), 156 num_b_deletes_(0),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 int num_c_deletes_; 238 int num_c_deletes_;
239 bool tester_called_quit_; 239 bool tester_called_quit_;
240 bool a_called_quit_; 240 bool a_called_quit_;
241 241
242 base::MessageLoop* loop_; 242 base::MessageLoop* loop_;
243 }; 243 };
244 244
245 // Used to test that the requestor url will be correctly passed. 245 // Used to test that the requestor url will be correctly passed.
246 class TestAImpl : public TestA { 246 class TestAImpl : public TestA {
247 public: 247 public:
248 TestAImpl(ApplicationImpl* app_impl, 248 TestAImpl(ShellConnection* app_impl,
249 TesterContext* test_context, 249 TesterContext* test_context,
250 InterfaceRequest<TestA> request, 250 InterfaceRequest<TestA> request,
251 InterfaceFactory<TestC>* factory) 251 InterfaceFactory<TestC>* factory)
252 : test_context_(test_context), binding_(this, std::move(request)) { 252 : test_context_(test_context), binding_(this, std::move(request)) {
253 connection_ = app_impl->Connect(kTestBURLString); 253 connection_ = app_impl->Connect(kTestBURLString);
254 connection_->AddService<TestC>(factory); 254 connection_->AddService<TestC>(factory);
255 connection_->ConnectToService(&b_); 255 connection_->ConnectToService(&b_);
256 } 256 }
257 257
258 ~TestAImpl() override { 258 ~TestAImpl() override {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 public InterfaceFactory<TestA>, 338 public InterfaceFactory<TestA>,
339 public InterfaceFactory<TestB>, 339 public InterfaceFactory<TestB>,
340 public InterfaceFactory<TestC> { 340 public InterfaceFactory<TestC> {
341 public: 341 public:
342 Tester(TesterContext* context, const std::string& requestor_url) 342 Tester(TesterContext* context, const std::string& requestor_url)
343 : context_(context), requestor_url_(requestor_url) {} 343 : context_(context), requestor_url_(requestor_url) {}
344 ~Tester() override {} 344 ~Tester() override {}
345 345
346 private: 346 private:
347 void Load(const GURL& url, 347 void Load(const GURL& url,
348 InterfaceRequest<mojom::Application> application_request) override { 348 InterfaceRequest<mojom::ShellClient> request) override {
349 app_.reset(new ApplicationImpl(this, std::move(application_request))); 349 app_.reset(new ShellConnection(this, std::move(request)));
350 } 350 }
351 351
352 bool AcceptConnection(Connection* connection) override { 352 bool AcceptConnection(Connection* connection) override {
353 if (!requestor_url_.empty() && 353 if (!requestor_url_.empty() &&
354 requestor_url_ != connection->GetRemoteApplicationURL()) { 354 requestor_url_ != connection->GetRemoteApplicationURL()) {
355 context_->set_tester_called_quit(); 355 context_->set_tester_called_quit();
356 context_->QuitSoon(); 356 context_->QuitSoon();
357 base::MessageLoop::current()->QuitWhenIdle(); 357 base::MessageLoop::current()->QuitWhenIdle();
358 return false; 358 return false;
359 } 359 }
(...skipping 15 matching lines...) Expand all
375 InterfaceRequest<TestB> request) override { 375 InterfaceRequest<TestB> request) override {
376 new TestBImpl(connection, context_, std::move(request)); 376 new TestBImpl(connection, context_, std::move(request));
377 } 377 }
378 378
379 void Create(Connection* connection, 379 void Create(Connection* connection,
380 InterfaceRequest<TestC> request) override { 380 InterfaceRequest<TestC> request) override {
381 new TestCImpl(connection, context_, std::move(request)); 381 new TestCImpl(connection, context_, std::move(request));
382 } 382 }
383 383
384 TesterContext* context_; 384 TesterContext* context_;
385 scoped_ptr<ApplicationImpl> app_; 385 scoped_ptr<ShellConnection> app_;
386 std::string requestor_url_; 386 std::string requestor_url_;
387 ScopedVector<TestAImpl> a_bindings_; 387 ScopedVector<TestAImpl> a_bindings_;
388 }; 388 };
389 389
390 class ApplicationManagerTest : public testing::Test { 390 class ApplicationManagerTest : public testing::Test {
391 public: 391 public:
392 ApplicationManagerTest() : tester_context_(&loop_) {} 392 ApplicationManagerTest() : tester_context_(&loop_) {}
393 393
394 ~ApplicationManagerTest() override {} 394 ~ApplicationManagerTest() override {}
395 395
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 621
622 // A different identity because the domain is different. 622 // A different identity because the domain is different.
623 ConnectToService(application_manager_.get(), 623 ConnectToService(application_manager_.get(),
624 GURL("http://www.another_domain.org/abc"), &test_service); 624 GURL("http://www.another_domain.org/abc"), &test_service);
625 EXPECT_EQ(4, test_loader_->num_loads()); 625 EXPECT_EQ(4, test_loader_->num_loads());
626 } 626 }
627 627
628 } // namespace test 628 } // namespace test
629 } // namespace shell 629 } // namespace shell
630 } // namespace mojo 630 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.cc ('k') | mojo/shell/application_package_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698