Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / webkit_test_runner.cc
index 4141520..e82c423 100644 (file)
@@ -22,7 +22,6 @@
 #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"
@@ -36,8 +35,8 @@
 #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"
@@ -72,9 +71,10 @@ using blink::WebDevToolsAgent;
 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;
@@ -83,13 +83,10 @@ using blink::WebString;
 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 {
 
@@ -213,9 +210,7 @@ WebKitTestRunner::WebKitTestRunner(RenderView* render_view)
       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() {
@@ -258,7 +253,7 @@ void WebKitTestRunner::setDeviceOrientationData(
 }
 
 void WebKitTestRunner::setScreenOrientation(
-    const WebScreenOrientation& orientation) {
+    const WebScreenOrientationType& orientation) {
   SetMockScreenOrientation(orientation);
 }
 
@@ -343,7 +338,7 @@ WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
   return WebURL(GURL(new_url));
 }
 
-WebTestRunner::WebPreferences* WebKitTestRunner::preferences() {
+TestPreferences* WebKitTestRunner::preferences() {
   return &prefs_;
 }
 
@@ -405,8 +400,10 @@ void WebKitTestRunner::clearDevToolsLocalStorage() {
   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() {
@@ -435,6 +432,10 @@ void WebKitTestRunner::setDeviceScaleFactor(float factor) {
   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);
@@ -538,10 +539,7 @@ bool WebKitTestRunner::allowExternalPages() {
   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) {
@@ -556,21 +554,16 @@ void WebKitTestRunner::captureHistoryForWindow(
 
   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);
@@ -605,7 +598,7 @@ void WebKitTestRunner::Navigate(const GURL& url) {
   }
 }
 
-void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame,
+void WebKitTestRunner::DidCommitProvisionalLoad(WebLocalFrame* frame,
                                                 bool is_new_navigation) {
   if (!focus_on_next_commit_)
     return;
@@ -613,7 +606,7 @@ void WebKitTestRunner::DidCommitProvisionalLoad(WebFrame* frame,
   render_view()->GetWebView()->setFocusedFrame(frame);
 }
 
-void WebKitTestRunner::DidFailProvisionalLoad(WebFrame* frame,
+void WebKitTestRunner::DidFailProvisionalLoad(WebLocalFrame* frame,
                                               const WebURLError& error) {
   focus_on_next_commit_ = false;
 }
@@ -624,7 +617,7 @@ void WebKitTestRunner::Reset() {
   // 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();
@@ -638,7 +631,7 @@ void WebKitTestRunner::Reset() {
   // 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());
 }
 
@@ -647,6 +640,7 @@ void WebKitTestRunner::Reset() {
 void WebKitTestRunner::CaptureDump() {
   WebTestInterfaces* interfaces =
       ShellRenderProcessObserver::GetInstance()->test_interfaces();
+  TRACE_EVENT0("shell", "WebKitTestRunner::CaptureDump");
 
   if (interfaces->testRunner()->shouldDumpAsAudio()) {
     std::vector<unsigned char> vector_data;
@@ -658,25 +652,44 @@ void WebKitTestRunner::CaptureDump() {
 
     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(
@@ -729,19 +742,17 @@ void WebKitTestRunner::OnNotifyDone() {
 }
 
 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