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

Side by Side Diff: chrome/renderer/render_widget_unittest.cc

Issue 8885: Implementation of the UI part of the autofill (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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
« no previous file with comments | « chrome/renderer/render_widget.cc ('k') | webkit/build/glue/glue.vcproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "chrome/common/child_process.h" 8 #include "chrome/common/child_process.h"
9 #include "chrome/renderer/render_widget.h" 9 #include "chrome/renderer/render_widget.h"
10 #include "chrome/renderer/render_thread.h" 10 #include "chrome/renderer/render_thread.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok) 107 IPC_BEGIN_MESSAGE_MAP_EX(MockRenderThread, msg, msg_is_ok)
108 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget); 108 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget);
109 IPC_MESSAGE_UNHANDLED(handled = false) 109 IPC_MESSAGE_UNHANDLED(handled = false)
110 IPC_END_MESSAGE_MAP_EX() 110 IPC_END_MESSAGE_MAP_EX()
111 111
112 // This test must handle all messages that RenderWidget generates. 112 // This test must handle all messages that RenderWidget generates.
113 EXPECT_TRUE(handled); 113 EXPECT_TRUE(handled);
114 } 114 }
115 115
116 // The Widget expects to be returned valid route_id. 116 // The Widget expects to be returned valid route_id.
117 void OnMsgCreateWidget(int opener_id, int* route_id) { 117 void OnMsgCreateWidget(int opener_id,
118 bool focus_on_show,
119 int* route_id) {
118 opener_id_ = opener_id; 120 opener_id_ = opener_id;
119 *route_id = routing_id_; 121 *route_id = routing_id_;
120 } 122 }
121 123
122 // Routing id what will be assigned to the Widget. 124 // Routing id what will be assigned to the Widget.
123 int32 routing_id_; 125 int32 routing_id_;
124 // Opener id reported by the Widget. 126 // Opener id reported by the Widget.
125 int32 opener_id_; 127 int32 opener_id_;
126 // We only keep track of one Widget, we learn its pointer when it 128 // We only keep track of one Widget, we learn its pointer when it
127 // adds a new route. 129 // adds a new route.
128 IPC::Channel::Listener* widget_; 130 IPC::Channel::Listener* widget_;
129 // The last known good deserializer for sync messages. 131 // The last known good deserializer for sync messages.
130 IPC::MessageReplyDeserializer* reply_deserializer_; 132 IPC::MessageReplyDeserializer* reply_deserializer_;
131 }; 133 };
132 134
133 TEST(RenderWidgetTest, CreateAndCloseWidget) { 135 TEST(RenderWidgetTest, CreateAndCloseWidget) {
134 MessageLoop msg_loop; 136 MessageLoop msg_loop;
135 MockRenderThread render_thread; 137 MockRenderThread render_thread;
136 MockProcess::GlobalInit(); 138 MockProcess::GlobalInit();
137 139
138 const int32 kRouteId = 5; 140 const int32 kRouteId = 5;
139 const int32 kOpenerId = 7; 141 const int32 kOpenerId = 7;
140 render_thread.set_routing_id(kRouteId); 142 render_thread.set_routing_id(kRouteId);
141 143
142 { 144 {
143 scoped_refptr<RenderWidget> rw = 145 scoped_refptr<RenderWidget> rw =
144 RenderWidget::Create(kOpenerId, &render_thread); 146 RenderWidget::Create(kOpenerId, &render_thread, true);
145 ASSERT_TRUE(rw != NULL); 147 ASSERT_TRUE(rw != NULL);
146 148
147 // After the RenderWidget it must have sent a message to the render thread 149 // After the RenderWidget it must have sent a message to the render thread
148 // that sets the opener id. 150 // that sets the opener id.
149 EXPECT_EQ(kOpenerId, render_thread.opener_id()); 151 EXPECT_EQ(kOpenerId, render_thread.opener_id());
150 ASSERT_TRUE(render_thread.has_widget()); 152 ASSERT_TRUE(render_thread.has_widget());
151 153
152 // Now simulate a close of the Widget. 154 // Now simulate a close of the Widget.
153 render_thread.SendCloseMessage(); 155 render_thread.SendCloseMessage();
154 EXPECT_FALSE(render_thread.has_widget()); 156 EXPECT_FALSE(render_thread.has_widget());
155 157
156 // Run the loop so the release task from the renderwidget executes. 158 // Run the loop so the release task from the renderwidget executes.
157 msg_loop.PostTask(FROM_HERE, new MessageLoop::QuitTask()); 159 msg_loop.PostTask(FROM_HERE, new MessageLoop::QuitTask());
158 msg_loop.Run(); 160 msg_loop.Run();
159 } 161 }
160 162
161 // There is a delayed task that the child process posts to terminate the 163 // There is a delayed task that the child process posts to terminate the
162 // message loop so we need to spin the message loop to delete the task. 164 // message loop so we need to spin the message loop to delete the task.
163 MockProcess::GlobalCleanup(); 165 MockProcess::GlobalCleanup();
164 msg_loop.Run(); 166 msg_loop.Run();
165 } 167 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_widget.cc ('k') | webkit/build/glue/glue.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698