OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | |
5 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 4 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
6 | 5 |
7 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/prefs/browser_prefs.h" | 7 #include "chrome/browser/prefs/browser_prefs.h" |
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 8 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
10 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/global_error/global_error.h" | 10 #include "chrome/browser/ui/global_error/global_error.h" |
12 #include "chrome/browser/ui/global_error/global_error_service.h" | 11 #include "chrome/browser/ui/global_error/global_error_service.h" |
13 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 12 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // the exact number. | 124 // the exact number. |
126 EXPECT_GT(itemCount, 10); | 125 EXPECT_GT(itemCount, 10); |
127 | 126 |
128 // Execute a couple of the items and make sure it gets back to our delegate. | 127 // Execute a couple of the items and make sure it gets back to our delegate. |
129 // We can't use CountEnabledExecutable() here because the encoding menu's | 128 // We can't use CountEnabledExecutable() here because the encoding menu's |
130 // delegate is internal, it doesn't use the one we pass in. | 129 // delegate is internal, it doesn't use the one we pass in. |
131 // Note: The new menu has a spacing separator at the first slot. | 130 // Note: The new menu has a spacing separator at the first slot. |
132 model.ActivatedAt(1); | 131 model.ActivatedAt(1); |
133 EXPECT_TRUE(model.IsEnabledAt(1)); | 132 EXPECT_TRUE(model.IsEnabledAt(1)); |
134 // Make sure to use the index that is not separator in all configurations. | 133 // Make sure to use the index that is not separator in all configurations. |
| 134 #if defined(OS_MACOSX) || defined(CHROMEOS) |
135 model.ActivatedAt(2); | 135 model.ActivatedAt(2); |
136 EXPECT_TRUE(model.IsEnabledAt(2)); | 136 EXPECT_TRUE(model.IsEnabledAt(2)); |
| 137 #else |
| 138 model.ActivatedAt(3); |
| 139 EXPECT_TRUE(model.IsEnabledAt(3)); |
| 140 #endif |
137 EXPECT_EQ(model.execute_count_, 2); | 141 EXPECT_EQ(model.execute_count_, 2); |
138 EXPECT_EQ(model.enable_count_, 2); | 142 EXPECT_EQ(model.enable_count_, 2); |
139 | 143 |
140 model.execute_count_ = 0; | 144 model.execute_count_ = 0; |
141 model.enable_count_ = 0; | 145 model.enable_count_ = 0; |
142 | 146 |
143 // Choose something from the bookmark submenu and make sure it makes it back | 147 // Choose something from the bookmark submenu and make sure it makes it back |
144 // to the delegate as well. | 148 // to the delegate as well. |
145 int bookmarksModelIndex = -1; | 149 int bookmarksModelIndex = -1; |
146 for (int i = 0; i < itemCount; ++i) { | 150 for (int i = 0; i < itemCount; ++i) { |
147 if (model.GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { | 151 if (model.GetTypeAt(i) == ui::MenuModel::TYPE_SUBMENU) { |
148 bookmarksModelIndex = i; | 152 // Tabs is the first submenu item. Bookmarks submenu is under tabs. |
| 153 bookmarksModelIndex = i + 1; |
149 break; | 154 break; |
150 } | 155 } |
151 } | 156 } |
152 EXPECT_GT(bookmarksModelIndex, -1); | 157 EXPECT_GT(bookmarksModelIndex, -1); |
153 ui::MenuModel* bookmarksModel = model.GetSubmenuModelAt(bookmarksModelIndex); | 158 ui::MenuModel* bookmarksModel = model.GetSubmenuModelAt(bookmarksModelIndex); |
154 EXPECT_TRUE(bookmarksModel); | 159 EXPECT_TRUE(bookmarksModel); |
155 // The bookmarks model may be empty until we tell it we're going to show it. | 160 // The bookmarks model may be empty until we tell it we're going to show it. |
156 bookmarksModel->MenuWillShow(); | 161 bookmarksModel->MenuWillShow(); |
157 EXPECT_GT(bookmarksModel->GetItemCount(), 1); | 162 EXPECT_GT(bookmarksModel->GetItemCount(), 1); |
158 bookmarksModel->ActivatedAt(1); | 163 |
159 EXPECT_TRUE(bookmarksModel->IsEnabledAt(1)); | 164 // Bookmark manager item. |
| 165 bookmarksModel->ActivatedAt(4); |
| 166 EXPECT_TRUE(bookmarksModel->IsEnabledAt(4)); |
160 EXPECT_EQ(model.execute_count_, 1); | 167 EXPECT_EQ(model.execute_count_, 1); |
161 EXPECT_EQ(model.enable_count_, 1); | 168 EXPECT_EQ(model.enable_count_, 1); |
162 } | 169 } |
163 | 170 |
164 // Tests global error menu items in the wrench menu. | 171 // Tests global error menu items in the wrench menu. |
165 TEST_F(WrenchMenuModelTest, GlobalError) { | 172 TEST_F(WrenchMenuModelTest, GlobalError) { |
166 // Make sure services required for tests are initialized. | 173 // Make sure services required for tests are initialized. |
167 GlobalErrorService* service = | 174 GlobalErrorService* service = |
168 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); | 175 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); |
169 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); | 176 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); |
(...skipping 25 matching lines...) Expand all Loading... |
195 | 202 |
196 class EncodingMenuModelTest : public BrowserWithTestWindowTest, | 203 class EncodingMenuModelTest : public BrowserWithTestWindowTest, |
197 public MenuModelTest { | 204 public MenuModelTest { |
198 }; | 205 }; |
199 | 206 |
200 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { | 207 TEST_F(EncodingMenuModelTest, IsCommandIdCheckedWithNoTabs) { |
201 EncodingMenuModel model(browser()); | 208 EncodingMenuModel model(browser()); |
202 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); | 209 ASSERT_EQ(NULL, browser()->tab_strip_model()->GetActiveWebContents()); |
203 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_WINDOWS1252)); | 210 EXPECT_FALSE(model.IsCommandIdChecked(IDC_ENCODING_WINDOWS1252)); |
204 } | 211 } |
OLD | NEW |