Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: chrome/browser/ui/panels/panel_browser_view_browsertest.cc

Issue 7005006: Add options menu on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 ValidateOptionsMenuItems(
41 ui::SimpleMenuModel* options_menu_contents, size_t count, int* ids) {
42 ASSERT_TRUE(options_menu_contents);
43 EXPECT_EQ(static_cast<int>(count), options_menu_contents->GetItemCount());
44 for (size_t i = 0; i < count; ++i) {
45 if (ids[i] == -1) {
46 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR,
47 options_menu_contents->GetTypeAt(i));
48 } else {
49 EXPECT_EQ(ids[i] , options_menu_contents->GetCommandIdAt(i));
50 }
51 }
52 }
27 }; 53 };
28 54
29 // Panel is not supported for Linux view yet. 55 // Panel is not supported for Linux view yet.
30 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) 56 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS)
31 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { 57 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 = 58 PanelBrowserFrameView* frame_view =
39 static_cast<PanelBrowserView*>(static_cast<Panel*>( 59 CreatePanelBrowserView("PanelTest")->GetFrameView();
40 panel_browser->window())->browser_window())->GetFrameView();
41 60
42 // We should have icon, text, options button and close button. 61 // We should have icon, text, options button and close button.
43 EXPECT_EQ(4, frame_view->child_count()); 62 EXPECT_EQ(4, frame_view->child_count());
44 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_)); 63 EXPECT_TRUE(frame_view->Contains(frame_view->title_icon_));
45 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_)); 64 EXPECT_TRUE(frame_view->Contains(frame_view->title_label_));
46 EXPECT_TRUE(frame_view->Contains(frame_view->options_button_)); 65 EXPECT_TRUE(frame_view->Contains(frame_view->options_button_));
47 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_)); 66 EXPECT_TRUE(frame_view->Contains(frame_view->close_button_));
48 67
49 // These controls should be visible. 68 // These controls should be visible.
50 EXPECT_TRUE(frame_view->title_icon_->IsVisible()); 69 EXPECT_TRUE(frame_view->title_icon_->IsVisible());
(...skipping 25 matching lines...) Expand all
76 frame_view->close_button_->x()); 95 frame_view->close_button_->x());
77 96
78 // Validate that the controls should be updated when the activation state is 97 // Validate that the controls should be updated when the activation state is
79 // changed. 98 // changed.
80 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE); 99 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_ACTIVE);
81 SkColor title_label_color1 = frame_view->title_label_->GetColor(); 100 SkColor title_label_color1 = frame_view->title_label_->GetColor();
82 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE); 101 frame_view->UpdateControlStyles(PanelBrowserFrameView::PAINT_AS_INACTIVE);
83 SkColor title_label_color2 = frame_view->title_label_->GetColor(); 102 SkColor title_label_color2 = frame_view->title_label_->GetColor();
84 EXPECT_NE(title_label_color1, title_label_color2); 103 EXPECT_NE(title_label_color1, title_label_color2);
85 } 104 }
105
106 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateOptionsMenu) {
107 int single_panel_menu[] = { PanelBrowserFrameView::COMMAND_ABOUT };
108 int multi_panel_menu_for_minimize[] = {
109 PanelBrowserFrameView::COMMAND_MINIMIZE_ALL,
110 PanelBrowserFrameView::COMMAND_CLOSE_ALL,
111 -1,
jennb 2011/05/11 18:06:10 Add // Separator comment here and line 116?
jianli 2011/05/11 18:31:31 Done.
112 PanelBrowserFrameView::COMMAND_ABOUT };
113 int multi_panel_menu_for_restore[] = {
114 PanelBrowserFrameView::COMMAND_RESTORE_ALL,
115 PanelBrowserFrameView::COMMAND_CLOSE_ALL,
116 -1,
117 PanelBrowserFrameView::COMMAND_ABOUT };
118
119 // With only one panel, we should only have 1 menu item: "About this panel".
120 PanelBrowserFrameView* frame_view1 =
121 CreatePanelBrowserView("PanelTest1")->GetFrameView();
122
123 frame_view1->CreateOptionsMenu();
124 ASSERT_TRUE(frame_view1->options_menu_.get());
125 ValidateOptionsMenuItems(frame_view1->options_menu_contents_.get(),
126 arraysize(single_panel_menu),
jennb 2011/05/11 18:06:10 You could store the sizes in vars up above where y
jianli 2011/05/11 18:31:31 Done.
127 single_panel_menu);
128
129 // With another panel, we should have 4 menu items, including separator.
130 PanelBrowserFrameView* frame_view2 =
131 CreatePanelBrowserView("PanelTest2")->GetFrameView();
132
133 frame_view1->CreateOptionsMenu();
134 ValidateOptionsMenuItems(frame_view1->options_menu_contents_.get(),
135 arraysize(multi_panel_menu_for_minimize),
136 multi_panel_menu_for_minimize);
137
138 frame_view2->CreateOptionsMenu();
139 ValidateOptionsMenuItems(frame_view2->options_menu_contents_.get(),
140 arraysize(multi_panel_menu_for_minimize),
141 multi_panel_menu_for_minimize);
142
143 // When we minimize one panel, "Minimize all" remain intact.
jennb 2011/05/11 18:06:10 s/remain/remains
jianli 2011/05/11 18:31:31 Done.
144 frame_view1->browser_view_->panel_->Minimize();
145
146 frame_view1->CreateOptionsMenu();
147 ValidateOptionsMenuItems(frame_view2->options_menu_contents_.get(),
148 arraysize(multi_panel_menu_for_minimize),
149 multi_panel_menu_for_minimize);
150
151 frame_view2->CreateOptionsMenu();
152 ValidateOptionsMenuItems(frame_view2->options_menu_contents_.get(),
153 arraysize(multi_panel_menu_for_minimize),
154 multi_panel_menu_for_minimize);
155
156 // When we minimize the remaining panel, "Minimize all" should become
157 // "Restore all".
158 frame_view2->browser_view_->panel_->Minimize();
159
160 frame_view1->CreateOptionsMenu();
161 ValidateOptionsMenuItems(frame_view1->options_menu_contents_.get(),
162 arraysize(multi_panel_menu_for_restore),
163 multi_panel_menu_for_restore);
164
165 frame_view2->CreateOptionsMenu();
166 ValidateOptionsMenuItems(frame_view2->options_menu_contents_.get(),
167 arraysize(multi_panel_menu_for_restore),
168 multi_panel_menu_for_restore);
169
170 // When we close one panel, we should be back to have only 1 menu item.
171 frame_view1->browser_view_->panel_->Close();
172
173 frame_view2->CreateOptionsMenu();
174 ValidateOptionsMenuItems(frame_view2->options_menu_contents_.get(),
175 arraysize(single_panel_menu),
176 single_panel_menu);
177 }
86 #endif 178 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698