| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #import "base/test/ios/wait_util.h" | 9 #import "base/test/ios/wait_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 private: | 148 private: |
| 149 std::unique_ptr<WebStateImpl> web_state_; | 149 std::unique_ptr<WebStateImpl> web_state_; |
| 150 std::unique_ptr<TestUIHandler> ui_handler_; | 150 std::unique_ptr<TestUIHandler> ui_handler_; |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 // Tests that JS can send messages to the native code and vice versa. | 153 // Tests that JS can send messages to the native code and vice versa. |
| 154 // TestUIHandler is used for communication and test suceeds only when | 154 // TestUIHandler is used for communication and test suceeds only when |
| 155 // |TestUIHandler| sucessfully receives "ack" message from WebUI page. | 155 // |TestUIHandler| sucessfully receives "ack" message from WebUI page. |
| 156 TEST_F(WebUIMojoTest, MessageExchange) { | 156 TEST_F(WebUIMojoTest, MessageExchange) { |
| 157 web_state()->SetWebUsageEnabled(true); | 157 web_state()->SetWebUsageEnabled(true); |
| 158 web_state()->GetView(); // WebState won't load URL without view. | |
| 159 NavigationManager::WebLoadParams load_params(GURL( | 158 NavigationManager::WebLoadParams load_params(GURL( |
| 160 url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0).Serialize())); | 159 url::SchemeHostPort(kTestWebUIScheme, kTestWebUIURLHost, 0).Serialize())); |
| 161 web_state()->GetNavigationManager()->LoadURLWithParams(load_params); | 160 web_state()->GetNavigationManager()->LoadURLWithParams(load_params); |
| 162 | 161 |
| 163 // Wait until |TestUIHandler| receives "ack" message from WebUI page. | 162 // Wait until |TestUIHandler| receives "ack" message from WebUI page. |
| 164 base::test::ios::WaitUntilCondition(^{ | 163 base::test::ios::WaitUntilCondition(^{ |
| 165 // Flush any pending tasks. Don't RunUntilIdle() because | 164 // Flush any pending tasks. Don't RunUntilIdle() because |
| 166 // RunUntilIdle() is incompatible with mojo::SimpleWatcher's | 165 // RunUntilIdle() is incompatible with mojo::SimpleWatcher's |
| 167 // automatic arming behavior, which Mojo JS still depends upon. | 166 // automatic arming behavior, which Mojo JS still depends upon. |
| 168 // | 167 // |
| 169 // TODO(crbug.com/701875): Introduce the full watcher API to JS and get rid | 168 // TODO(crbug.com/701875): Introduce the full watcher API to JS and get rid |
| 170 // of this hack. | 169 // of this hack. |
| 171 base::RunLoop loop; | 170 base::RunLoop loop; |
| 172 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 171 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 173 loop.QuitClosure()); | 172 loop.QuitClosure()); |
| 174 loop.Run(); | 173 loop.Run(); |
| 175 return test_ui_handler()->IsFinReceived(); | 174 return test_ui_handler()->IsFinReceived(); |
| 176 }); | 175 }); |
| 177 } | 176 } |
| 178 | 177 |
| 179 } // namespace web | 178 } // namespace web |
| OLD | NEW |