#ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
#define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_TEST_HELPER_H_
#include <vector>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_test_sink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
class GURL;
namespace content {
class EmbeddedWorkerRegistry;
class EmbeddedWorkerTestHelper;
class ServiceWorkerContextCore;
struct ServiceWorkerFetchRequest;
class EmbeddedWorkerTestHelper : public IPC::Sender,
public IPC::Listener {
public:
EmbeddedWorkerTestHelper(ServiceWorkerContextCore* context,
int mock_render_process_id);
virtual ~EmbeddedWorkerTestHelper();
void SimulateAddProcessToWorker(int embedded_worker_id, int process_id);
virtual bool Send(IPC::Message* message) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
IPC::TestSink* ipc_sink() { return &sink_; }
IPC::TestSink* inner_ipc_sink() { return &inner_sink_; }
protected:
virtual void OnStartWorker(int embedded_worker_id,
int64 service_worker_version_id,
const GURL& script_url);
virtual void OnStopWorker(int embedded_worker_id);
virtual bool OnSendMessageToWorker(int thread_id,
int embedded_worker_id,
int request_id,
const IPC::Message& message);
virtual void OnActivateEvent(int embedded_worker_id, int request_id);
virtual void OnInstallEvent(int embedded_worker_id,
int request_id,
int active_version_id);
virtual void OnFetchEvent(int embedded_worker_id,
int request_id,
const ServiceWorkerFetchRequest& request);
void SimulateWorkerStarted(int thread_id, int embedded_worker_id);
void SimulateWorkerStopped(int embedded_worker_id);
void SimulateSendMessageToBrowser(int embedded_worker_id,
int request_id,
const IPC::Message& message);
protected:
EmbeddedWorkerRegistry* registry();
private:
void OnStartWorkerStub(int embedded_worker_id,
int64 service_worker_version_id,
const GURL& script_url);
void OnStopWorkerStub(int embedded_worker_id);
void OnSendMessageToWorkerStub(int thread_id,
int embedded_worker_id,
int request_id,
const IPC::Message& message);
void OnActivateEventStub();
void OnInstallEventStub(int active_version_id);
void OnFetchEventStub(const ServiceWorkerFetchRequest& request);
base::WeakPtr<ServiceWorkerContextCore> context_;
IPC::TestSink sink_;
IPC::TestSink inner_sink_;
int next_thread_id_;
int current_embedded_worker_id_;
int current_request_id_;
base::WeakPtrFactory<EmbeddedWorkerTestHelper> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerTestHelper);
};
}
#endif