summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 16:42:16 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-01 16:42:16 +0000
commit754bebc123ff35ecd50c68f43b7675953b1cb431 (patch)
tree744f3516d716d7c4ca66c98424a05176d64cc789
parent0e12d7d59d4778e1a8ef692d244bf66aea1a80b8 (diff)
downloadchromium_src-754bebc123ff35ecd50c68f43b7675953b1cb431.zip
chromium_src-754bebc123ff35ecd50c68f43b7675953b1cb431.tar.gz
chromium_src-754bebc123ff35ecd50c68f43b7675953b1cb431.tar.bz2
aura: Fix unit_tests on linux
Make sure the aura::Desktop is destroyed with the message-loop. This is done by adding a DestroyMessagePump notification to MessagePumpObserver. Also remove some views_unittests that were added to test NativeWidgetViews (which aren't used anymore), and do proper cleanup in AccessibilityEventRouter unittest. TBR=darin@chromium.org BUG=104559, 105613 TEST=unit_tests Review URL: http://codereview.chromium.org/8566037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112474 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_pump_x.cc8
-rw-r--r--chrome/browser/profiles/profile_info_cache_unittest.cc8
-rw-r--r--chrome/browser/ui/views/accessibility_event_router_views_unittest.cc12
-rw-r--r--ui/aura/desktop.cc11
-rw-r--r--ui/aura/desktop_host_linux.cc18
-rw-r--r--ui/views/widget/widget_unittest.cc62
6 files changed, 25 insertions, 94 deletions
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc
index 3b1ed3d..8a253df 100644
--- a/base/message_pump_x.cc
+++ b/base/message_pump_x.cc
@@ -183,6 +183,8 @@ bool MessagePumpX::RunOnce(GMainContext* context, bool block) {
}
bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
+ if (!observers().might_have_observers())
+ return false;
ObserverListBase<MessagePumpObserver>::Iterator it(observers());
MessagePumpObserver* obs;
while ((obs = it.GetNext()) != NULL) {
@@ -193,11 +195,7 @@ bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
}
void MessagePumpX::DidProcessXEvent(XEvent* xevent) {
- ObserverListBase<MessagePumpObserver>::Iterator it(observers());
- MessagePumpObserver* obs;
- while ((obs = it.GetNext()) != NULL) {
- obs->DidProcessEvent(xevent);
- }
+ FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent));
}
} // namespace base
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index a3009c4..ccbefcf 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -305,13 +305,7 @@ TEST_F(ProfileInfoCacheTest, GAIAPicture) {
profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
}
-#if defined(USE_AURA)
-#define MAYBE_PersistGAIAPicture DISABLED_PersistGAIAPicture
-#else
-#define MAYBE_PersistGAIAPicture PersistGAIAPicture
-#endif
-
-TEST_F(ProfileInfoCacheTest, MAYBE_PersistGAIAPicture) {
+TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) {
GetCache()->AddProfileToCache(
GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
gfx::Image gaia_image(gfx::test::CreateImage());
diff --git a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
index 1f5dbba..be7c828 100644
--- a/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
+++ b/chrome/browser/ui/views/accessibility_event_router_views_unittest.cc
@@ -90,20 +90,17 @@ class AccessibilityEventRouterViewsTest
public:
virtual void SetUp() {
views::ViewsDelegate::views_delegate = new AccessibilityViewsDelegate();
- window_delegate_ = NULL;
}
virtual void TearDown() {
delete views::ViewsDelegate::views_delegate;
views::ViewsDelegate::views_delegate = NULL;
- if (window_delegate_)
- delete window_delegate_;
}
views::Widget* CreateWindowWithContents(views::View* contents) {
- window_delegate_ = new AccessibilityWindowDelegate(contents);
- return views::Widget::CreateWindowWithBounds(window_delegate_,
- gfx::Rect(0, 0, 500, 500));
+ return views::Widget::CreateWindowWithBounds(
+ new AccessibilityWindowDelegate(contents),
+ gfx::Rect(0, 0, 500, 500));
}
protected:
@@ -122,7 +119,6 @@ class AccessibilityEventRouterViewsTest
MessageLoopForUI message_loop_;
int focus_event_count_;
std::string last_control_name_;
- AccessibilityWindowDelegate* window_delegate_;
};
TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
@@ -184,6 +180,8 @@ TEST_F(AccessibilityEventRouterViewsTest, TestFocusNotification) {
focus_manager->AdvanceFocus(false);
EXPECT_EQ(3, focus_event_count_);
EXPECT_EQ(kButton1ASCII, last_control_name_);
+
+ window->CloseNow();
}
#endif // defined(TOOLKIT_VIEWS)
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc
index f5bd54d..fd2e38a 100644
--- a/ui/aura/desktop.cc
+++ b/ui/aura/desktop.cc
@@ -32,10 +32,6 @@
#include "ui/gfx/compositor/compositor_cc.h"
#endif
-#if defined(USE_X11)
-#include "base/message_pump_x.h"
-#endif
-
using std::string;
using std::vector;
@@ -429,16 +425,9 @@ Desktop::Desktop()
host_->GetSize());
}
DCHECK(compositor_.get());
-#if defined(USE_X11)
- base::MessagePumpX::SetDefaultDispatcher(host_.get());
-#endif
}
Desktop::~Desktop() {
-#if defined(USE_X11)
- base::MessagePumpX::SetDefaultDispatcher(NULL);
-#endif
-
in_destructor_ = true;
#ifdef USE_WEBKIT_COMPOSITOR
if (!ui::Compositor::compositor_factory())
diff --git a/ui/aura/desktop_host_linux.cc b/ui/aura/desktop_host_linux.cc
index 9934467..48dcf7f 100644
--- a/ui/aura/desktop_host_linux.cc
+++ b/ui/aura/desktop_host_linux.cc
@@ -222,13 +222,14 @@ bool ShouldSendCharEventForKeyboardCode(ui::KeyboardCode keycode) {
}
}
-class DesktopHostLinux : public DesktopHost {
+class DesktopHostLinux : public DesktopHost,
+ public MessageLoop::DestructionObserver {
public:
explicit DesktopHostLinux(const gfx::Rect& bounds);
virtual ~DesktopHostLinux();
private:
- // base::MessageLoop::Dispatcher Override.
+ // MessageLoop::Dispatcher Override.
virtual DispatchStatus Dispatch(XEvent* xev) OVERRIDE;
// DesktopHost Overrides.
@@ -243,6 +244,9 @@ class DesktopHostLinux : public DesktopHost {
virtual gfx::Point QueryMouseLocation() OVERRIDE;
virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE;
+ // MessageLoop::DestructionObserver Overrides.
+ virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
+
// Returns true if there's an X window manager present... in most cases. Some
// window managers (notably, ion3) don't implement enough of ICCCM for us to
// detect that they're there.
@@ -292,6 +296,9 @@ DesktopHostLinux::DesktopHostLinux(const gfx::Rect& bounds)
if (base::MessagePumpForUI::HasXInput2())
ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_);
#endif
+
+ base::MessagePumpX::SetDefaultDispatcher(this);
+ MessageLoopForUI::current()->AddDestructionObserver(this);
}
DesktopHostLinux::~DesktopHostLinux() {
@@ -299,6 +306,9 @@ DesktopHostLinux::~DesktopHostLinux() {
// Clears XCursorCache.
ui::GetXCursor(ui::kCursorClearXCursorCache);
+
+ MessageLoopForUI::current()->RemoveDestructionObserver(this);
+ base::MessagePumpX::SetDefaultDispatcher(NULL);
}
base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
@@ -534,6 +544,10 @@ void DesktopHostLinux::PostNativeEvent(const base::NativeEvent& native_event) {
DLOG(WARNING) << "PostEvent:" << xevent.type << ", status=" << status;
}
+void DesktopHostLinux::WillDestroyCurrentMessageLoop() {
+ desktop_->DeleteInstance();
+}
+
bool DesktopHostLinux::IsWindowManagerPresent() {
// Per ICCCM 2.8, "Manager Selections", window managers should take ownership
// of WM_Sn selections (where n is a screen number).
diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc
index 81e7515..63d27ef 100644
--- a/ui/views/widget/widget_unittest.cc
+++ b/ui/views/widget/widget_unittest.cc
@@ -172,39 +172,6 @@ TEST_F(WidgetTest, GetTopLevelWidget_Native) {
// |child| should be automatically destroyed with |toplevel|.
}
-TEST_F(WidgetTest, GetTopLevelWidget_Synthetic) {
- // Create a hierarchy consisting of a top level platform native widget and a
- // child NativeWidget.
- Widget* toplevel = CreateTopLevelPlatformWidget();
- Widget* child = CreateTopLevelNativeWidget();
-
- EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget());
- EXPECT_EQ(child, child->GetTopLevelWidget());
-
- toplevel->CloseNow();
- // |child| should be automatically destroyed with |toplevel|.
-}
-
-// Creates a hierarchy consisting of a desktop platform native widget, a
-// toplevel NativeWidget, and a child of that toplevel, another NativeWidget.
-TEST_F(WidgetTest, GetTopLevelWidget_SyntheticDesktop) {
- // Create a hierarchy consisting of a desktop platform native widget,
- // a toplevel NativeWidget and a chlid NativeWidget.
- Widget* desktop = CreateTopLevelPlatformWidget();
- Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented
- // automatically to
- // |toplevel|.
-
- Widget* child = CreateChildNativeWidgetWithParent(toplevel);
-
- EXPECT_EQ(desktop, desktop->GetTopLevelWidget());
- EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget());
- EXPECT_EQ(toplevel, child->GetTopLevelWidget());
-
- desktop->CloseNow();
- // |toplevel|, |child| should be automatically destroyed with |toplevel|.
-}
-
// Tests some grab/ungrab events.
TEST_F(WidgetTest, DISABLED_GrabUngrab) {
Widget* toplevel = CreateTopLevelPlatformWidget();
@@ -342,35 +309,6 @@ TEST_F(WidgetTest, Visibility_ChildPopup) {
}
#endif
-// Tests visibility of synthetic child widgets.
-TEST_F(WidgetTest, Visibility_Synthetic) {
- // Create a hierarchy consisting of a desktop platform native widget,
- // a toplevel NativeWidget and a chlid NativeWidget.
- Widget* desktop = CreateTopLevelPlatformWidget();
- desktop->Show();
-
- Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented
- // automatically to
- // |toplevel|.
-
- Widget* child = CreateChildNativeWidgetWithParent(toplevel);
-
- EXPECT_FALSE(toplevel->IsVisible());
- EXPECT_FALSE(child->IsVisible());
-
- child->Show();
-
- EXPECT_FALSE(toplevel->IsVisible());
- EXPECT_FALSE(child->IsVisible());
-
- toplevel->Show();
-
- EXPECT_TRUE(toplevel->IsVisible());
- EXPECT_TRUE(child->IsVisible());
-
- desktop->CloseNow();
-}
-
////////////////////////////////////////////////////////////////////////////////
// Widget ownership tests.
//