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

Side by Side Diff: chrome/browser/ui/toolbar/app_menu_model_unittest.cc

Issue 2409443002: Make GlobalErrorService's ownership model slightly less insane. (Closed)
Patch Set: commentary Created 4 years 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
« no previous file with comments | « chrome/browser/ui/global_error/global_error_service_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 4
5 #include "chrome/browser/ui/toolbar/app_menu_model.h" 5 #include "chrome/browser/ui/toolbar/app_menu_model.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h"
8 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 11 #include "chrome/browser/prefs/browser_prefs.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/global_error/global_error.h" 14 #include "chrome/browser/ui/global_error/global_error.h"
14 #include "chrome/browser/ui/global_error/global_error_service.h" 15 #include "chrome/browser/ui/global_error/global_error_service.h"
15 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 16 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/upgrade_detector.h" 18 #include "chrome/browser/upgrade_detector.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 EXPECT_EQ(model.enable_count_, 1); 173 EXPECT_EQ(model.enable_count_, 1);
173 } 174 }
174 175
175 // Tests global error menu items in the app menu. 176 // Tests global error menu items in the app menu.
176 TEST_F(AppMenuModelTest, GlobalError) { 177 TEST_F(AppMenuModelTest, GlobalError) {
177 // Make sure services required for tests are initialized. 178 // Make sure services required for tests are initialized.
178 GlobalErrorService* service = 179 GlobalErrorService* service =
179 GlobalErrorServiceFactory::GetForProfile(browser()->profile()); 180 GlobalErrorServiceFactory::GetForProfile(browser()->profile());
180 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()); 181 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile());
181 const int command1 = 1234567; 182 const int command1 = 1234567;
182 // AddGlobalError takes ownership of error1.
183 MenuError* error1 = new MenuError(command1); 183 MenuError* error1 = new MenuError(command1);
184 service->AddGlobalError(error1); 184 service->AddGlobalError(base::WrapUnique(error1));
185 const int command2 = 1234568; 185 const int command2 = 1234568;
186 // AddGlobalError takes ownership of error2.
187 MenuError* error2 = new MenuError(command2); 186 MenuError* error2 = new MenuError(command2);
188 service->AddGlobalError(error2); 187 service->AddGlobalError(base::WrapUnique(error2));
189 188
190 AppMenuModel model(this, browser()); 189 AppMenuModel model(this, browser());
191 int index1 = model.GetIndexOfCommandId(command1); 190 int index1 = model.GetIndexOfCommandId(command1);
192 EXPECT_GT(index1, -1); 191 EXPECT_GT(index1, -1);
193 int index2 = model.GetIndexOfCommandId(command2); 192 int index2 = model.GetIndexOfCommandId(command2);
194 EXPECT_GT(index2, -1); 193 EXPECT_GT(index2, -1);
195 194
196 EXPECT_TRUE(model.IsEnabledAt(index1)); 195 EXPECT_TRUE(model.IsEnabledAt(index1));
197 EXPECT_EQ(0, error1->execute_count()); 196 EXPECT_EQ(0, error1->execute_count());
198 model.ActivatedAt(index1); 197 model.ActivatedAt(index1);
199 EXPECT_EQ(1, error1->execute_count()); 198 EXPECT_EQ(1, error1->execute_count());
200 199
201 EXPECT_TRUE(model.IsEnabledAt(index2)); 200 EXPECT_TRUE(model.IsEnabledAt(index2));
202 EXPECT_EQ(0, error2->execute_count()); 201 EXPECT_EQ(0, error2->execute_count());
203 model.ActivatedAt(index2); 202 model.ActivatedAt(index2);
204 EXPECT_EQ(1, error1->execute_count()); 203 EXPECT_EQ(1, error1->execute_count());
205 } 204 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/global_error/global_error_service_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698