OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
6 #include "chrome/browser/ui/views/dom_view.h" | 6 #include "chrome/browser/ui/views/dom_view.h" |
7 #include "chrome/test/base/in_process_browser_test.h" | 7 #include "chrome/test/base/in_process_browser_test.h" |
8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "content/public/browser/notification_service.h" |
9 #include "content/public/browser/notification_types.h" | 10 #include "content/public/browser/notification_types.h" |
10 #include "views/widget/widget.h" | 11 #include "views/widget/widget.h" |
11 | 12 |
12 using views::Widget; | 13 using views::Widget; |
13 | 14 |
14 class DOMViewTest : public InProcessBrowserTest { | 15 class DOMViewTest : public InProcessBrowserTest { |
15 public: | 16 public: |
16 Widget* CreatePopupWindow() { | 17 Widget* CreatePopupWindow() { |
17 Widget* widget = new Widget; | 18 Widget* widget = new Widget; |
18 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 19 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
19 params.bounds = gfx::Rect(0, 0, 400, 400); | 20 params.bounds = gfx::Rect(0, 0, 400, 400); |
20 widget->Init(params); | 21 widget->Init(params); |
21 return widget; | 22 return widget; |
22 } | 23 } |
23 }; | 24 }; |
24 | 25 |
25 // Tests if creating and deleting dom_view | 26 // Tests if creating and deleting dom_view |
26 // does not crash and leak memory. | 27 // does not crash and leak memory. |
27 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestShowAndHide) { | 28 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestShowAndHide) { |
28 Widget* one = CreatePopupWindow(); | 29 Widget* one = CreatePopupWindow(); |
29 | 30 |
30 DOMView* dom_view = new DOMView(); | 31 DOMView* dom_view = new DOMView(); |
31 one->GetRootView()->AddChildView(dom_view); | 32 one->GetRootView()->AddChildView(dom_view); |
32 | 33 |
33 dom_view->Init(browser()->profile(), NULL); | 34 dom_view->Init(browser()->profile(), NULL); |
34 ui_test_utils::WindowedNotificationObserver load_stop_observer( | 35 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
35 content::NOTIFICATION_LOAD_STOP, | 36 content::NOTIFICATION_LOAD_STOP, |
36 NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
37 dom_view->LoadURL(GURL("http://www.google.com")); | 38 dom_view->LoadURL(GURL("http://www.google.com")); |
38 load_stop_observer.Wait(); | 39 load_stop_observer.Wait(); |
39 one->Show(); | 40 one->Show(); |
40 | 41 |
41 ui_test_utils::RunAllPendingInMessageLoop(); | 42 ui_test_utils::RunAllPendingInMessageLoop(); |
42 | 43 |
43 one->Hide(); | 44 one->Hide(); |
44 } | 45 } |
45 | 46 |
46 // Tests if removing from tree then deleting dom_view | 47 // Tests if removing from tree then deleting dom_view |
47 // does not crash and leak memory. | 48 // does not crash and leak memory. |
48 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestRemoveAndDelete) { | 49 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestRemoveAndDelete) { |
49 Widget* one = CreatePopupWindow(); | 50 Widget* one = CreatePopupWindow(); |
50 | 51 |
51 DOMView* dom_view = new DOMView(); | 52 DOMView* dom_view = new DOMView(); |
52 one->GetRootView()->AddChildView(dom_view); | 53 one->GetRootView()->AddChildView(dom_view); |
53 | 54 |
54 dom_view->Init(browser()->profile(), NULL); | 55 dom_view->Init(browser()->profile(), NULL); |
55 ui_test_utils::WindowedNotificationObserver load_stop_observer( | 56 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
56 content::NOTIFICATION_LOAD_STOP, | 57 content::NOTIFICATION_LOAD_STOP, |
57 NotificationService::AllSources()); | 58 content::NotificationService::AllSources()); |
58 dom_view->LoadURL(GURL("http://www.google.com")); | 59 dom_view->LoadURL(GURL("http://www.google.com")); |
59 load_stop_observer.Wait(); | 60 load_stop_observer.Wait(); |
60 one->Show(); | 61 one->Show(); |
61 | 62 |
62 ui_test_utils::RunAllPendingInMessageLoop(); | 63 ui_test_utils::RunAllPendingInMessageLoop(); |
63 | 64 |
64 one->GetRootView()->RemoveChildView(dom_view); | 65 one->GetRootView()->RemoveChildView(dom_view); |
65 | 66 |
66 delete dom_view; | 67 delete dom_view; |
67 | 68 |
68 one->Hide(); | 69 one->Hide(); |
69 } | 70 } |
70 | 71 |
71 // Tests if reparenting dom_view does not crash and does not leak | 72 // Tests if reparenting dom_view does not crash and does not leak |
72 // memory. | 73 // memory. |
73 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestReparent) { | 74 IN_PROC_BROWSER_TEST_F(DOMViewTest, TestReparent) { |
74 Widget* one = CreatePopupWindow(); | 75 Widget* one = CreatePopupWindow(); |
75 | 76 |
76 DOMView* dom_view = new DOMView(); | 77 DOMView* dom_view = new DOMView(); |
77 one->GetRootView()->AddChildView(dom_view); | 78 one->GetRootView()->AddChildView(dom_view); |
78 | 79 |
79 dom_view->Init(browser()->profile(), NULL); | 80 dom_view->Init(browser()->profile(), NULL); |
80 ui_test_utils::WindowedNotificationObserver load_stop_observer( | 81 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
81 content::NOTIFICATION_LOAD_STOP, | 82 content::NOTIFICATION_LOAD_STOP, |
82 NotificationService::AllSources()); | 83 content::NotificationService::AllSources()); |
83 dom_view->LoadURL(GURL("http://www.google.com")); | 84 dom_view->LoadURL(GURL("http://www.google.com")); |
84 load_stop_observer.Wait(); | 85 load_stop_observer.Wait(); |
85 one->Show(); | 86 one->Show(); |
86 | 87 |
87 ui_test_utils::RunAllPendingInMessageLoop(); | 88 ui_test_utils::RunAllPendingInMessageLoop(); |
88 | 89 |
89 one->GetRootView()->RemoveChildView(dom_view); | 90 one->GetRootView()->RemoveChildView(dom_view); |
90 one->Hide(); | 91 one->Hide(); |
91 | 92 |
92 // Re-attach to another Widget. | 93 // Re-attach to another Widget. |
93 Widget* two = CreatePopupWindow(); | 94 Widget* two = CreatePopupWindow(); |
94 two->GetRootView()->AddChildView(dom_view); | 95 two->GetRootView()->AddChildView(dom_view); |
95 two->Show(); | 96 two->Show(); |
96 | 97 |
97 ui_test_utils::RunAllPendingInMessageLoop(); | 98 ui_test_utils::RunAllPendingInMessageLoop(); |
98 | 99 |
99 two->Hide(); | 100 two->Hide(); |
100 } | 101 } |
OLD | NEW |