summaryrefslogtreecommitdiffstats
path: root/mojo/shell/tests/connect
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/shell/tests/connect')
-rw-r--r--mojo/shell/tests/connect/BUILD.gn19
-rw-r--r--mojo/shell/tests/connect/connect_test_app_manifest.json2
-rw-r--r--mojo/shell/tests/connect/connect_test_singleton_app.cc36
-rw-r--r--mojo/shell/tests/connect/connect_test_singleton_app_manifest.json10
-rw-r--r--mojo/shell/tests/connect/connect_unittest.cc19
5 files changed, 78 insertions, 8 deletions
diff --git a/mojo/shell/tests/connect/BUILD.gn b/mojo/shell/tests/connect/BUILD.gn
index 48c19a15..fc70dd0 100644
--- a/mojo/shell/tests/connect/BUILD.gn
+++ b/mojo/shell/tests/connect/BUILD.gn
@@ -24,6 +24,7 @@ source_set("connect") {
data_deps = [
":connect_test_app",
":connect_test_class_app",
+ ":connect_test_singleton_app",
":connect_test_driver",
":connect_test_exe",
":connect_test_package",
@@ -123,6 +124,24 @@ mojo_application_manifest("connect_test_class_app_manifest") {
source = "connect_test_class_app_manifest.json"
}
+mojo_native_application("connect_test_singleton_app") {
+ testonly = true
+ sources = [
+ "connect_test_singleton_app.cc",
+ ]
+ deps = [
+ ":connect_test_singleton_app_manifest",
+ "//base",
+ "//mojo/common:common_base",
+ "//mojo/shell/public/cpp:sources",
+ ]
+}
+
+mojo_application_manifest("connect_test_singleton_app_manifest") {
+ application_name = "connect_test_singleton_app"
+ source = "connect_test_singleton_app_manifest.json"
+}
+
executable("connect_test_driver") {
testonly = true
diff --git a/mojo/shell/tests/connect/connect_test_app_manifest.json b/mojo/shell/tests/connect/connect_test_app_manifest.json
index 93b9782..7c45922 100644
--- a/mojo/shell/tests/connect/connect_test_app_manifest.json
+++ b/mojo/shell/tests/connect/connect_test_app_manifest.json
@@ -9,7 +9,7 @@
"classes": [ "class" ],
"interfaces": ["mojo::shell::test::mojom::ConnectTestService"]
},
- "mojo:shell": { "classes": [ "user_id", "all_users" ] }
+ "mojo:shell": { "classes": [ "user_id" ] }
}
}
}
diff --git a/mojo/shell/tests/connect/connect_test_singleton_app.cc b/mojo/shell/tests/connect/connect_test_singleton_app.cc
new file mode 100644
index 0000000..1ee8cbd
--- /dev/null
+++ b/mojo/shell/tests/connect/connect_test_singleton_app.cc
@@ -0,0 +1,36 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/shell/public/cpp/application_runner.h"
+#include "mojo/shell/public/cpp/shell_client.h"
+
+namespace mojo {
+namespace shell {
+
+class ConnectTestSingletonApp : public ShellClient {
+ public:
+ ConnectTestSingletonApp() {}
+ ~ConnectTestSingletonApp() override {}
+
+ private:
+ // mojo::ShellClient:
+ void Initialize(Connector* connector, const Identity& identity,
+ uint32_t id) override {}
+ bool AcceptConnection(Connection* connection) override {
+ return true;
+ }
+
+ DISALLOW_COPY_AND_ASSIGN(ConnectTestSingletonApp);
+};
+
+} // namespace shell
+} // namespace mojo
+
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ return mojo::ApplicationRunner(
+ new mojo::shell::ConnectTestSingletonApp).Run(shell_handle);
+}
diff --git a/mojo/shell/tests/connect/connect_test_singleton_app_manifest.json b/mojo/shell/tests/connect/connect_test_singleton_app_manifest.json
new file mode 100644
index 0000000..550314d
--- /dev/null
+++ b/mojo/shell/tests/connect/connect_test_singleton_app_manifest.json
@@ -0,0 +1,10 @@
+{
+ "manifest_version": 1,
+ "name": "mojo:connect_test_singleton_app",
+ "display_name": "Connect Test Singleton App",
+ "capabilities": {
+ "required": {
+ "mojo:shell": { "classes": [ "all_users" ] }
+ }
+ }
+}
diff --git a/mojo/shell/tests/connect/connect_unittest.cc b/mojo/shell/tests/connect/connect_unittest.cc
index 9cfb0a7..355f6bac 100644
--- a/mojo/shell/tests/connect/connect_unittest.cc
+++ b/mojo/shell/tests/connect/connect_unittest.cc
@@ -30,6 +30,7 @@ const char kTestAppName[] = "mojo:connect_test_app";
const char kTestAppAName[] = "mojo:connect_test_a";
const char kTestAppBName[] = "mojo:connect_test_b";
const char kTestClassAppName[] = "mojo:connect_test_class_app";
+const char kTestSingletonAppName[] = "mojo:connect_test_singleton_app";
const char kTestDriverName[] = "exe:connect_test_driver";
void ReceiveOneString(std::string* out_string,
@@ -355,26 +356,30 @@ TEST_F(ConnectTest, ConnectToClientProcess_Blocked) {
// Verifies that a client with the "all_users" capability class can receive
// connections from clients run as other users.
TEST_F(ConnectTest, AllUsersSingleton) {
- // Connect to an instance with an explicitly different user_id.
+ // Connect to an instance with an explicitly different user_id. This supplied
+ // user id should be ignored by the shell (which will generate its own
+ // synthetic user id for all-user singleton instances).
const std::string singleton_userid = base::GenerateGUID();
- Connector::ConnectParams params(Identity(kTestAppName, singleton_userid));
+ Connector::ConnectParams params(
+ Identity(kTestSingletonAppName, singleton_userid));
scoped_ptr<Connection> connection = connector()->Connect(&params);
{
base::RunLoop loop;
connection->AddConnectionCompletedClosure(base::Bind(&QuitLoop, &loop));
loop.Run();
- EXPECT_EQ(connection->GetRemoteIdentity().user_id(), singleton_userid);
+ EXPECT_NE(connection->GetRemoteIdentity().user_id(), singleton_userid);
}
- // This connects using the current client's user_id, but should be bound to
- // the instance run as |singleton_userid|.
+ // This connects using the current client's user_id. It should be bound to the
+ // same service started above, with the same shell-generated user id.
scoped_ptr<Connection> inherit_connection =
- connector()->Connect(kTestAppName);
+ connector()->Connect(kTestSingletonAppName);
{
base::RunLoop loop;
inherit_connection->AddConnectionCompletedClosure(
base::Bind(&QuitLoop, &loop));
loop.Run();
- EXPECT_EQ(connection->GetRemoteIdentity().user_id(), singleton_userid);
+ EXPECT_EQ(inherit_connection->GetRemoteIdentity().user_id(),
+ connection->GetRemoteIdentity().user_id());
}
}