| 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 "ui/views/controls/webview/webview.h" | 5 #include "ui/views/controls/webview/webview.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 something_to_focus->RequestFocus(); | 430 something_to_focus->RequestFocus(); |
| 431 EXPECT_FALSE(web_view()->HasFocus()); | 431 EXPECT_FALSE(web_view()->HasFocus()); |
| 432 EXPECT_FALSE(holder()->HasFocus()); | 432 EXPECT_FALSE(holder()->HasFocus()); |
| 433 EXPECT_TRUE(something_to_focus->HasFocus()); | 433 EXPECT_TRUE(something_to_focus->HasFocus()); |
| 434 | 434 |
| 435 // Send mouse press event to WebView outside the bounds of the holder, and | 435 // Send mouse press event to WebView outside the bounds of the holder, and |
| 436 // confirm WebView took focus. | 436 // confirm WebView took focus. |
| 437 const ui::MouseEvent click_outside_holder( | 437 const ui::MouseEvent click_outside_holder( |
| 438 ui::ET_MOUSE_PRESSED, gfx::Point(1, 1), | 438 ui::ET_MOUSE_PRESSED, gfx::Point(1, 1), |
| 439 gfx::Point(), // Immaterial. | 439 gfx::Point(), // Immaterial. |
| 440 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 440 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0, |
| 441 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 441 EXPECT_TRUE(static_cast<views::View*>(web_view())-> | 442 EXPECT_TRUE(static_cast<views::View*>(web_view())-> |
| 442 OnMousePressed(click_outside_holder)); | 443 OnMousePressed(click_outside_holder)); |
| 443 EXPECT_TRUE(web_view()->HasFocus()); | 444 EXPECT_TRUE(web_view()->HasFocus()); |
| 444 EXPECT_FALSE(holder()->HasFocus()); | 445 EXPECT_FALSE(holder()->HasFocus()); |
| 445 EXPECT_FALSE(something_to_focus->HasFocus()); | 446 EXPECT_FALSE(something_to_focus->HasFocus()); |
| 446 | 447 |
| 447 // Focus the other widget again. | 448 // Focus the other widget again. |
| 448 something_to_focus->RequestFocus(); | 449 something_to_focus->RequestFocus(); |
| 449 EXPECT_FALSE(web_view()->HasFocus()); | 450 EXPECT_FALSE(web_view()->HasFocus()); |
| 450 EXPECT_FALSE(holder()->HasFocus()); | 451 EXPECT_FALSE(holder()->HasFocus()); |
| 451 EXPECT_TRUE(something_to_focus->HasFocus()); | 452 EXPECT_TRUE(something_to_focus->HasFocus()); |
| 452 | 453 |
| 453 // Send a mouse press event within the bounds of the holder and expect no | 454 // Send a mouse press event within the bounds of the holder and expect no |
| 454 // focus change. The reason is that WebView is not supposed to handle mouse | 455 // focus change. The reason is that WebView is not supposed to handle mouse |
| 455 // events within the bounds of the holder, and it would be up to the | 456 // events within the bounds of the holder, and it would be up to the |
| 456 // WebContents native view to grab the focus instead. In this test | 457 // WebContents native view to grab the focus instead. In this test |
| 457 // environment, the WebContents native view doesn't include the implementation | 458 // environment, the WebContents native view doesn't include the implementation |
| 458 // needed to grab focus, so no focus change will occur. | 459 // needed to grab focus, so no focus change will occur. |
| 459 const ui::MouseEvent click_inside_holder( | 460 const ui::MouseEvent click_inside_holder( |
| 460 ui::ET_MOUSE_PRESSED, web_view()->bounds().CenterPoint(), | 461 ui::ET_MOUSE_PRESSED, web_view()->bounds().CenterPoint(), |
| 461 gfx::Point(), // Immaterial. | 462 gfx::Point(), // Immaterial. |
| 462 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 463 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0, |
| 464 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
| 463 EXPECT_FALSE(static_cast<views::View*>(web_view())-> | 465 EXPECT_FALSE(static_cast<views::View*>(web_view())-> |
| 464 OnMousePressed(click_inside_holder)); | 466 OnMousePressed(click_inside_holder)); |
| 465 EXPECT_FALSE(web_view()->HasFocus()); | 467 EXPECT_FALSE(web_view()->HasFocus()); |
| 466 EXPECT_FALSE(holder()->HasFocus()); | 468 EXPECT_FALSE(holder()->HasFocus()); |
| 467 EXPECT_TRUE(something_to_focus->HasFocus()); | 469 EXPECT_TRUE(something_to_focus->HasFocus()); |
| 468 } | 470 } |
| 469 | 471 |
| 470 // Verifies that there is no crash in WebView destructor | 472 // Verifies that there is no crash in WebView destructor |
| 471 // if WebView is already removed from Widget. | 473 // if WebView is already removed from Widget. |
| 472 TEST_F(WebViewUnitTest, DetachedWebViewDestructor) { | 474 TEST_F(WebViewUnitTest, DetachedWebViewDestructor) { |
| 473 // Init WebView with attached NativeView. | 475 // Init WebView with attached NativeView. |
| 474 const std::unique_ptr<content::WebContents> web_contents(CreateWebContents()); | 476 const std::unique_ptr<content::WebContents> web_contents(CreateWebContents()); |
| 475 std::unique_ptr<WebView> webview( | 477 std::unique_ptr<WebView> webview( |
| 476 new WebView(web_contents->GetBrowserContext())); | 478 new WebView(web_contents->GetBrowserContext())); |
| 477 View* contents_view = top_level_widget()->GetContentsView(); | 479 View* contents_view = top_level_widget()->GetContentsView(); |
| 478 contents_view->AddChildView(webview.get()); | 480 contents_view->AddChildView(webview.get()); |
| 479 webview->SetWebContents(web_contents.get()); | 481 webview->SetWebContents(web_contents.get()); |
| 480 | 482 |
| 481 // Remove WebView from views hierarchy. NativeView should be detached | 483 // Remove WebView from views hierarchy. NativeView should be detached |
| 482 // from Widget. | 484 // from Widget. |
| 483 contents_view->RemoveChildView(webview.get()); | 485 contents_view->RemoveChildView(webview.get()); |
| 484 // Destroy WebView. NativeView should be detached secondary. | 486 // Destroy WebView. NativeView should be detached secondary. |
| 485 // There should be no crash. | 487 // There should be no crash. |
| 486 webview.reset(); | 488 webview.reset(); |
| 487 } | 489 } |
| 488 | 490 |
| 489 } // namespace views | 491 } // namespace views |
| OLD | NEW |