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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac_editcommand_helper_unittest.mm

Issue 2005013002: mac: ensure ui::Compositor exists for visible RWHVs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ensure in ctor and always in show Created 4 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
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 "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" 5 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "base/mac/scoped_nsautorelease_pool.h" 11 #include "base/mac/scoped_nsautorelease_pool.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "content/browser/compositor/test/no_transport_image_transport_factory.h " 13 #include "content/browser/compositor/test/no_transport_image_transport_factory.h "
14 #include "content/browser/gpu/compositor_util.h" 14 #include "content/browser/gpu/compositor_util.h"
15 #include "content/browser/renderer_host/render_widget_host_delegate.h" 15 #include "content/browser/renderer_host/render_widget_host_delegate.h"
16 #include "content/browser/renderer_host/render_widget_host_impl.h" 16 #include "content/browser/renderer_host/render_widget_host_impl.h"
17 #include "content/common/input_messages.h" 17 #include "content/common/input_messages.h"
18 #include "content/public/test/mock_render_process_host.h" 18 #include "content/public/test/mock_render_process_host.h"
19 #include "content/public/test/test_browser_context.h" 19 #include "content/public/test/test_browser_context.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/platform_test.h" 22 #include "testing/platform_test.h"
23 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
23 #include "ui/base/layout.h" 24 #include "ui/base/layout.h"
24 25
25 using content::RenderWidgetHostViewMac; 26 using content::RenderWidgetHostViewMac;
26 27
27 // Bare bones obj-c class for testing purposes. 28 // Bare bones obj-c class for testing purposes.
28 @interface RenderWidgetHostViewMacEditCommandHelperTestClass : NSObject 29 @interface RenderWidgetHostViewMacEditCommandHelperTestClass : NSObject
29 @end 30 @end
30 31
31 @implementation RenderWidgetHostViewMacEditCommandHelperTestClass 32 @implementation RenderWidgetHostViewMacEditCommandHelperTestClass
32 @end 33 @end
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 supported_factors.push_back(ui::SCALE_FACTOR_100P); 127 supported_factors.push_back(ui::SCALE_FACTOR_100P);
127 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); 128 ui::test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
128 129
129 int32_t routing_id = process_host.GetNextRoutingID(); 130 int32_t routing_id = process_host.GetNextRoutingID();
130 RenderWidgetHostEditCommandCounter* render_widget = 131 RenderWidgetHostEditCommandCounter* render_widget =
131 new RenderWidgetHostEditCommandCounter(&delegate, &process_host, 132 new RenderWidgetHostEditCommandCounter(&delegate, &process_host,
132 routing_id); 133 routing_id);
133 134
134 base::mac::ScopedNSAutoreleasePool pool; 135 base::mac::ScopedNSAutoreleasePool pool;
135 136
137 base::MessageLoop message_loop;
138 ui::WindowResizeHelperMac::Get()->Init(
139 base::MessageLoop::current()->task_runner());
140
136 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa|. 141 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa|.
137 RenderWidgetHostViewMac* rwhv_mac = new RenderWidgetHostViewMac( 142 RenderWidgetHostViewMac* rwhv_mac = new RenderWidgetHostViewMac(
138 render_widget, false); 143 render_widget, false);
139 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa( 144 base::scoped_nsobject<RenderWidgetHostViewCocoa> rwhv_cocoa(
140 [rwhv_mac->cocoa_view() retain]); 145 [rwhv_mac->cocoa_view() retain]);
141 146
142 RenderWidgetHostViewMacEditCommandHelper helper; 147 RenderWidgetHostViewMacEditCommandHelper helper;
143 NSArray* edit_command_strings = helper.GetEditSelectorNames(); 148 NSArray* edit_command_strings = helper.GetEditSelectorNames();
144 RenderWidgetHostViewMacOwner* rwhwvm_owner = 149 RenderWidgetHostViewMacOwner* rwhwvm_owner =
145 [[[RenderWidgetHostViewMacOwner alloc] 150 [[[RenderWidgetHostViewMacOwner alloc]
146 initWithRenderWidgetHostViewMac:rwhv_mac] autorelease]; 151 initWithRenderWidgetHostViewMac:rwhv_mac] autorelease];
147 152
148 helper.AddEditingSelectorsToClass([rwhwvm_owner class]); 153 helper.AddEditingSelectorsToClass([rwhwvm_owner class]);
149 154
150 for (NSString* edit_command_name in edit_command_strings) { 155 for (NSString* edit_command_name in edit_command_strings) {
151 NSString* sel_str = [edit_command_name stringByAppendingString:@":"]; 156 NSString* sel_str = [edit_command_name stringByAppendingString:@":"];
152 [rwhwvm_owner performSelector:NSSelectorFromString(sel_str) withObject:nil]; 157 [rwhwvm_owner performSelector:NSSelectorFromString(sel_str) withObject:nil];
153 } 158 }
154 159
155 size_t num_edit_commands = [edit_command_strings count]; 160 size_t num_edit_commands = [edit_command_strings count];
156 EXPECT_EQ(render_widget->edit_command_message_count_, num_edit_commands); 161 EXPECT_EQ(render_widget->edit_command_message_count_, num_edit_commands);
157 rwhv_cocoa.reset(); 162 rwhv_cocoa.reset();
158 pool.Recycle(); 163 pool.Recycle();
159 164
160 { 165 // The |render_widget|'s process needs to be deleted within |message_loop|.
161 // The |render_widget|'s process needs to be deleted within |message_loop|. 166 delete render_widget;
162 base::MessageLoop message_loop; 167
163 delete render_widget; 168 ui::WindowResizeHelperMac::Get()->ShutdownForTests();
164 }
165 } 169 }
166 170
167 // Test RenderWidgetHostViewMacEditCommandHelper::AddEditingSelectorsToClass 171 // Test RenderWidgetHostViewMacEditCommandHelper::AddEditingSelectorsToClass
168 TEST_F(RenderWidgetHostViewMacEditCommandHelperTest, 172 TEST_F(RenderWidgetHostViewMacEditCommandHelperTest,
169 TestAddEditingSelectorsToClass) { 173 TestAddEditingSelectorsToClass) {
170 RenderWidgetHostViewMacEditCommandHelper helper; 174 RenderWidgetHostViewMacEditCommandHelper helper;
171 NSArray* edit_command_strings = helper.GetEditSelectorNames(); 175 NSArray* edit_command_strings = helper.GetEditSelectorNames();
172 ASSERT_GT([edit_command_strings count], 0U); 176 ASSERT_GT([edit_command_strings count], 0U);
173 177
174 // Create a class instance and add methods to the class. 178 // Create a class instance and add methods to the class.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 210
207 // Random selectors should be enabled by the function. 211 // Random selectors should be enabled by the function.
208 SEL garbage_selector = NSSelectorFromString(@"randomGarbageSelector:"); 212 SEL garbage_selector = NSSelectorFromString(@"randomGarbageSelector:");
209 ASSERT_FALSE(helper.IsMenuItemEnabled(garbage_selector, rwhvm_owner)); 213 ASSERT_FALSE(helper.IsMenuItemEnabled(garbage_selector, rwhvm_owner));
210 214
211 // TODO(jeremy): Currently IsMenuItemEnabled just returns true for all edit 215 // TODO(jeremy): Currently IsMenuItemEnabled just returns true for all edit
212 // selectors. Once we go past that we should do more extensive testing here. 216 // selectors. Once we go past that we should do more extensive testing here.
213 } 217 }
214 218
215 } // namespace content 219 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_mac.mm ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698