Chromium Code Reviews| 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..a5fecaca8eca887c4a1b1f0531713b2366576ac8 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,54 @@ 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 |
|
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.
|
| +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(); |
| + } |
| + } |
| + |
| + private: |
| + void GotPageScaleUpdate() { |
| + got_page_scale_update_ = true; |
| + on_page_scale_update_.Run(); |
| + } |
| + |
| + base::Closure on_page_scale_update_; |
| + bool got_page_scale_update_; |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, ChangePageScale) { |
| + // When the page scale factor is set in the renderer it should send |
| + // 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.
|
| + |
| + 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.
|
| + |
| + MockPageScaleObserver observer(shell()); |
| + |
| + EXPECT_CALL(observer, OnPageScaleFactorChanged(::testing::FloatEq(1.5))); |
| + |
| + shell()->web_contents()->SetPageScale(1.5); |
| + observer.WaitForPageScaleUpdate(); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, NewNamedWindow) { |
| ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |