TEST_F(WebEmbeddedWorkerImplTest, ScriptNotFound)
{
    WebURL scriptURL = URLTestHelpers::toKURL("https://www.example.com/sw-404.js");
    WebURLResponse response;
    response.initialize();
    response.setMIMEType("text/javascript");
    response.setHTTPStatusCode(404);
    WebURLError error;
    error.reason = 1010;
    error.domain = "WebEmbeddedWorkerImplTest";
    Platform::current()->unitTestSupport()->registerMockedErrorURL(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()->unitTestSupport()->serveAsynchronousMockedRequests();
    ::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()->unitTestSupport()->serveAsynchronousMockedRequests();
    ::testing::Mock::VerifyAndClearExpectations(m_mockClient);
}
예제 #2
0
 void registerRedirect(const WebString& fromURL, const WebString& toURL) {
     KURL redirectURL(ParsedURLString, fromURL);
     WebURLResponse redirectResponse;
     redirectResponse.setURL(redirectURL);
     redirectResponse.setHTTPStatusCode(301);
     redirectResponse.setHTTPHeaderField(HTTPNames::Location, toURL);
     redirectResponse.addToEncodedDataLength(kRedirectResponseOverheadBytes);
     Platform::current()->getURLLoaderMockFactory()->registerURL(
         redirectURL, redirectResponse, "");
 }
    void registerErrorURL(const char* file, int statusCode)
    {
        WebURLError error;
        error.reason = 0xdead + statusCode;
        error.domain = "PageSerializerTest";

        WebURLResponse response;
        response.initialize();
        response.setMIMEType("text/html");
        response.setHTTPStatusCode(statusCode);

        Platform::current()->unitTestSupport()->registerMockedErrorURL(KURL(m_baseUrl, file), response, error);
    }