#include "base/time/time.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
-#include "content/public/renderer/history_item_serialization.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_visitor.h"
#include "content/public/test/layouttest_support.h"
#include "content/shell/renderer/test_runner/WebTestInterfaces.h"
#include "content/shell/renderer/test_runner/WebTestProxy.h"
#include "content/shell/renderer/test_runner/WebTestRunner.h"
+#include "net/base/filename_util.h"
#include "net/base/net_errors.h"
-#include "net/base/net_util.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/web/WebDevToolsAgent.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLeakDetector.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebTestingSupport.h"
#include "third_party/WebKit/public/web/WebView.h"
using blink::WebDeviceMotionData;
using blink::WebDeviceOrientationData;
using blink::WebElement;
-using blink::WebFrame;
+using blink::WebLocalFrame;
using blink::WebGamepads;
using blink::WebHistoryItem;
+using blink::WebLocalFrame;
using blink::WebPoint;
using blink::WebRect;
using blink::WebScriptSource;
using blink::WebURL;
using blink::WebURLError;
using blink::WebURLRequest;
-using blink::WebScreenOrientation;
+using blink::WebScreenOrientationType;
using blink::WebTestingSupport;
using blink::WebVector;
using blink::WebView;
-using WebTestRunner::WebTask;
-using WebTestRunner::WebTestInterfaces;
-using WebTestRunner::WebTestProxyBase;
namespace content {
focused_view_(NULL),
is_main_window_(false),
focus_on_next_commit_(false),
- leak_detector_(new LeakDetector())
-{
- UseMockMediaStreams(render_view);
+ leak_detector_(new LeakDetector(this)) {
}
WebKitTestRunner::~WebKitTestRunner() {
}
void WebKitTestRunner::setScreenOrientation(
- const WebScreenOrientation& orientation) {
+ const WebScreenOrientationType& orientation) {
SetMockScreenOrientation(orientation);
}
return WebURL(GURL(new_url));
}
-WebTestRunner::WebPreferences* WebKitTestRunner::preferences() {
+TestPreferences* WebKitTestRunner::preferences() {
return &prefs_;
}
Send(new ShellViewHostMsg_ClearDevToolsLocalStorage(routing_id()));
}
-void WebKitTestRunner::showDevTools(const std::string& settings) {
- Send(new ShellViewHostMsg_ShowDevTools(routing_id(), settings));
+void WebKitTestRunner::showDevTools(const std::string& settings,
+ const std::string& frontend_url) {
+ Send(new ShellViewHostMsg_ShowDevTools(
+ routing_id(), settings, frontend_url));
}
void WebKitTestRunner::closeDevTools() {
SetDeviceScaleFactor(render_view(), factor);
}
+void WebKitTestRunner::setDeviceColorProfile(const std::string& name) {
+ SetDeviceColorProfile(render_view(), name);
+}
+
void WebKitTestRunner::setFocus(WebTestProxyBase* proxy, bool focus) {
ProxyToRenderViewVisitor visitor(proxy);
RenderView::ForEach(&visitor);
return test_config_.allow_external_pages;
}
-void WebKitTestRunner::captureHistoryForWindow(
- WebTestProxyBase* proxy,
- WebVector<blink::WebHistoryItem>* history,
- size_t* currentEntryIndex) {
+std::string WebKitTestRunner::dumpHistoryForWindow(WebTestProxyBase* proxy) {
size_t pos = 0;
std::vector<int>::iterator id;
for (id = routing_ids_.begin(); id != routing_ids_.end(); ++id, ++pos) {
if (id == routing_ids_.end()) {
NOTREACHED();
- return;
+ return std::string();
}
- size_t num_entries = session_histories_[pos].size();
- *currentEntryIndex = current_entry_indexes_[pos];
- WebVector<WebHistoryItem> result(num_entries);
- for (size_t entry = 0; entry < num_entries; ++entry) {
- result[entry] =
- PageStateToHistoryItem(session_histories_[pos][entry]);
- }
- history->swap(result);
+ return DumpBackForwardList(session_histories_[pos],
+ current_entry_indexes_[pos]);
}
// RenderViewObserver --------------------------------------------------------
-void WebKitTestRunner::DidClearWindowObject(WebFrame* frame, int world_id) {
+void WebKitTestRunner::DidClearWindowObject(WebLocalFrame* frame,
+ int world_id) {
WebTestingSupport::injectInternalsObject(frame);
if (world_id == 0) {
ShellRenderProcessObserver::GetInstance()->test_interfaces()->bindTo(frame);
}
}
-void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame,
+void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame,
bool is_new_navigation) {
if (!focus_on_next_commit_)
return;
render_view()->GetWebView()->setFocusedFrame(frame);
}
-void WebKitTestRunner::DidFailProvisionalLoad(WebFrame* frame,
+void WebKitTestRunner::DidFailProvisionalLoad(WebLocalFrame* frame,
const WebURLError& error) {
focus_on_next_commit_ = false;
}
// The proxy_ is always non-NULL, it is set right after construction.
proxy_->setWidget(render_view()->GetWebView());
proxy_->reset();
- prefs_.reset();
+ prefs_.Reset();
routing_ids_.clear();
session_histories_.clear();
current_entry_indexes_.clear();
// Resetting the internals object also overrides the WebPreferences, so we
// have to sync them to WebKit again.
WebTestingSupport::resetInternalsObject(
- render_view()->GetWebView()->mainFrame());
+ render_view()->GetWebView()->mainFrame()->toWebLocalFrame());
render_view()->SetWebkitPreferences(render_view()->GetWebkitPreferences());
}
void WebKitTestRunner::CaptureDump() {
WebTestInterfaces* interfaces =
ShellRenderProcessObserver::GetInstance()->test_interfaces();
+ TRACE_EVENT0("shell", "WebKitTestRunner::CaptureDump");
if (interfaces->testRunner()->shouldDumpAsAudio()) {
std::vector<unsigned char> vector_data;
if (test_config_.enable_pixel_dumping &&
interfaces->testRunner()->shouldGeneratePixelResults()) {
- SkBitmap snapshot;
- CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
-
- SkAutoLockPixels snapshot_lock(snapshot);
- base::MD5Digest digest;
- base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
- std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
-
- if (actual_pixel_hash == test_config_.expected_pixel_hash) {
- SkBitmap empty_image;
- Send(new ShellViewHostMsg_ImageDump(
- routing_id(), actual_pixel_hash, empty_image));
+ // TODO(danakj): Remove when kForceCompositingMode is everywhere.
+ if (!render_view()->GetWebView()->isAcceleratedCompositingActive()) {
+ SkBitmap snapshot;
+ CopyCanvasToBitmap(proxy()->capturePixels(), &snapshot);
+ CaptureDumpPixels(snapshot);
} else {
- Send(new ShellViewHostMsg_ImageDump(
- routing_id(), actual_pixel_hash, snapshot));
+ proxy()->CapturePixelsAsync(base::Bind(
+ &WebKitTestRunner::CaptureDumpPixels, base::Unretained(this)));
}
+ return;
}
}
+ CaptureDumpComplete();
+}
+
+void WebKitTestRunner::CaptureDumpPixels(const SkBitmap& snapshot) {
+ DCHECK_NE(0, snapshot.info().fWidth);
+ DCHECK_NE(0, snapshot.info().fHeight);
+
+ SkAutoLockPixels snapshot_lock(snapshot);
+ base::MD5Digest digest;
+ base::MD5Sum(snapshot.getPixels(), snapshot.getSize(), &digest);
+ std::string actual_pixel_hash = base::MD5DigestToBase16(digest);
+
+ if (actual_pixel_hash == test_config_.expected_pixel_hash) {
+ SkBitmap empty_image;
+ Send(new ShellViewHostMsg_ImageDump(
+ routing_id(), actual_pixel_hash, empty_image));
+ } else {
+ Send(new ShellViewHostMsg_ImageDump(
+ routing_id(), actual_pixel_hash, snapshot));
+ }
+
+ CaptureDumpComplete();
+}
+
+void WebKitTestRunner::CaptureDumpComplete() {
render_view()->GetWebView()->mainFrame()->stopLoading();
base::MessageLoop::current()->PostTask(
}
void WebKitTestRunner::OnTryLeakDetection() {
- base::MessageLoop::current()->PostTask(
- FROM_HERE,
- base::Bind(&WebKitTestRunner::TryLeakDetection, base::Unretained(this)));
-}
-
-void WebKitTestRunner::TryLeakDetection() {
- WebFrame* main_frame = render_view()->GetWebView()->mainFrame();
+ WebLocalFrame* main_frame =
+ render_view()->GetWebView()->mainFrame()->toWebLocalFrame();
DCHECK_EQ(GURL(kAboutBlankURL), GURL(main_frame->document().url()));
DCHECK(!main_frame->isLoading());
- LeakDetectionResult result = leak_detector_->TryLeakDetection(
- render_view()->GetWebView()->mainFrame());
- Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), result));
+ leak_detector_->TryLeakDetection(main_frame);
+}
+
+void WebKitTestRunner::ReportLeakDetectionResult(
+ const LeakDetectionResult& report) {
+ Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
}
} // namespace content