| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "content/public/browser/render_frame_host.h" | 7 #include "content/public/browser/render_frame_host.h" |
| 8 #include "content/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/public/renderer/render_frame_observer.h" |
| 10 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 11 #include "content/public/renderer/render_view_observer.h" | |
| 12 #include "content/public/test/browser_test_utils.h" | 12 #include "content/public/test/browser_test_utils.h" |
| 13 #include "content/public/test/content_browser_test.h" | 13 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/content_browser_test_utils.h" | 14 #include "content/public/test/content_browser_test_utils.h" |
| 15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "content/renderer/render_frame_impl.h" | 16 #include "content/renderer/render_frame_impl.h" |
| 17 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 class CommitObserver : public RenderViewObserver { | 21 class CommitObserver : public RenderFrameObserver { |
| 22 public: | 22 public: |
| 23 CommitObserver(RenderView* render_view) | 23 CommitObserver(RenderFrame* render_frame) |
| 24 : RenderViewObserver(render_view), quit_closures_(), commit_count_(0) {} | 24 : RenderFrameObserver(render_frame), quit_closures_(), commit_count_(0) {} |
| 25 | 25 |
| 26 // RenderFrameObserver |
| 26 void DidCommitCompositorFrame() override { | 27 void DidCommitCompositorFrame() override { |
| 27 commit_count_++; | 28 commit_count_++; |
| 28 for (base::Closure* closure : quit_closures_) { | 29 for (base::Closure* closure : quit_closures_) { |
| 29 closure->Run(); | 30 closure->Run(); |
| 30 } | 31 } |
| 31 } | 32 } |
| 32 | 33 |
| 33 void QuitAfterCommit(int commit_number, | 34 void QuitAfterCommit(int commit_number, |
| 34 scoped_refptr<MessageLoopRunner> runner) { | 35 scoped_refptr<MessageLoopRunner> runner) { |
| 35 if (commit_number >= commit_count_) runner->Quit(); | 36 if (commit_number >= commit_count_) runner->Quit(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // single commit. We first load "about:blank" and wait for this single | 92 // single commit. We first load "about:blank" and wait for this single |
| 92 // commit. At that point we know that the page has stabilized and no | 93 // commit. At that point we know that the page has stabilized and no |
| 93 // further commits are expected. We then insert a visual state callback | 94 // further commits are expected. We then insert a visual state callback |
| 94 // and verify that this causes an additional commit in order to deliver | 95 // and verify that this causes an additional commit in order to deliver |
| 95 // the callback. | 96 // the callback. |
| 96 // Unfortunately, if loading "about:blank" changes and starts requiring | 97 // Unfortunately, if loading "about:blank" changes and starts requiring |
| 97 // two commits then this test will prove nothing. We could detect this | 98 // two commits then this test will prove nothing. We could detect this |
| 98 // with a high level of confidence if we used a timeout, but that's | 99 // with a high level of confidence if we used a timeout, but that's |
| 99 // discouraged (see https://codereview.chromium.org/939673002). | 100 // discouraged (see https://codereview.chromium.org/939673002). |
| 100 NavigateToURL(shell(), GURL("about:blank")); | 101 NavigateToURL(shell(), GURL("about:blank")); |
| 101 CommitObserver observer( | 102 RenderView* render_view = |
| 102 RenderView::FromRoutingID(shell()->web_contents()->GetRoutingID())); | 103 RenderView::FromRoutingID(shell()->web_contents()->GetRoutingID()); |
| 104 CommitObserver observer(render_view->GetMainRenderFrame()); |
| 103 | 105 |
| 104 // Wait for the commit corresponding to the load. | 106 // Wait for the commit corresponding to the load. |
| 105 | 107 |
| 106 PostTaskToInProcessRendererAndWait(base::Bind( | 108 PostTaskToInProcessRendererAndWait(base::Bind( |
| 107 &VisualStateTest::WaitForCommit, base::Unretained(this), &observer, 1)); | 109 &VisualStateTest::WaitForCommit, base::Unretained(this), &observer, 1)); |
| 108 | 110 |
| 109 // Try our best to check that there are no pending updates or commits. | 111 // Try our best to check that there are no pending updates or commits. |
| 110 PostTaskToInProcessRendererAndWait( | 112 PostTaskToInProcessRendererAndWait( |
| 111 base::Bind(&VisualStateTest::AssertIsIdle, base::Unretained(this))); | 113 base::Bind(&VisualStateTest::AssertIsIdle, base::Unretained(this))); |
| 112 | 114 |
| 113 // Insert a visual state callback. | 115 // Insert a visual state callback. |
| 114 shell()->web_contents()->GetMainFrame()->InsertVisualStateCallback(base::Bind( | 116 shell()->web_contents()->GetMainFrame()->InsertVisualStateCallback(base::Bind( |
| 115 &VisualStateTest::InvokeVisualStateCallback, base::Unretained(this))); | 117 &VisualStateTest::InvokeVisualStateCallback, base::Unretained(this))); |
| 116 | 118 |
| 117 // Verify that the callback is invoked and a new commit completed. | 119 // Verify that the callback is invoked and a new commit completed. |
| 118 PostTaskToInProcessRendererAndWait(base::Bind( | 120 PostTaskToInProcessRendererAndWait(base::Bind( |
| 119 &VisualStateTest::WaitForCommit, base::Unretained(this), &observer, 2)); | 121 &VisualStateTest::WaitForCommit, base::Unretained(this), &observer, 2)); |
| 120 EXPECT_EQ(1, GetCallbackCount()); | 122 EXPECT_EQ(1, GetCallbackCount()); |
| 121 } | 123 } |
| 122 | 124 |
| 123 } // namespace content | 125 } // namespace content |
| OLD | NEW |