| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.
h" | 5 #import "chrome/browser/ui/cocoa/permission_bubble/permission_bubble_controller.
h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_objc_class_swizzler.h" | 10 #import "base/mac/scoped_objc_class_swizzler.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 bridge:bridge_.get()]; | 86 bridge:bridge_.get()]; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void TearDown() override { | 89 void TearDown() override { |
| 90 [controller_ close]; | 90 [controller_ close]; |
| 91 chrome::testing::NSRunLoopRunAllPending(); | 91 chrome::testing::NSRunLoopRunAllPending(); |
| 92 owned_requests_.clear(); | 92 owned_requests_.clear(); |
| 93 CocoaProfileTest::TearDown(); | 93 CocoaProfileTest::TearDown(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 const std::vector<PermissionRequest*>& Requests() override { |
| 97 return requests_; |
| 98 } |
| 99 |
| 100 const std::vector<bool>& AcceptStates() override { return accept_states_; } |
| 101 |
| 96 void AddRequest(const std::string& title) { | 102 void AddRequest(const std::string& title) { |
| 97 std::unique_ptr<MockPermissionRequest> request = | 103 std::unique_ptr<MockPermissionRequest> request = |
| 98 base::MakeUnique<MockPermissionRequest>( | 104 base::MakeUnique<MockPermissionRequest>( |
| 99 title, l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW), | 105 title, l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW), |
| 100 l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)); | 106 l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)); |
| 101 requests_.push_back(request.get()); | 107 requests_.push_back(request.get()); |
| 102 owned_requests_.push_back(std::move(request)); | 108 owned_requests_.push_back(std::move(request)); |
| 103 } | 109 } |
| 104 | 110 |
| 105 NSButton* FindButtonWithTitle(const std::string& title) { | 111 NSButton* FindButtonWithTitle(const std::string& title) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 191 |
| 186 [controller_ showWindow:nil]; | 192 [controller_ showWindow:nil]; |
| 187 EXPECT_TRUE([[controller_ window] isVisible]); | 193 EXPECT_TRUE([[controller_ window] isVisible]); |
| 188 EXPECT_TRUE(decoration->active()); | 194 EXPECT_TRUE(decoration->active()); |
| 189 | 195 |
| 190 [controller_ close]; | 196 [controller_ close]; |
| 191 EXPECT_FALSE(decoration->active()); | 197 EXPECT_FALSE(decoration->active()); |
| 192 } | 198 } |
| 193 | 199 |
| 194 TEST_F(PermissionBubbleControllerTest, ShowSinglePermission) { | 200 TEST_F(PermissionBubbleControllerTest, ShowSinglePermission) { |
| 195 [controller_ showWithDelegate:this | 201 [controller_ showWithDelegate:this]; |
| 196 forRequests:requests_ | |
| 197 acceptStates:accept_states_]; | |
| 198 | 202 |
| 199 EXPECT_TRUE(FindTextFieldWithString(kPermissionA)); | 203 EXPECT_TRUE(FindTextFieldWithString(kPermissionA)); |
| 200 EXPECT_TRUE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); | 204 EXPECT_TRUE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 201 EXPECT_TRUE(FindButtonWithTitle(IDS_PERMISSION_DENY)); | 205 EXPECT_TRUE(FindButtonWithTitle(IDS_PERMISSION_DENY)); |
| 202 EXPECT_FALSE(FindButtonWithTitle(IDS_OK)); | 206 EXPECT_FALSE(FindButtonWithTitle(IDS_OK)); |
| 203 } | 207 } |
| 204 | 208 |
| 205 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissions) { | 209 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissions) { |
| 206 AddRequest(kPermissionB); | 210 AddRequest(kPermissionB); |
| 207 AddRequest(kPermissionC); | 211 AddRequest(kPermissionC); |
| 208 | 212 |
| 209 accept_states_.push_back(true); // A | 213 accept_states_.push_back(true); // A |
| 210 accept_states_.push_back(true); // B | 214 accept_states_.push_back(true); // B |
| 211 accept_states_.push_back(true); // C | 215 accept_states_.push_back(true); // C |
| 212 | 216 |
| 213 [controller_ showWithDelegate:this | 217 [controller_ showWithDelegate:this]; |
| 214 forRequests:requests_ | |
| 215 acceptStates:accept_states_]; | |
| 216 | 218 |
| 217 EXPECT_TRUE(FindTextFieldWithString(kPermissionA)); | 219 EXPECT_TRUE(FindTextFieldWithString(kPermissionA)); |
| 218 EXPECT_TRUE(FindTextFieldWithString(kPermissionB)); | 220 EXPECT_TRUE(FindTextFieldWithString(kPermissionB)); |
| 219 EXPECT_TRUE(FindTextFieldWithString(kPermissionC)); | 221 EXPECT_TRUE(FindTextFieldWithString(kPermissionC)); |
| 220 | 222 |
| 221 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); | 223 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 222 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); | 224 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); |
| 223 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); | 225 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); |
| 224 } | 226 } |
| 225 | 227 |
| 226 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsAllow) { | 228 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsAllow) { |
| 227 AddRequest(kPermissionB); | 229 AddRequest(kPermissionB); |
| 228 | 230 |
| 229 accept_states_.push_back(true); // A | 231 accept_states_.push_back(true); // A |
| 230 accept_states_.push_back(true); // B | 232 accept_states_.push_back(true); // B |
| 231 | 233 |
| 232 [controller_ showWithDelegate:this | 234 [controller_ showWithDelegate:this]; |
| 233 forRequests:requests_ | |
| 234 acceptStates:accept_states_]; | |
| 235 | 235 |
| 236 // Test that all menus have 'Allow' visible. | 236 // Test that all menus have 'Allow' visible. |
| 237 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); | 237 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 238 EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); | 238 EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); |
| 239 | 239 |
| 240 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); | 240 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); |
| 241 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); | 241 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 242 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); | 242 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsBlock) { | 245 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsBlock) { |
| 246 AddRequest(kPermissionB); | 246 AddRequest(kPermissionB); |
| 247 | 247 |
| 248 accept_states_.push_back(false); // A | 248 accept_states_.push_back(false); // A |
| 249 accept_states_.push_back(false); // B | 249 accept_states_.push_back(false); // B |
| 250 | 250 |
| 251 [controller_ showWithDelegate:this | 251 [controller_ showWithDelegate:this]; |
| 252 forRequests:requests_ | |
| 253 acceptStates:accept_states_]; | |
| 254 | 252 |
| 255 // Test that all menus have 'Block' visible. | 253 // Test that all menus have 'Block' visible. |
| 256 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); | 254 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); |
| 257 EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); | 255 EXPECT_FALSE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 258 | 256 |
| 259 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); | 257 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); |
| 260 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); | 258 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 261 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); | 259 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); |
| 262 } | 260 } |
| 263 | 261 |
| 264 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsMixed) { | 262 TEST_F(PermissionBubbleControllerTest, ShowMultiplePermissionsMixed) { |
| 265 AddRequest(kPermissionB); | 263 AddRequest(kPermissionB); |
| 266 AddRequest(kPermissionC); | 264 AddRequest(kPermissionC); |
| 267 | 265 |
| 268 accept_states_.push_back(false); // A | 266 accept_states_.push_back(false); // A |
| 269 accept_states_.push_back(false); // B | 267 accept_states_.push_back(false); // B |
| 270 accept_states_.push_back(true); // C | 268 accept_states_.push_back(true); // C |
| 271 | 269 |
| 272 [controller_ showWithDelegate:this | 270 [controller_ showWithDelegate:this]; |
| 273 forRequests:requests_ | |
| 274 acceptStates:accept_states_]; | |
| 275 | 271 |
| 276 // Test that both 'allow' and 'deny' are visible. | 272 // Test that both 'allow' and 'deny' are visible. |
| 277 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); | 273 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_DENY)); |
| 278 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); | 274 EXPECT_TRUE(FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 279 | 275 |
| 280 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); | 276 EXPECT_TRUE(FindButtonWithTitle(IDS_OK)); |
| 281 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); | 277 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_ALLOW)); |
| 282 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); | 278 EXPECT_FALSE(FindButtonWithTitle(IDS_PERMISSION_DENY)); |
| 283 } | 279 } |
| 284 | 280 |
| 285 TEST_F(PermissionBubbleControllerTest, OK) { | 281 TEST_F(PermissionBubbleControllerTest, OK) { |
| 286 AddRequest(kPermissionB); | 282 AddRequest(kPermissionB); |
| 287 | 283 |
| 288 accept_states_.push_back(true); // A | 284 accept_states_.push_back(true); // A |
| 289 accept_states_.push_back(true); // B | 285 accept_states_.push_back(true); // B |
| 290 | 286 |
| 291 [controller_ showWithDelegate:this | 287 [controller_ showWithDelegate:this]; |
| 292 forRequests:requests_ | |
| 293 acceptStates:accept_states_]; | |
| 294 | 288 |
| 295 EXPECT_CALL(*this, Accept()).Times(1); | 289 EXPECT_CALL(*this, Accept()).Times(1); |
| 296 [FindButtonWithTitle(IDS_OK) performClick:nil]; | 290 [FindButtonWithTitle(IDS_OK) performClick:nil]; |
| 297 } | 291 } |
| 298 | 292 |
| 299 TEST_F(PermissionBubbleControllerTest, Allow) { | 293 TEST_F(PermissionBubbleControllerTest, Allow) { |
| 300 [controller_ showWithDelegate:this | 294 [controller_ showWithDelegate:this]; |
| 301 forRequests:requests_ | |
| 302 acceptStates:accept_states_]; | |
| 303 | 295 |
| 304 EXPECT_CALL(*this, Accept()).Times(1); | 296 EXPECT_CALL(*this, Accept()).Times(1); |
| 305 [FindButtonWithTitle(IDS_PERMISSION_ALLOW) performClick:nil]; | 297 [FindButtonWithTitle(IDS_PERMISSION_ALLOW) performClick:nil]; |
| 306 } | 298 } |
| 307 | 299 |
| 308 TEST_F(PermissionBubbleControllerTest, Deny) { | 300 TEST_F(PermissionBubbleControllerTest, Deny) { |
| 309 [controller_ showWithDelegate:this | 301 [controller_ showWithDelegate:this]; |
| 310 forRequests:requests_ | |
| 311 acceptStates:accept_states_]; | |
| 312 | 302 |
| 313 EXPECT_CALL(*this, Deny()).Times(1); | 303 EXPECT_CALL(*this, Deny()).Times(1); |
| 314 [FindButtonWithTitle(IDS_PERMISSION_DENY) performClick:nil]; | 304 [FindButtonWithTitle(IDS_PERMISSION_DENY) performClick:nil]; |
| 315 } | 305 } |
| 316 | 306 |
| 317 TEST_F(PermissionBubbleControllerTest, ChangePermissionSelection) { | 307 TEST_F(PermissionBubbleControllerTest, ChangePermissionSelection) { |
| 318 AddRequest(kPermissionB); | 308 AddRequest(kPermissionB); |
| 319 | 309 |
| 320 accept_states_.push_back(true); // A | 310 accept_states_.push_back(true); // A |
| 321 accept_states_.push_back(false); // B | 311 accept_states_.push_back(false); // B |
| 322 | 312 |
| 323 [controller_ showWithDelegate:this | 313 [controller_ showWithDelegate:this]; |
| 324 forRequests:requests_ | |
| 325 acceptStates:accept_states_]; | |
| 326 | 314 |
| 327 EXPECT_CALL(*this, ToggleAccept(0, false)).Times(1); | 315 EXPECT_CALL(*this, ToggleAccept(0, false)).Times(1); |
| 328 EXPECT_CALL(*this, ToggleAccept(1, true)).Times(1); | 316 EXPECT_CALL(*this, ToggleAccept(1, true)).Times(1); |
| 329 NSButton* menu_a = FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW); | 317 NSButton* menu_a = FindMenuButtonWithTitle(IDS_PERMISSION_ALLOW); |
| 330 NSButton* menu_b = FindMenuButtonWithTitle(IDS_PERMISSION_DENY); | 318 NSButton* menu_b = FindMenuButtonWithTitle(IDS_PERMISSION_DENY); |
| 331 ChangePermissionMenuSelection(menu_a, IDS_PERMISSION_DENY); | 319 ChangePermissionMenuSelection(menu_a, IDS_PERMISSION_DENY); |
| 332 ChangePermissionMenuSelection(menu_b, IDS_PERMISSION_ALLOW); | 320 ChangePermissionMenuSelection(menu_b, IDS_PERMISSION_ALLOW); |
| 333 } | 321 } |
| 334 | 322 |
| 335 TEST_F(PermissionBubbleControllerTest, EscapeCloses) { | 323 TEST_F(PermissionBubbleControllerTest, EscapeCloses) { |
| 336 [controller_ showWithDelegate:this | 324 [controller_ showWithDelegate:this]; |
| 337 forRequests:requests_ | |
| 338 acceptStates:accept_states_]; | |
| 339 | 325 |
| 340 EXPECT_TRUE([[controller_ window] isVisible]); | 326 EXPECT_TRUE([[controller_ window] isVisible]); |
| 341 [[controller_ window] | 327 [[controller_ window] |
| 342 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( | 328 performKeyEquivalent:cocoa_test_event_utils::KeyEventWithKeyCode( |
| 343 kVK_Escape, '\e', NSKeyDown, 0)]; | 329 kVK_Escape, '\e', NSKeyDown, 0)]; |
| 344 EXPECT_FALSE([[controller_ window] isVisible]); | 330 EXPECT_FALSE([[controller_ window] isVisible]); |
| 345 } | 331 } |
| 346 | 332 |
| 347 TEST_F(PermissionBubbleControllerTest, EnterFullscreen) { | 333 TEST_F(PermissionBubbleControllerTest, EnterFullscreen) { |
| 348 [controller_ showWithDelegate:this | 334 [controller_ showWithDelegate:this]; |
| 349 forRequests:requests_ | |
| 350 acceptStates:accept_states_]; | |
| 351 | 335 |
| 352 EXPECT_TRUE([[controller_ window] isVisible]); | 336 EXPECT_TRUE([[controller_ window] isVisible]); |
| 353 | 337 |
| 354 // Post the "enter fullscreen" notification. | 338 // Post the "enter fullscreen" notification. |
| 355 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 339 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 356 [center postNotificationName:NSWindowWillEnterFullScreenNotification | 340 [center postNotificationName:NSWindowWillEnterFullScreenNotification |
| 357 object:test_window()]; | 341 object:test_window()]; |
| 358 | 342 |
| 359 EXPECT_TRUE([[controller_ window] isVisible]); | 343 EXPECT_TRUE([[controller_ window] isVisible]); |
| 360 } | 344 } |
| 361 | 345 |
| 362 TEST_F(PermissionBubbleControllerTest, ExitFullscreen) { | 346 TEST_F(PermissionBubbleControllerTest, ExitFullscreen) { |
| 363 [controller_ showWithDelegate:this | 347 [controller_ showWithDelegate:this]; |
| 364 forRequests:requests_ | |
| 365 acceptStates:accept_states_]; | |
| 366 | 348 |
| 367 EXPECT_TRUE([[controller_ window] isVisible]); | 349 EXPECT_TRUE([[controller_ window] isVisible]); |
| 368 | 350 |
| 369 // Post the "enter fullscreen" notification. | 351 // Post the "enter fullscreen" notification. |
| 370 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 352 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 371 [center postNotificationName:NSWindowWillExitFullScreenNotification | 353 [center postNotificationName:NSWindowWillExitFullScreenNotification |
| 372 object:test_window()]; | 354 object:test_window()]; |
| 373 | 355 |
| 374 EXPECT_TRUE([[controller_ window] isVisible]); | 356 EXPECT_TRUE([[controller_ window] isVisible]); |
| 375 } | 357 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 407 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 426 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 408 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 427 @selector(hasVisibleLocationBarForBrowser:)); | 409 @selector(hasVisibleLocationBarForBrowser:)); |
| 428 withoutLocationBar = [controller_ getExpectedAnchorPoint]; | 410 withoutLocationBar = [controller_ getExpectedAnchorPoint]; |
| 429 } | 411 } |
| 430 | 412 |
| 431 // The bubble should be in different places depending if the location bar is | 413 // The bubble should be in different places depending if the location bar is |
| 432 // available or not. | 414 // available or not. |
| 433 EXPECT_NSNE(withLocationBar, withoutLocationBar); | 415 EXPECT_NSNE(withLocationBar, withoutLocationBar); |
| 434 } | 416 } |
| OLD | NEW |