| 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/website_settings/permission_selector_button.h" | 5 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h" |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 7 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
| 9 #include "chrome/browser/ui/website_settings/website_settings_ui.h" | 9 #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
| 10 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 | 12 |
| 11 @interface PermissionSelectorButton (Testing) | 13 @interface PermissionSelectorButton (Testing) |
| 12 - (NSMenu*)permissionMenu; | 14 - (NSMenu*)permissionMenu; |
| 13 @end | 15 @end |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 const ContentSettingsType kTestPermissionType = | 19 const ContentSettingsType kTestPermissionType = |
| 18 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; | 20 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC; |
| 19 | 21 |
| 20 class PermissionSelectorButtonTest : public CocoaTest { | 22 class PermissionSelectorButtonTest : public CocoaTest { |
| 21 public: | 23 public: |
| 22 PermissionSelectorButtonTest() { | 24 PermissionSelectorButtonTest() { |
| 23 got_callback_ = false; | 25 got_callback_ = false; |
| 24 WebsiteSettingsUI::PermissionInfo test_info; | 26 WebsiteSettingsUI::PermissionInfo test_info; |
| 25 test_info.type = kTestPermissionType; | 27 test_info.type = kTestPermissionType; |
| 26 test_info.setting = CONTENT_SETTING_BLOCK; | 28 test_info.setting = CONTENT_SETTING_BLOCK; |
| 27 test_info.source = content_settings::SETTING_SOURCE_USER; | 29 test_info.source = content_settings::SETTING_SOURCE_USER; |
| 28 test_info.is_incognito = false; | 30 test_info.is_incognito = false; |
| 29 GURL test_url("http://www.google.com"); | 31 GURL test_url("http://www.google.com"); |
| 30 PermissionMenuModel::ChangeCallback callback = base::Bind( | 32 PermissionMenuModel::ChangeCallback callback = base::Bind( |
| 31 &PermissionSelectorButtonTest::Callback, base::Unretained(this)); | 33 &PermissionSelectorButtonTest::Callback, base::Unretained(this)); |
| 32 view_.reset( | 34 view_.reset([[PermissionSelectorButton alloc] |
| 33 [[PermissionSelectorButton alloc] initWithPermissionInfo:test_info | 35 initWithPermissionInfo:test_info |
| 34 forURL:test_url | 36 forURL:test_url |
| 35 withCallback:callback]); | 37 withCallback:callback |
| 38 profile:&profile_]); |
| 36 [[test_window() contentView] addSubview:view_]; | 39 [[test_window() contentView] addSubview:view_]; |
| 37 } | 40 } |
| 38 | 41 |
| 39 void Callback(const WebsiteSettingsUI::PermissionInfo& permission) { | 42 void Callback(const WebsiteSettingsUI::PermissionInfo& permission) { |
| 40 EXPECT_TRUE(permission.type == kTestPermissionType); | 43 EXPECT_TRUE(permission.type == kTestPermissionType); |
| 41 got_callback_ = true; | 44 got_callback_ = true; |
| 42 } | 45 } |
| 43 | 46 |
| 47 content::TestBrowserThreadBundle thread_bundle_; |
| 48 TestingProfile profile_; |
| 49 |
| 44 bool got_callback_; | 50 bool got_callback_; |
| 45 base::scoped_nsobject<PermissionSelectorButton> view_; | 51 base::scoped_nsobject<PermissionSelectorButton> view_; |
| 46 }; | 52 }; |
| 47 | 53 |
| 48 TEST_VIEW(PermissionSelectorButtonTest, view_); | 54 TEST_VIEW(PermissionSelectorButtonTest, view_); |
| 49 | 55 |
| 50 TEST_F(PermissionSelectorButtonTest, Callback) { | 56 TEST_F(PermissionSelectorButtonTest, Callback) { |
| 51 NSMenu* menu = [view_ permissionMenu]; | 57 NSMenu* menu = [view_ permissionMenu]; |
| 52 NSMenuItem* item = [menu itemAtIndex:0]; | 58 NSMenuItem* item = [menu itemAtIndex:0]; |
| 53 [[item target] performSelector:[item action] withObject:item]; | 59 [[item target] performSelector:[item action] withObject:item]; |
| 54 EXPECT_TRUE(got_callback_); | 60 EXPECT_TRUE(got_callback_); |
| 55 } | 61 } |
| 56 | 62 |
| 57 } // namespace | 63 } // namespace |
| OLD | NEW |