Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Unified Diff: content/browser/web_contents/web_contents_view_aura_browsertest.cc

Issue 166533002: [wip] Introduce SiteInstanceKeepAlive. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/web_contents/web_contents_view_aura_browsertest.cc
diff --git a/content/browser/web_contents/web_contents_view_aura_browsertest.cc b/content/browser/web_contents/web_contents_view_aura_browsertest.cc
index 8079c9ce71b9127b38c76bce4a31c3d5dbf78eef..c7f8e44a7d11f149daccf05238f1c2b72e77cf0a 100644
--- a/content/browser/web_contents/web_contents_view_aura_browsertest.cc
+++ b/content/browser/web_contents/web_contents_view_aura_browsertest.cc
@@ -32,6 +32,33 @@
namespace content {
+// Keeps track of whether a RenderProcessHost is alive or not.
+class RenderProcessHostTracker : public RenderProcessHostObserver {
+ public:
+ explicit RenderProcessHostTracker(RenderProcessHost* host)
+ : host_(host) {
+ host_->AddObserver(this);
+ }
+
+ virtual ~RenderProcessHostTracker() {
+ if (host_)
+ host_->RemoveObserver(this);
+ }
+
+ bool alive() const { return host_; }
+
+ private:
+ // RenderProcessHostObserver:
+ virtual void RenderProcessHostDestroyed(RenderProcessHost* host) OVERRIDE {
+ CHECK_EQ(host_, host);
+ host_ = NULL;
+ }
+
+ RenderProcessHost* host_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderProcessHostTracker);
+};
+
// This class keeps track of the RenderViewHost whose screenshot was captured.
class ScreenshotTracker : public NavigationEntryScreenshotManager {
public:
@@ -73,12 +100,22 @@ class ScreenshotTracker : public NavigationEntryScreenshotManager {
++waiting_for_screenshots_;
screenshot_taken_for_ = host;
NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry);
+
+ // The screenshot-manager should start observing the lifetime of the
+ // WebContents, to make sure that it can cancel the screenshot requests if
+ // the WebContents is destroyed before the screenshot-capture completes.
+ EXPECT_TRUE(web_contents());
}
virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE {
--waiting_for_screenshots_;
screenshot_set_[entry] = true;
NavigationEntryScreenshotManager::OnScreenshotSet(entry);
+ if (waiting_for_screenshots_ == 0) {
+ // If the screenshot manager is not waiting for any pending screenshot
+ // capture requests, then it shouldn't be observing the WebContents.
+ EXPECT_FALSE(web_contents());
+ }
if (waiting_for_screenshots_ == 0 && message_loop_runner_.get())
message_loop_runner_->Quit();
}
@@ -518,9 +555,16 @@ IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest,
params.transition_type = PageTransitionFromInt(navigations[i].transition);
RenderViewHost* old_host = web_contents->GetRenderViewHost();
+ scoped_ptr<RenderProcessHostTracker> process_tracker(
+ new RenderProcessHostTracker(old_host->GetProcess()));
+ EXPECT_TRUE(process_tracker->alive());
+
web_contents->GetController().LoadURLWithParams(params);
WaitForLoadStop(web_contents);
screenshot_manager()->WaitUntilScreenshotIsReady();
+ // The RenderProcessHost should be destroyed, since this is a cross-process
+ // navigation.
+ EXPECT_FALSE(process_tracker->alive());
EXPECT_NE(old_host, web_contents->GetRenderViewHost())
<< navigations[i].url.spec();

Powered by Google App Engine
This is Rietveld 408576698