OLD | NEW |
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 "extensions/common/mojo/keep_alive.mojom.h" | 5 #include "extensions/common/mojo/keep_alive.mojom.h" |
6 #include "extensions/renderer/api_test_base.h" | 6 #include "extensions/renderer/api_test_base.h" |
7 #include "grit/extensions_renderer_resources.h" | 7 #include "grit/extensions_renderer_resources.h" |
8 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" | 8 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
9 | 9 |
10 // A test launcher for tests for the stash client defined in | 10 // A test launcher for tests for the stash client defined in |
11 // extensions/test/data/keep_alive_client_unittest.js. | 11 // extensions/test/data/keep_alive_client_unittest.js. |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // A KeepAlive implementation that calls provided callbacks on creation and | 16 // A KeepAlive implementation that calls provided callbacks on creation and |
17 // destruction. | 17 // destruction. |
18 class TestKeepAlive : public mojo::InterfaceImpl<KeepAlive> { | 18 class TestKeepAlive : public KeepAlive { |
19 public: | 19 public: |
20 explicit TestKeepAlive(const base::Closure& on_destruction) | 20 TestKeepAlive(const base::Closure& on_destruction, |
21 : on_destruction_(on_destruction) {} | 21 mojo::InterfaceRequest<KeepAlive> keep_alive) |
| 22 : on_destruction_(on_destruction), binding_(this, keep_alive.Pass()) {} |
22 | 23 |
23 ~TestKeepAlive() override { on_destruction_.Run(); } | 24 ~TestKeepAlive() override { on_destruction_.Run(); } |
24 | 25 |
25 static void Create(const base::Closure& on_creation, | 26 static void Create(const base::Closure& on_creation, |
26 const base::Closure& on_destruction, | 27 const base::Closure& on_destruction, |
27 mojo::InterfaceRequest<KeepAlive> keep_alive) { | 28 mojo::InterfaceRequest<KeepAlive> keep_alive) { |
28 mojo::BindToRequest(new TestKeepAlive(on_destruction), &keep_alive); | 29 new TestKeepAlive(on_destruction, keep_alive.Pass()); |
29 on_creation.Run(); | 30 on_creation.Run(); |
30 } | 31 } |
31 | 32 |
32 private: | 33 private: |
33 const base::Closure on_destruction_; | 34 const base::Closure on_destruction_; |
| 35 mojo::StrongBinding<KeepAlive> binding_; |
34 }; | 36 }; |
35 | 37 |
36 } // namespace | 38 } // namespace |
37 | 39 |
38 class KeepAliveClientTest : public ApiTestBase { | 40 class KeepAliveClientTest : public ApiTestBase { |
39 public: | 41 public: |
40 KeepAliveClientTest() {} | 42 KeepAliveClientTest() {} |
41 | 43 |
42 void SetUp() override { | 44 void SetUp() override { |
43 ApiTestBase::SetUp(); | 45 ApiTestBase::SetUp(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithSuccessfulCall"); | 87 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithSuccessfulCall"); |
86 WaitForKeepAlive(); | 88 WaitForKeepAlive(); |
87 } | 89 } |
88 | 90 |
89 TEST_F(KeepAliveClientTest, KeepAliveWithError) { | 91 TEST_F(KeepAliveClientTest, KeepAliveWithError) { |
90 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithError"); | 92 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithError"); |
91 WaitForKeepAlive(); | 93 WaitForKeepAlive(); |
92 } | 94 } |
93 | 95 |
94 } // namespace extensions | 96 } // namespace extensions |
OLD | NEW |