OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "components/html_viewer/public/interfaces/test_html_viewer.mojom.h" | 14 #include "components/html_viewer/public/interfaces/test_html_viewer.mojom.h" |
15 #include "components/mus/public/cpp/tests/view_manager_test_base.h" | 15 #include "components/mus/public/cpp/tests/view_manager_test_base.h" |
16 #include "components/mus/public/cpp/view.h" | 16 #include "components/mus/public/cpp/view.h" |
17 #include "components/mus/public/cpp/view_tree_connection.h" | 17 #include "components/mus/public/cpp/view_tree_connection.h" |
18 #include "components/web_view/frame.h" | 18 #include "components/web_view/frame.h" |
19 #include "components/web_view/frame_connection.h" | 19 #include "components/web_view/frame_connection.h" |
20 #include "components/web_view/frame_tree.h" | 20 #include "components/web_view/frame_tree.h" |
21 #include "components/web_view/public/interfaces/frame_tree.mojom.h" | 21 #include "components/web_view/public/interfaces/frame_tree.mojom.h" |
22 #include "components/web_view/test_frame_tree_delegate.h" | 22 #include "components/web_view/test_frame_tree_delegate.h" |
23 #include "mojo/application/public/cpp/application_impl.h" | 23 #include "mojo/application/public/cpp/application_impl.h" |
24 #include "net/test/spawned_test_server/spawned_test_server.h" | 24 #include "net/test/spawned_test_server/spawned_test_server.h" |
25 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" | 25 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" |
26 | 26 |
| 27 using mus::ViewManagerTestBase; |
27 using web_view::Frame; | 28 using web_view::Frame; |
28 using web_view::FrameConnection; | 29 using web_view::FrameConnection; |
29 using web_view::FrameTree; | 30 using web_view::FrameTree; |
30 using web_view::FrameTreeClient; | 31 using web_view::FrameTreeClient; |
31 using web_view::FrameTreeDelegate; | 32 using web_view::FrameTreeDelegate; |
32 | 33 |
33 namespace mojo { | 34 namespace mojo { |
34 | 35 |
35 namespace { | 36 namespace { |
36 | 37 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 135 |
135 class HTMLFrameTest : public ViewManagerTestBase { | 136 class HTMLFrameTest : public ViewManagerTestBase { |
136 public: | 137 public: |
137 HTMLFrameTest() {} | 138 HTMLFrameTest() {} |
138 ~HTMLFrameTest() override {} | 139 ~HTMLFrameTest() override {} |
139 | 140 |
140 protected: | 141 protected: |
141 // Creates the frame tree showing an empty page at the root and adds (via | 142 // Creates the frame tree showing an empty page at the root and adds (via |
142 // script) a frame showing the same empty page. | 143 // script) a frame showing the same empty page. |
143 Frame* LoadEmptyPageAndCreateFrame() { | 144 Frame* LoadEmptyPageAndCreateFrame() { |
144 View* embed_view = window_manager()->CreateView(); | 145 mus::View* embed_view = window_manager()->CreateView(); |
145 frame_tree_delegate_.reset( | 146 frame_tree_delegate_.reset( |
146 new TestFrameTreeDelegateImpl(application_impl())); | 147 new TestFrameTreeDelegateImpl(application_impl())); |
147 FrameConnection* root_connection = | 148 FrameConnection* root_connection = |
148 InitFrameTree(embed_view, "http://127.0.0.1:%u/files/empty_page2.html"); | 149 InitFrameTree(embed_view, "http://127.0.0.1:%u/files/empty_page2.html"); |
149 if (!root_connection) { | 150 if (!root_connection) { |
150 ADD_FAILURE() << "unable to establish root connection"; | 151 ADD_FAILURE() << "unable to establish root connection"; |
151 return nullptr; | 152 return nullptr; |
152 } | 153 } |
153 const std::string frame_text = | 154 const std::string frame_text = |
154 GetFrameText(root_connection->application_connection()); | 155 GetFrameText(root_connection->application_connection()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 const uint16_t assigned_port = http_server_->host_port_pair().port(); | 188 const uint16_t assigned_port = http_server_->host_port_pair().port(); |
188 return base::StringPrintf(string.c_str(), assigned_port); | 189 return base::StringPrintf(string.c_str(), assigned_port); |
189 } | 190 } |
190 | 191 |
191 mojo::URLRequestPtr BuildRequestForURL(const std::string& url_string) { | 192 mojo::URLRequestPtr BuildRequestForURL(const std::string& url_string) { |
192 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 193 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
193 request->url = mojo::String::From(AddPortToString(url_string)); | 194 request->url = mojo::String::From(AddPortToString(url_string)); |
194 return request.Pass(); | 195 return request.Pass(); |
195 } | 196 } |
196 | 197 |
197 FrameConnection* InitFrameTree(View* view, const std::string& url_string) { | 198 FrameConnection* InitFrameTree(mus::View* view, |
| 199 const std::string& url_string) { |
198 frame_tree_delegate_.reset( | 200 frame_tree_delegate_.reset( |
199 new TestFrameTreeDelegateImpl(application_impl())); | 201 new TestFrameTreeDelegateImpl(application_impl())); |
200 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); | 202 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); |
201 bool got_callback = false; | 203 bool got_callback = false; |
202 frame_connection->Init( | 204 frame_connection->Init( |
203 application_impl(), BuildRequestForURL(url_string), | 205 application_impl(), BuildRequestForURL(url_string), |
204 base::Bind(&OnGotContentHandlerForRoot, &got_callback)); | 206 base::Bind(&OnGotContentHandlerForRoot, &got_callback)); |
205 ignore_result(ViewManagerTestBase::DoRunLoopWithTimeout()); | 207 ignore_result(ViewManagerTestBase::DoRunLoopWithTimeout()); |
206 if (!got_callback) | 208 if (!got_callback) |
207 return nullptr; | 209 return nullptr; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 scoped_ptr<net::SpawnedTestServer> http_server_; | 245 scoped_ptr<net::SpawnedTestServer> http_server_; |
244 scoped_ptr<FrameTree> frame_tree_; | 246 scoped_ptr<FrameTree> frame_tree_; |
245 | 247 |
246 scoped_ptr<TestFrameTreeDelegateImpl> frame_tree_delegate_; | 248 scoped_ptr<TestFrameTreeDelegateImpl> frame_tree_delegate_; |
247 | 249 |
248 private: | 250 private: |
249 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTest); | 251 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTest); |
250 }; | 252 }; |
251 | 253 |
252 TEST_F(HTMLFrameTest, PageWithSingleFrame) { | 254 TEST_F(HTMLFrameTest, PageWithSingleFrame) { |
253 View* embed_view = window_manager()->CreateView(); | 255 mus::View* embed_view = window_manager()->CreateView(); |
254 | 256 |
255 FrameConnection* root_connection = InitFrameTree( | 257 FrameConnection* root_connection = InitFrameTree( |
256 embed_view, "http://127.0.0.1:%u/files/page_with_single_frame.html"); | 258 embed_view, "http://127.0.0.1:%u/files/page_with_single_frame.html"); |
257 ASSERT_TRUE(root_connection); | 259 ASSERT_TRUE(root_connection); |
258 | 260 |
259 ASSERT_EQ("Page with single frame", | 261 ASSERT_EQ("Page with single frame", |
260 GetFrameText(root_connection->application_connection())); | 262 GetFrameText(root_connection->application_connection())); |
261 | 263 |
262 // page_with_single_frame contains a child frame. The child frame should | 264 // page_with_single_frame contains a child frame. The child frame should |
263 // create a new View and Frame. | 265 // create a new View and Frame. |
264 if (frame_tree_->root()->children().empty() || | 266 if (frame_tree_->root()->children().empty() || |
265 !frame_tree_->root()->children().back()->user_data()) { | 267 !frame_tree_->root()->children().back()->user_data()) { |
266 ASSERT_TRUE(WaitForNavigateFrame()); | 268 ASSERT_TRUE(WaitForNavigateFrame()); |
267 } | 269 } |
268 | 270 |
269 ASSERT_EQ(1u, embed_view->children().size()); | 271 ASSERT_EQ(1u, embed_view->children().size()); |
270 Frame* child_frame = | 272 Frame* child_frame = |
271 frame_tree_->root()->FindFrame(embed_view->children()[0]->id()); | 273 frame_tree_->root()->FindFrame(embed_view->children()[0]->id()); |
272 ASSERT_TRUE(child_frame); | 274 ASSERT_TRUE(child_frame); |
273 | 275 |
274 ASSERT_EQ("child", | 276 ASSERT_EQ("child", |
275 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 277 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
276 ->application_connection())); | 278 ->application_connection())); |
277 } | 279 } |
278 | 280 |
279 // Creates two frames. The parent navigates the child frame by way of changing | 281 // Creates two frames. The parent navigates the child frame by way of changing |
280 // the location of the child frame. | 282 // the location of the child frame. |
281 TEST_F(HTMLFrameTest, ChangeLocationOfChildFrame) { | 283 TEST_F(HTMLFrameTest, ChangeLocationOfChildFrame) { |
282 View* embed_view = window_manager()->CreateView(); | 284 mus::View* embed_view = window_manager()->CreateView(); |
283 | 285 |
284 ASSERT_TRUE(InitFrameTree( | 286 ASSERT_TRUE(InitFrameTree( |
285 embed_view, "http://127.0.0.1:%u/files/page_with_single_frame.html")); | 287 embed_view, "http://127.0.0.1:%u/files/page_with_single_frame.html")); |
286 | 288 |
287 // page_with_single_frame contains a child frame. The child frame should | 289 // page_with_single_frame contains a child frame. The child frame should |
288 // create a new View and Frame. | 290 // create a new View and Frame. |
289 if (frame_tree_->root()->children().empty() || | 291 if (frame_tree_->root()->children().empty() || |
290 !frame_tree_->root()->children().back()->user_data()) { | 292 !frame_tree_->root()->children().back()->user_data()) { |
291 ASSERT_TRUE(WaitForNavigateFrame()); | 293 ASSERT_TRUE(WaitForNavigateFrame()); |
292 } | 294 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 script_value_as_list->GetString(0u, &message_in_child); | 470 script_value_as_list->GetString(0u, &message_in_child); |
469 } | 471 } |
470 } | 472 } |
471 } while (message_in_child != "hello from parent" && | 473 } while (message_in_child != "hello from parent" && |
472 base::TimeTicks::Now() - start_time < | 474 base::TimeTicks::Now() - start_time < |
473 TestTimeouts::action_timeout()); | 475 TestTimeouts::action_timeout()); |
474 EXPECT_EQ("hello from parent", message_in_child); | 476 EXPECT_EQ("hello from parent", message_in_child); |
475 } | 477 } |
476 | 478 |
477 } // namespace mojo | 479 } // namespace mojo |
OLD | NEW |