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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_impl_browsertest.cc
diff --git a/content/browser/web_contents/web_contents_impl_browsertest.cc b/content/browser/web_contents/web_contents_impl_browsertest.cc
index aa975789fcf7f8f2efc6a826a7aef45ce368c0b0..3cc1c1211d645324f3251888d79ef9bd648b5b47 100644
--- a/content/browser/web_contents/web_contents_impl_browsertest.cc
+++ b/content/browser/web_contents/web_contents_impl_browsertest.cc
@@ -27,6 +27,7 @@
#include "content/shell/browser/shell.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "testing/gmock/include/gmock/gmock.h"
namespace content {
@@ -715,6 +716,63 @@ IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangeDisplayMode) {
EXPECT_EQ(base::ASCIIToUTF16("true"), shell()->web_contents()->GetTitle());
}
+// Observer class used to verify that WebContentsObservers are notified
+// when the page scale factor changes.
+// See WebContentsImplBrowserTest.ChangePageScale.
+class MockPageScaleObserver : public WebContentsObserver {
+ public:
+ MockPageScaleObserver(Shell* shell)
+ : WebContentsObserver(shell->web_contents()),
+ got_page_scale_update_(false) {
+ // Once OnPageScaleFactorChanged is called, quit the run loop.
+ ON_CALL(*this, OnPageScaleFactorChanged(::testing::_)).WillByDefault(
+ ::testing::InvokeWithoutArgs(
+ this, &MockPageScaleObserver::GotPageScaleUpdate));
+ }
+
+ MOCK_METHOD1(OnPageScaleFactorChanged, void(float page_scale_factor));
+
+ void WaitForPageScaleUpdate() {
+ if (!got_page_scale_update_) {
+ base::RunLoop run_loop;
+ on_page_scale_update_ = run_loop.QuitClosure();
+ run_loop.Run();
+ }
+ got_page_scale_update_ = false;
+ }
+
+ private:
+ void GotPageScaleUpdate() {
+ got_page_scale_update_ = true;
+ on_page_scale_update_.Run();
+ }
+
+ base::Closure on_page_scale_update_;
+ bool got_page_scale_update_;
+};
+
+// When the page scale factor is set in the renderer it should send
+// a notification to the browser so that WebContentsObservers are notified.
+// We also get notifications upon navigation.
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangePageScale) {
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+
+ MockPageScaleObserver observer(shell());
+ testing::InSequence expect_call_sequence;
+
+ shell()->LoadURL(embedded_test_server()->GetURL("/title1.html"));
+ EXPECT_CALL(observer, OnPageScaleFactorChanged(testing::_));
+ observer.WaitForPageScaleUpdate();
+
+ shell()->web_contents()->SetPageScale(1.5);
+ EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::FloatEq(1.5)));
+ observer.WaitForPageScaleUpdate();
+
+ shell()->LoadURL(embedded_test_server()->GetURL("/title2.html"));
+ EXPECT_CALL(observer, OnPageScaleFactorChanged(testing::_));
+ observer.WaitForPageScaleUpdate();
+}
+
IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) {
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());

Powered by Google App Engine
This is Rietveld 408576698