OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 ListValue* list = static_cast<ListValue*>(root_val.get()); | 221 ListValue* list = static_cast<ListValue*>(root_val.get()); |
222 Value* result_val; | 222 Value* result_val; |
223 if (!list || !list->GetSize() || | 223 if (!list || !list->GetSize() || |
224 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. | 224 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. |
225 return false; | 225 return false; |
226 | 226 |
227 result->reset(result_val); | 227 result->reset(result_val); |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
| 231 void RunAllPendingMessageAndSendQuit(content::BrowserThread::ID thread_id) { |
| 232 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 233 RunMessageLoop(); |
| 234 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
| 235 new MessageLoop::QuitTask()); |
| 236 } |
| 237 |
231 } // namespace | 238 } // namespace |
232 | 239 |
233 void RunMessageLoop() { | 240 void RunMessageLoop() { |
234 MessageLoopForUI* loop = MessageLoopForUI::current(); | 241 MessageLoop* loop = MessageLoop::current(); |
| 242 MessageLoopForUI* ui_loop = |
| 243 content::BrowserThread::CurrentlyOn(content::BrowserThread::UI) ? |
| 244 MessageLoopForUI::current() : NULL; |
235 bool did_allow_task_nesting = loop->NestableTasksAllowed(); | 245 bool did_allow_task_nesting = loop->NestableTasksAllowed(); |
236 loop->SetNestableTasksAllowed(true); | 246 loop->SetNestableTasksAllowed(true); |
| 247 if (ui_loop) { |
237 #if defined(USE_AURA) | 248 #if defined(USE_AURA) |
238 aura::Desktop::GetInstance()->Run(); | 249 aura::Desktop::GetInstance()->Run(); |
239 #elif defined(TOOLKIT_VIEWS) | 250 #elif defined(TOOLKIT_VIEWS) |
240 views::AcceleratorHandler handler; | 251 views::AcceleratorHandler handler; |
241 loop->RunWithDispatcher(&handler); | 252 ui_loop->RunWithDispatcher(&handler); |
242 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 253 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
243 loop->RunWithDispatcher(NULL); | 254 ui_loop->RunWithDispatcher(NULL); |
244 #else | 255 #else |
245 loop->Run(); | 256 ui_loop->Run(); |
246 #endif | 257 #endif |
| 258 } else { |
| 259 loop->Run(); |
| 260 } |
247 loop->SetNestableTasksAllowed(did_allow_task_nesting); | 261 loop->SetNestableTasksAllowed(did_allow_task_nesting); |
248 } | 262 } |
249 | 263 |
250 void RunAllPendingInMessageLoop() { | 264 void RunAllPendingInMessageLoop() { |
251 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 265 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
252 ui_test_utils::RunMessageLoop(); | 266 ui_test_utils::RunMessageLoop(); |
253 } | 267 } |
254 | 268 |
| 269 void RunAllPendingInMessageLoop(content::BrowserThread::ID thread_id) { |
| 270 if (content::BrowserThread::CurrentlyOn(thread_id)) { |
| 271 RunAllPendingInMessageLoop(); |
| 272 return; |
| 273 } |
| 274 content::BrowserThread::ID current_thread_id; |
| 275 if (!content::BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id)) { |
| 276 NOTREACHED(); |
| 277 return; |
| 278 } |
| 279 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
| 280 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id)); |
| 281 |
| 282 ui_test_utils::RunMessageLoop(); |
| 283 } |
| 284 |
255 bool GetCurrentTabTitle(const Browser* browser, string16* title) { | 285 bool GetCurrentTabTitle(const Browser* browser, string16* title) { |
256 TabContents* tab_contents = browser->GetSelectedTabContents(); | 286 TabContents* tab_contents = browser->GetSelectedTabContents(); |
257 if (!tab_contents) | 287 if (!tab_contents) |
258 return false; | 288 return false; |
259 NavigationEntry* last_entry = tab_contents->controller().GetActiveEntry(); | 289 NavigationEntry* last_entry = tab_contents->controller().GetActiveEntry(); |
260 if (!last_entry) | 290 if (!last_entry) |
261 return false; | 291 return false; |
262 title->assign(last_entry->GetTitleForDisplay("")); | 292 title->assign(last_entry->GetTitleForDisplay("")); |
263 return true; | 293 return true; |
264 } | 294 } |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1025 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
996 } | 1026 } |
997 | 1027 |
998 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1028 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
999 DCHECK(bitmap); | 1029 DCHECK(bitmap); |
1000 SnapshotTaker taker; | 1030 SnapshotTaker taker; |
1001 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1031 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
1002 } | 1032 } |
1003 | 1033 |
1004 } // namespace ui_test_utils | 1034 } // namespace ui_test_utils |
OLD | NEW |