Changeset 139234 in webkit


Ignore:
Timestamp:
Jan 9, 2013 1:44:18 PM (11 years ago)
Author:
jochen@chromium.org
Message:

[chromium] move resource load callback dumping to TestRunner library
https://bugs.webkit.org/show_bug.cgi?id=106449

Reviewed by Adam Barth.

  • DumpRenderTree/chromium/DRTTestRunner.cpp:

(DRTTestRunner::DRTTestRunner):
(DRTTestRunner::reset):

  • DumpRenderTree/chromium/DRTTestRunner.h:

(DRTTestRunner):

  • DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h:

(WebKit):
(WebTestRunner::WebTestDelegate::makeURLErrorDescription):

  • DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h:

(WebKit):
(WebTestProxyBase):
(WebTestRunner::WebTestProxy::assignIdentifierToRequest):
(WebTestRunner::WebTestProxy::willRequestResource):
(WebTestRunner::WebTestProxy::willSendRequest):
(WebTestRunner::WebTestProxy::didReceiveResponse):
(WebTestRunner::WebTestProxy::didFinishResourceLoad):
(WebTestRunner::WebTestProxy::didFailResourceLoad):

  • DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h:

(WebTestRunner::WebTestRunner::shouldDumpResourceLoadCallbacks):
(WebTestRunner::WebTestRunner::shouldDumpResourceRequestCallbacks):
(WebTestRunner::WebTestRunner::shouldDumpResourceResponseMIMETypes):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:

(WebTestRunner::TestRunner::TestRunner):
(WebTestRunner::TestRunner::reset):
(WebTestRunner::TestRunner::shouldDumpResourceLoadCallbacks):
(WebTestRunner::TestRunner::shouldDumpResourceRequestCallbacks):
(WebTestRunner::TestRunner::shouldDumpResourceResponseMIMETypes):
(WebTestRunner):
(WebTestRunner::TestRunner::dumpResourceLoadCallbacks):
(WebTestRunner::TestRunner::dumpResourceRequestCallbacks):
(WebTestRunner::TestRunner::dumpResourceResponseMIMETypes):

  • DumpRenderTree/chromium/TestRunner/src/TestRunner.h:

(TestRunner):

  • DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp:

(WebTestRunner::WebTestProxyBase::reset):
(WebTestRunner):
(WebTestRunner::WebTestProxyBase::assignIdentifierToRequest):
(WebTestRunner::WebTestProxyBase::willRequestResource):
(WebTestRunner::WebTestProxyBase::willSendRequest):
(WebTestRunner::WebTestProxyBase::didReceiveResponse):
(WebTestRunner::WebTestProxyBase::didFinishResourceLoad):
(WebTestRunner::WebTestProxyBase::didFailResourceLoad):

  • DumpRenderTree/chromium/WebViewHost.cpp:

(WebViewHost::willSendRequest):
(WebViewHost::makeURLErrorDescription):
(WebViewHost::reset):

  • DumpRenderTree/chromium/WebViewHost.h:

(WebViewHost):

Location:
trunk/Tools
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r139231 r139234  
     12013-01-09  Jochen Eisinger  <jochen@chromium.org>
     2
     3        [chromium] move resource load callback dumping to TestRunner library
     4        https://bugs.webkit.org/show_bug.cgi?id=106449
     5
     6        Reviewed by Adam Barth.
     7
     8        * DumpRenderTree/chromium/DRTTestRunner.cpp:
     9        (DRTTestRunner::DRTTestRunner):
     10        (DRTTestRunner::reset):
     11        * DumpRenderTree/chromium/DRTTestRunner.h:
     12        (DRTTestRunner):
     13        * DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h:
     14        (WebKit):
     15        (WebTestRunner::WebTestDelegate::makeURLErrorDescription):
     16        * DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h:
     17        (WebKit):
     18        (WebTestProxyBase):
     19        (WebTestRunner::WebTestProxy::assignIdentifierToRequest):
     20        (WebTestRunner::WebTestProxy::willRequestResource):
     21        (WebTestRunner::WebTestProxy::willSendRequest):
     22        (WebTestRunner::WebTestProxy::didReceiveResponse):
     23        (WebTestRunner::WebTestProxy::didFinishResourceLoad):
     24        (WebTestRunner::WebTestProxy::didFailResourceLoad):
     25        * DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h:
     26        (WebTestRunner::WebTestRunner::shouldDumpResourceLoadCallbacks):
     27        (WebTestRunner::WebTestRunner::shouldDumpResourceRequestCallbacks):
     28        (WebTestRunner::WebTestRunner::shouldDumpResourceResponseMIMETypes):
     29        * DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp:
     30        (WebTestRunner::TestRunner::TestRunner):
     31        (WebTestRunner::TestRunner::reset):
     32        (WebTestRunner::TestRunner::shouldDumpResourceLoadCallbacks):
     33        (WebTestRunner::TestRunner::shouldDumpResourceRequestCallbacks):
     34        (WebTestRunner::TestRunner::shouldDumpResourceResponseMIMETypes):
     35        (WebTestRunner):
     36        (WebTestRunner::TestRunner::dumpResourceLoadCallbacks):
     37        (WebTestRunner::TestRunner::dumpResourceRequestCallbacks):
     38        (WebTestRunner::TestRunner::dumpResourceResponseMIMETypes):
     39        * DumpRenderTree/chromium/TestRunner/src/TestRunner.h:
     40        (TestRunner):
     41        * DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp:
     42        (WebTestRunner::WebTestProxyBase::reset):
     43        (WebTestRunner):
     44        (WebTestRunner::WebTestProxyBase::assignIdentifierToRequest):
     45        (WebTestRunner::WebTestProxyBase::willRequestResource):
     46        (WebTestRunner::WebTestProxyBase::willSendRequest):
     47        (WebTestRunner::WebTestProxyBase::didReceiveResponse):
     48        (WebTestRunner::WebTestProxyBase::didFinishResourceLoad):
     49        (WebTestRunner::WebTestProxyBase::didFailResourceLoad):
     50        * DumpRenderTree/chromium/WebViewHost.cpp:
     51        (WebViewHost::willSendRequest):
     52        (WebViewHost::makeURLErrorDescription):
     53        (WebViewHost::reset):
     54        * DumpRenderTree/chromium/WebViewHost.h:
     55        (WebViewHost):
     56
    1572013-01-09  Dan Carney  <dcarney@google.com>
    258
  • trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp

    r139231 r139234  
    120120    bindMethod("dumpBackForwardList", &DRTTestRunner::dumpBackForwardList);
    121121    bindMethod("dumpProgressFinishedCallback", &DRTTestRunner::dumpProgressFinishedCallback);
    122     bindMethod("dumpResourceLoadCallbacks", &DRTTestRunner::dumpResourceLoadCallbacks);
    123     bindMethod("dumpResourceRequestCallbacks", &DRTTestRunner::dumpResourceRequestCallbacks);
    124     bindMethod("dumpResourceResponseMIMETypes", &DRTTestRunner::dumpResourceResponseMIMETypes);
    125122    bindMethod("dumpSelectionRect", &DRTTestRunner::dumpSelectionRect);
    126123    bindMethod("dumpStatusCallbacks", &DRTTestRunner::dumpWindowStatusChanges);
     
    252249}
    253250
    254 void DRTTestRunner::dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant* result)
    255 {
    256     m_dumpResourceLoadCallbacks = true;
    257     result->setNull();
    258 }
    259 
    260 void DRTTestRunner::dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant* result)
    261 {
    262     m_dumpResourceRequestCallbacks = true;
    263     result->setNull();
    264 }
    265 
    266 void DRTTestRunner::dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant* result)
    267 {
    268     m_dumpResourceResponseMIMETypes = true;
    269     result->setNull();
    270 }
    271 
    272251void DRTTestRunner::dumpWindowStatusChanges(const CppArgumentList&, CppVariant* result)
    273252{
     
    467446        m_shell->webViewHost()->setDeviceScaleFactor(1);
    468447    m_dumpProgressFinishedCallback = false;
    469     m_dumpResourceLoadCallbacks = false;
    470     m_dumpResourceRequestCallbacks = false;
    471     m_dumpResourceResponseMIMETypes = false;
    472448    m_dumpBackForwardList = false;
    473449    m_dumpWindowStatusChanges = false;
  • trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h

    r139231 r139234  
    8585    void dumpBackForwardList(const CppArgumentList&, CppVariant*);
    8686
    87     // This function sets a flag that tells the test_shell to dump a descriptive
    88     // line for each resource load callback. It takes no arguments, and ignores
    89     // any that may be present.
    90     void dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant*);   
    91 
    92     // This function sets a flag that tells the test_shell to print a line of
    93     // descriptive text for each element that requested a resource. It takes no
    94     // arguments, and ignores any that may be present.
    95     void dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant*);
    96 
    97     // This function sets a flag that tells the test_shell to dump the MIME type
    98     // for each resource that was loaded. It takes no arguments, and ignores any
    99     // that may be present.
    100     void dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant*);
    101 
    10287    // This function sets a flag that tells the test_shell to dump all calls
    10388    // to window.status().
     
    244229    bool shouldDumpProgressFinishedCallback() { return m_dumpProgressFinishedCallback; }
    245230    void setShouldDumpProgressFinishedCallback(bool value) { m_dumpProgressFinishedCallback = value; }
    246     bool shouldDumpResourceLoadCallbacks() {return m_dumpResourceLoadCallbacks; }
    247     void setShouldDumpResourceRequestCallbacks(bool value) { m_dumpResourceRequestCallbacks = value; }
    248     bool shouldDumpResourceRequestCallbacks() { return m_dumpResourceRequestCallbacks; }
    249     void setShouldDumpResourceResponseMIMETypes(bool value) { m_dumpResourceResponseMIMETypes = value; }
    250     bool shouldDumpResourceResponseMIMETypes() {return m_dumpResourceResponseMIMETypes; }
    251231    bool shouldDumpStatusCallbacks() { return m_dumpWindowStatusChanges; }
    252232    bool shouldDumpSelectionRect() { return m_dumpSelectionRect; }
     
    350330    bool m_dumpProgressFinishedCallback;
    351331
    352     // If true, the test_shell will output a descriptive line for each resource
    353     // load callback.
    354     bool m_dumpResourceLoadCallbacks;
    355 
    356     // If true, the test_shell will output a descriptive line for each resource
    357     // request callback.
    358     bool m_dumpResourceRequestCallbacks;
    359 
    360     // If true, the test_shell will output the MIME type for each resource that
    361     // was loaded.
    362     bool m_dumpResourceResponseMIMETypes;
    363 
    364332    // If true, the test_shell will produce a dump of the back forward list as
    365333    // well.
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestDelegate.h

    r137997 r139234  
    3535#include "Platform/chromium/public/WebURL.h"
    3636#include "Platform/chromium/public/WebVector.h"
     37#include <string>
    3738
    3839namespace WebKit {
    39 struct WebContextMenuData;
    4040class WebGamepads;
    4141class WebIntentRequest;
     42struct WebContextMenuData;
     43struct WebURLError;
    4244}
    4345
     
    7577    virtual void setCurrentWebIntentRequest(const WebKit::WebIntentRequest&) { };
    7678    virtual WebKit::WebIntentRequest* currentWebIntentRequest() { return 0; }
     79    virtual std::string makeURLErrorDescription(const WebKit::WebURLError&) { return std::string(); }
    7780};
    7881
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestProxy.h

    r139231 r139234  
    3939#include "WebKit/chromium/public/WebTextAffinity.h"
    4040#include "WebKit/chromium/public/WebTextDirection.h"
     41#include <map>
     42#include <string>
    4143
    4244namespace WebKit {
    4345class WebAccessibilityObject;
     46class WebCachedURLRequest;
    4447class WebDragData;
    4548class WebFrame;
     
    5457class WebURL;
    5558class WebURLRequest;
     59class WebURLResponse;
    5660class WebView;
    5761struct WebPoint;
     
    7175    void setInterfaces(WebTestInterfaces*);
    7276    void setDelegate(WebTestDelegate*);
     77
     78    void reset();
    7379
    7480    void setPaintRect(const WebKit::WebRect&);
     
    117123    void didRunInsecureContent(WebKit::WebFrame*, const WebKit::WebSecurityOrigin&, const WebKit::WebURL& insecureURL);
    118124    void didDetectXSS(WebKit::WebFrame*, const WebKit::WebURL& insecureURL, bool didBlockEntirePage);
     125    void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
     126    void willRequestResource(WebKit::WebFrame*, const WebKit::WebCachedURLRequest&);
     127    void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse& redirectResponse);
     128    void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
     129    void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
     130    void didFailResourceLoad(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&);
    119131
    120132private:
     
    123135
    124136    WebKit::WebRect m_paintRect;
     137    std::map<unsigned, std::string> m_resourceIdentifierMap;
    125138};
    126139
     
    330343        Base::didDetectXSS(frame, insecureURL, didBlockEntirePage);
    331344    }
     345    virtual void assignIdentifierToRequest(WebKit::WebFrame* frame, unsigned identifier, const WebKit::WebURLRequest& request)
     346    {
     347        WebTestProxyBase::assignIdentifierToRequest(frame, identifier, request);
     348        Base::assignIdentifierToRequest(frame, identifier, request);
     349    }
     350    virtual void willRequestResource(WebKit::WebFrame* frame, const WebKit::WebCachedURLRequest& request)
     351    {
     352        WebTestProxyBase::willRequestResource(frame, request);
     353        Base::willRequestResource(frame, request);
     354    }
     355    virtual void willSendRequest(WebKit::WebFrame* frame, unsigned identifier, WebKit::WebURLRequest& request, const WebKit::WebURLResponse& redirectResponse)
     356    {
     357        WebTestProxyBase::willSendRequest(frame, identifier, request, redirectResponse);
     358        Base::willSendRequest(frame, identifier, request, redirectResponse);
     359    }
     360    virtual void didReceiveResponse(WebKit::WebFrame* frame, unsigned identifier, const WebKit::WebURLResponse& response)
     361    {
     362        WebTestProxyBase::didReceiveResponse(frame, identifier, response);
     363        Base::didReceiveResponse(frame, identifier, response);
     364    }
     365    virtual void didFinishResourceLoad(WebKit::WebFrame* frame, unsigned identifier)
     366    {
     367        WebTestProxyBase::didFinishResourceLoad(frame, identifier);
     368        Base::didFinishResourceLoad(frame, identifier);
     369    }
     370    virtual void didFailResourceLoad(WebKit::WebFrame* frame, unsigned identifier, const WebKit::WebURLError& error)
     371    {
     372        WebTestProxyBase::didFailResourceLoad(frame, identifier, error);
     373        Base::didFailResourceLoad(frame, identifier, error);
     374    }
    332375};
    333376
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/public/WebTestRunner.h

    r139231 r139234  
    5959    virtual bool shouldDumpCreateView() const { return false; }
    6060    virtual bool canOpenWindows() const { return false; }
     61    virtual bool shouldDumpResourceLoadCallbacks() const { return false; }
     62    virtual bool shouldDumpResourceRequestCallbacks() const { return false; }
     63    virtual bool shouldDumpResourceResponseMIMETypes() const { return false; }
    6164};
    6265
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.cpp

    r139231 r139234  
    145145    bindMethod("dumpCreateView", &TestRunner::dumpCreateView);
    146146    bindMethod("setCanOpenWindows", &TestRunner::setCanOpenWindows);
     147    bindMethod("dumpResourceLoadCallbacks", &TestRunner::dumpResourceLoadCallbacks);
     148    bindMethod("dumpResourceRequestCallbacks", &TestRunner::dumpResourceRequestCallbacks);
     149    bindMethod("dumpResourceResponseMIMETypes", &TestRunner::dumpResourceResponseMIMETypes);
    147150
    148151    // The following methods interact with the WebTestProxy.
     
    221224    m_dumpCreateView = false;
    222225    m_canOpenWindows = false;
     226    m_dumpResourceLoadCallbacks = false;
     227    m_dumpResourceRequestCallbacks = false;
     228    m_dumpResourceResponseMIMETypes = false;
    223229
    224230    m_globalFlag.set(false);
     
    311317{
    312318    return m_canOpenWindows;
     319}
     320
     321bool TestRunner::shouldDumpResourceLoadCallbacks() const
     322{
     323    return m_testIsRunning && m_dumpResourceLoadCallbacks;
     324}
     325
     326bool TestRunner::shouldDumpResourceRequestCallbacks() const
     327{
     328    return m_testIsRunning && m_dumpResourceRequestCallbacks;
     329}
     330
     331bool TestRunner::shouldDumpResourceResponseMIMETypes() const
     332{
     333    return m_testIsRunning && m_dumpResourceResponseMIMETypes;
    313334}
    314335
     
    10901111}
    10911112
     1113void TestRunner::dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant* result)
     1114{
     1115    m_dumpResourceLoadCallbacks = true;
     1116    result->setNull();
     1117}
     1118
     1119void TestRunner::dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant* result)
     1120{
     1121    m_dumpResourceRequestCallbacks = true;
     1122    result->setNull();
     1123}
     1124
     1125void TestRunner::dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant* result)
     1126{
     1127    m_dumpResourceResponseMIMETypes = true;
     1128    result->setNull();
     1129}
     1130
    10921131void TestRunner::workerThreadCount(CppVariant* result)
    10931132{
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/TestRunner.h

    r139231 r139234  
    7777    virtual bool shouldDumpCreateView() const OVERRIDE;
    7878    virtual bool canOpenWindows() const OVERRIDE;
     79    virtual bool shouldDumpResourceLoadCallbacks() const OVERRIDE;
     80    virtual bool shouldDumpResourceRequestCallbacks() const OVERRIDE;
     81    virtual bool shouldDumpResourceResponseMIMETypes() const OVERRIDE;
    7982
    8083protected:
     
    242245    void setCanOpenWindows(const CppArgumentList&, CppVariant*);
    243246
     247    // This function sets a flag that tells the test_shell to dump a descriptive
     248    // line for each resource load callback. It takes no arguments, and ignores
     249    // any that may be present.
     250    void dumpResourceLoadCallbacks(const CppArgumentList&, CppVariant*);
     251
     252    // This function sets a flag that tells the test_shell to print a line of
     253    // descriptive text for each element that requested a resource. It takes no
     254    // arguments, and ignores any that may be present.
     255    void dumpResourceRequestCallbacks(const CppArgumentList&, CppVariant*);
     256
     257    // This function sets a flag that tells the test_shell to dump the MIME type
     258    // for each resource that was loaded. It takes no arguments, and ignores any
     259    // that may be present.
     260    void dumpResourceResponseMIMETypes(const CppArgumentList&, CppVariant*);
     261
    244262    ///////////////////////////////////////////////////////////////////////////
    245263    // Methods interacting with the WebTestProxy
     
    332350    bool m_canOpenWindows;
    333351
     352    // If true, the test_shell will output a descriptive line for each resource
     353    // load callback.
     354    bool m_dumpResourceLoadCallbacks;
     355
     356    // If true, the test_shell will output a descriptive line for each resource
     357    // request callback.
     358    bool m_dumpResourceRequestCallbacks;
     359
     360    // If true, the test_shell will output the MIME type for each resource that
     361    // was loaded.
     362    bool m_dumpResourceResponseMIMETypes;
     363
    334364    // WAV audio data is stored here.
    335365    WebKit::WebArrayBufferView m_audioData;
  • trunk/Tools/DumpRenderTree/chromium/TestRunner/src/WebTestProxy.cpp

    r139231 r139234  
    3535#include "WebAccessibilityNotification.h"
    3636#include "WebAccessibilityObject.h"
     37#include "WebCachedURLRequest.h"
    3738#include "WebElement.h"
    3839#include "WebEventSender.h"
     
    4950#include "platform/WebCString.h"
    5051#include "platform/WebURLRequest.h"
     52#include "platform/WebURLResponse.h"
    5153#include <wtf/StringExtras.h>
    5254
     
    142144}
    143145
     146// Used to write a platform neutral file:/// URL by taking the
     147// filename and its directory. (e.g., converts
     148// "file:///tmp/foo/bar.txt" to just "bar.txt").
     149string descriptionSuitableForTestResult(const string& url)
     150{
     151    if (url.empty() || string::npos == url.find("file://"))
     152        return url;
     153
     154    size_t pos = url.rfind('/');
     155    if (pos == string::npos || !pos)
     156        return "ERROR:" + url;
     157    pos = url.rfind('/', pos - 1);
     158    if (pos == string::npos)
     159        return "ERROR:" + url;
     160
     161    return url.substr(pos + 1);
     162}
     163
     164void printResponseDescription(WebTestDelegate* delegate, const WebURLResponse& response)
     165{
     166    if (response.isNull()) {
     167        delegate->printMessage("(null)");
     168        return;
     169    }
     170    string url = response.url().spec();
     171    char data[100];
     172    snprintf(data, sizeof(data), "%d", response. httpStatusCode());
     173    delegate->printMessage(string("<NSURLResponse ") + descriptionSuitableForTestResult(url) + ", http status code " + data + ">");
     174}
     175
    144176string URLDescription(const GURL& url)
    145177{
     
    169201{
    170202    m_delegate = delegate;
     203}
     204
     205void WebTestProxyBase::reset()
     206{
     207    m_paintRect = WebRect();
     208    m_resourceIdentifierMap.clear();
    171209}
    172210
     
    610648}
    611649
    612 }
     650void WebTestProxyBase::assignIdentifierToRequest(WebFrame*, unsigned identifier, const WebKit::WebURLRequest& request)
     651{
     652    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
     653        ASSERT(m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.end());
     654        m_resourceIdentifierMap[identifier] = descriptionSuitableForTestResult(request.url().spec());
     655    }
     656}
     657
     658void WebTestProxyBase::willRequestResource(WebFrame* frame, const WebKit::WebCachedURLRequest& request)
     659{
     660    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceRequestCallbacks()) {
     661        printFrameDescription(m_delegate, frame);
     662        WebElement element = request.initiatorElement();
     663        if (!element.isNull()) {
     664            m_delegate->printMessage(" - element with ");
     665            if (element.hasAttribute("id"))
     666                m_delegate->printMessage(string("id '") + element.getAttribute("id").utf8().data() + "'");
     667            else
     668                m_delegate->printMessage("no id");
     669        } else
     670            m_delegate->printMessage(string(" - ") + request.initiatorName().utf8().data());
     671        m_delegate->printMessage(string(" requested '") + URLDescription(request.urlRequest().url()).c_str() + "'\n");
     672    }
     673}
     674
     675void WebTestProxyBase::willSendRequest(WebFrame*, unsigned identifier, WebKit::WebURLRequest& request, const WebKit::WebURLResponse& redirectResponse)
     676{
     677    // Need to use GURL for host() and SchemeIs()
     678    GURL url = request.url();
     679    string requestURL = url.possibly_invalid_spec();
     680
     681    GURL mainDocumentURL = request.firstPartyForCookies();
     682
     683    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
     684        if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.end())
     685            m_delegate->printMessage("<unknown>");
     686        else
     687            m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
     688        m_delegate->printMessage(" - willSendRequest <NSURLRequest URL ");
     689        m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_str());
     690        m_delegate->printMessage(", main document URL ");
     691        m_delegate->printMessage(URLDescription(mainDocumentURL).c_str());
     692        m_delegate->printMessage(", http method ");
     693        m_delegate->printMessage(request.httpMethod().utf8().data());
     694        m_delegate->printMessage("> redirectResponse ");
     695        printResponseDescription(m_delegate, redirectResponse);
     696        m_delegate->printMessage("\n");
     697    }
     698}
     699
     700void WebTestProxyBase::didReceiveResponse(WebFrame*, unsigned identifier, const WebKit::WebURLResponse& response)
     701{
     702    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
     703        if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.end())
     704            m_delegate->printMessage("<unknown>");
     705        else
     706            m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
     707        m_delegate->printMessage(" - didReceiveResponse ");
     708        printResponseDescription(m_delegate, response);
     709        m_delegate->printMessage("\n");
     710    }
     711    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceResponseMIMETypes()) {
     712        GURL url = response.url();
     713        WebString mimeType = response.mimeType();
     714        m_delegate->printMessage(url.ExtractFileName());
     715        m_delegate->printMessage(" has MIME type ");
     716        // Simulate NSURLResponse's mapping of empty/unknown MIME types to application/octet-stream
     717        m_delegate->printMessage(mimeType.isEmpty() ? "application/octet-stream" : mimeType.utf8().data());
     718        m_delegate->printMessage("\n");
     719    }
     720}
     721
     722void WebTestProxyBase::didFinishResourceLoad(WebFrame*, unsigned identifier)
     723{
     724    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
     725        if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.end())
     726            m_delegate->printMessage("<unknown>");
     727        else
     728            m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
     729        m_delegate->printMessage(" - didFinishLoading\n");
     730    }
     731    m_resourceIdentifierMap.erase(identifier);
     732}
     733
     734void WebTestProxyBase::didFailResourceLoad(WebFrame*, unsigned identifier, const WebKit::WebURLError& error)
     735{
     736    if (m_testInterfaces->testRunner() && m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) {
     737        if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.end())
     738            m_delegate->printMessage("<unknown>");
     739        else
     740            m_delegate->printMessage(m_resourceIdentifierMap[identifier]);
     741        m_delegate->printMessage(" - didFailLoadingWithError: ");
     742        m_delegate->printMessage(m_delegate->makeURLErrorDescription(error));
     743        m_delegate->printMessage("\n");
     744    }
     745    m_resourceIdentifierMap.erase(identifier);
     746}
     747
     748}
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.cpp

    r139231 r139234  
    127127}
    128128
    129 // Used to write a platform neutral file:/// URL by taking the
    130 // filename and its directory. (e.g., converts
    131 // "file:///tmp/foo/bar.txt" to just "bar.txt").
    132 static string descriptionSuitableForTestResult(const string& url)
    133 {
    134     if (url.empty() || string::npos == url.find("file://"))
    135         return url;
    136 
    137     size_t pos = url.rfind('/');
    138     if (pos == string::npos || !pos)
    139         return "ERROR:" + url;
    140     pos = url.rfind('/', pos - 1);
    141     if (pos == string::npos)
    142         return "ERROR:" + url;
    143 
    144     return url.substr(pos + 1);
    145 }
    146 
    147129// Get a debugging string from a WebNavigationType.
    148130static const char* webNavigationTypeToString(WebNavigationType type)
     
    170152        return url.ExtractFileName();
    171153    return url.possibly_invalid_spec();
    172 }
    173 
    174 static void printResponseDescription(const WebURLResponse& response)
    175 {
    176     if (response.isNull()) {
    177         fputs("(null)", stdout);
    178         return;
    179     }
    180     string url = response.url().spec();
    181     printf("<NSURLResponse %s, http status code %d>",
    182            descriptionSuitableForTestResult(url).c_str(),
    183            response.httpStatusCode());
    184154}
    185155
     
    915885}
    916886
    917 void WebViewHost::assignIdentifierToRequest(WebFrame*, unsigned identifier, const WebURLRequest& request)
    918 {
    919      if (!m_shell->shouldDumpResourceLoadCallbacks())
    920         return;
    921     ASSERT(!m_resourceIdentifierMap.contains(identifier));
    922     m_resourceIdentifierMap.set(identifier, descriptionSuitableForTestResult(request.url().spec()));
    923 }
    924 
    925 void WebViewHost::removeIdentifierForRequest(unsigned identifier)
    926 {
    927     m_resourceIdentifierMap.remove(identifier);
    928 }
    929 
    930887static void blockRequest(WebURLRequest& request)
    931888{
     
    941898{
    942899    return host == "255.255.255.255";
    943 }
    944 
    945 void WebViewHost::willRequestResource(WebKit::WebFrame* frame, const WebKit::WebCachedURLRequest& request)
    946 {
    947     if (m_shell->shouldDumpResourceRequestCallbacks()) {
    948         printFrameDescription(frame);
    949         WebElement element = request.initiatorElement();
    950         if (!element.isNull()) {
    951             printf(" - element with ");
    952             if (element.hasAttribute("id"))
    953                 printf("id '%s'", element.getAttribute("id").utf8().data());
    954             else
    955                 printf("no id");
    956         } else
    957             printf(" - %s", request.initiatorName().utf8().data());
    958         printf(" requested '%s'\n", URLDescription(request.urlRequest().url()).c_str());
    959     }
    960900}
    961901
     
    967907
    968908    GURL mainDocumentURL = request.firstPartyForCookies();
    969     if (testRunner()->shouldDumpResourceLoadCallbacks()) {
    970         printResourceDescription(identifier);
    971         printf(" - willSendRequest <NSURLRequest URL %s, main document URL %s,"
    972                " http method %s> redirectResponse ",
    973                descriptionSuitableForTestResult(requestURL).c_str(),
    974                URLDescription(mainDocumentURL).c_str(),
    975                request.httpMethod().utf8().data());
    976         printResponseDescription(redirectResponse);
    977         fputs("\n", stdout);
    978     }
    979909
    980910    request.setExtraData(webkit_support::CreateWebURLRequestExtraData(frame->document().referrerPolicy()));
     
    1010940}
    1011941
    1012 void WebViewHost::didReceiveResponse(WebFrame*, unsigned identifier, const WebURLResponse& response)
    1013 {
    1014     if (m_shell->shouldDumpResourceLoadCallbacks()) {
    1015         printResourceDescription(identifier);
    1016         fputs(" - didReceiveResponse ", stdout);
    1017         printResponseDescription(response);
    1018         fputs("\n", stdout);
    1019     }
    1020     if (m_shell->shouldDumpResourceResponseMIMETypes()) {
    1021         GURL url = response.url();
    1022         WebString mimeType = response.mimeType();
    1023         printf("%s has MIME type %s\n",
    1024             url.ExtractFileName().c_str(),
    1025             // Simulate NSURLResponse's mapping of empty/unknown MIME types to application/octet-stream
    1026             mimeType.isEmpty() ? "application/octet-stream" : mimeType.utf8().data());
    1027     }
    1028 }
    1029 
    1030 void WebViewHost::didFinishResourceLoad(WebFrame*, unsigned identifier)
    1031 {
    1032     if (m_shell->shouldDumpResourceLoadCallbacks()) {
    1033         printResourceDescription(identifier);
    1034         fputs(" - didFinishLoading\n", stdout);
    1035     }
    1036     removeIdentifierForRequest(identifier);
    1037 }
    1038 
    1039 void WebViewHost::didFailResourceLoad(WebFrame*, unsigned identifier, const WebURLError& error)
    1040 {
    1041     if (m_shell->shouldDumpResourceLoadCallbacks()) {
    1042         printResourceDescription(identifier);
    1043         fputs(" - didFailLoadingWithError: ", stdout);
    1044         fputs(webkit_support::MakeURLErrorDescription(error).c_str(), stdout);
    1045         fputs("\n", stdout);
    1046     }
    1047     removeIdentifierForRequest(identifier);
    1048 }
    1049 
    1050942void WebViewHost::openFileSystem(WebFrame* frame, WebFileSystem::Type type, long long size, bool create, WebFileSystemCallbacks* callbacks)
    1051943{
     
    11601052{
    11611053    return &m_currentRequest;
     1054}
     1055
     1056std::string WebViewHost::makeURLErrorDescription(const WebKit::WebURLError& error)
     1057{
     1058    return webkit_support::MakeURLErrorDescription(error);
    11621059}
    11631060
     
    12561153
    12571154    m_pendingExtraData.clear();
    1258     m_resourceIdentifierMap.clear();
    12591155    m_clearHeaders.clear();
    12601156    m_editCommandName.clear();
     
    12731169    // m_proxy is not set when reset() is invoked from the constructor.
    12741170    if (m_proxy)
    1275         proxy()->setPaintRect(WebRect());
     1171        proxy()->reset();
    12761172
    12771173    if (m_webWidget) {
     
    14741370    }
    14751371    printf("frame \"%s\"", name8.c_str());
    1476 }
    1477 
    1478 void WebViewHost::printResourceDescription(unsigned identifier)
    1479 {
    1480     ResourceMap::iterator it = m_resourceIdentifierMap.find(identifier);
    1481     printf("%s", it != m_resourceIdentifierMap.end() ? it->value.c_str() : "<unknown>");
    14821372}
    14831373
  • trunk/Tools/DumpRenderTree/chromium/WebViewHost.h

    r139090 r139234  
    149149    virtual void setCurrentWebIntentRequest(const WebKit::WebIntentRequest&) OVERRIDE;
    150150    virtual WebKit::WebIntentRequest* currentWebIntentRequest() OVERRIDE;
     151    virtual std::string makeURLErrorDescription(const WebKit::WebURLError&) OVERRIDE;
    151152
    152153    // NavigationHost
     
    255256    virtual void didFinishLoad(WebKit::WebFrame*);
    256257    virtual void didNavigateWithinPage(WebKit::WebFrame*, bool isNewNavigation);
    257     virtual void assignIdentifierToRequest(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLRequest&);
    258     virtual void removeIdentifierForRequest(unsigned identifier);
    259     virtual void willRequestResource(WebKit::WebFrame*, const WebKit::WebCachedURLRequest&);
    260258    virtual void willSendRequest(WebKit::WebFrame*, unsigned identifier, WebKit::WebURLRequest&, const WebKit::WebURLResponse&);
    261     virtual void didReceiveResponse(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLResponse&);
    262     virtual void didFinishResourceLoad(WebKit::WebFrame*, unsigned identifier);
    263     virtual void didFailResourceLoad(WebKit::WebFrame*, unsigned identifier, const WebKit::WebURLError&);
    264259    virtual void openFileSystem(WebKit::WebFrame*, WebKit::WebFileSystem::Type, long long size, bool create, WebKit::WebFileSystemCallbacks*);
    265260    virtual void deleteFileSystem(WebKit::WebFrame*, WebKit::WebFileSystem::Type, WebKit::WebFileSystemCallbacks*);
     
    364359    OwnPtr<TestShellExtraData> m_pendingExtraData;
    365360
    366     // Maps resource identifiers to a descriptive string.
    367     typedef HashMap<unsigned, std::string> ResourceMap;
    368     ResourceMap m_resourceIdentifierMap;
    369     void printResourceDescription(unsigned identifier);
    370 
    371361    WebKit::WebCursorInfo m_currentCursor;
    372362
Note: See TracChangeset for help on using the changeset viewer.