Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / website_settings / permission_selector_button_unittest.mm
blobc819bec16a1df8714cdc7dc5ba9b0604f5c2d2af
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;
13 @end
15 namespace {
17 const ContentSettingsType kTestPermissionType =
18     CONTENT_SETTINGS_TYPE_MEDIASTREAM;
20 class PermissionSelectorButtonTest : public CocoaTest {
21  public:
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));
31     view_.reset(
32         [[PermissionSelectorButton alloc] initWithPermissionInfo:test_info
33                                                           forURL:test_url
34                                                     withCallback:callback]);
35     [[test_window() contentView] addSubview:view_];
36   }
38   void Callback(const WebsiteSettingsUI::PermissionInfo& permission) {
39     EXPECT_TRUE(permission.type == kTestPermissionType);
40     got_callback_ = true;
41   }
43   bool got_callback_;
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_);
56 }  // namespace