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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/website_settings/permission_selector_button.h"
7 #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"
11 @interface PermissionSelectorButton (Testing)
12 - (NSMenu*)permissionMenu;
17 const ContentSettingsType kTestPermissionType =
18 CONTENT_SETTINGS_TYPE_MEDIASTREAM;
20 class PermissionSelectorButtonTest : public CocoaTest {
22 PermissionSelectorButtonTest() {
23 got_callback_ = false;
24 WebsiteSettingsUI::PermissionInfo test_info;
25 test_info.type = kTestPermissionType;
26 test_info.setting = CONTENT_SETTING_BLOCK;
27 test_info.source = content_settings::SETTING_SOURCE_USER;
28 GURL test_url("http://www.google.com");
29 PermissionMenuModel::ChangeCallback callback = base::Bind(
30 &PermissionSelectorButtonTest::Callback, base::Unretained(this));
32 [[PermissionSelectorButton alloc] initWithPermissionInfo:test_info
34 withCallback:callback]);
35 [[test_window() contentView] addSubview:view_];
38 void Callback(const WebsiteSettingsUI::PermissionInfo& permission) {
39 EXPECT_TRUE(permission.type == kTestPermissionType);
44 base::scoped_nsobject<PermissionSelectorButton> view_;
47 TEST_VIEW(PermissionSelectorButtonTest, view_);
49 TEST_F(PermissionSelectorButtonTest, Callback) {
50 NSMenu* menu = [view_ permissionMenu];
51 NSMenuItem* item = [menu itemAtIndex:0];
52 [[item target] performSelector:[item action] withObject:item];
53 EXPECT_TRUE(got_callback_);