OLD | NEW |
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 #include "content/test/content_browser_test_utils.h" | 5 #include "content/test/content_browser_test_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "content/public/browser/dom_operation_notification_details.h" |
11 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/notification_service.h" |
13 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/content_paths.h" | 17 #include "content/public/common/content_paths.h" |
15 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
17 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
18 #include "content/shell/shell.h" | 21 #include "content/shell/shell.h" |
19 #include "content/shell/shell_javascript_dialog_creator.h" | 22 #include "content/shell/shell_javascript_dialog_creator.h" |
20 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
21 | 24 |
22 namespace content { | 25 namespace content { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 return shell_; | 85 return shell_; |
83 } | 86 } |
84 | 87 |
85 void ShellAddedObserver::ShellCreated(Shell* shell) { | 88 void ShellAddedObserver::ShellCreated(Shell* shell) { |
86 DCHECK(!shell_); | 89 DCHECK(!shell_); |
87 shell_ = shell; | 90 shell_ = shell; |
88 if (runner_) | 91 if (runner_) |
89 runner_->QuitClosure().Run(); | 92 runner_->QuitClosure().Run(); |
90 } | 93 } |
91 | 94 |
| 95 DOMMessageQueue::DOMMessageQueue() : waiting_for_message_(false) { |
| 96 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 97 content::NotificationService::AllSources()); |
| 98 } |
| 99 |
| 100 DOMMessageQueue::~DOMMessageQueue() {} |
| 101 |
| 102 void DOMMessageQueue::Observe(int type, |
| 103 const content::NotificationSource& source, |
| 104 const content::NotificationDetails& details) { |
| 105 content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| 106 content::Source<RenderViewHost> sender(source); |
| 107 message_queue_.push(dom_op_details->json); |
| 108 if (waiting_for_message_) { |
| 109 waiting_for_message_ = false; |
| 110 message_loop_runner_->Quit(); |
| 111 } |
| 112 } |
| 113 |
| 114 void DOMMessageQueue::ClearQueue() { |
| 115 message_queue_ = std::queue<std::string>(); |
| 116 } |
| 117 |
| 118 bool DOMMessageQueue::WaitForMessage(std::string* message) { |
| 119 if (message_queue_.empty()) { |
| 120 waiting_for_message_ = true; |
| 121 // This will be quit when a new message comes in. |
| 122 message_loop_runner_ = new content::MessageLoopRunner; |
| 123 message_loop_runner_->Run(); |
| 124 } |
| 125 // The queue should not be empty, unless we were quit because of a timeout. |
| 126 if (message_queue_.empty()) |
| 127 return false; |
| 128 if (message) |
| 129 *message = message_queue_.front(); |
| 130 return true; |
| 131 } |
| 132 |
92 } // namespace content | 133 } // namespace content |
OLD | NEW |