Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa_unittest.mm

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/content_settings/content_setting_bubble_cocoa.h " 5 #import "chrome/browser/ui/cocoa/content_settings/content_setting_bubble_cocoa.h "
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_nsautorelease_pool.h" 9 #include "base/mac/scoped_nsautorelease_pool.h"
10 #include "base/memory/scoped_nsobject.h" 10 #include "base/memory/scoped_nsobject.h"
11 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
11 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
12 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 13 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
13 #include "chrome/common/content_settings_types.h" 14 #include "chrome/common/content_settings_types.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/common/media_stream_request.h" 17 #include "content/public/common/media_stream_request.h"
17 #include "content/public/test/test_browser_thread.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/gtest_mac.h" 20 #include "testing/gtest_mac.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 22
23 using content::BrowserThread;
24
25 namespace { 23 namespace {
26 24
27 class DummyContentSettingBubbleModel : public ContentSettingBubbleModel { 25 class DummyContentSettingBubbleModel : public ContentSettingBubbleModel {
28 public: 26 public:
29 DummyContentSettingBubbleModel(content::WebContents* web_contents, 27 DummyContentSettingBubbleModel(content::WebContents* web_contents,
30 Profile* profile, 28 Profile* profile,
31 ContentSettingsType content_type) 29 ContentSettingsType content_type)
32 : ContentSettingBubbleModel(web_contents, profile, content_type) { 30 : ContentSettingBubbleModel(web_contents, profile, content_type) {
33 RadioGroup radio_group; 31 RadioGroup radio_group;
34 radio_group.default_item = 0; 32 radio_group.default_item = 0;
35 radio_group.radio_items.resize(2); 33 radio_group.radio_items.resize(2);
36 set_radio_group(radio_group); 34 set_radio_group(radio_group);
37 MediaMenu micMenu; 35 MediaMenu micMenu;
38 micMenu.label = "Microphone:"; 36 micMenu.label = "Microphone:";
39 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, micMenu); 37 add_media_menu(content::MEDIA_DEVICE_AUDIO_CAPTURE, micMenu);
40 MediaMenu cameraMenu; 38 MediaMenu cameraMenu;
41 cameraMenu.label = "Camera:"; 39 cameraMenu.label = "Camera:";
42 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, cameraMenu); 40 add_media_menu(content::MEDIA_DEVICE_VIDEO_CAPTURE, cameraMenu);
43 } 41 }
44 }; 42 };
45 43
46 class ContentSettingBubbleControllerTest 44 class ContentSettingBubbleControllerTest
47 : public ChromeRenderViewHostTestHarness { 45 : public ChromeRenderViewHostTestHarness {
48 public:
49 ContentSettingBubbleControllerTest();
50 virtual ~ContentSettingBubbleControllerTest();
51
52 protected: 46 protected:
53 // Helper function to create the bubble controller. 47 // Helper function to create the bubble controller.
54 ContentSettingBubbleController* CreateBubbleController( 48 ContentSettingBubbleController* CreateBubbleController(
55 ContentSettingsType settingsType); 49 ContentSettingsType settingsType);
56 50
57 scoped_nsobject<NSWindow> parent_; 51 scoped_nsobject<NSWindow> parent_;
58 52
59 private: 53 private:
60 content::TestBrowserThread browser_thread_;
61
62 base::mac::ScopedNSAutoreleasePool pool_; 54 base::mac::ScopedNSAutoreleasePool pool_;
63 }; 55 };
64 56
65 ContentSettingBubbleControllerTest::ContentSettingBubbleControllerTest()
66 : ChromeRenderViewHostTestHarness(),
67 browser_thread_(BrowserThread::UI, &message_loop_) {
68 }
69
70 ContentSettingBubbleControllerTest::~ContentSettingBubbleControllerTest() {
71 }
72
73 ContentSettingBubbleController* 57 ContentSettingBubbleController*
74 ContentSettingBubbleControllerTest::CreateBubbleController( 58 ContentSettingBubbleControllerTest::CreateBubbleController(
75 ContentSettingsType settingsType) { 59 ContentSettingsType settingsType) {
76 parent_.reset([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) 60 parent_.reset([[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
77 styleMask:NSBorderlessWindowMask 61 styleMask:NSBorderlessWindowMask
78 backing:NSBackingStoreBuffered 62 backing:NSBackingStoreBuffered
79 defer:NO]); 63 defer:NO]);
80 [parent_ setReleasedWhenClosed:NO]; 64 [parent_ setReleasedWhenClosed:NO];
81 [parent_ orderFront:nil]; 65 [parent_ orderFront:nil];
82 66
(...skipping 29 matching lines...) Expand all
112 96
113 ContentSettingBubbleController* controller = 97 ContentSettingBubbleController* controller =
114 CreateBubbleController(settingsType); 98 CreateBubbleController(settingsType);
115 EXPECT_EQ(0u, [controller mediaMenus]->size()); 99 EXPECT_EQ(0u, [controller mediaMenus]->size());
116 [parent_ close]; 100 [parent_ close];
117 } 101 }
118 } 102 }
119 103
120 // Check that the bubble works for CONTENT_SETTINGS_TYPE_MEDIASTREAM. 104 // Check that the bubble works for CONTENT_SETTINGS_TYPE_MEDIASTREAM.
121 TEST_F(ContentSettingBubbleControllerTest, MediaStreamBubble) { 105 TEST_F(ContentSettingBubbleControllerTest, MediaStreamBubble) {
106 MediaCaptureDevicesDispatcher::GetInstance()->
107 DisableDeviceEnumerationForTesting();
122 ContentSettingBubbleController* controller = 108 ContentSettingBubbleController* controller =
123 CreateBubbleController(CONTENT_SETTINGS_TYPE_MEDIASTREAM); 109 CreateBubbleController(CONTENT_SETTINGS_TYPE_MEDIASTREAM);
124 content_setting_bubble::MediaMenuPartsMap* mediaMenus = 110 content_setting_bubble::MediaMenuPartsMap* mediaMenus =
125 [controller mediaMenus]; 111 [controller mediaMenus];
126 EXPECT_EQ(2u, mediaMenus->size()); 112 EXPECT_EQ(2u, mediaMenus->size());
127 NSString* title = l10n_util::GetNSString(IDS_MEDIA_MENU_NO_DEVICE_TITLE); 113 NSString* title = l10n_util::GetNSString(IDS_MEDIA_MENU_NO_DEVICE_TITLE);
128 for (content_setting_bubble::MediaMenuPartsMap::const_iterator i = 114 for (content_setting_bubble::MediaMenuPartsMap::const_iterator i =
129 mediaMenus->begin(); i != mediaMenus->end(); ++i) { 115 mediaMenus->begin(); i != mediaMenus->end(); ++i) {
130 EXPECT_TRUE((content::MEDIA_DEVICE_AUDIO_CAPTURE == i->second->type) || 116 EXPECT_TRUE((content::MEDIA_DEVICE_AUDIO_CAPTURE == i->second->type) ||
131 (content::MEDIA_DEVICE_VIDEO_CAPTURE == i->second->type)); 117 (content::MEDIA_DEVICE_VIDEO_CAPTURE == i->second->type));
132 EXPECT_EQ(0, [i->first numberOfItems]); 118 EXPECT_EQ(0, [i->first numberOfItems]);
133 EXPECT_NSEQ(title, [i->first title]); 119 EXPECT_NSEQ(title, [i->first title]);
134 EXPECT_FALSE([i->first isEnabled]); 120 EXPECT_FALSE([i->first isEnabled]);
135 } 121 }
136 122
137 [parent_ close]; 123 [parent_ close];
138 } 124 }
139 125
140 } // namespace 126 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698