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

Side by Side Diff: mojo/shell/public/cpp/lib/application_test_base.cc

Issue 1719193003: Add a user id parameter to connections (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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/public/cpp/connection.h ('k') | mojo/shell/public/cpp/lib/connection_impl.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 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 <utility> 5 #include <utility>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "mojo/public/cpp/bindings/binding.h" 10 #include "mojo/public/cpp/bindings/binding.h"
11 #include "mojo/public/cpp/environment/environment.h" 11 #include "mojo/public/cpp/environment/environment.h"
12 #include "mojo/public/cpp/system/message_pipe.h" 12 #include "mojo/public/cpp/system/message_pipe.h"
13 #include "mojo/shell/public/cpp/application_test_base.h" 13 #include "mojo/shell/public/cpp/application_test_base.h"
14 #include "mojo/shell/public/cpp/shell_connection.h" 14 #include "mojo/shell/public/cpp/shell_connection.h"
15 #include "mojo/shell/public/interfaces/shell_client.mojom.h" 15 #include "mojo/shell/public/interfaces/shell_client.mojom.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace test { 18 namespace test {
19 19
20 namespace { 20 namespace {
21 // Share the application URL with multiple application tests. 21 // Share the application URL with multiple application tests.
22 String g_url; 22 String g_url;
23 uint32_t g_id = shell::mojom::Shell::kInvalidApplicationID; 23 uint32_t g_id = shell::mojom::Shell::kInvalidApplicationID;
24 uint32_t g_user_id = shell::mojom::Shell::kUserRoot;
24 25
25 // ShellClient request handle passed from the shell in MojoMain, stored in 26 // ShellClient request handle passed from the shell in MojoMain, stored in
26 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections. 27 // between SetUp()/TearDown() so we can (re-)intialize new ShellConnections.
27 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request; 28 InterfaceRequest<shell::mojom::ShellClient> g_shell_client_request;
28 29
29 // Shell pointer passed in the initial mojo.ShellClient.Initialize() call, 30 // Shell pointer passed in the initial mojo.ShellClient.Initialize() call,
30 // stored in between initial setup and the first test and between SetUp/TearDown 31 // stored in between initial setup and the first test and between SetUp/TearDown
31 // calls so we can (re-)initialize new ShellConnections. 32 // calls so we can (re-)initialize new ShellConnections.
32 shell::mojom::ShellPtr g_shell; 33 shell::mojom::ShellPtr g_shell;
33 34
34 class ShellGrabber : public shell::mojom::ShellClient { 35 class ShellGrabber : public shell::mojom::ShellClient {
35 public: 36 public:
36 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request) 37 explicit ShellGrabber(InterfaceRequest<shell::mojom::ShellClient> request)
37 : binding_(this, std::move(request)) {} 38 : binding_(this, std::move(request)) {}
38 39
39 void WaitForInitialize() { 40 void WaitForInitialize() {
40 // Initialize is always the first call made on ShellClient. 41 // Initialize is always the first call made on ShellClient.
41 CHECK(binding_.WaitForIncomingMethodCall()); 42 CHECK(binding_.WaitForIncomingMethodCall());
42 } 43 }
43 44
44 private: 45 private:
45 // shell::mojom::ShellClient implementation. 46 // shell::mojom::ShellClient implementation.
46 void Initialize(shell::mojom::ShellPtr shell, 47 void Initialize(shell::mojom::ShellPtr shell,
47 const mojo::String& url, 48 const mojo::String& url,
48 uint32_t id) override { 49 uint32_t id,
50 uint32_t user_id) override {
49 g_url = url; 51 g_url = url;
50 g_id = id; 52 g_id = id;
53 g_user_id = user_id;
51 g_shell_client_request = binding_.Unbind(); 54 g_shell_client_request = binding_.Unbind();
52 g_shell = std::move(shell); 55 g_shell = std::move(shell);
53 } 56 }
54 57
55 void AcceptConnection( 58 void AcceptConnection(
56 const String& requestor_url, 59 const String& requestor_url,
60 uint32_t requestor_user_id,
57 uint32_t requestor_id, 61 uint32_t requestor_id,
58 shell::mojom::InterfaceProviderRequest local_interfaces, 62 shell::mojom::InterfaceProviderRequest local_interfaces,
59 shell::mojom::InterfaceProviderPtr remote_interfaces, 63 shell::mojom::InterfaceProviderPtr remote_interfaces,
60 Array<String> allowed_interfaces, 64 Array<String> allowed_interfaces,
61 const String& url) override { 65 const String& url) override {
62 CHECK(false); 66 CHECK(false);
63 } 67 }
64 68
65 void OnQuitRequested(const Callback<void(bool)>& callback) override { 69 void OnQuitRequested(const Callback<void(bool)>& callback) override {
66 CHECK(false); 70 CHECK(false);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 118 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
115 } 119 }
116 120
117 TestHelper::TestHelper(ShellClient* client) 121 TestHelper::TestHelper(ShellClient* client)
118 : shell_connection_(new ShellConnection( 122 : shell_connection_(new ShellConnection(
119 client == nullptr ? &default_shell_client_ : client, 123 client == nullptr ? &default_shell_client_ : client,
120 std::move(g_shell_client_request))), 124 std::move(g_shell_client_request))),
121 url_(g_url) { 125 url_(g_url) {
122 // Fake ShellClient initialization. 126 // Fake ShellClient initialization.
123 shell::mojom::ShellClient* shell_client = shell_connection_.get(); 127 shell::mojom::ShellClient* shell_client = shell_connection_.get();
124 shell_client->Initialize(std::move(g_shell), g_url, g_id); 128 shell_client->Initialize(std::move(g_shell), g_url, g_id, g_user_id);
125 } 129 }
126 130
127 TestHelper::~TestHelper() { 131 TestHelper::~TestHelper() {
128 // TODO: commented out until http://crbug.com/533107 is solved. 132 // TODO: commented out until http://crbug.com/533107 is solved.
129 // { 133 // {
130 // ShellConnection::TestApi test_api(shell_connection_); 134 // ShellConnection::TestApi test_api(shell_connection_);
131 // test_api.UnbindConnections(&g_shell_client_request, &g_shell); 135 // test_api.UnbindConnections(&g_shell_client_request, &g_shell);
132 // } 136 // }
133 // We may have supplied a member as the client. Delete |shell_connection_| 137 // We may have supplied a member as the client. Delete |shell_connection_|
134 // while still valid. 138 // while still valid.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 if (ShouldCreateDefaultRunLoop()) 170 if (ShouldCreateDefaultRunLoop())
167 Environment::DestroyDefaultRunLoop(); 171 Environment::DestroyDefaultRunLoop();
168 } 172 }
169 173
170 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { 174 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() {
171 return true; 175 return true;
172 } 176 }
173 177
174 } // namespace test 178 } // namespace test
175 } // namespace mojo 179 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/connection.h ('k') | mojo/shell/public/cpp/lib/connection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698