OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ | 5 #ifndef CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ |
6 #define CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ | 6 #define CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <map> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "chrome/test/chromedriver/devtools_client.h" | 16 #include "chrome/test/chromedriver/devtools_client.h" |
16 #include "chrome/test/chromedriver/net/sync_websocket_factory.h" | 17 #include "chrome/test/chromedriver/net/sync_websocket_factory.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 | 19 |
(...skipping 24 matching lines...) Expand all Loading... |
43 }; | 44 }; |
44 | 45 |
45 } // namespace internal | 46 } // namespace internal |
46 | 47 |
47 class DevToolsEventListener; | 48 class DevToolsEventListener; |
48 class Status; | 49 class Status; |
49 class SyncWebSocket; | 50 class SyncWebSocket; |
50 | 51 |
51 class DevToolsClientImpl : public DevToolsClient { | 52 class DevToolsClientImpl : public DevToolsClient { |
52 public: | 53 public: |
53 // Listener may be NULL. | |
54 DevToolsClientImpl(const SyncWebSocketFactory& factory, | 54 DevToolsClientImpl(const SyncWebSocketFactory& factory, |
55 const std::string& url); | 55 const std::string& url); |
56 | 56 |
57 typedef base::Callback<bool( | 57 typedef base::Callback<bool( |
58 const std::string&, | 58 const std::string&, |
59 int, | 59 int, |
60 internal::InspectorMessageType*, | 60 internal::InspectorMessageType*, |
61 internal::InspectorEvent*, | 61 internal::InspectorEvent*, |
62 internal::InspectorCommandResponse*)> ParserFunc; | 62 internal::InspectorCommandResponse*)> ParserFunc; |
63 DevToolsClientImpl(const SyncWebSocketFactory& factory, | 63 DevToolsClientImpl(const SyncWebSocketFactory& factory, |
64 const std::string& url, | 64 const std::string& url, |
65 const ParserFunc& parser_func); | 65 const ParserFunc& parser_func); |
66 | 66 |
67 virtual ~DevToolsClientImpl(); | 67 virtual ~DevToolsClientImpl(); |
68 | 68 |
| 69 void SetParserFuncForTesting(const ParserFunc& parser_func); |
| 70 |
69 // Overridden from DevToolsClient: | 71 // Overridden from DevToolsClient: |
70 virtual Status SendCommand(const std::string& method, | 72 virtual Status SendCommand(const std::string& method, |
71 const base::DictionaryValue& params) OVERRIDE; | 73 const base::DictionaryValue& params) OVERRIDE; |
72 virtual Status SendCommandAndGetResult( | 74 virtual Status SendCommandAndGetResult( |
73 const std::string& method, | 75 const std::string& method, |
74 const base::DictionaryValue& params, | 76 const base::DictionaryValue& params, |
75 scoped_ptr<base::DictionaryValue>* result) OVERRIDE; | 77 scoped_ptr<base::DictionaryValue>* result) OVERRIDE; |
76 virtual void AddListener(DevToolsEventListener* listener) OVERRIDE; | 78 virtual void AddListener(DevToolsEventListener* listener) OVERRIDE; |
77 virtual Status HandleEventsUntil( | 79 virtual Status HandleEventsUntil( |
78 const ConditionalFunc& conditional_func) OVERRIDE; | 80 const ConditionalFunc& conditional_func) OVERRIDE; |
(...skipping 10 matching lines...) Expand all Loading... |
89 int expected_id, | 91 int expected_id, |
90 internal::InspectorMessageType* type, | 92 internal::InspectorMessageType* type, |
91 internal::InspectorEvent* event, | 93 internal::InspectorEvent* event, |
92 internal::InspectorCommandResponse* response); | 94 internal::InspectorCommandResponse* response); |
93 virtual Status NotifyEventListeners(const std::string& method, | 95 virtual Status NotifyEventListeners(const std::string& method, |
94 const base::DictionaryValue& params); | 96 const base::DictionaryValue& params); |
95 scoped_ptr<SyncWebSocket> socket_; | 97 scoped_ptr<SyncWebSocket> socket_; |
96 GURL url_; | 98 GURL url_; |
97 ParserFunc parser_func_; | 99 ParserFunc parser_func_; |
98 std::list<DevToolsEventListener*> listeners_; | 100 std::list<DevToolsEventListener*> listeners_; |
| 101 typedef std::map<int, base::DictionaryValue*> ResponseMap; |
| 102 ResponseMap cmd_response_map_; |
99 bool connected_; | 103 bool connected_; |
100 int next_id_; | 104 int next_id_; |
101 | 105 |
102 DISALLOW_COPY_AND_ASSIGN(DevToolsClientImpl); | 106 DISALLOW_COPY_AND_ASSIGN(DevToolsClientImpl); |
103 }; | 107 }; |
104 | 108 |
105 namespace internal { | 109 namespace internal { |
106 | 110 |
107 bool ParseInspectorMessage( | 111 bool ParseInspectorMessage( |
108 const std::string& message, | 112 const std::string& message, |
109 int expected_id, | 113 int expected_id, |
110 InspectorMessageType* type, | 114 InspectorMessageType* type, |
111 InspectorEvent* event, | 115 InspectorEvent* event, |
112 InspectorCommandResponse* command_response); | 116 InspectorCommandResponse* command_response); |
113 | 117 |
114 } // namespace internal | 118 } // namespace internal |
115 | 119 |
116 #endif // CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ | 120 #endif // CHROME_TEST_CHROMEDRIVER_DEVTOOLS_CLIENT_IMPL_H_ |
OLD | NEW |