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 | |
Charlie Reis
2015/10/21 21:37:09
nit: End sentence with a period. (Same below on l
Kevin McNee - google account
2015/10/22 20:28:48
Done.
| |
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 } | |
742 | |
743 private: | |
744 void GotPageScaleUpdate() { | |
745 got_page_scale_update_ = true; | |
746 on_page_scale_update_.Run(); | |
747 } | |
748 | |
749 base::Closure on_page_scale_update_; | |
750 bool got_page_scale_update_; | |
751 }; | |
752 | |
753 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangePageScale) { | |
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. | |
Charlie Reis
2015/10/21 21:37:10
nit: Move comment before test declaration and remo
Kevin McNee - google account
2015/10/22 20:28:48
Done.
| |
756 | |
757 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); | |
Charlie Reis
2015/10/21 21:37:09
You should probably use a real URL here. about:bl
Kevin McNee - google account
2015/10/22 20:28:48
Done.
| |
758 | |
759 MockPageScaleObserver observer(shell()); | |
760 | |
761 EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::FloatEq(1.5))); | |
762 | |
763 shell()->web_contents()->SetPageScale(1.5); | |
764 observer.WaitForPageScaleUpdate(); | |
765 } | |
766 | |
718 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { | 767 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { |
719 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 768 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
720 | 769 |
721 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); | 770 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); |
722 EXPECT_TRUE(NavigateToURL(shell(), url)); | 771 EXPECT_TRUE(NavigateToURL(shell(), url)); |
723 | 772 |
724 { | 773 { |
725 ShellAddedObserver new_shell_observer; | 774 ShellAddedObserver new_shell_observer; |
726 | 775 |
727 // Open a new, named window. | 776 // Open a new, named window. |
(...skipping 29 matching lines...) Expand all Loading... | |
757 Shell* new_shell = new_shell_observer.GetShell(); | 806 Shell* new_shell = new_shell_observer.GetShell(); |
758 WaitForLoadStop(new_shell->web_contents()); | 807 WaitForLoadStop(new_shell->web_contents()); |
759 | 808 |
760 EXPECT_EQ("foo", | 809 EXPECT_EQ("foo", |
761 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 810 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
762 ->GetFrameTree()->root()->frame_name()); | 811 ->GetFrameTree()->root()->frame_name()); |
763 } | 812 } |
764 } | 813 } |
765 | 814 |
766 } // namespace content | 815 } // namespace content |
OLD | NEW |