Chromium Code Reviews| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
| 9 #include "chrome/browser/ui/panels/panel.h" | 9 #include "chrome/browser/ui/panels/panel.h" |
| 10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
| 11 #include "chrome/browser/ui/panels/panel_browser_view.h" | 11 #include "chrome/browser/ui/panels/panel_browser_view.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/test/in_process_browser_test.h" | 13 #include "chrome/test/in_process_browser_test.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "views/controls/button/image_button.h" | 15 #include "views/controls/button/image_button.h" |
| 16 #include "views/controls/button/menu_button.h" | 16 #include "views/controls/button/menu_button.h" |
| 17 #include "views/controls/label.h" | 17 #include "views/controls/label.h" |
| 18 #include "views/controls/menu/menu_2.h" | |
| 18 | 19 |
| 19 | 20 |
| 20 class PanelBrowserViewTest : public InProcessBrowserTest { | 21 class PanelBrowserViewTest : public InProcessBrowserTest { |
| 21 public: | 22 public: |
| 22 PanelBrowserViewTest() : InProcessBrowserTest() { } | 23 PanelBrowserViewTest() : InProcessBrowserTest() { } |
| 23 | 24 |
| 24 virtual void SetUpCommandLine(CommandLine* command_line) { | 25 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 25 command_line->AppendSwitch(switches::kEnablePanels); | 26 command_line->AppendSwitch(switches::kEnablePanels); |
| 26 } | 27 } |
| 28 | |
| 29 protected: | |
| 30 PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name) { | |
| 31 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, | |
| 32 panel_name, | |
| 33 gfx::Size(), | |
| 34 browser()->profile()); | |
| 35 panel_browser->window()->Show(); | |
| 36 return static_cast<PanelBrowserView*>( | |
| 37 static_cast<Panel*>(panel_browser->window())->browser_window()); | |
| 38 } | |
| 39 | |
| 40 void ValidateSingleOptionsMenuItem( | |
| 41 ui::SimpleMenuModel* options_menu_contents, int id) { | |
| 42 ASSERT_TRUE(options_menu_contents); | |
| 43 EXPECT_EQ(1, options_menu_contents->GetItemCount()); | |
| 44 EXPECT_EQ(id, options_menu_contents->GetCommandIdAt(0)); | |
| 45 } | |
| 46 | |
| 47 void ValidateMultipleOptionsMenuItems( | |
| 48 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.
| |
| 49 ASSERT_TRUE(options_menu_contents); | |
| 50 EXPECT_EQ(4, options_menu_contents->GetItemCount()); | |
| 51 EXPECT_EQ(id1, options_menu_contents->GetCommandIdAt(0)); | |
| 52 EXPECT_EQ(id2, options_menu_contents->GetCommandIdAt(1)); | |
| 53 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | |
| 54 options_menu_contents->GetTypeAt(2)); | |
| 55 EXPECT_EQ(id3, options_menu_contents->GetCommandIdAt(3)); | |
| 56 } | |
| 27 }; | 57 }; |
| 28 | 58 |
| 29 // Panel is not supported for Linux view yet. | 59 // Panel is not supported for Linux view yet. |
| 30 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 60 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
| 31 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 61 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
| 32 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, | |
| 33 "PanelTest", | |
| 34 gfx::Size(), | |
| 35 browser()->profile()); | |
| 36 panel_browser->window()->Show(); | |
| 37 | |
| 38 PanelBrowserFrameView* frame_view = | 62 PanelBrowserFrameView* frame_view = |
| 39 static_cast<PanelBrowserView*>(static_cast<Panel*>( | 63 CreatePanelBrowserView("PanelTest")->GetFrameView(); |
| 40 panel_browser->window())->browser_window())->GetFrameView(); | |
| 41 | 64 |
| 42 // We should have icon, text, options button and close button. | 65 // We should have icon, text, options button and close button. |
| 43 EXPECT_EQ(4, frame_view->child_count()); | 66 EXPECT_EQ(4, frame_view->child_count()); |
| 44 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); | 67 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); |
| 45 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); | 68 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); |
| 46 EXPECT_TRUE(frame_view->Contains(frame_view->options_button_)); | 69 EXPECT_TRUE(frame_view->Contains(frame_view->options_button_)); |
| 47 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_)); | 70 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_)); |
| 48 | 71 |
| 49 // These controls should be visible. | 72 // These controls should be visible. |
| 50 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); | 73 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 76 frame_view->close_button_->x()); | 99 frame_view->close_button_->x()); |
| 77 | 100 |
| 78 // Validate that the controls should be updated when the activation state is | 101 // Validate that the controls should be updated when the activation state is |
| 79 // changed. | 102 // changed. |
| 80 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); | 103 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); |
| 81 SkColor title_label_color1 = frame_view->title_label_->GetColor(); | 104 SkColor title_label_color1 = frame_view->title_label_->GetColor(); |
| 82 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); | 105 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); |
| 83 SkColor title_label_color2 = frame_view->title_label_->GetColor(); | 106 SkColor title_label_color2 = frame_view->title_label_->GetColor(); |
| 84 EXPECT_NE(title_label_color1, title_label_color2); | 107 EXPECT_NE(title_label_color1, title_label_color2); |
| 85 } | 108 } |
| 109 | |
| 110 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateOptionsMenu) { | |
| 111 // With only one panel, we should only have 1 menu item: "About this panel". | |
| 112 PanelBrowserFrameView* frame_view1 = | |
| 113 CreatePanelBrowserView("PanelTest1")->GetFrameView(); | |
| 114 | |
| 115 frame_view1->CreateOptionsMenu(); | |
| 116 ASSERT_TRUE(frame_view1->options_menu_.get()); | |
| 117 ValidateSingleOptionsMenuItem(frame_view1->options_menu_contents_.get(), | |
| 118 PanelBrowserFrameView::kAboutCommand); | |
| 119 | |
| 120 // With another panel, we should have 4 menu items, including separator. | |
| 121 PanelBrowserFrameView* frame_view2 = | |
| 122 CreatePanelBrowserView("PanelTest2")->GetFrameView(); | |
| 123 | |
| 124 frame_view1->CreateOptionsMenu(); | |
| 125 ValidateMultipleOptionsMenuItems(frame_view1->options_menu_contents_.get(), | |
| 126 PanelBrowserFrameView::kMinimizeAllCommand, | |
| 127 PanelBrowserFrameView::kCloseAllCommand, | |
| 128 PanelBrowserFrameView::kAboutCommand); | |
| 129 | |
| 130 frame_view2->CreateOptionsMenu(); | |
| 131 ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), | |
| 132 PanelBrowserFrameView::kMinimizeAllCommand, | |
| 133 PanelBrowserFrameView::kCloseAllCommand, | |
| 134 PanelBrowserFrameView::kAboutCommand); | |
| 135 | |
| 136 // When we minimize one panel, "Minimize all" remain intact. | |
| 137 frame_view1->browser_view_->panel_->Minimize(); | |
| 138 | |
| 139 frame_view1->CreateOptionsMenu(); | |
| 140 ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), | |
| 141 PanelBrowserFrameView::kMinimizeAllCommand, | |
| 142 PanelBrowserFrameView::kCloseAllCommand, | |
| 143 PanelBrowserFrameView::kAboutCommand); | |
| 144 | |
| 145 frame_view2->CreateOptionsMenu(); | |
| 146 ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), | |
| 147 PanelBrowserFrameView::kMinimizeAllCommand, | |
| 148 PanelBrowserFrameView::kCloseAllCommand, | |
| 149 PanelBrowserFrameView::kAboutCommand); | |
| 150 | |
| 151 // When we minimize remaining panel, "Minimize all" should become | |
| 152 // "Restore all. | |
| 153 frame_view2->browser_view_->panel_->Minimize(); | |
| 154 | |
| 155 frame_view1->CreateOptionsMenu(); | |
| 156 ValidateMultipleOptionsMenuItems(frame_view1->options_menu_contents_.get(), | |
| 157 PanelBrowserFrameView::kRestoreAllCommand, | |
| 158 PanelBrowserFrameView::kCloseAllCommand, | |
| 159 PanelBrowserFrameView::kAboutCommand); | |
| 160 | |
| 161 frame_view2->CreateOptionsMenu(); | |
| 162 ValidateMultipleOptionsMenuItems(frame_view2->options_menu_contents_.get(), | |
| 163 PanelBrowserFrameView::kRestoreAllCommand, | |
| 164 PanelBrowserFrameView::kCloseAllCommand, | |
| 165 PanelBrowserFrameView::kAboutCommand); | |
| 166 | |
| 167 // When we close one panel, we should be back to have only 1 menu item. | |
| 168 frame_view1->browser_view_->panel_->Close(); | |
| 169 | |
| 170 frame_view2->CreateOptionsMenu(); | |
| 171 ValidateSingleOptionsMenuItem(frame_view2->options_menu_contents_.get(), | |
| 172 PanelBrowserFrameView::kAboutCommand); | |
| 173 } | |
| 86 #endif | 174 #endif |
| OLD | NEW |