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