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/time/time.h" | 13 #include "base/time/time.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "components/html_viewer/public/interfaces/test_html_viewer.mojom.h" | 15 #include "components/html_viewer/public/interfaces/test_html_viewer.mojom.h" |
16 #include "components/mus/public/cpp/tests/window_server_test_base.h" | 16 #include "components/mus/public/cpp/tests/window_server_test_base.h" |
17 #include "components/mus/public/cpp/window.h" | 17 #include "components/mus/public/cpp/window.h" |
18 #include "components/mus/public/cpp/window_tree_connection.h" | 18 #include "components/mus/public/cpp/window_tree_connection.h" |
19 #include "components/web_view/frame.h" | 19 #include "components/web_view/frame.h" |
20 #include "components/web_view/frame_connection.h" | 20 #include "components/web_view/frame_connection.h" |
21 #include "components/web_view/frame_tree.h" | 21 #include "components/web_view/frame_tree.h" |
22 #include "components/web_view/public/interfaces/frame.mojom.h" | 22 #include "components/web_view/public/interfaces/frame.mojom.h" |
23 #include "components/web_view/test_frame_tree_delegate.h" | 23 #include "components/web_view/test_frame_tree_delegate.h" |
24 #include "mojo/application/public/cpp/application_impl.h" | 24 #include "mojo/application/public/cpp/application_impl.h" |
25 #include "net/test/spawned_test_server/spawned_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
26 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" | 26 #include "third_party/mojo_services/src/accessibility/public/interfaces/accessib
ility.mojom.h" |
27 | 27 |
28 using mus::mojom::WindowTreeClientPtr; | 28 using mus::mojom::WindowTreeClientPtr; |
29 using mus::WindowServerTestBase; | 29 using mus::WindowServerTestBase; |
30 using web_view::Frame; | 30 using web_view::Frame; |
31 using web_view::FrameConnection; | 31 using web_view::FrameConnection; |
32 using web_view::FrameTree; | 32 using web_view::FrameTree; |
33 using web_view::FrameTreeDelegate; | 33 using web_view::FrameTreeDelegate; |
34 using web_view::mojom::FrameClient; | 34 using web_view::mojom::FrameClient; |
35 | 35 |
36 namespace mojo { | 36 namespace mojo { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kAddFrameWithEmptyPageScript[] = | 40 const char kAddFrameWithEmptyPageScript[] = |
41 "var iframe = document.createElement(\"iframe\");" | 41 "var iframe = document.createElement(\"iframe\");" |
42 "iframe.src = \"http://127.0.0.1:%u/files/empty_page.html\";" | 42 "iframe.src = \"http://127.0.0.1:%u/empty_page.html\";" |
43 "document.body.appendChild(iframe);"; | 43 "document.body.appendChild(iframe);"; |
44 | 44 |
45 void OnGotContentHandlerForRoot(bool* got_callback) { | 45 void OnGotContentHandlerForRoot(bool* got_callback) { |
46 *got_callback = true; | 46 *got_callback = true; |
47 ignore_result(WindowServerTestBase::QuitRunLoop()); | 47 ignore_result(WindowServerTestBase::QuitRunLoop()); |
48 } | 48 } |
49 | 49 |
50 mojo::ApplicationConnection* ApplicationConnectionForFrame(Frame* frame) { | 50 mojo::ApplicationConnection* ApplicationConnectionForFrame(Frame* frame) { |
51 return static_cast<FrameConnection*>(frame->user_data()) | 51 return static_cast<FrameConnection*>(frame->user_data()) |
52 ->application_connection(); | 52 ->application_connection(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 ~HTMLFrameTest() override {} | 166 ~HTMLFrameTest() override {} |
167 | 167 |
168 protected: | 168 protected: |
169 // Creates the frame tree showing an empty page at the root and adds (via | 169 // Creates the frame tree showing an empty page at the root and adds (via |
170 // script) a frame showing the same empty page. | 170 // script) a frame showing the same empty page. |
171 Frame* LoadEmptyPageAndCreateFrame() { | 171 Frame* LoadEmptyPageAndCreateFrame() { |
172 mus::Window* embed_window = window_manager()->NewWindow(); | 172 mus::Window* embed_window = window_manager()->NewWindow(); |
173 frame_tree_delegate_.reset( | 173 frame_tree_delegate_.reset( |
174 new TestFrameTreeDelegateImpl(application_impl())); | 174 new TestFrameTreeDelegateImpl(application_impl())); |
175 FrameConnection* root_connection = InitFrameTree( | 175 FrameConnection* root_connection = InitFrameTree( |
176 embed_window, "http://127.0.0.1:%u/files/empty_page2.html"); | 176 embed_window, "http://127.0.0.1:%u/empty_page2.html"); |
177 if (!root_connection) { | 177 if (!root_connection) { |
178 ADD_FAILURE() << "unable to establish root connection"; | 178 ADD_FAILURE() << "unable to establish root connection"; |
179 return nullptr; | 179 return nullptr; |
180 } | 180 } |
181 const std::string frame_text = | 181 const std::string frame_text = |
182 GetFrameText(root_connection->application_connection()); | 182 GetFrameText(root_connection->application_connection()); |
183 if (frame_text != "child2") { | 183 if (frame_text != "child2") { |
184 ADD_FAILURE() << "unexpected text " << frame_text; | 184 ADD_FAILURE() << "unexpected text " << frame_text; |
185 return nullptr; | 185 return nullptr; |
186 } | 186 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 Frame::ClientPropertyMap(), base::TimeTicks::Now())); | 234 Frame::ClientPropertyMap(), base::TimeTicks::Now())); |
235 frame_tree_delegate_->set_frame_tree(frame_tree_.get()); | 235 frame_tree_delegate_->set_frame_tree(frame_tree_.get()); |
236 return result; | 236 return result; |
237 } | 237 } |
238 | 238 |
239 // ViewManagerTest: | 239 // ViewManagerTest: |
240 void SetUp() override { | 240 void SetUp() override { |
241 WindowServerTestBase::SetUp(); | 241 WindowServerTestBase::SetUp(); |
242 | 242 |
243 // Start a test server. | 243 // Start a test server. |
244 http_server_.reset(new net::SpawnedTestServer( | 244 http_server_.reset(new net::EmbeddedTestServer); |
245 net::SpawnedTestServer::TYPE_HTTP, net::SpawnedTestServer::kLocalhost, | 245 http_server_->ServeFilesFromSourceDirectory( |
246 base::FilePath(FILE_PATH_LITERAL("components/test/data/html_viewer")))); | 246 "components/test/data/html_viewer"); |
247 ASSERT_TRUE(http_server_->Start()); | 247 ASSERT_TRUE(http_server_->Start()); |
248 } | 248 } |
249 void TearDown() override { | 249 void TearDown() override { |
250 frame_tree_.reset(); | 250 frame_tree_.reset(); |
251 http_server_.reset(); | 251 http_server_.reset(); |
252 WindowServerTestBase::TearDown(); | 252 WindowServerTestBase::TearDown(); |
253 } | 253 } |
254 | 254 |
255 scoped_ptr<net::SpawnedTestServer> http_server_; | 255 scoped_ptr<net::EmbeddedTestServer> http_server_; |
256 scoped_ptr<FrameTree> frame_tree_; | 256 scoped_ptr<FrameTree> frame_tree_; |
257 | 257 |
258 scoped_ptr<TestFrameTreeDelegateImpl> frame_tree_delegate_; | 258 scoped_ptr<TestFrameTreeDelegateImpl> frame_tree_delegate_; |
259 | 259 |
260 private: | 260 private: |
261 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTest); | 261 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTest); |
262 }; | 262 }; |
263 | 263 |
264 TEST_F(HTMLFrameTest, PageWithSingleFrame) { | 264 TEST_F(HTMLFrameTest, PageWithSingleFrame) { |
265 mus::Window* embed_window = window_manager()->NewWindow(); | 265 mus::Window* embed_window = window_manager()->NewWindow(); |
266 | 266 |
267 FrameConnection* root_connection = InitFrameTree( | 267 FrameConnection* root_connection = InitFrameTree( |
268 embed_window, "http://127.0.0.1:%u/files/page_with_single_frame.html"); | 268 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html"); |
269 ASSERT_TRUE(root_connection); | 269 ASSERT_TRUE(root_connection); |
270 | 270 |
271 ASSERT_EQ("Page with single frame", | 271 ASSERT_EQ("Page with single frame", |
272 GetFrameText(root_connection->application_connection())); | 272 GetFrameText(root_connection->application_connection())); |
273 | 273 |
274 ASSERT_NO_FATAL_FAILURE( | 274 ASSERT_NO_FATAL_FAILURE( |
275 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); | 275 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); |
276 | 276 |
277 ASSERT_EQ(1u, embed_window->children().size()); | 277 ASSERT_EQ(1u, embed_window->children().size()); |
278 Frame* child_frame = | 278 Frame* child_frame = |
279 frame_tree_->root()->FindFrame(embed_window->children()[0]->id()); | 279 frame_tree_->root()->FindFrame(embed_window->children()[0]->id()); |
280 ASSERT_TRUE(child_frame); | 280 ASSERT_TRUE(child_frame); |
281 | 281 |
282 ASSERT_EQ("child", | 282 ASSERT_EQ("child", |
283 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 283 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
284 ->application_connection())); | 284 ->application_connection())); |
285 } | 285 } |
286 | 286 |
287 // Creates two frames. The parent navigates the child frame by way of changing | 287 // Creates two frames. The parent navigates the child frame by way of changing |
288 // the location of the child frame. | 288 // the location of the child frame. |
289 TEST_F(HTMLFrameTest, ChangeLocationOfChildFrame) { | 289 TEST_F(HTMLFrameTest, ChangeLocationOfChildFrame) { |
290 mus::Window* embed_window = window_manager()->NewWindow(); | 290 mus::Window* embed_window = window_manager()->NewWindow(); |
291 | 291 |
292 ASSERT_TRUE(InitFrameTree( | 292 ASSERT_TRUE(InitFrameTree( |
293 embed_window, "http://127.0.0.1:%u/files/page_with_single_frame.html")); | 293 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html")); |
294 | 294 |
295 // page_with_single_frame contains a child frame. The child frame should | 295 // page_with_single_frame contains a child frame. The child frame should |
296 // create a new View and Frame. | 296 // create a new View and Frame. |
297 ASSERT_NO_FATAL_FAILURE( | 297 ASSERT_NO_FATAL_FAILURE( |
298 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); | 298 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); |
299 | 299 |
300 Frame* child_frame = frame_tree_->root()->children().back(); | 300 Frame* child_frame = frame_tree_->root()->children().back(); |
301 | 301 |
302 ASSERT_EQ("child", | 302 ASSERT_EQ("child", |
303 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 303 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
304 ->application_connection())); | 304 ->application_connection())); |
305 | 305 |
306 // Change the location and wait for the navigation to occur. | 306 // Change the location and wait for the navigation to occur. |
307 const char kNavigateFrame[] = | 307 const char kNavigateFrame[] = |
308 "window.frames[0].location = " | 308 "window.frames[0].location = " |
309 "'http://127.0.0.1:%u/files/empty_page2.html'"; | 309 "'http://127.0.0.1:%u/empty_page2.html'"; |
310 frame_tree_delegate_->ClearGotNavigate(child_frame); | 310 frame_tree_delegate_->ClearGotNavigate(child_frame); |
311 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 311 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), |
312 AddPortToString(kNavigateFrame)); | 312 AddPortToString(kNavigateFrame)); |
313 ASSERT_TRUE(frame_tree_delegate_->WaitForFrameNavigation(child_frame)); | 313 ASSERT_TRUE(frame_tree_delegate_->WaitForFrameNavigation(child_frame)); |
314 | 314 |
315 // There should still only be one frame. | 315 // There should still only be one frame. |
316 ASSERT_EQ(1u, frame_tree_->root()->children().size()); | 316 ASSERT_EQ(1u, frame_tree_->root()->children().size()); |
317 | 317 |
318 // The navigation should have changed the text of the frame. | 318 // The navigation should have changed the text of the frame. |
319 ASSERT_TRUE(child_frame->user_data()); | 319 ASSERT_TRUE(child_frame->user_data()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 script_value_as_list->GetString(0u, &message_in_child); | 473 script_value_as_list->GetString(0u, &message_in_child); |
474 } | 474 } |
475 } | 475 } |
476 } while (message_in_child != "hello from parent" && | 476 } while (message_in_child != "hello from parent" && |
477 base::TimeTicks::Now() - start_time < | 477 base::TimeTicks::Now() - start_time < |
478 TestTimeouts::action_timeout()); | 478 TestTimeouts::action_timeout()); |
479 EXPECT_EQ("hello from parent", message_in_child); | 479 EXPECT_EQ("hello from parent", message_in_child); |
480 } | 480 } |
481 | 481 |
482 } // namespace mojo | 482 } // namespace mojo |
OLD | NEW |