Index: chrome/browser/ui/panels/panel_browser_view_browsertest.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_browser_view_browsertest.cc (revision 86006) |
+++ chrome/browser/ui/panels/panel_browser_view_browsertest.cc (working copy) |
@@ -13,11 +13,8 @@ |
#include "chrome/test/in_process_browser_test.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "views/controls/button/image_button.h" |
-#include "views/controls/button/menu_button.h" |
#include "views/controls/label.h" |
-#include "views/controls/menu/menu_2.h" |
- |
class PanelBrowserViewTest : public InProcessBrowserTest { |
public: |
PanelBrowserViewTest() : InProcessBrowserTest() { } |
@@ -27,6 +24,35 @@ |
} |
protected: |
+ class MockMouseWatcher : public PanelBrowserFrameView::MouseWatcher { |
+ public: |
+ explicit MockMouseWatcher(PanelBrowserFrameView* view) |
+ : PanelBrowserFrameView::MouseWatcher(view), |
+ cursor_in_view_(false) { |
Dmitry Titov
2011/05/24 20:21:56
Same: "is_cursor_in_view_"?
jianli
2011/05/24 21:58:56
Done.
|
+ } |
+ |
+ virtual bool IsCursorInViewBounds() const { |
+ return cursor_in_view_; |
+ } |
+ |
+ void MoveMouse(bool cursor_in_view) { |
+ cursor_in_view_ = cursor_in_view; |
+ |
+#if defined(OS_WIN) |
+ MSG msg; |
+ msg.message = WM_MOUSEMOVE; |
+ DidProcessMessage(msg); |
+#else |
+ GdkEvent event; |
+ event.type = GDK_MOTION_NOTIFY; |
+ DidProcessEvent(&event); |
+#endif |
+ } |
+ |
+ private: |
+ bool cursor_in_view_; |
+ }; |
+ |
PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { |
Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
panel_name, |
@@ -37,20 +63,6 @@ |
static_cast<Panel*>(panel_browser->window())->browser_window()); |
} |
- void ValidateOptionsMenuItems( |
- ui::SimpleMenuModel* options_menu_contents, size_t count, int* ids) { |
- ASSERT_TRUE(options_menu_contents); |
- EXPECT_EQ(static_cast<int>(count), options_menu_contents->GetItemCount()); |
- for (size_t i = 0; i < count; ++i) { |
- if (ids[i] == -1) { |
- EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, |
- options_menu_contents->GetTypeAt(i)); |
- } else { |
- EXPECT_EQ(ids[i] , options_menu_contents->GetCommandIdAt(i)); |
- } |
- } |
- } |
- |
void ValidateDragging(PanelBrowserView** browser_views, |
size_t num_browser_views, |
size_t index_to_drag, |
@@ -155,7 +167,6 @@ |
// These controls should be visible. |
EXPECT_TRUE(frame_view->title_icon_->IsVisible()); |
EXPECT_TRUE(frame_view->title_label_->IsVisible()); |
- EXPECT_TRUE(frame_view->info_button_->IsVisible()); |
EXPECT_TRUE(frame_view->close_button_->IsVisible()); |
// Validate their layouts. |
@@ -190,6 +201,37 @@ |
EXPECT_NE(title_label_font1.GetStyle(), title_label_font2.GetStyle()); |
} |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ShowOrHideInfoButton) { |
Dmitry Titov
2011/05/24 20:21:56
I wonder if it can be a unit test. The benefit of
jianli
2011/05/24 21:58:56
For this case, probably we need to use browser tes
|
+ PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest"); |
+ PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
+ |
+ // Create and hook up the MockMouseWatcher so that we can simulate if the |
+ // mouse is over the panel. |
+ MockMouseWatcher* mouse_watcher = new MockMouseWatcher(frame_view); |
+ frame_view->set_mouse_watcher(mouse_watcher); |
+ |
+ // When the panel is created, it is active. Since we cannot programatically |
+ // bring the panel back to active state once it is deactivated, we have to |
+ // test the cases that the panel is active first. |
+ EXPECT_TRUE(browser_view->panel()->IsActive()); |
+ |
+ // When the panel is active, the info button should always be visible. |
+ mouse_watcher->MoveMouse(true); |
+ EXPECT_TRUE(frame_view->info_button_->IsVisible()); |
+ mouse_watcher->MoveMouse(false); |
+ EXPECT_TRUE(frame_view->info_button_->IsVisible()); |
+ |
+ // When the panel is inactive, the info button is active per the mouse over |
+ // the panel or not. |
+ browser_view->panel()->Deactivate(); |
+ EXPECT_FALSE(browser_view->panel()->IsActive()); |
+ |
+ mouse_watcher->MoveMouse(true); |
+ EXPECT_TRUE(frame_view->info_button_->IsVisible()); |
+ mouse_watcher->MoveMouse(false); |
+ EXPECT_FALSE(frame_view->info_button_->IsVisible()); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, TitleBarMouseEvent) { |
// TODO(jianli): Move the test to platform-independent PanelManager unittest. |