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