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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 476 |
| 477 private: | 477 private: |
| 478 // BrowserMessageFilter: | 478 // BrowserMessageFilter: |
| 479 bool OnMessageReceived(const IPC::Message& message) override { | 479 bool OnMessageReceived(const IPC::Message& message) override { |
| 480 return message.type() == FrameHostMsg_SwapOut_ACK::ID; | 480 return message.type() == FrameHostMsg_SwapOut_ACK::ID; |
| 481 } | 481 } |
| 482 | 482 |
| 483 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); | 483 DISALLOW_COPY_AND_ASSIGN(SwapoutACKMessageFilter); |
| 484 }; | 484 }; |
| 485 | 485 |
| 486 class RenderWidgetHostVisibilityObserver : public NotificationObserver { | |
| 487 public: | |
| 488 explicit RenderWidgetHostVisibilityObserver(RenderWidgetHostImpl* rwhi, | |
| 489 bool expected_visibility_state) | |
| 490 : expected_visibility_state_(expected_visibility_state), | |
| 491 observed_(false), | |
| 492 failed_(false), | |
| 493 source_(rwhi) { | |
| 494 registrar_.Add(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | |
| 495 source_); | |
| 496 message_loop_runner_ = new MessageLoopRunner; | |
| 497 } | |
| 498 | |
| 499 bool WaitUntilSatisfied() { | |
| 500 if (!observed_) | |
| 501 message_loop_runner_->Run(); | |
| 502 registrar_.Remove(this, NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | |
| 503 source_); | |
| 504 return !failed_; | |
| 505 } | |
| 506 | |
| 507 private: | |
| 508 void Observe(int type, | |
| 509 const NotificationSource& source, | |
| 510 const NotificationDetails& details) override { | |
| 511 observed_ = true; | |
| 512 failed_ = expected_visibility_state_ != | |
| 513 (*static_cast<const Details<bool>&>(details).ptr()); | |
| 514 if (message_loop_runner_->loop_running()) | |
| 515 message_loop_runner_->Quit(); | |
| 516 } | |
| 517 | |
| 518 RenderWidgetHostImpl* render_widget_host_; | |
| 519 bool expected_visibility_state_; | |
| 520 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 521 NotificationRegistrar registrar_; | |
| 522 bool observed_; | |
|
Charlie Reis
2015/12/08 19:18:34
nit: was_observed_
EhsanK
2015/12/09 00:14:17
Done.
| |
| 523 bool failed_; | |
|
Charlie Reis
2015/12/08 19:18:34
nit: did_fail_
EhsanK
2015/12/09 00:14:16
Done.
| |
| 524 Source<RenderWidgetHost> source_; | |
| 525 | |
| 526 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostVisibilityObserver); | |
| 527 }; | |
| 528 | |
| 486 } // namespace | 529 } // namespace |
| 487 | 530 |
| 488 // | 531 // |
| 489 // SitePerProcessBrowserTest | 532 // SitePerProcessBrowserTest |
| 490 // | 533 // |
| 491 | 534 |
| 492 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 535 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { |
| 493 }; | 536 }; |
| 494 | 537 |
| 495 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 538 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| (...skipping 3678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4174 router->RouteMouseEvent(root_view, &click_event); | 4217 router->RouteMouseEvent(root_view, &click_event); |
| 4175 | 4218 |
| 4176 context_menu_delegate.Wait(); | 4219 context_menu_delegate.Wait(); |
| 4177 | 4220 |
| 4178 ContextMenuParams params = context_menu_delegate.getParams(); | 4221 ContextMenuParams params = context_menu_delegate.getParams(); |
| 4179 | 4222 |
| 4180 EXPECT_EQ(point.x(), params.x); | 4223 EXPECT_EQ(point.x(), params.x); |
| 4181 EXPECT_EQ(point.y(), params.y); | 4224 EXPECT_EQ(point.y(), params.y); |
| 4182 } | 4225 } |
| 4183 | 4226 |
| 4227 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, VisibilityChanged) { | |
| 4228 GURL main_url( | |
| 4229 embedded_test_server()->GetURL("a.com", "/page_with_iframe.html")); | |
| 4230 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 4231 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), main_url); | |
| 4232 | |
| 4233 GURL cross_site_url = | |
| 4234 embedded_test_server()->GetURL("oopif.com", "/title1.html"); | |
| 4235 | |
| 4236 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 4237 ->GetFrameTree() | |
| 4238 ->root(); | |
| 4239 | |
| 4240 TestNavigationObserver observer(shell()->web_contents()); | |
| 4241 | |
| 4242 NavigateFrameToURL(root->child_at(0), cross_site_url); | |
| 4243 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | |
| 4244 EXPECT_TRUE(observer.last_navigation_succeeded()); | |
| 4245 | |
| 4246 RenderWidgetHostImpl* render_widget_host = | |
| 4247 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(); | |
| 4248 EXPECT_FALSE(render_widget_host->is_hidden()); | |
| 4249 | |
| 4250 std::string show_script = | |
| 4251 "document.querySelector('iframe').style.visibility = 'visible';"; | |
| 4252 std::string hide_script = | |
| 4253 "document.querySelector('iframe').style.visibility = 'hidden';"; | |
| 4254 | |
| 4255 // Verify that hiding leads to a notification from RenderWidgetHost | |
|
Charlie Reis
2015/12/08 19:18:33
nit: End with period.
EhsanK
2015/12/09 00:14:16
Done.
| |
| 4256 RenderWidgetHostVisibilityObserver hide_observer( | |
| 4257 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), false); | |
| 4258 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), hide_script)); | |
| 4259 EXPECT_TRUE(hide_observer.WaitUntilSatisfied()); | |
| 4260 // Verify showing leads to a notification as well. | |
|
Charlie Reis
2015/12/08 19:18:34
nit: Add blank line above.
EhsanK
2015/12/09 00:14:17
Done.
| |
| 4261 RenderWidgetHostVisibilityObserver show_observer( | |
| 4262 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), true); | |
| 4263 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), show_script)); | |
| 4264 EXPECT_TRUE(show_observer.WaitUntilSatisfied()); | |
| 4265 } | |
| 4266 | |
| 4184 } // namespace content | 4267 } // namespace content |
| OLD | NEW |