// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "public/web/WebEmbeddedWorker.h"

#include "platform/testing/URLTestHelpers.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebURLLoaderMockFactory.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
#include "public/web/WebCache.h"
#include "public/web/WebEmbeddedWorkerStartData.h"
#include "public/web/WebSettings.h"
#include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/PtrUtil.h"
#include <memory>

namespace blink {
namespace {

class MockServiceWorkerContextClient : public WebServiceWorkerContextClient {
 public:
  MockServiceWorkerContextClient() : m_hasAssociatedRegistration(true) {}
  ~MockServiceWorkerContextClient() override {}
  MOCK_METHOD0(workerReadyForInspection, void());
  MOCK_METHOD0(workerContextFailedToStart, void());
  MOCK_METHOD0(workerScriptLoaded, void());
  MOCK_METHOD1(createServiceWorkerNetworkProvider,
               WebServiceWorkerNetworkProvider*(WebDataSource*));
  MOCK_METHOD0(createServiceWorkerProvider, WebServiceWorkerProvider*());
  bool hasAssociatedRegistration() override {
    return m_hasAssociatedRegistration;
  }
  void setHasAssociatedRegistration(bool hasAssociatedRegistration) {
    m_hasAssociatedRegistration = hasAssociatedRegistration;
  }
  void getClient(const WebString&,
                 std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
    NOTREACHED();
  }
  void getClients(const WebServiceWorkerClientQueryOptions&,
                  std::unique_ptr<WebServiceWorkerClientsCallbacks>) override {
    NOTREACHED();
  }
  void openWindow(const WebURL&,
                  std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
    NOTREACHED();
  }
  void postMessageToClient(const WebString& uuid,
                           const WebString&,
                           WebMessagePortChannelArray*) override {
    NOTREACHED();
  }
  void postMessageToCrossOriginClient(const WebCrossOriginServiceWorkerClient&,
                                      const WebString&,
                                      WebMessagePortChannelArray*) override {
    NOTREACHED();
  }
  void skipWaiting(
      std::unique_ptr<WebServiceWorkerSkipWaitingCallbacks>) override {
    NOTREACHED();
  }
  void claim(std::unique_ptr<WebServiceWorkerClientsClaimCallbacks>) override {
    NOTREACHED();
  }
  void focus(const WebString& uuid,
             std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
    NOTREACHED();
  }
  void navigate(const WebString& uuid,
                const WebURL&,
                std::unique_ptr<WebServiceWorkerClientCallbacks>) override {
    NOTREACHED();
  }
  void registerForeignFetchScopes(
      const WebVector<WebURL>& subScopes,
      const WebVector<WebSecurityOrigin>& origins) override {
    NOTREACHED();
  }

 private:
  bool m_hasAssociatedRegistration;
};

class WebEmbeddedWorkerImplTest : public ::testing::Test {
 protected:
  void SetUp() override {
    m_mockClient = new MockServiceWorkerContextClient();
    m_worker = wrapUnique(WebEmbeddedWorker::create(m_mockClient, nullptr));

    WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw.js");
    WebURLResponse response;
    response.setMIMEType("text/javascript");
    response.setHTTPStatusCode(200);
    Platform::current()->getURLLoaderMockFactory()->registerURL(scriptURL,
                                                                response, "");

    m_startData.scriptURL = scriptURL;
    m_startData.userAgent = WebString("dummy user agent");
    m_startData.pauseAfterDownloadMode =
        WebEmbeddedWorkerStartData::DontPauseAfterDownload;
    m_startData.waitForDebuggerMode =
        WebEmbeddedWorkerStartData::DontWaitForDebugger;
    m_startData.v8CacheOptions = WebSettings::V8CacheOptionsDefault;
  }

  void TearDown() override {
    Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs();
    WebCache::clear();
  }

  WebEmbeddedWorkerStartData m_startData;
  MockServiceWorkerContextClient* m_mockClient;
  std::unique_ptr<WebEmbeddedWorker> m_worker;
};

}  // namespace

TEST_F(WebEmbeddedWorkerImplTest, TerminateSoonAfterStart) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  m_worker->terminateWorkerContext();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileWaitingForDebugger) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_startData.waitForDebuggerMode = WebEmbeddedWorkerStartData::WaitForDebugger;
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  m_worker->terminateWorkerContext();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

TEST_F(WebEmbeddedWorkerImplTest, TerminateWhileLoadingScript) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Terminate before loading the script.
  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  m_worker->terminateWorkerContext();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

TEST_F(WebEmbeddedWorkerImplTest, TerminateWhilePausedAfterDownload) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_startData.pauseAfterDownloadMode =
      WebEmbeddedWorkerStartData::PauseAfterDownload;
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the script.
  EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Terminate before resuming after download.
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  m_worker->terminateWorkerContext();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound) {
  WebURL scriptURL =
      URLTestHelpers::toKURL("https://www.example.com/sw-404.js");
  WebURLResponse response;
  response.setMIMEType("text/javascript");
  response.setHTTPStatusCode(404);
  WebURLError error;
  error.reason = 1010;
  error.domain = "WebEmbeddedWorkerImplTest";
  Platform::current()->getURLLoaderMockFactory()->registerErrorURL(
      scriptURL, response, error);
  m_startData.scriptURL = scriptURL;

  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the script.
  EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0);
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

TEST_F(WebEmbeddedWorkerImplTest, NoRegistration) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_startData.pauseAfterDownloadMode =
      WebEmbeddedWorkerStartData::PauseAfterDownload;
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the script.
  m_mockClient->setHasAssociatedRegistration(false);
  EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(0);
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
  EXPECT_CALL(*m_mockClient, workerContextFailedToStart()).Times(1);
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

// The running worker is detected as a memory leak. crbug.com/586897
#if defined(ADDRESS_SANITIZER)
#define MAYBE_DontPauseAfterDownload DISABLED_DontPauseAfterDownload
#else
#define MAYBE_DontPauseAfterDownload DontPauseAfterDownload
#endif

TEST_F(WebEmbeddedWorkerImplTest, MAYBE_DontPauseAfterDownload) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the script.
  EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

// The running worker is detected as a memory leak. crbug.com/586897
#if defined(ADDRESS_SANITIZER)
#define MAYBE_PauseAfterDownload DISABLED_PauseAfterDownload
#else
#define MAYBE_PauseAfterDownload PauseAfterDownload
#endif

TEST_F(WebEmbeddedWorkerImplTest, MAYBE_PauseAfterDownload) {
  EXPECT_CALL(*m_mockClient, workerReadyForInspection()).Times(1);
  m_startData.pauseAfterDownloadMode =
      WebEmbeddedWorkerStartData::PauseAfterDownload;
  m_worker->startWorkerContext(m_startData);
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the shadow page.
  EXPECT_CALL(*m_mockClient, createServiceWorkerNetworkProvider(::testing::_))
      .WillOnce(::testing::Return(nullptr));
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Load the script.
  EXPECT_CALL(*m_mockClient, workerScriptLoaded()).Times(1);
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider()).Times(0);
  Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);

  // Resume after download.
  EXPECT_CALL(*m_mockClient, createServiceWorkerProvider())
      .WillOnce(::testing::Return(nullptr));
  m_worker->resumeAfterDownload();
  ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}

}  // namespace blink
