Index: chrome/browser/ui/panels/panel_browser_view_browsertest.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_browser_view_browsertest.cc (revision 84709) |
+++ chrome/browser/ui/panels/panel_browser_view_browsertest.cc (working copy) |
@@ -15,6 +15,7 @@ |
#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 { |
@@ -24,20 +25,42 @@ |
virtual void SetUpCommandLine(CommandLine* command_line) { |
command_line->AppendSwitch(switches::kEnablePanels); |
} |
+ |
+ protected: |
+ PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { |
+ Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
+ panel_name, |
+ gfx::Size(), |
+ browser()->profile()); |
+ panel_browser->window()->Show(); |
+ return static_cast<PanelBrowserView*>( |
+ static_cast<Panel*>(panel_browser->window())->browser_window()); |
+ } |
+ |
+ void ValidateSingleOptionsMenuItem( |
+ ui::SimpleMenuModel* options_menu_contents, int id) { |
+ ASSERT_TRUE(options_menu_contents); |
+ EXPECT_EQ(1, options_menu_contents->GetItemCount()); |
+ EXPECT_EQ(id, options_menu_contents->GetCommandIdAt(0)); |
+ } |
+ |
+ void ValidateMultipleOptionsMenuItems( |
+ ui::SimpleMenuModel* options_menu_contents, int id1, int id2, int id3) { |
jennb
2011/05/10 22:38:44
You could make this more flexible and pass in expe
jianli
2011/05/10 23:46:58
Done.
|
+ ASSERT_TRUE(options_menu_contents); |
+ EXPECT_EQ(4, options_menu_contents->GetItemCount()); |
+ EXPECT_EQ(id1, options_menu_contents->GetCommandIdAt(0)); |
+ EXPECT_EQ(id2, options_menu_contents->GetCommandIdAt(1)); |
+ EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, |
+ options_menu_contents->GetTypeAt(2)); |
+ EXPECT_EQ(id3, options_menu_contents->GetCommandIdAt(3)); |
+ } |
}; |
// Panel is not supported for Linux view yet. |
#if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
- Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
- "PanelTest", |
- gfx::Size(), |
- browser()->profile()); |
- panel_browser->window()->Show(); |
- |
PanelBrowserFrameView* frame_view = |
- static_cast<PanelBrowserView*>(static_cast<Panel*>( |
- panel_browser->window())->browser_window())->GetFrameView(); |
+ CreatePanelBrowserView("PanelTest")->GetFrameView(); |
// We should have icon, text, options button and close button. |
EXPECT_EQ(4, frame_view->child_count()); |
@@ -83,4 +106,69 @@ |
SkColor title_label_color2 = frame_view->title_label_->GetColor(); |
EXPECT_NE(title_label_color1, title_label_color2); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateOptionsMenu) { |
+ // With only one panel, we should only have 1 menu item: "About this panel". |
+ PanelBrowserFrameView* frame_view1 = |
+ CreatePanelBrowserView("PanelTest1")->GetFrameView(); |
+ |
+ frame_view1->CreateOptionsMenu(); |
+ ASSERT_TRUE(frame_view1->options_menu_.get()); |
+ ValidateSingleOptionsMenuItem(frame_view1->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ // With another panel, we should have 4 menu items, including separator. |
+ PanelBrowserFrameView* frame_view2 = |
+ CreatePanelBrowserView("PanelTest2")->GetFrameView(); |
+ |
+ frame_view1->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view1->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kMinimizeAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ frame_view2->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kMinimizeAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ // When we minimize one panel, "Minimize all" remain intact. |
+ frame_view1->browser_view_->panel_->Minimize(); |
+ |
+ frame_view1->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kMinimizeAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ frame_view2->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kMinimizeAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ // When we minimize remaining panel, "Minimize all" should become |
+ // "Restore all. |
+ frame_view2->browser_view_->panel_->Minimize(); |
+ |
+ frame_view1->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view1->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kRestoreAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ frame_view2->CreateOptionsMenu(); |
+ ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kRestoreAllCommand, |
+ PanelBrowserFrameView::kCloseAllCommand, |
+ PanelBrowserFrameView::kAboutCommand); |
+ |
+ // When we close one panel, we should be back to have only 1 menu item. |
+ frame_view1->browser_view_->panel_->Close(); |
+ |
+ frame_view2->CreateOptionsMenu(); |
+ ValidateSingleOptionsMenuItem(frame_view2->options_menu_contents_.get(), |
+ PanelBrowserFrameView::kAboutCommand); |
+} |
#endif |