| OLD | NEW | 
|   1 // Copyright 2015 The Chromium Authors. All rights reserved. |   1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
|   2 // Use of this source code is governed by a BSD-style license that can be |   2 // Use of this source code is governed by a BSD-style license that can be | 
|   3 // found in the LICENSE file. |   3 // found in the LICENSE file. | 
|   4  |   4  | 
|   5 #ifndef SimNetwork_h |   5 #ifndef SimNetwork_h | 
|   6 #define SimNetwork_h |   6 #define SimNetwork_h | 
|   7  |   7  | 
|   8 #include "public/platform/WebURLLoaderTestDelegate.h" |   8 #include "public/platform/WebURLLoaderTestDelegate.h" | 
|   9 #include "wtf/HashMap.h" |   9 #include "wtf/HashMap.h" | 
|  10 #include "wtf/text/StringHash.h" |  10 #include "wtf/text/StringHash.h" | 
|  11 #include "wtf/text/WTFString.h" |  11 #include "wtf/text/WTFString.h" | 
|  12  |  12  | 
|  13 namespace blink { |  13 namespace blink { | 
|  14  |  14  | 
|  15 class SimRequest; |  15 class SimRequest; | 
|  16 class WebURLLoader; |  | 
|  17 class WebURLLoaderClient; |  16 class WebURLLoaderClient; | 
|  18 class WebURLResponse; |  17 class WebURLResponse; | 
|  19  |  18  | 
|  20 // Simulates a network with precise flow control so you can make requests |  19 // Simulates a network with precise flow control so you can make requests | 
|  21 // return, write data, and finish in a specific order in a unit test. One of |  20 // return, write data, and finish in a specific order in a unit test. One of | 
|  22 // these must be created before using the SimRequest to issue requests. |  21 // these must be created before using the SimRequest to issue requests. | 
|  23 class SimNetwork final : public WebURLLoaderTestDelegate { |  22 class SimNetwork final : public WebURLLoaderTestDelegate { | 
|  24  public: |  23  public: | 
|  25   SimNetwork(); |  24   SimNetwork(); | 
|  26   ~SimNetwork(); |  25   ~SimNetwork(); | 
|  27  |  26  | 
|  28  private: |  27  private: | 
|  29   friend class SimRequest; |  28   friend class SimRequest; | 
|  30  |  29  | 
|  31   static SimNetwork& current(); |  30   static SimNetwork& current(); | 
|  32  |  31  | 
|  33   void servePendingRequests(); |  32   void servePendingRequests(); | 
|  34   void addRequest(SimRequest&); |  33   void addRequest(SimRequest&); | 
|  35   void removeRequest(SimRequest&); |  34   void removeRequest(SimRequest&); | 
|  36  |  35  | 
|  37   // WebURLLoaderTestDelegate |  36   // WebURLLoaderTestDelegate | 
|  38   void didReceiveResponse(WebURLLoaderClient*, |  37   void didReceiveResponse(WebURLLoaderClient*, | 
|  39                           WebURLLoader*, |  | 
|  40                           const WebURLResponse&) override; |  38                           const WebURLResponse&) override; | 
|  41   void didReceiveData(WebURLLoaderClient*, |  39   void didReceiveData(WebURLLoaderClient*, | 
|  42                       WebURLLoader*, |  | 
|  43                       const char* data, |  40                       const char* data, | 
|  44                       int dataLength, |  41                       int dataLength, | 
|  45                       int encodedDataLength) override; |  42                       int encodedDataLength) override; | 
|  46   void didFail(WebURLLoaderClient*, |  43   void didFail(WebURLLoaderClient*, | 
|  47                WebURLLoader*, |  | 
|  48                const WebURLError&, |  44                const WebURLError&, | 
|  49                int64_t totalEncodedDataLength, |  45                int64_t totalEncodedDataLength, | 
|  50                int64_t totalEncodedBodyLength) override; |  46                int64_t totalEncodedBodyLength) override; | 
|  51   void didFinishLoading(WebURLLoaderClient*, |  47   void didFinishLoading(WebURLLoaderClient*, | 
|  52                         WebURLLoader*, |  | 
|  53                         double finishTime, |  48                         double finishTime, | 
|  54                         int64_t totalEncodedDataLength, |  49                         int64_t totalEncodedDataLength, | 
|  55                         int64_t totalEncodedBodyLength) override; |  50                         int64_t totalEncodedBodyLength) override; | 
|  56  |  51  | 
|  57   SimRequest* m_currentRequest; |  52   SimRequest* m_currentRequest; | 
|  58   HashMap<String, SimRequest*> m_requests; |  53   HashMap<String, SimRequest*> m_requests; | 
|  59 }; |  54 }; | 
|  60  |  55  | 
|  61 }  // namespace blink |  56 }  // namespace blink | 
|  62  |  57  | 
|  63 #endif |  58 #endif | 
| OLD | NEW |