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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/shell/browser/shell.h" 25 #include "content/shell/browser/shell.h"
26 #include "content/test/content_browser_test.h" 26 #include "content/test/content_browser_test.h"
27 #include "content/test/content_browser_test_utils.h" 27 #include "content/test/content_browser_test_utils.h"
28 #include "ui/aura/root_window.h" 28 #include "ui/aura/root_window.h"
29 #include "ui/aura/test/event_generator.h" 29 #include "ui/aura/test/event_generator.h"
30 #include "ui/aura/window.h" 30 #include "ui/aura/window.h"
31 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 31 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
32 32
33 namespace content { 33 namespace content {
34 34
35 // Keeps track of whether a RenderProcessHost is alive or not.
36 class RenderProcessHostTracker : public RenderProcessHostObserver {
37 public:
38 explicit RenderProcessHostTracker(RenderProcessHost* host)
39 : host_(host) {
40 host_->AddObserver(this);
41 }
42
43 virtual ~RenderProcessHostTracker() {
44 if (host_)
45 host_->RemoveObserver(this);
46 }
47
48 bool alive() const { return host_; }
49
50 private:
51 // RenderProcessHostObserver:
52 virtual void RenderProcessHostDestroyed(RenderProcessHost* host) OVERRIDE {
53 CHECK_EQ(host_, host);
54 host_ = NULL;
55 }
56
57 RenderProcessHost* host_;
58
59 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostTracker);
60 };
61
35 // This class keeps track of the RenderViewHost whose screenshot was captured. 62 // This class keeps track of the RenderViewHost whose screenshot was captured.
36 class ScreenshotTracker : public NavigationEntryScreenshotManager { 63 class ScreenshotTracker : public NavigationEntryScreenshotManager {
37 public: 64 public:
38 explicit ScreenshotTracker(NavigationControllerImpl* controller) 65 explicit ScreenshotTracker(NavigationControllerImpl* controller)
39 : NavigationEntryScreenshotManager(controller), 66 : NavigationEntryScreenshotManager(controller),
40 screenshot_taken_for_(NULL), 67 screenshot_taken_for_(NULL),
41 waiting_for_screenshots_(0) { 68 waiting_for_screenshots_(0) {
42 } 69 }
43 70
44 virtual ~ScreenshotTracker() { 71 virtual ~ScreenshotTracker() {
(...skipping 21 matching lines...) Expand all
66 return screenshot_set_.count(entry) > 0; 93 return screenshot_set_.count(entry) > 0;
67 } 94 }
68 95
69 private: 96 private:
70 // Overridden from NavigationEntryScreenshotManager: 97 // Overridden from NavigationEntryScreenshotManager:
71 virtual void TakeScreenshotImpl(RenderViewHost* host, 98 virtual void TakeScreenshotImpl(RenderViewHost* host,
72 NavigationEntryImpl* entry) OVERRIDE { 99 NavigationEntryImpl* entry) OVERRIDE {
73 ++waiting_for_screenshots_; 100 ++waiting_for_screenshots_;
74 screenshot_taken_for_ = host; 101 screenshot_taken_for_ = host;
75 NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry); 102 NavigationEntryScreenshotManager::TakeScreenshotImpl(host, entry);
103
104 // The screenshot-manager should start observing the lifetime of the
105 // WebContents, to make sure that it can cancel the screenshot requests if
106 // the WebContents is destroyed before the screenshot-capture completes.
107 EXPECT_TRUE(web_contents());
76 } 108 }
77 109
78 virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE { 110 virtual void OnScreenshotSet(NavigationEntryImpl* entry) OVERRIDE {
79 --waiting_for_screenshots_; 111 --waiting_for_screenshots_;
80 screenshot_set_[entry] = true; 112 screenshot_set_[entry] = true;
81 NavigationEntryScreenshotManager::OnScreenshotSet(entry); 113 NavigationEntryScreenshotManager::OnScreenshotSet(entry);
114 if (waiting_for_screenshots_ == 0) {
115 // If the screenshot manager is not waiting for any pending screenshot
116 // capture requests, then it shouldn't be observing the WebContents.
117 EXPECT_FALSE(web_contents());
118 }
82 if (waiting_for_screenshots_ == 0 && message_loop_runner_.get()) 119 if (waiting_for_screenshots_ == 0 && message_loop_runner_.get())
83 message_loop_runner_->Quit(); 120 message_loop_runner_->Quit();
84 } 121 }
85 122
86 RenderViewHost* screenshot_taken_for_; 123 RenderViewHost* screenshot_taken_for_;
87 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
88 int waiting_for_screenshots_; 125 int waiting_for_screenshots_;
89 std::map<NavigationEntryImpl*, bool> screenshot_set_; 126 std::map<NavigationEntryImpl*, bool> screenshot_set_;
90 127
91 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); 128 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 { GURL(), 0 } 548 { GURL(), 0 }
512 }; 549 };
513 550
514 screenshot_manager()->Reset(); 551 screenshot_manager()->Reset();
515 for (int i = 0; !navigations[i].url.is_empty(); ++i) { 552 for (int i = 0; !navigations[i].url.is_empty(); ++i) {
516 // Navigate via the user initiating a navigation from the UI. 553 // Navigate via the user initiating a navigation from the UI.
517 NavigationController::LoadURLParams params(navigations[i].url); 554 NavigationController::LoadURLParams params(navigations[i].url);
518 params.transition_type = PageTransitionFromInt(navigations[i].transition); 555 params.transition_type = PageTransitionFromInt(navigations[i].transition);
519 556
520 RenderViewHost* old_host = web_contents->GetRenderViewHost(); 557 RenderViewHost* old_host = web_contents->GetRenderViewHost();
558 scoped_ptr<RenderProcessHostTracker> process_tracker(
559 new RenderProcessHostTracker(old_host->GetProcess()));
560 EXPECT_TRUE(process_tracker->alive());
561
521 web_contents->GetController().LoadURLWithParams(params); 562 web_contents->GetController().LoadURLWithParams(params);
522 WaitForLoadStop(web_contents); 563 WaitForLoadStop(web_contents);
523 screenshot_manager()->WaitUntilScreenshotIsReady(); 564 screenshot_manager()->WaitUntilScreenshotIsReady();
565 // The RenderProcessHost should be destroyed, since this is a cross-process
566 // navigation.
567 EXPECT_FALSE(process_tracker->alive());
524 568
525 EXPECT_NE(old_host, web_contents->GetRenderViewHost()) 569 EXPECT_NE(old_host, web_contents->GetRenderViewHost())
526 << navigations[i].url.spec(); 570 << navigations[i].url.spec();
527 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for()); 571 EXPECT_EQ(old_host, screenshot_manager()->screenshot_taken_for());
528 572
529 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( 573 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
530 web_contents->GetController().GetEntryAtOffset(-1)); 574 web_contents->GetController().GetEntryAtOffset(-1));
531 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry)); 575 EXPECT_TRUE(screenshot_manager()->ScreenshotSetForEntry(entry));
532 576
533 entry = NavigationEntryImpl::FromNavigationEntry( 577 entry = NavigationEntryImpl::FromNavigationEntry(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 10); 702 10);
659 base::string16 actual_title = title_watcher.WaitAndGetTitle(); 703 base::string16 actual_title = title_watcher.WaitAndGetTitle();
660 EXPECT_EQ(expected_title, actual_title); 704 EXPECT_EQ(expected_title, actual_title);
661 705
662 EXPECT_EQ(2, GetCurrentIndex()); 706 EXPECT_EQ(2, GetCurrentIndex());
663 EXPECT_TRUE(controller.CanGoBack()); 707 EXPECT_TRUE(controller.CanGoBack());
664 EXPECT_FALSE(controller.CanGoForward()); 708 EXPECT_FALSE(controller.CanGoForward());
665 } 709 }
666 710
667 } // namespace content 711 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698