• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/ui/browser.h"
6 #include "chrome/browser/ui/views/dom_view.h"
7 #include "chrome/test/in_process_browser_test.h"
8 #include "chrome/test/ui_test_utils.h"
9 #include "views/widget/root_view.h"
10 #include "views/widget/widget.h"
11 
12 using namespace views;
13 
14 class DOMViewTest : public InProcessBrowserTest {
15  public:
CreatePopupWindow()16   Widget* CreatePopupWindow() {
17     Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP);
18     params.mirror_origin_in_rtl = false;
19     Widget* widget = Widget::CreateWidget(params);
20     widget->Init(NULL, gfx::Rect(0, 0, 400, 400));
21     return widget;
22   }
23 };
24 
25 // Tests if creating and deleting dom_view
26 // does not crash and leak memory.
IN_PROC_BROWSER_TEST_F(DOMViewTest,TestShowAndHide)27 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestShowAndHide) {
28   Widget* one = CreatePopupWindow();
29 
30   DOMView* dom_view = new DOMView();
31   one->GetRootView()->AddChildView(dom_view);
32 
33   dom_view->Init(browser()->profile(), NULL);
34   dom_view->LoadURL(GURL("http://www.google.com"));
35   ui_test_utils::WaitForNotification(NotificationType::LOAD_STOP);
36   one->Show();
37 
38   ui_test_utils::RunAllPendingInMessageLoop();
39 
40   one->Hide();
41 }
42 
43 // Tests if removing from tree then deleting dom_view
44 // does not crash and leak memory.
IN_PROC_BROWSER_TEST_F(DOMViewTest,TestRemoveAndDelete)45 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestRemoveAndDelete) {
46   Widget* one = CreatePopupWindow();
47 
48   DOMView* dom_view = new DOMView();
49   one->GetRootView()->AddChildView(dom_view);
50 
51   dom_view->Init(browser()->profile(), NULL);
52   dom_view->LoadURL(GURL("http://www.google.com"));
53   ui_test_utils::WaitForNotification(NotificationType::LOAD_STOP);
54   one->Show();
55 
56   ui_test_utils::RunAllPendingInMessageLoop();
57 
58   one->GetRootView()->RemoveChildView(dom_view);
59 
60   delete dom_view;
61 
62   one->Hide();
63 }
64 
65 // Tests if reparenting dom_view does not crash and does not leak
66 // memory.
IN_PROC_BROWSER_TEST_F(DOMViewTest,TestReparent)67 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestReparent) {
68   Widget* one = CreatePopupWindow();
69 
70   DOMView* dom_view = new DOMView();
71   one->GetRootView()->AddChildView(dom_view);
72 
73   dom_view->Init(browser()->profile(), NULL);
74   dom_view->LoadURL(GURL("http://www.google.com"));
75   ui_test_utils::WaitForNotification(NotificationType::LOAD_STOP);
76   one->Show();
77 
78   ui_test_utils::RunAllPendingInMessageLoop();
79 
80   one->GetRootView()->RemoveChildView(dom_view);
81   one->Hide();
82 
83   // Re-attach to another Widget.
84   Widget* two = CreatePopupWindow();
85   two->GetRootView()->AddChildView(dom_view);
86   two->Show();
87 
88   ui_test_utils::RunAllPendingInMessageLoop();
89 
90   two->Hide();
91 }
92