summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 18:48:14 +0000
committerdcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-02 18:48:14 +0000
commit92c7f876ef1041d01dc37750420513e19391874c (patch)
treea499603d2d3496d148d9d1b303d8cf234e1ac5a4
parent62cfba3d474a85bd874039c4b05c754f1bbdefc0 (diff)
downloadchromium_src-92c7f876ef1041d01dc37750420513e19391874c.zip
chromium_src-92c7f876ef1041d01dc37750420513e19391874c.tar.gz
chromium_src-92c7f876ef1041d01dc37750420513e19391874c.tar.bz2
Attempt 2 to enable async data: URL loading.
BUG=308321 Review URL: https://codereview.chromium.org/251903006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267886 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_tests.gypi2
-rw-r--r--content/public/test/render_view_test.cc7
-rw-r--r--content/renderer/render_view_browsertest.cc9
-rw-r--r--content/test/frame_load_waiter.cc27
-rw-r--r--content/test/frame_load_waiter.h32
5 files changed, 70 insertions, 7 deletions
diff --git a/content/content_tests.gypi b/content/content_tests.gypi
index 0d75120..46993d6 100644
--- a/content/content_tests.gypi
+++ b/content/content_tests.gypi
@@ -161,6 +161,8 @@
'test/content_browser_test_utils_internal.h',
'test/content_test_suite.cc',
'test/content_test_suite.h',
+ 'test/frame_load_waiter.cc',
+ 'test/frame_load_waiter.h',
'test/mock_google_streaming_server.cc',
'test/mock_google_streaming_server.h',
'test/mock_keyboard.cc',
diff --git a/content/public/test/render_view_test.cc b/content/public/test/render_view_test.cc
index cb0d132..9c2e8dc 100644
--- a/content/public/test/render_view_test.cc
+++ b/content/public/test/render_view_test.cc
@@ -20,6 +20,7 @@
#include "content/renderer/render_view_impl.h"
#include "content/renderer/renderer_main_platform_delegate.h"
#include "content/renderer/renderer_webkitplatformsupport_impl.h"
+#include "content/test/frame_load_waiter.h"
#include "content/test/mock_render_process.h"
#include "third_party/WebKit/public/platform/WebScreenInfo.h"
#include "third_party/WebKit/public/platform/WebURLRequest.h"
@@ -117,12 +118,10 @@ void RenderViewTest::LoadHTML(const char* html) {
std::string url_str = "data:text/html;charset=utf-8,";
url_str.append(html);
GURL url(url_str);
-
GetMainFrame()->loadRequest(WebURLRequest(url));
-
// The load actually happens asynchronously, so we pump messages to process
// the pending continuation.
- ProcessPendingMessages();
+ FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
}
void RenderViewTest::GoBack(const PageState& state) {
@@ -425,7 +424,7 @@ void RenderViewTest::GoToOffset(int offset, const PageState& state) {
// The load actually happens asynchronously, so we pump messages to process
// the pending continuation.
- ProcessPendingMessages();
+ FrameLoadWaiter(view_->GetMainRenderFrame()).Wait();
}
} // namespace content
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index f0a8802..b06151b 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -35,6 +35,7 @@
#include "content/renderer/render_view_impl.h"
#include "content/shell/browser/shell.h"
#include "content/shell/browser/shell_browser_context.h"
+#include "content/test/frame_load_waiter.h"
#include "content/test/mock_keyboard.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h"
@@ -2014,7 +2015,8 @@ TEST_F(RenderViewImplTest, NavigateFrame) {
nav_params.page_id = -1;
nav_params.frame_to_navigate = "frame";
frame()->OnNavigate(nav_params);
- ProcessPendingMessages();
+ FrameLoadWaiter(
+ RenderFrame::FromWebFrame(frame()->GetWebFrame()->firstChild())).Wait();
// Copy the document content to std::wstring and compare with the
// expected result.
@@ -2164,7 +2166,8 @@ TEST_F(SuppressErrorPageTest, MAYBE_DoesNotSuppress) {
// An error occurred.
view()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
- ProcessPendingMessages();
+ // The error page itself is loaded asynchronously.
+ FrameLoadWaiter(frame()).Wait();
const int kMaxOutputCharacters = 22;
EXPECT_EQ("A suffusion of yellow.",
base::UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
@@ -2249,7 +2252,7 @@ TEST_F(RenderViewImplTest, SendProgressCompletionUpdates) {
EXPECT_EQ(0.1, progress_value.a);
render_thread_->sink().ClearMessages();
- ProcessPendingMessages();
+ FrameLoadWaiter(frame()).Wait();
// The data url has loaded, so we should see a progress change to 1.0 (done)
// and a stop notification.
diff --git a/content/test/frame_load_waiter.cc b/content/test/frame_load_waiter.cc
new file mode 100644
index 0000000..6343f85
--- /dev/null
+++ b/content/test/frame_load_waiter.cc
@@ -0,0 +1,27 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/test/frame_load_waiter.h"
+
+#include "base/location.h"
+#include "base/message_loop/message_loop.h"
+
+namespace content {
+
+FrameLoadWaiter::FrameLoadWaiter(RenderFrame* frame)
+ : RenderFrameObserver(frame) {
+}
+
+void FrameLoadWaiter::Wait() {
+ // Pump messages until Blink's threaded HTML parser finishes.
+ run_loop_.Run();
+}
+
+void FrameLoadWaiter::DidFinishLoad() {
+ // Post a task to quit instead of quitting directly, since the load completion
+ // may trigger other IPCs that tests are expecting.
+ base::MessageLoop::current()->PostTask(FROM_HERE, run_loop_.QuitClosure());
+}
+
+} // namespace content
diff --git a/content/test/frame_load_waiter.h b/content/test/frame_load_waiter.h
new file mode 100644
index 0000000..81b0baa
--- /dev/null
+++ b/content/test/frame_load_waiter.h
@@ -0,0 +1,32 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_TEST_FRAME_LOAD_WAITER_H_
+#define CONTENT_TEST_FRAME_LOAD_WAITER_H_
+
+#include "base/macros.h"
+#include "base/run_loop.h"
+#include "content/public/renderer/render_frame_observer.h"
+
+namespace content {
+
+// Helper class to spin the run loop when waiting for a frame load to complete.
+// Blink uses a threaded HTML parser, so it's no longer sufficient to just spin
+// the run loop once to process all pending messages.
+class FrameLoadWaiter : public RenderFrameObserver {
+ public:
+ explicit FrameLoadWaiter(RenderFrame* frame);
+ void Wait();
+
+ private:
+ virtual void DidFinishLoad() OVERRIDE;
+
+ base::RunLoop run_loop_;
+
+ DISALLOW_COPY_AND_ASSIGN(FrameLoadWaiter);
+};
+
+} // namespace content
+
+#endif // CONTENT_TEST_FRAME_LOAD_WAITER_H_