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 { | |
| 309 public: | |
| 310 explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi, | |
| 311 bool expected_visibility_state) | |
| 312 : render_widget_host_(rwhi), | |
| 313 expected_visibility_state_(expected_visibility_state), | |
| 314 weak_ptr_factory_(this) {} | |
| 315 | |
| 316 std::string toString(bool value) { return value ? "TRUE" : "FALSE"; } | |
| 317 | |
| 318 void WaitUntilSatisfied() { | |
| 319 if (expected_visibility_state_ ^ render_widget_host_->is_hidden()) | |
| 320 return; | |
| 321 message_loop_runner_ = new MessageLoopRunner; | |
|
lazyboy
2015/11/11 22:04:27
This tight polling should be avoided.
Use NOTIFIC
EhsanK
2015/11/12 19:54:30
Done.
| |
| 322 BrowserThread::PostDelayedTask( | |
| 323 BrowserThread::UI, FROM_HERE, | |
| 324 base::Bind(&RenderWidgetHostVisibilityObserver::CheckVisibility, | |
| 325 weak_ptr_factory_.GetWeakPtr()), | |
| 326 base::TimeDelta::FromMilliseconds(1)); | |
| 327 message_loop_runner_->Run(); | |
| 328 } | |
| 329 | |
| 330 private: | |
| 331 void CheckVisibility() { | |
| 332 if (expected_visibility_state_ ^ render_widget_host_->is_hidden()) | |
| 333 message_loop_runner_->Quit(); | |
| 334 else | |
| 335 BrowserThread::PostDelayedTask( | |
| 336 BrowserThread::UI, FROM_HERE, | |
| 337 base::Bind(&RenderWidgetHostVisibilityObserver::CheckVisibility, | |
| 338 weak_ptr_factory_.GetWeakPtr()), | |
| 339 base::TimeDelta::FromMilliseconds(1)); | |
| 340 } | |
| 341 | |
| 342 RenderWidgetHostImpl* render_widget_host_; | |
| 343 bool expected_visibility_state_; | |
| 344 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 345 | |
| 346 base::WeakPtrFactory<RenderWidgetHostVisibilityObserver> weak_ptr_factory_; | |
| 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 std::string script = | |
| 3977 "document.querySelector('iframe').style.visibility = 'hidden';"; | |
| 3978 RenderWidgetHostVisibilityObserver visibility_observer( | |
| 3979 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); | |
| 3980 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), script)); | |
| 3981 visibility_observer.WaitUntilSatisfied(); | |
| 3982 } | |
| 3983 | |
| 3914 } // namespace content | 3984 } // namespace content |
| OLD | NEW |