Chromium Code Reviews| 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: | |
|
sky
2014/04/24 23:19:11
indent this and 132 one space (ya, one space, go f
| |
| 118 FrameLoadWaiter(RenderView* view, base::MessageLoop& msg_loop) | |
|
sky
2014/04/24 23:19:11
Only references allowed are to const object. Since
| |
| 119 : content::RenderViewObserver(view), | |
|
sky
2014/04/24 23:19:11
indent this 4 more spaces.
| |
| 120 msg_loop_(msg_loop) { | |
| 121 } | |
| 122 | |
| 123 virtual void DidFinishLoad(blink::WebLocalFrame* frame) { | |
|
sky
2014/04/24 23:19:11
Add OVERRIDE.
| |
| 124 msg_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | |
| 125 } | |
| 126 | |
| 127 void Wait() { | |
| 128 // We can't just post a quit message here, blink parses on another | |
| 129 // thread and may post additional messages as it parses content. | |
| 130 msg_loop_.Run(); | |
| 131 } | |
| 132 private: | |
| 133 base::MessageLoop& msg_loop_; | |
| 134 }; | |
|
sky
2014/04/24 23:19:11
Good practice to add DISALLOW_COPY_AND_ASSIGN.
| |
| 135 | |
| 116 void RenderViewTest::LoadHTML(const char* html) { | 136 void RenderViewTest::LoadHTML(const char* html) { |
| 117 std::string url_str = "data:text/html;charset=utf-8,"; | 137 std::string url_str = "data:text/html;charset=utf-8,"; |
| 118 url_str.append(html); | 138 url_str.append(html); |
| 119 GURL url(url_str); | 139 GURL url(url_str); |
| 120 | 140 FrameLoadWaiter waiter(view_, msg_loop_); |
| 121 GetMainFrame()->loadRequest(WebURLRequest(url)); | 141 GetMainFrame()->loadRequest(WebURLRequest(url)); |
| 122 | |
| 123 // The load actually happens asynchronously, so we pump messages to process | 142 // The load actually happens asynchronously, so we pump messages to process |
| 124 // the pending continuation. | 143 // the pending continuation. |
| 125 ProcessPendingMessages(); | 144 waiter.Wait(); |
| 126 } | 145 } |
| 127 | 146 |
| 128 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { | 147 void RenderViewTest::GoBack(const blink::WebHistoryItem& item) { |
| 129 GoToOffset(-1, item); | 148 GoToOffset(-1, item); |
| 130 } | 149 } |
| 131 | 150 |
| 132 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { | 151 void RenderViewTest::GoForward(const blink::WebHistoryItem& item) { |
| 133 GoToOffset(1, item); | 152 GoToOffset(1, item); |
| 134 } | 153 } |
| 135 | 154 |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), | 440 FrameMsg_Navigate navigate_message(impl->main_render_frame()->GetRoutingID(), |
| 422 navigate_params); | 441 navigate_params); |
| 423 impl->main_render_frame()->OnMessageReceived(navigate_message); | 442 impl->main_render_frame()->OnMessageReceived(navigate_message); |
| 424 | 443 |
| 425 // The load actually happens asynchronously, so we pump messages to process | 444 // The load actually happens asynchronously, so we pump messages to process |
| 426 // the pending continuation. | 445 // the pending continuation. |
| 427 ProcessPendingMessages(); | 446 ProcessPendingMessages(); |
| 428 } | 447 } |
| 429 | 448 |
| 430 } // namespace content | 449 } // namespace content |
| OLD | NEW |