Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 1408393003: Propagate pageScaleFactor to GuestViews (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Give OnPageScaleFactorChanged suitable behaviour upon navigation Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // We also get notifications upon navigation.
757 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangePageScale) {
758 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
759
760 MockPageScaleObserver observer(shell());
761 testing::InSequence expect_call_sequence;
762
763 shell()->LoadURL(embedded_test_server()->GetURL("/title1.html"));
764 EXPECT_CALL(observer, OnPageScaleFactorChanged(testing::_));
765 observer.WaitForPageScaleUpdate();
766
767 shell()->web_contents()->SetPageScale(1.5);
768 EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::FloatEq(1.5)));
769 observer.WaitForPageScaleUpdate();
770
771 shell()->LoadURL(embedded_test_server()->GetURL("/title2.html"));
772 EXPECT_CALL(observer, OnPageScaleFactorChanged(testing::_));
773 observer.WaitForPageScaleUpdate();
774 }
775
718 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { 776 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
719 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 777 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
720 778
721 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html"); 779 GURL url = embedded_test_server()->GetURL("/click-noreferrer-links.html");
722 EXPECT_TRUE(NavigateToURL(shell(), url)); 780 EXPECT_TRUE(NavigateToURL(shell(), url));
723 781
724 { 782 {
725 ShellAddedObserver new_shell_observer; 783 ShellAddedObserver new_shell_observer;
726 784
727 // Open a new, named window. 785 // Open a new, named window.
(...skipping 29 matching lines...) Expand all
757 Shell* new_shell = new_shell_observer.GetShell(); 815 Shell* new_shell = new_shell_observer.GetShell();
758 WaitForLoadStop(new_shell->web_contents()); 816 WaitForLoadStop(new_shell->web_contents());
759 817
760 EXPECT_EQ("foo", 818 EXPECT_EQ("foo",
761 static_cast<WebContentsImpl*>(new_shell->web_contents()) 819 static_cast<WebContentsImpl*>(new_shell->web_contents())
762 ->GetFrameTree()->root()->frame_name()); 820 ->GetFrameTree()->root()->frame_name());
763 } 821 }
764 } 822 }
765 823
766 } // namespace content 824 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698