OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
8 #include "content/browser/renderer_host/render_widget_host_impl.h" | 8 #include "content/browser/renderer_host/render_widget_host_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/browser/web_contents/web_contents_view.h" | 10 #include "content/browser/web_contents/web_contents_view.h" |
11 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
12 #include "content/public/browser/load_notification_details.h" | 12 #include "content/public/browser/load_notification_details.h" |
13 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
14 #include "content/public/browser/notification_details.h" | 14 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_widget_host_view.h" | 18 #include "content/public/browser/render_widget_host_view.h" |
19 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
20 #include "content/public/common/content_paths.h" | 20 #include "content/public/common/content_paths.h" |
21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
22 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/content_browser_test.h" | 23 #include "content/public/test/content_browser_test.h" |
24 #include "content/public/test/content_browser_test_utils.h" | 24 #include "content/public/test/content_browser_test_utils.h" |
25 #include "content/public/test/test_navigation_observer.h" | 25 #include "content/public/test/test_navigation_observer.h" |
26 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
27 #include "content/shell/browser/shell.h" | 27 #include "content/shell/browser/shell.h" |
28 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
29 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
33 void ResizeWebContentsView(Shell* shell, const gfx::Size& size, | 34 void ResizeWebContentsView(Shell* shell, const gfx::Size& size, |
34 bool set_start_page) { | 35 bool set_start_page) { |
35 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents | 36 // Shell::SizeTo is not implemented on Aura; WebContentsView::SizeContents |
36 // works on Win and ChromeOS but not Linux - we need to resize the shell | 37 // works on Win and ChromeOS but not Linux - we need to resize the shell |
37 // window on Linux because if we don't, the next layout of the unchanged shell | 38 // window on Linux because if we don't, the next layout of the unchanged shell |
38 // window will resize WebContentsView back to the previous size. | 39 // window will resize WebContentsView back to the previous size. |
39 // SizeContents is a hack and should not be relied on. | 40 // SizeContents is a hack and should not be relied on. |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 // Simulate widget is entering fullscreen (changing size is enough). | 709 // Simulate widget is entering fullscreen (changing size is enough). |
709 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); | 710 shell()->web_contents()->GetRenderViewHost()->GetWidget()->WasResized(); |
710 | 711 |
711 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), | 712 ASSERT_TRUE(ExecuteScript(shell()->web_contents(), |
712 "document.title = " | 713 "document.title = " |
713 " window.matchMedia('(display-mode:" | 714 " window.matchMedia('(display-mode:" |
714 " fullscreen)').matches")); | 715 " fullscreen)').matches")); |
715 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); | 716 EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle()); |
716 } | 717 } |
717 | 718 |
| 719 // Observer class used to verify that WebContentsObservers are notified |
| 720 // when the page scale factor changes. |
| 721 // See WebContentsImplBrowserTest.ChangePageScale. |
| 722 class MockPageScaleObserver : public WebContentsObserver { |
| 723 public: |
| 724 MockPageScaleObserver(Shell* shell) |
| 725 : WebContentsObserver(shell->web_contents()), |
| 726 got_page_scale_update_(false) { |
| 727 // Once OnPageScaleFactorChanged is called, quit the run loop. |
| 728 ON_CALL(*this, OnPageScaleFactorChanged(::testing::_)).WillByDefault( |
| 729 ::testing::InvokeWithoutArgs( |
| 730 this, &MockPageScaleObserver::GotPageScaleUpdate)); |
| 731 } |
| 732 |
| 733 MOCK_METHOD1(OnPageScaleFactorChanged, void(float page_scale_factor)); |
| 734 |
| 735 void WaitForPageScaleUpdate() { |
| 736 if (!got_page_scale_update_) { |
| 737 base::RunLoop run_loop; |
| 738 on_page_scale_update_ = run_loop.QuitClosure(); |
| 739 run_loop.Run(); |
| 740 } |
| 741 got_page_scale_update_ = false; |
| 742 } |
| 743 |
| 744 private: |
| 745 void GotPageScaleUpdate() { |
| 746 got_page_scale_update_ = true; |
| 747 on_page_scale_update_.Run(); |
| 748 } |
| 749 |
| 750 base::Closure on_page_scale_update_; |
| 751 bool got_page_scale_update_; |
| 752 }; |
| 753 |
| 754 // When the page scale factor is set in the renderer it should send |
| 755 // a notification to the browser so that WebContentsObservers are notified. |
| 756 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangePageScale) { |
| 757 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 758 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 759 |
| 760 MockPageScaleObserver observer(shell()); |
| 761 ::testing::InSequence expect_call_sequence; |
| 762 |
| 763 shell()->web_contents()->SetPageScale(1.5); |
| 764 EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::FloatEq(1.5))); |
| 765 observer.WaitForPageScaleUpdate(); |
| 766 |
| 767 // Navigate to reset the page scale factor. |
| 768 shell()->LoadURL(embedded_test_server()->GetURL("/title2.html")); |
| 769 EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::_)); |
| 770 observer.WaitForPageScaleUpdate(); |
| 771 } |
| 772 |
718 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { | 773 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { |
719 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 774 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
720 | 775 |
721 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); | 776 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); |
722 EXPECT_TRUE(NavigateToURL(shell(), url)); | 777 EXPECT_TRUE(NavigateToURL(shell(), url)); |
723 | 778 |
724 { | 779 { |
725 ShellAddedObserver new_shell_observer; | 780 ShellAddedObserver new_shell_observer; |
726 | 781 |
727 // Open a new, named window. | 782 // Open a new, named window. |
(...skipping 29 matching lines...) Expand all Loading... |
757 Shell* new_shell = new_shell_observer.GetShell(); | 812 Shell* new_shell = new_shell_observer.GetShell(); |
758 WaitForLoadStop(new_shell->web_contents()); | 813 WaitForLoadStop(new_shell->web_contents()); |
759 | 814 |
760 EXPECT_EQ("foo", | 815 EXPECT_EQ("foo", |
761 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 816 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
762 ->GetFrameTree()->root()->frame_name()); | 817 ->GetFrameTree()->root()->frame_name()); |
763 } | 818 } |
764 } | 819 } |
765 | 820 |
766 } // namespace content | 821 } // namespace content |
OLD | NEW |