[content shell] eliminate the pause between reset and starting a new test
When receiving the configuration for the next test, we don't immediately set the
config but wait for the render view to navigate to the next test. Only then,
reset all test interfaces, and apply the new config
BUG=171128
[email protected]
Review URL: https://codereview.chromium.org/12597002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186654 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/shell/webkit_test_runner.cc b/content/shell/webkit_test_runner.cc
index fc662bb..f63b20f 100644
--- a/content/shell/webkit_test_runner.cc
+++ b/content/shell/webkit_test_runner.cc
@@ -45,6 +45,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebTestingSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTask.h"
#include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestInterfaces.h"
@@ -68,6 +69,7 @@
using WebKit::WebRect;
using WebKit::WebSize;
using WebKit::WebString;
+using WebKit::WebTestingSupport;
using WebKit::WebURL;
using WebKit::WebURLError;
using WebKit::WebVector;
@@ -81,8 +83,6 @@
namespace {
-int kDefaultLayoutTestTimeoutMs = 30 * 1000;
-
void InvokeTaskHelper(void* context) {
WebTask* task = reinterpret_cast<WebTask*>(context);
task->run();
@@ -162,10 +162,9 @@
RenderViewObserverTracker<WebKitTestRunner>(render_view),
proxy_(NULL),
focused_view_(NULL),
- enable_pixel_dumping_(true),
- layout_test_timeout_(kDefaultLayoutTestTimeoutMs),
- allow_external_pages_(false),
- is_main_window_(false) {
+ is_main_window_(false),
+ reset_on_next_navigation_(false),
+ test_is_running_(false) {
}
WebKitTestRunner::~WebKitTestRunner() {
@@ -403,11 +402,12 @@
}
void WebKitTestRunner::testFinished() {
- if (!is_main_window_)
+ if (!is_main_window_ || !test_is_running_)
return;
WebTestInterfaces* interfaces =
ShellRenderProcessObserver::GetInstance()->test_interfaces();
interfaces->setTestIsRunning(false);
+ test_is_running_ = false;
if (interfaces->testRunner()->shouldDumpBackForwardList()) {
SyncNavigationStateVisitor visitor;
RenderView::ForEach(&visitor);
@@ -418,11 +418,12 @@
}
void WebKitTestRunner::testTimedOut() {
- if (!is_main_window_)
+ if (!is_main_window_ || !test_is_running_)
return;
WebTestInterfaces* interfaces =
ShellRenderProcessObserver::GetInstance()->test_interfaces();
interfaces->setTestIsRunning(false);
+ test_is_running_ = false;
Send(new ShellViewHostMsg_TestFinished(routing_id(), true));
}
@@ -431,7 +432,7 @@
}
int WebKitTestRunner::layoutTestTimeout() {
- return layout_test_timeout_;
+ return test_config_.layout_test_timeout;
}
void WebKitTestRunner::closeRemainingWindows() {
@@ -457,7 +458,7 @@
}
bool WebKitTestRunner::allowExternalPages() {
- return allow_external_pages_;
+ return test_config_.allow_external_pages;
}
void WebKitTestRunner::captureHistoryForWindow(
@@ -493,7 +494,8 @@
// RenderViewObserver --------------------------------------------------------
void WebKitTestRunner::DidClearWindowObject(WebFrame* frame) {
- ShellRenderProcessObserver::GetInstance()->BindTestRunnersToWindow(frame);
+ WebTestingSupport::injectInternalsObject(frame);
+ ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame);
}
bool WebKitTestRunner::OnMessageReceived(const IPC::Message& message) {
@@ -508,19 +510,36 @@
return handled;
}
+void WebKitTestRunner::Navigate(const GURL& url) {
+ if (!reset_on_next_navigation_)
+ return;
+
+ reset_on_next_navigation_ = false;
+ Reset();
+
+ WebTestInterfaces* interfaces =
+ ShellRenderProcessObserver::GetInstance()->test_interfaces();
+ interfaces->configureForTestWithURL(test_config_.test_url,
+ test_config_.enable_pixel_dumping);
+ interfaces->setTestIsRunning(true);
+ test_is_running_ = true;
+}
+
// Public methods - -----------------------------------------------------------
void WebKitTestRunner::Reset() {
+ ShellRenderProcessObserver::GetInstance()->test_interfaces()->resetAll();
// The proxy_ is always non-NULL, it is set right after construction.
proxy_->reset();
prefs_.reset();
- enable_pixel_dumping_ = true;
- layout_test_timeout_ = kDefaultLayoutTestTimeoutMs;
- allow_external_pages_ = false;
- expected_pixel_hash_ = std::string();
routing_ids_.clear();
session_histories_.clear();
current_entry_indexes_.clear();
+ // This overrides the WebPreferences, so we have to reset them again.
+ WebTestingSupport::resetInternalsObject(
+ render_view()->GetWebView()->mainFrame());
+ render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences());
+ setFocus(proxy_, true);
}
// Private methods -----------------------------------------------------------
@@ -544,7 +563,7 @@
Send(
new ShellViewHostMsg_TextDump(routing_id(), proxy()->captureTree(false)));
- if (enable_pixel_dumping_ &&
+ if (test_config_.enable_pixel_dumping &&
interfaces->testRunner()->shouldGeneratePixelResults()) {
SkBitmap snapshot;
CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
@@ -570,7 +589,7 @@
#endif
std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
- if (actual_pixel_hash == expected_pixel_hash_) {
+ if (actual_pixel_hash == test_config_.expected_pixel_hash) {
SkBitmap empty_image;
Send(new ShellViewHostMsg_ImageDump(
routing_id(), actual_pixel_hash, empty_image));
@@ -584,21 +603,10 @@
}
void WebKitTestRunner::OnSetTestConfiguration(
- const ShellViewMsg_SetTestConfiguration_Params& params) {
- current_working_directory_ = params.current_working_directory;
- temp_path_ = params.temp_path;
- enable_pixel_dumping_ = params.enable_pixel_dumping;
- layout_test_timeout_ = params.layout_test_timeout;
- allow_external_pages_ = params.allow_external_pages;
- expected_pixel_hash_ = params.expected_pixel_hash;
+ const ShellTestConfiguration& params) {
+ test_config_ = params;
+ reset_on_next_navigation_ = true;
is_main_window_ = true;
-
- setFocus(proxy_, true);
-
- WebTestInterfaces* interfaces =
- ShellRenderProcessObserver::GetInstance()->test_interfaces();
- interfaces->setTestIsRunning(true);
- interfaces->configureForTestWithURL(params.test_url, enable_pixel_dumping_);
}
void WebKitTestRunner::OnSessionHistory(