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