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

Side by Side Diff: mojo/shell/tests/application_manager_apptest.cc

Issue 1743473002: Change Mojo URLs to structured names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@18collapse
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
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 public: 69 public:
70 ApplicationManagerAppTest() : delegate_(nullptr), binding_(this) {} 70 ApplicationManagerAppTest() : delegate_(nullptr), binding_(this) {}
71 ~ApplicationManagerAppTest() override {} 71 ~ApplicationManagerAppTest() override {}
72 72
73 void OnDriverQuit() { 73 void OnDriverQuit() {
74 base::MessageLoop::current()->QuitNow(); 74 base::MessageLoop::current()->QuitNow();
75 } 75 }
76 76
77 protected: 77 protected:
78 struct ApplicationInfo { 78 struct ApplicationInfo {
79 ApplicationInfo(uint32_t id, const std::string& url) 79 ApplicationInfo(uint32_t id, const std::string& name)
80 : id(id), url(url), pid(base::kNullProcessId) {} 80 : id(id), name(name), pid(base::kNullProcessId) {}
81 81
82 uint32_t id; 82 uint32_t id;
83 std::string url; 83 std::string name;
84 base::ProcessId pid; 84 base::ProcessId pid;
85 }; 85 };
86 86
87 void AddListenerAndWaitForApplications() { 87 void AddListenerAndWaitForApplications() {
88 mojom::ApplicationManagerPtr application_manager; 88 mojom::ApplicationManagerPtr application_manager;
89 connector()->ConnectToInterface("mojo:shell", &application_manager); 89 connector()->ConnectToInterface("mojo:shell", &application_manager);
90 90
91 application_manager->AddListener(binding_.CreateInterfacePtrAndBind()); 91 application_manager->AddListener(binding_.CreateInterfacePtrAndBind());
92 binding_.WaitForIncomingMethodCall(); 92 binding_.WaitForIncomingMethodCall();
93 } 93 }
94 94
95 bool ContainsApplicationWithURL(const std::string& url) const { 95 bool ContainsApplicationWithName(const std::string& name) const {
96 for (const auto& application : initial_applications_) { 96 for (const auto& application : initial_applications_) {
97 if (application.url == url) 97 if (application.name == name)
98 return true; 98 return true;
99 } 99 }
100 for (const auto& application : applications_) { 100 for (const auto& application : applications_) {
101 if (application.url == url) 101 if (application.name == name)
102 return true; 102 return true;
103 } 103 }
104 return false; 104 return false;
105 } 105 }
106 106
107 uint32_t target_id() const { 107 uint32_t target_id() const {
108 DCHECK(delegate_); 108 DCHECK(delegate_);
109 return delegate_->target_id(); 109 return delegate_->target_id();
110 } 110 }
111 111
112 const std::vector<ApplicationInfo>& applications() const { 112 const std::vector<ApplicationInfo>& applications() const {
113 return applications_; 113 return applications_;
114 } 114 }
115 115
116 ApplicationManagerAppTestDelegate* delegate() { return delegate_; } 116 ApplicationManagerAppTestDelegate* delegate() { return delegate_; }
117 117
118 private: 118 private:
119 // test::ApplicationTestBase: 119 // test::ApplicationTestBase:
120 ShellClient* GetShellClient() override { 120 ShellClient* GetShellClient() override {
121 delegate_ = new ApplicationManagerAppTestDelegate; 121 delegate_ = new ApplicationManagerAppTestDelegate;
122 return delegate_; 122 return delegate_;
123 } 123 }
124 124
125 // mojom::ApplicationManagerListener: 125 // mojom::ApplicationManagerListener:
126 void SetRunningApplications( 126 void SetRunningApplications(
127 Array<mojom::ApplicationInfoPtr> applications) override { 127 Array<mojom::ApplicationInfoPtr> applications) override {
128 for (size_t i = 0; i < applications.size(); ++i) { 128 for (size_t i = 0; i < applications.size(); ++i) {
129 initial_applications_.push_back(ApplicationInfo(applications[i]->id, 129 initial_applications_.push_back(ApplicationInfo(applications[i]->id,
130 applications[i]->url)); 130 applications[i]->name));
131 } 131 }
132 } 132 }
133 void ApplicationInstanceCreated( 133 void ApplicationInstanceCreated(
134 mojom::ApplicationInfoPtr application) override { 134 mojom::ApplicationInfoPtr application) override {
135 applications_.push_back(ApplicationInfo(application->id, application->url)); 135 applications_.push_back(
136 ApplicationInfo(application->id, application->name));
136 } 137 }
137 void ApplicationInstanceDestroyed(uint32_t id) override { 138 void ApplicationInstanceDestroyed(uint32_t id) override {
138 for (auto it = applications_.begin(); it != applications_.end(); ++it) { 139 for (auto it = applications_.begin(); it != applications_.end(); ++it) {
139 auto& application = *it; 140 auto& application = *it;
140 if (application.id == id) { 141 if (application.id == id) {
141 applications_.erase(it); 142 applications_.erase(it);
142 break; 143 break;
143 } 144 }
144 } 145 }
145 } 146 }
(...skipping 25 matching lines...) Expand all
171 connection->GetInterface(&driver); 172 connection->GetInterface(&driver);
172 173
173 // 2. Wait for the target to connect to us. (via 174 // 2. Wait for the target to connect to us. (via
174 // mojo:application_manager_apptests) 175 // mojo:application_manager_apptests)
175 base::MessageLoop::current()->Run(); 176 base::MessageLoop::current()->Run();
176 177
177 uint32_t remote_id = mojom::Connector::kInvalidApplicationID; 178 uint32_t remote_id = mojom::Connector::kInvalidApplicationID;
178 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id)); 179 EXPECT_TRUE(connection->GetRemoteApplicationID(&remote_id));
179 EXPECT_NE(mojom::Connector::kInvalidApplicationID, remote_id); 180 EXPECT_NE(mojom::Connector::kInvalidApplicationID, remote_id);
180 181
181 // 3. Validate that this test suite's URL was received from the application 182 // 3. Validate that this test suite's name was received from the application
182 // manager. 183 // manager.
183 EXPECT_TRUE(ContainsApplicationWithURL("mojo://mojo_shell_apptests/")); 184 EXPECT_TRUE(ContainsApplicationWithName("mojo:mojo_shell_apptests"));
184 185
185 // 4. Validate that the right applications/processes were created. 186 // 4. Validate that the right applications/processes were created.
186 // Note that the target process will be created even if the tests are 187 // Note that the target process will be created even if the tests are
187 // run with --single-process. 188 // run with --single-process.
188 EXPECT_EQ(2u, applications().size()); 189 EXPECT_EQ(2u, applications().size());
189 { 190 {
190 auto& application = applications().front(); 191 auto& application = applications().front();
191 EXPECT_EQ(remote_id, application.id); 192 EXPECT_EQ(remote_id, application.id);
192 EXPECT_EQ("exe://application_manager_apptest_driver/", application.url); 193 EXPECT_EQ("exe:application_manager_apptest_driver", application.name);
193 EXPECT_NE(base::kNullProcessId, application.pid); 194 EXPECT_NE(base::kNullProcessId, application.pid);
194 } 195 }
195 { 196 {
196 auto& application = applications().back(); 197 auto& application = applications().back();
197 // We learn about the target process id via a ping from it. 198 // We learn about the target process id via a ping from it.
198 EXPECT_EQ(target_id(), application.id); 199 EXPECT_EQ(target_id(), application.id);
199 EXPECT_EQ("exe://application_manager_apptest_target/", application.url); 200 EXPECT_EQ("exe:application_manager_apptest_target", application.name);
200 EXPECT_NE(base::kNullProcessId, application.pid); 201 EXPECT_NE(base::kNullProcessId, application.pid);
201 } 202 }
202 203
203 driver.set_connection_error_handler( 204 driver.set_connection_error_handler(
204 base::Bind(&ApplicationManagerAppTest::OnDriverQuit, 205 base::Bind(&ApplicationManagerAppTest::OnDriverQuit,
205 base::Unretained(this))); 206 base::Unretained(this)));
206 driver->QuitDriver(); 207 driver->QuitDriver();
207 base::MessageLoop::current()->Run(); 208 base::MessageLoop::current()->Run();
208 } 209 }
209 210
210 } // namespace shell 211 } // namespace shell
211 } // namespace mojo 212 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/standalone/desktop/main_helper.h ('k') | mojo/shell/tests/application_manager_apptest_driver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698