Index: content/browser/web_contents/web_contents_impl_browsertest.cc |
=================================================================== |
--- content/browser/web_contents/web_contents_impl_browsertest.cc (revision 256801) |
+++ content/browser/web_contents/web_contents_impl_browsertest.cc (working copy) |
@@ -385,4 +385,67 @@ |
EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame()); |
} |
+class RenderViewCreatedObserver : public WebContentsObserver { |
+ public: |
+ static void Create(WebContents* web_contents) { |
+ current_ = new RenderViewCreatedObserver(web_contents); |
+ } |
+ |
+ static void Clean() { |
+ if (!current_) return; |
+ delete current_; |
+ current_ = NULL; |
+ } |
+ |
+ public: |
+ RenderViewCreatedObserver(WebContents* web_contents) |
+ : WebContentsObserver(web_contents), |
+ call_render_view_created_(false) { |
+ } |
+ |
+ // WebContentsObserver: |
+ virtual void RenderViewCreated(RenderViewHost* rvh) OVERRIDE { |
+ call_render_view_created_ = true; |
+ } |
+ |
+ bool call_render_view_created_; |
+ static RenderViewCreatedObserver* current_; |
+}; |
+ |
+RenderViewCreatedObserver* RenderViewCreatedObserver::current_ = NULL; |
+ |
+class NewChildWindowNotificationObserver : public WindowedNotificationObserver { |
+ public: |
+ NewChildWindowNotificationObserver(WebContents* web_contens) |
+ : WindowedNotificationObserver( |
+ NOTIFICATION_WEB_CONTENTS_CREATE_NEW_WINDOW, |
+ Source<WebContents>(web_contens)) { |
+ } |
+ virtual void Observe(int type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) OVERRIDE { |
+ if (type == |
+ NOTIFICATION_WEB_CONTENTS_CREATE_NEW_WINDOW) { |
+ WebContents* child_web_contents = |
+ content::Details<WebContents>(details).ptr(); |
+ RenderViewCreatedObserver::Create(child_web_contents); |
+ } |
+ WindowedNotificationObserver::Observe(type, source, details); |
+ } |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
+ RenderViewCreatedForChildWindow) { |
+ ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
+ |
+ NewChildWindowNotificationObserver observer(shell()->web_contents()); |
Charlie Reis
2014/04/29 16:55:25
You can use a ShellAddedObserver here instead, wit
|
+ NavigateToURL(shell(), |
+ embedded_test_server()->GetURL("/openChildWindow.html")); |
+ |
+ observer.Wait(); |
+ EXPECT_TRUE( |
+ RenderViewCreatedObserver::current_->call_render_view_created_ == true); |
Charlie Reis
2014/04/29 16:55:25
nit: No need for "== true"
|
+ RenderViewCreatedObserver::Clean(); |
+} |
+ |
} // namespace content |