| 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/browser/mojo/keep_alive_impl.h" | 5 #include "extensions/browser/mojo/keep_alive_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 std::unique_ptr<base::MessageLoop> message_loop_; | 73 std::unique_ptr<base::MessageLoop> message_loop_; |
| 74 scoped_refptr<const Extension> extension_; | 74 scoped_refptr<const Extension> extension_; |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(KeepAliveTest); | 76 DISALLOW_COPY_AND_ASSIGN(KeepAliveTest); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 TEST_F(KeepAliveTest, Basic) { | 79 TEST_F(KeepAliveTest, Basic) { |
| 80 mojo::InterfacePtr<KeepAlive> keep_alive; | 80 mojo::InterfacePtr<KeepAlive> keep_alive; |
| 81 CreateKeepAlive(mojo::GetProxy(&keep_alive)); | 81 CreateKeepAlive(mojo::MakeRequest(&keep_alive)); |
| 82 EXPECT_EQ(1, GetKeepAliveCount()); | 82 EXPECT_EQ(1, GetKeepAliveCount()); |
| 83 | 83 |
| 84 keep_alive.reset(); | 84 keep_alive.reset(); |
| 85 WaitUntilLazyKeepAliveChanges(); | 85 WaitUntilLazyKeepAliveChanges(); |
| 86 EXPECT_EQ(0, GetKeepAliveCount()); | 86 EXPECT_EQ(0, GetKeepAliveCount()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 TEST_F(KeepAliveTest, TwoKeepAlives) { | 89 TEST_F(KeepAliveTest, TwoKeepAlives) { |
| 90 mojo::InterfacePtr<KeepAlive> keep_alive; | 90 mojo::InterfacePtr<KeepAlive> keep_alive; |
| 91 CreateKeepAlive(mojo::GetProxy(&keep_alive)); | 91 CreateKeepAlive(mojo::MakeRequest(&keep_alive)); |
| 92 EXPECT_EQ(1, GetKeepAliveCount()); | 92 EXPECT_EQ(1, GetKeepAliveCount()); |
| 93 | 93 |
| 94 mojo::InterfacePtr<KeepAlive> other_keep_alive; | 94 mojo::InterfacePtr<KeepAlive> other_keep_alive; |
| 95 CreateKeepAlive(mojo::GetProxy(&other_keep_alive)); | 95 CreateKeepAlive(mojo::MakeRequest(&other_keep_alive)); |
| 96 EXPECT_EQ(2, GetKeepAliveCount()); | 96 EXPECT_EQ(2, GetKeepAliveCount()); |
| 97 | 97 |
| 98 keep_alive.reset(); | 98 keep_alive.reset(); |
| 99 WaitUntilLazyKeepAliveChanges(); | 99 WaitUntilLazyKeepAliveChanges(); |
| 100 EXPECT_EQ(1, GetKeepAliveCount()); | 100 EXPECT_EQ(1, GetKeepAliveCount()); |
| 101 | 101 |
| 102 other_keep_alive.reset(); | 102 other_keep_alive.reset(); |
| 103 WaitUntilLazyKeepAliveChanges(); | 103 WaitUntilLazyKeepAliveChanges(); |
| 104 EXPECT_EQ(0, GetKeepAliveCount()); | 104 EXPECT_EQ(0, GetKeepAliveCount()); |
| 105 } | 105 } |
| 106 | 106 |
| 107 TEST_F(KeepAliveTest, UnloadExtension) { | 107 TEST_F(KeepAliveTest, UnloadExtension) { |
| 108 mojo::InterfacePtr<KeepAlive> keep_alive; | 108 mojo::InterfacePtr<KeepAlive> keep_alive; |
| 109 CreateKeepAlive(mojo::GetProxy(&keep_alive)); | 109 CreateKeepAlive(mojo::MakeRequest(&keep_alive)); |
| 110 EXPECT_EQ(1, GetKeepAliveCount()); | 110 EXPECT_EQ(1, GetKeepAliveCount()); |
| 111 | 111 |
| 112 scoped_refptr<const Extension> other_extension = | 112 scoped_refptr<const Extension> other_extension = |
| 113 ExtensionBuilder() | 113 ExtensionBuilder() |
| 114 .SetManifest( | 114 .SetManifest( |
| 115 DictionaryBuilder() | 115 DictionaryBuilder() |
| 116 .Set("name", "app") | 116 .Set("name", "app") |
| 117 .Set("version", "1") | 117 .Set("version", "1") |
| 118 .Set("manifest_version", 2) | 118 .Set("manifest_version", 2) |
| 119 .Set("app", | 119 .Set("app", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 EXPECT_EQ(0, GetKeepAliveCount()); | 142 EXPECT_EQ(0, GetKeepAliveCount()); |
| 143 | 143 |
| 144 // Wait for |keep_alive| to disconnect. | 144 // Wait for |keep_alive| to disconnect. |
| 145 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
| 146 keep_alive.set_connection_error_handler(run_loop.QuitClosure()); | 146 keep_alive.set_connection_error_handler(run_loop.QuitClosure()); |
| 147 run_loop.Run(); | 147 run_loop.Run(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(KeepAliveTest, Shutdown) { | 150 TEST_F(KeepAliveTest, Shutdown) { |
| 151 mojo::InterfacePtr<KeepAlive> keep_alive; | 151 mojo::InterfacePtr<KeepAlive> keep_alive; |
| 152 CreateKeepAlive(mojo::GetProxy(&keep_alive)); | 152 CreateKeepAlive(mojo::MakeRequest(&keep_alive)); |
| 153 EXPECT_EQ(1, GetKeepAliveCount()); | 153 EXPECT_EQ(1, GetKeepAliveCount()); |
| 154 | 154 |
| 155 ExtensionRegistry::Get(browser_context())->Shutdown(); | 155 ExtensionRegistry::Get(browser_context())->Shutdown(); |
| 156 // After a shutdown event, the KeepAliveImpl should not access its | 156 // After a shutdown event, the KeepAliveImpl should not access its |
| 157 // ProcessManager and so the keep-alive count should remain unchanged. | 157 // ProcessManager and so the keep-alive count should remain unchanged. |
| 158 EXPECT_EQ(1, GetKeepAliveCount()); | 158 EXPECT_EQ(1, GetKeepAliveCount()); |
| 159 | 159 |
| 160 // Wait for |keep_alive| to disconnect. | 160 // Wait for |keep_alive| to disconnect. |
| 161 base::RunLoop run_loop; | 161 base::RunLoop run_loop; |
| 162 keep_alive.set_connection_error_handler(run_loop.QuitClosure()); | 162 keep_alive.set_connection_error_handler(run_loop.QuitClosure()); |
| 163 run_loop.Run(); | 163 run_loop.Run(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace extensions | 166 } // namespace extensions |
| OLD | NEW |