- add sources.
[platform/framework/web/crosswalk.git] / src / chrome_frame / test / net / test_automation_provider.h
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
3 // found in the LICENSE file.
4 #ifndef CHROME_FRAME_TEST_NET_TEST_AUTOMATION_PROVIDER_H_
5 #define CHROME_FRAME_TEST_NET_TEST_AUTOMATION_PROVIDER_H_
6
7 #include <string>
8 #include "chrome/browser/automation/automation_provider.h"
9
10 namespace net {
11 class NetworkDelegate;
12 class URLRequest;
13 class URLRequestJob;
14 }  // namespace net
15
16 class TestAutomationResourceMessageFilter;
17
18 // Callback interface for TestAutomationProvider.
19 class TestAutomationProviderDelegate {
20  public:
21   virtual void OnInitialTabLoaded() = 0;
22   virtual void OnProviderDestroyed() = 0;
23 };
24
25 // A slightly customized version of AutomationProvider.
26 // We override AutomationProvider to be able to filter received messages
27 // (see TestAutomationResourceMessageFilter) and know when the initial
28 // ExternalTab has been loaded.
29 // In order to intercept UrlRequests and make the URLRequestAutomationJob class
30 // handle requests from unit tests, we register a protocol factory for
31 // http/https.
32 class TestAutomationProvider
33     : public AutomationProvider {
34  public:
35   TestAutomationProvider(Profile* profile,
36                          TestAutomationProviderDelegate* delegate);
37
38   virtual ~TestAutomationProvider();
39
40   // AutomationProvider overrides.
41   virtual bool OnMessageReceived(const IPC::Message& msg);
42   virtual bool Send(IPC::Message* msg);
43
44   // Protocol factory for handling http/https requests over automation.
45   static net::URLRequestJob* Factory(net::URLRequest* request,
46                                      net::NetworkDelegate* network_delegate,
47                                      const std::string& scheme);
48
49   // Call to instantiate and initialize a new instance of
50   // TestAutomationProvider.
51   static TestAutomationProvider* NewAutomationProvider(
52       Profile* p,
53       const std::string& channel,
54       TestAutomationProviderDelegate* delegate);
55
56  protected:
57   virtual std::string GetProtocolVersion();
58
59   int tab_handle_;
60   TestAutomationProviderDelegate* delegate_;
61
62   static TestAutomationProvider* g_provider_instance_;
63 };
64
65 #endif  // CHROME_FRAME_TEST_NET_TEST_AUTOMATION_PROVIDER_H_