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/public/test/render_view_test.h" | 5 #include "content/public/test/render_view_test.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "content/common/dom_storage/dom_storage_types.h" | 8 #include "content/common/dom_storage/dom_storage_types.h" |
9 #include "content/common/frame_messages.h" | 9 #include "content/common/frame_messages.h" |
10 #include "content/common/input_messages.h" | 10 #include "content/common/input_messages.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 GetMainFrame()->executeScriptAndReturnValue(WebScriptSource(script)); | 106 GetMainFrame()->executeScriptAndReturnValue(WebScriptSource(script)); |
107 if (result.IsEmpty() || !result->IsInt32()) | 107 if (result.IsEmpty() || !result->IsInt32()) |
108 return false; | 108 return false; |
109 | 109 |
110 if (int_result) | 110 if (int_result) |
111 *int_result = result->Int32Value(); | 111 *int_result = result->Int32Value(); |
112 | 112 |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 class FrameLoadWaiter : public content::RenderViewObserver { | |
117 public: | |
118 FrameLoadWaiter(RenderView* view, base::MessageLoop* msg_loop) | |
119 : content::RenderViewObserver(view), | |
120 msg_loop_(msg_loop) {} | |
121 | |
122 virtual void DidFinishLoad(blink::WebLocalFrame* frame) OVERRIDE { | |
123 msg_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | |
124 } | |
125 | |
126 void Wait() { | |
127 // We can't just post a quit message here, blink parses on another | |
128 // thread and may post additional messages as it parses content. | |
129 msg_loop_->Run(); | |
130 } | |
131 private: | |
132 base::MessageLoop* msg_loop_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(FrameLoadWaiter); | |
135 }; | |
136 | |
137 void RenderViewTest::LoadHTML(const char* html) { | 116 void RenderViewTest::LoadHTML(const char* html) { |
138 std::string url_str = "data:text/html;charset=utf-8,"; | 117 std::string url_str = "data:text/html;charset=utf-8,"; |
139 url_str.append(html); | 118 url_str.append(html); |
140 GURL url(url_str); | 119 GURL url(url_str); |
141 FrameLoadWaiter waiter(view_, &msg_loop_); | 120 |
142 GetMainFrame()->loadRequest(WebURLRequest(url)); | 121 GetMainFrame()->loadRequest(WebURLRequest(url)); |
| 122 |
143 // The load actually happens asynchronously, so we pump messages to process | 123 // The load actually happens asynchronously, so we pump messages to process |
144 // the pending continuation. | 124 // the pending continuation. |
145 waiter.Wait(); | 125 ProcessPendingMessages(); |
146 } | 126 } |
147 | 127 |
148 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { | 128 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { |
149 GoToOffset(-1, item); | 129 GoToOffset(-1, item); |
150 } | 130 } |
151 | 131 |
152 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { | 132 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { |
153 GoToOffset(1, item); | 133 GoToOffset(1, item); |
154 } | 134 } |
155 | 135 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), | 421 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), |
442 navigate_params); | 422 navigate_params); |
443 impl->main_render_frame()->OnMessageReceived(navigate_message); | 423 impl->main_render_frame()->OnMessageReceived(navigate_message); |
444 | 424 |
445 // The load actually happens asynchronously, so we pump messages to process | 425 // The load actually happens asynchronously, so we pump messages to process |
446 // the pending continuation. | 426 // the pending continuation. |
447 ProcessPendingMessages(); | 427 ProcessPendingMessages(); |
448 } | 428 } |
449 | 429 |
450 } // namespace content | 430 } // namespace content |
OLD | NEW |