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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 196283013: Make to call WebContentsImpl::RenderViewCreated() when we create child window. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/values.h" 5 #include "base/values.h"
6 #include "content/browser/frame_host/navigation_entry_impl.h" 6 #include "content/browser/frame_host/navigation_entry_impl.h"
7 #include "content/browser/web_contents/web_contents_impl.h" 7 #include "content/browser/web_contents/web_contents_impl.h"
8 #include "content/public/browser/load_notification_details.h" 8 #include "content/public/browser/load_notification_details.h"
9 #include "content/public/browser/navigation_controller.h" 9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/notification_details.h" 10 #include "content/public/browser/notification_details.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 // Install the observer and navigate cross-site. 378 // Install the observer and navigate cross-site.
379 RenderFrameCreatedObserver observer(shell()); 379 RenderFrameCreatedObserver observer(shell());
380 NavigateToURL(shell(), cross_site_url); 380 NavigateToURL(shell(), cross_site_url);
381 381
382 // The observer should've seen a RenderFrameCreated call for the new frame 382 // The observer should've seen a RenderFrameCreated call for the new frame
383 // and not the old one. 383 // and not the old one.
384 EXPECT_NE(observer.last_rfh(), orig_rfh); 384 EXPECT_NE(observer.last_rfh(), orig_rfh);
385 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame()); 385 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame());
386 } 386 }
387 387
388 class RenderViewCreatedObserver : public WebContentsObserver {
389 public:
390 static void Create(WebContents* web_contents) {
391 current_ = new RenderViewCreatedObserver(web_contents);
392 }
393
394 static void Clean() {
395 if (!current_) return;
396 delete current_;
397 current_ = NULL;
398 }
399
400 public:
401 RenderViewCreatedObserver(WebContents* web_contents)
402 : WebContentsObserver(web_contents),
403 call_render_view_created_(false) {
404 }
405
406 // WebContentsObserver:
407 virtual void RenderViewCreated(RenderViewHost* rvh) OVERRIDE {
408 call_render_view_created_ = true;
409 }
410
411 bool call_render_view_created_;
412 static RenderViewCreatedObserver* current_;
413 };
414
415 RenderViewCreatedObserver* RenderViewCreatedObserver::current_ = NULL;
416
417 class NewChildWindowNotificationObserver : public WindowedNotificationObserver {
418 public:
419 NewChildWindowNotificationObserver(WebContents* web_contens)
420 : WindowedNotificationObserver(
421 NOTIFICATION_WEB_CONTENTS_CREATE_NEW_WINDOW,
422 Source<WebContents>(web_contens)) {
423 }
424 virtual void Observe(int type,
425 const NotificationSource& source,
426 const NotificationDetails& details) OVERRIDE {
427 if (type ==
428 NOTIFICATION_WEB_CONTENTS_CREATE_NEW_WINDOW) {
429 WebContents* child_web_contents =
430 content::Details<WebContents>(details).ptr();
431 RenderViewCreatedObserver::Create(child_web_contents);
432 }
433 WindowedNotificationObserver::Observe(type, source, details);
434 }
435 };
436
437 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
438 RenderViewCreatedForChildWindow) {
439 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
440
441 NewChildWindowNotificationObserver observer(shell()->web_contents());
Charlie Reis 2014/04/29 16:55:25 You can use a ShellAddedObserver here instead, wit
442 NavigateToURL(shell(),
443 embedded_test_server()->GetURL("/openChildWindow.html"));
444
445 observer.Wait();
446 EXPECT_TRUE(
447 RenderViewCreatedObserver::current_->call_render_view_created_ == true);
Charlie Reis 2014/04/29 16:55:25 nit: No need for "== true"
448 RenderViewCreatedObserver::Clean();
449 }
450
388 } // namespace content 451 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698