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

Side by Side Diff: ipc/ipc_channel_mojo_unittest.cc

Issue 2665053002: Add tests for detecting lost associated interfaces. (Closed)
Patch Set: Created 3 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 | « no previous file | ipc/ipc_test.mojom » ('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 "ipc/ipc_channel_mojo.h" 5 #include "ipc/ipc_channel_mojo.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/base_paths.h" 13 #include "base/base_paths.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback_helpers.h"
15 #include "base/files/file.h" 16 #include "base/files/file.h"
16 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
17 #include "base/location.h" 18 #include "base/location.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
20 #include "base/path_service.h" 21 #include "base/path_service.h"
21 #include "base/pickle.h" 22 #include "base/pickle.h"
22 #include "base/run_loop.h" 23 #include "base/run_loop.h"
23 #include "base/single_thread_task_runner.h" 24 #include "base/single_thread_task_runner.h"
24 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 expected_values.push(4); 1258 expected_values.push(4);
1258 expected_values.push(5); 1259 expected_values.push(5);
1259 expected_values.push(2); 1260 expected_values.push(2);
1260 expected_values.push(3); 1261 expected_values.push(3);
1261 RunProxy(); 1262 RunProxy();
1262 base::RunLoop().Run(); 1263 base::RunLoop().Run();
1263 EXPECT_TRUE(expected_values.empty()); 1264 EXPECT_TRUE(expected_values.empty());
1264 DestroyProxy(); 1265 DestroyProxy();
1265 } 1266 }
1266 1267
1268 TEST_F(IPCChannelProxyMojoTest, AssociatedRequestClose) {
1269 Init("DropAssociatedRequest");
1270
1271 DummyListener listener;
1272 CreateProxy(&listener);
1273 RunProxy();
1274
1275 IPC::mojom::AssociatedInterfaceVendorAssociatedPtr vendor;
1276 proxy()->GetRemoteAssociatedInterface(&vendor);
1277 IPC::mojom::SimpleTestDriverAssociatedPtr tester;
1278 vendor->GetTestInterface(
1279 mojo::MakeRequest(&tester, vendor.associated_group()));
1280 base::RunLoop run_loop;
1281 tester.set_connection_error_handler(run_loop.QuitClosure());
1282 run_loop.Run();
1283
1284 proxy()->GetRemoteAssociatedInterface(&tester);
1285 EXPECT_TRUE(WaitForClientShutdown());
1286 DestroyProxy();
1287 }
1288
1289 class AssociatedInterfaceDroppingListener : public IPC::Listener {
1290 public:
1291 AssociatedInterfaceDroppingListener(const base::Closure& callback)
1292 : callback_(callback) {}
1293 bool OnMessageReceived(const IPC::Message& message) override { return false; }
1294
1295 void OnAssociatedInterfaceRequest(
1296 const std::string& interface_name,
1297 mojo::ScopedInterfaceEndpointHandle handle) override {
1298 if (interface_name == IPC::mojom::SimpleTestDriver::Name_)
1299 base::ResetAndReturn(&callback_).Run();
1300 }
1301
1302 private:
1303 base::Closure callback_;
1304 };
1305
1306 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(DropAssociatedRequest,
1307 ChannelProxyClient) {
1308 base::RunLoop run_loop;
1309 AssociatedInterfaceDroppingListener listener(run_loop.QuitClosure());
1310 CreateProxy(&listener);
1311 RunProxy();
1312 run_loop.Run();
1313 DestroyProxy();
1314 }
1315
1267 #if defined(OS_POSIX) 1316 #if defined(OS_POSIX)
1268 1317
1269 class ListenerThatExpectsFile : public IPC::Listener { 1318 class ListenerThatExpectsFile : public IPC::Listener {
1270 public: 1319 public:
1271 ListenerThatExpectsFile() : sender_(NULL) {} 1320 ListenerThatExpectsFile() : sender_(NULL) {}
1272 1321
1273 ~ListenerThatExpectsFile() override {} 1322 ~ListenerThatExpectsFile() override {}
1274 1323
1275 bool OnMessageReceived(const IPC::Message& message) override { 1324 bool OnMessageReceived(const IPC::Message& message) override {
1276 base::PickleIterator iter(message); 1325 base::PickleIterator iter(message);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 Connect(&listener); 1466 Connect(&listener);
1418 1467
1419 base::RunLoop().Run(); 1468 base::RunLoop().Run();
1420 1469
1421 Close(); 1470 Close();
1422 } 1471 }
1423 1472
1424 #endif // OS_LINUX 1473 #endif // OS_LINUX
1425 1474
1426 } // namespace 1475 } // namespace
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc_test.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698