Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 298 |
| 299 private: | 299 private: |
| 300 // BrowserMessageFilter: | 300 // BrowserMessageFilter: |
| 301 bool OnMessageReceived(const IPC::Message& message) override { | 301 bool OnMessageReceived(const IPC::Message& message) override { |
| 302 return message.type() == FrameHostMsg_SwapOut_ACK::ID; | 302 return message.type() == FrameHostMsg_SwapOut_ACK::ID; |
| 303 } | 303 } |
| 304 | 304 |
| 305 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); | 305 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 class RenderWidgetHostVisibilityObserver : public NotificationObserver { | |
| 309 public: | |
| 310 explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi, | |
| 311 bool expected_visibility_state) | |
| 312 : expected_visibility_state_(expected_visibility_state), | |
| 313 observed_(false), | |
| 314 failed_(false), | |
| 315 source_(rwhi) { | |
| 316 registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | |
| 317 source_); | |
| 318 message_loop_runner_ = new MessageLoopRunner; | |
| 319 } | |
| 320 | |
| 321 bool WaitUntilSatisfied() { | |
| 322 if (!observed_) | |
| 323 message_loop_runner_->Run(); | |
| 324 registrar_.Remove(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | |
| 325 source_); | |
| 326 return !failed_; | |
| 327 } | |
| 328 | |
| 329 private: | |
| 330 void Observe(int type, | |
| 331 const NotificationSource& source, | |
| 332 const NotificationDetails& details) override { | |
| 333 observed_ = true; | |
| 334 failed_ = expected_visibility_state_ ^ | |
|
dcheng
2015/12/02 00:15:05
I think == would be clearer (and that's fine, sinc
EhsanK
2015/12/07 16:10:15
Done.
| |
| 335 (*static_cast<const Details<bool>&>(details).ptr()); | |
| 336 if (message_loop_runner_->loop_running()) | |
| 337 message_loop_runner_->Quit(); | |
| 338 } | |
| 339 | |
| 340 RenderWidgetHostImpl* render_widget_host_; | |
| 341 bool expected_visibility_state_; | |
| 342 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 343 NotificationRegistrar registrar_; | |
| 344 bool observed_; | |
| 345 bool failed_; | |
| 346 Source<RenderWidgetHost> source_; | |
| 347 | |
| 348 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver); | |
| 349 }; | |
| 350 | |
| 308 } // namespace | 351 } // namespace |
| 309 | 352 |
| 310 // | 353 // |
| 311 // SitePerProcessBrowserTest | 354 // SitePerProcessBrowserTest |
| 312 // | 355 // |
| 313 | 356 |
| 314 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 357 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 315 }; | 358 }; |
| 316 | 359 |
| 317 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 360 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| (...skipping 3586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3904 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); | 3947 EXPECT_EQ(popup->web_contents()->GetLastCommittedURL(), cross_url); |
| 3905 | 3948 |
| 3906 // Use new window to navigate main window. | 3949 // Use new window to navigate main window. |
| 3907 std::string script = | 3950 std::string script = |
| 3908 "window.opener.location.href = '" + cross_url.spec() + "'"; | 3951 "window.opener.location.href = '" + cross_url.spec() + "'"; |
| 3909 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 3952 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); |
| 3910 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 3953 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 3911 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 3954 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
| 3912 } | 3955 } |
| 3913 | 3956 |
| 3957 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, VisibilityChanged) { | |
| 3958 GURL main_url( | |
| 3959 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html")); | |
| 3960 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 3961 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url); | |
| 3962 | |
| 3963 GURL cross_site_url = | |
| 3964 embedded_test_server()->GetURL("oopif.com", "/title1.html"); | |
| 3965 | |
| 3966 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 3967 ->GetFrameTree() | |
| 3968 ->root(); | |
| 3969 | |
| 3970 TestNavigationObserver observer(shell()->web_contents()); | |
| 3971 | |
| 3972 NavigateFrameToURL(root->child_at(0), cross_site_url); | |
| 3973 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | |
| 3974 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 3975 | |
| 3976 RenderWidgetHostImpl* render_widget_host = | |
| 3977 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(); | |
| 3978 EXPECT_FALSE(render_widget_host->is_hidden()); | |
| 3979 | |
| 3980 std::string show_script = | |
| 3981 "document.querySelector('iframe').style.visibility = 'visible';"; | |
| 3982 std::string hide_script = | |
| 3983 "document.querySelector('iframe').style.visibility = 'hidden';"; | |
| 3984 | |
| 3985 // Verify that hiding leads to a notification from RenderWidgetHost | |
| 3986 RenderWidgetHostVisibilityObserver hide_observer( | |
| 3987 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); | |
| 3988 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script)); | |
| 3989 EXPECT_TRUE(hide_observer.WaitUntilSatisfied()); | |
| 3990 // Verify showing leads to a notification as well. | |
| 3991 RenderWidgetHostVisibilityObserver show_observer( | |
| 3992 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true); | |
| 3993 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script)); | |
| 3994 EXPECT_TRUE(show_observer.WaitUntilSatisfied()); | |
| 3995 } | |
| 3996 | |
| 3914 } // namespace content | 3997 } // namespace content |
| OLD | NEW |