| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 namespace { | 62 namespace { |
| 63 const char* const kPermissionA = "Permission A"; | 63 const char* const kPermissionA = "Permission A"; |
| 64 const char* const kPermissionB = "Permission B"; | 64 const char* const kPermissionB = "Permission B"; |
| 65 const char* const kPermissionC = "Permission C"; | 65 const char* const kPermissionC = "Permission C"; |
| 66 } | 66 } |
| 67 | 67 |
| 68 class PermissionBubbleControllerTest : public CocoaProfileTest, | 68 class PermissionBubbleControllerTest : public CocoaProfileTest, |
| 69 public PermissionPrompt::Delegate { | 69 public PermissionPrompt::Delegate { |
| 70 public: | 70 public: |
| 71 | 71 |
| 72 MOCK_METHOD2(ToggleAccept, void(int, bool)); | |
| 73 MOCK_METHOD1(TogglePersist, void(bool)); | 72 MOCK_METHOD1(TogglePersist, void(bool)); |
| 74 MOCK_METHOD0(SetCustomizationMode, void()); | 73 MOCK_METHOD0(SetCustomizationMode, void()); |
| 75 MOCK_METHOD0(Accept, void()); | 74 MOCK_METHOD0(Accept, void()); |
| 76 MOCK_METHOD0(Deny, void()); | 75 MOCK_METHOD0(Deny, void()); |
| 77 MOCK_METHOD0(Closing, void()); | 76 MOCK_METHOD0(Closing, void()); |
| 78 MOCK_METHOD1(SetView, void(PermissionPrompt*)); | 77 MOCK_METHOD1(SetView, void(PermissionPrompt*)); |
| 79 | 78 |
| 80 void SetUp() override { | 79 void SetUp() override { |
| 81 CocoaProfileTest::SetUp(); | 80 CocoaProfileTest::SetUp(); |
| 82 bridge_.reset(new PermissionBubbleCocoa(browser())); | 81 bridge_.reset(new PermissionBubbleCocoa(browser())); |
| 83 AddRequest(kPermissionA); | 82 AddRequest(kPermissionA); |
| 84 controller_ = | 83 controller_ = |
| 85 [[PermissionBubbleController alloc] initWithBrowser:browser() | 84 [[PermissionBubbleController alloc] initWithBrowser:browser() |
| 86 bridge:bridge_.get()]; | 85 bridge:bridge_.get()]; |
| 87 } | 86 } |
| 88 | 87 |
| 89 void TearDown() override { | 88 void TearDown() override { |
| 90 [controller_ close]; | 89 [controller_ close]; |
| 91 chrome::testing::NSRunLoopRunAllPending(); | 90 chrome::testing::NSRunLoopRunAllPending(); |
| 92 owned_requests_.clear(); | 91 owned_requests_.clear(); |
| 93 CocoaProfileTest::TearDown(); | 92 CocoaProfileTest::TearDown(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 const std::vector<PermissionRequest*>& Requests() override { | 95 const std::vector<PermissionRequest*>& Requests() override { |
| 97 return requests_; | 96 return requests_; |
| 98 } | 97 } |
| 99 | 98 |
| 100 const std::vector<bool>& AcceptStates() override { | |
| 101 // TODO(crbug.com/728483): Remove this function. | |
| 102 CR_DEFINE_STATIC_LOCAL(std::vector<bool>, accept_states, ()); | |
| 103 return accept_states; | |
| 104 } | |
| 105 | |
| 106 void AddRequest(const std::string& title) { | 99 void AddRequest(const std::string& title) { |
| 107 std::unique_ptr<MockPermissionRequest> request = | 100 std::unique_ptr<MockPermissionRequest> request = |
| 108 base::MakeUnique<MockPermissionRequest>( | 101 base::MakeUnique<MockPermissionRequest>( |
| 109 title, l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW), | 102 title, l10n_util::GetStringUTF8(IDS_PERMISSION_ALLOW), |
| 110 l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)); | 103 l10n_util::GetStringUTF8(IDS_PERMISSION_DENY)); |
| 111 requests_.push_back(request.get()); | 104 requests_.push_back(request.get()); |
| 112 owned_requests_.push_back(std::move(request)); | 105 owned_requests_.push_back(std::move(request)); |
| 113 } | 106 } |
| 114 | 107 |
| 115 NSButton* FindButtonWithTitle(const std::string& title) { | 108 NSButton* FindButtonWithTitle(const std::string& title) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 144 } |
| 152 } | 145 } |
| 153 return textField; | 146 return textField; |
| 154 } | 147 } |
| 155 | 148 |
| 156 protected: | 149 protected: |
| 157 PermissionBubbleController* controller_; // Weak; it deletes itself. | 150 PermissionBubbleController* controller_; // Weak; it deletes itself. |
| 158 std::unique_ptr<PermissionBubbleCocoa> bridge_; | 151 std::unique_ptr<PermissionBubbleCocoa> bridge_; |
| 159 std::vector<PermissionRequest*> requests_; | 152 std::vector<PermissionRequest*> requests_; |
| 160 std::vector<std::unique_ptr<PermissionRequest>> owned_requests_; | 153 std::vector<std::unique_ptr<PermissionRequest>> owned_requests_; |
| 161 std::vector<bool> accept_states_; | |
| 162 }; | 154 }; |
| 163 | 155 |
| 164 TEST_F(PermissionBubbleControllerTest, ShowAndClose) { | 156 TEST_F(PermissionBubbleControllerTest, ShowAndClose) { |
| 165 EXPECT_FALSE([[controller_ window] isVisible]); | 157 EXPECT_FALSE([[controller_ window] isVisible]); |
| 166 [controller_ showWindow:nil]; | 158 [controller_ showWindow:nil]; |
| 167 EXPECT_TRUE([[controller_ window] isVisible]); | 159 EXPECT_TRUE([[controller_ window] isVisible]); |
| 168 } | 160 } |
| 169 | 161 |
| 170 // Tests the page icon decoration's active state. | 162 // Tests the page icon decoration's active state. |
| 171 TEST_F(PermissionBubbleControllerTest, PageIconDecorationActiveState) { | 163 TEST_F(PermissionBubbleControllerTest, PageIconDecorationActiveState) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 base::mac::ScopedObjCClassSwizzler locationSwizzle( | 320 base::mac::ScopedObjCClassSwizzler locationSwizzle( |
| 329 [PermissionBubbleController class], [MockBubbleNoLocationBar class], | 321 [PermissionBubbleController class], [MockBubbleNoLocationBar class], |
| 330 @selector(hasVisibleLocationBarForBrowser:)); | 322 @selector(hasVisibleLocationBarForBrowser:)); |
| 331 withoutLocationBar = [controller_ getExpectedAnchorPoint]; | 323 withoutLocationBar = [controller_ getExpectedAnchorPoint]; |
| 332 } | 324 } |
| 333 | 325 |
| 334 // The bubble should be in different places depending if the location bar is | 326 // The bubble should be in different places depending if the location bar is |
| 335 // available or not. | 327 // available or not. |
| 336 EXPECT_NSNE(withLocationBar, withoutLocationBar); | 328 EXPECT_NSNE(withLocationBar, withoutLocationBar); |
| 337 } | 329 } |
| OLD | NEW |