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

Side by Side Diff: extensions/renderer/mojo/keep_alive_client_unittest.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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 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/macros.h" 7 #include "base/macros.h"
8 #include "extensions/common/mojo/keep_alive.mojom.h" 8 #include "extensions/common/mojo/keep_alive.mojom.h"
9 #include "extensions/renderer/api_test_base.h" 9 #include "extensions/renderer/api_test_base.h"
10 #include "grit/extensions_renderer_resources.h" 10 #include "grit/extensions_renderer_resources.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 12
13 // A test launcher for tests for the stash client defined in 13 // A test launcher for tests for the stash client defined in
14 // extensions/test/data/keep_alive_client_unittest.js. 14 // extensions/test/data/keep_alive_client_unittest.js.
15 15
16 namespace extensions { 16 namespace extensions {
17 namespace { 17 namespace {
18 18
19 // A KeepAlive implementation that calls provided callbacks on creation and 19 // A KeepAlive implementation that calls provided callbacks on creation and
20 // destruction. 20 // destruction.
21 class TestKeepAlive : public KeepAlive { 21 class TestKeepAlive : public KeepAlive {
22 public: 22 public:
23 TestKeepAlive(const base::Closure& on_destruction, 23 explicit TestKeepAlive(const base::Closure& on_destruction)
24 mojo::InterfaceRequest<KeepAlive> keep_alive) 24 : on_destruction_(on_destruction) {}
25 : on_destruction_(on_destruction),
26 binding_(this, std::move(keep_alive)) {}
27 25
28 ~TestKeepAlive() override { on_destruction_.Run(); } 26 ~TestKeepAlive() override { on_destruction_.Run(); }
29 27
30 static void Create(const base::Closure& on_creation, 28 static void Create(const base::Closure& on_creation,
31 const base::Closure& on_destruction, 29 const base::Closure& on_destruction,
32 mojo::InterfaceRequest<KeepAlive> keep_alive) { 30 KeepAliveRequest keep_alive) {
33 new TestKeepAlive(on_destruction, std::move(keep_alive)); 31 mojo::MakeStrongBinding(base::MakeUnique<TestKeepAlive>(on_destruction),
32 std::move(keep_alive));
34 on_creation.Run(); 33 on_creation.Run();
35 } 34 }
36 35
37 private: 36 private:
38 const base::Closure on_destruction_; 37 const base::Closure on_destruction_;
39 mojo::StrongBinding<KeepAlive> binding_;
40 }; 38 };
41 39
42 } // namespace 40 } // namespace
43 41
44 class KeepAliveClientTest : public ApiTestBase { 42 class KeepAliveClientTest : public ApiTestBase {
45 public: 43 public:
46 KeepAliveClientTest() {} 44 KeepAliveClientTest() {}
47 45
48 void SetUp() override { 46 void SetUp() override {
49 ApiTestBase::SetUp(); 47 ApiTestBase::SetUp();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithSuccessfulCall"); 89 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithSuccessfulCall");
92 WaitForKeepAlive(); 90 WaitForKeepAlive();
93 } 91 }
94 92
95 TEST_F(KeepAliveClientTest, KeepAliveWithError) { 93 TEST_F(KeepAliveClientTest, KeepAliveWithError) {
96 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithError"); 94 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithError");
97 WaitForKeepAlive(); 95 WaitForKeepAlive();
98 } 96 }
99 97
100 } // namespace extensions 98 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api/serial/serial_api_unittest.cc ('k') | media/mojo/clients/mojo_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698