| Index: Source/web/tests/ManifestLoaderTest.cpp
|
| diff --git a/Source/web/tests/ManifestLoaderTest.cpp b/Source/web/tests/ManifestLoaderTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b44a6d52486ec724d5aa22092ac017e0c28bd153
|
| --- /dev/null
|
| +++ b/Source/web/tests/ManifestLoaderTest.cpp
|
| @@ -0,0 +1,244 @@
|
| +// Copyright 2014 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 "config.h"
|
| +#include "core/loader/ManifestLoader.h"
|
| +
|
| +#include "core/testing/URLTestHelpers.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/WebURLResponse.h"
|
| +#include "public/platform/WebUnitTestSupport.h"
|
| +#include "web/WebLocalFrameImpl.h"
|
| +#include "web/tests/FrameTestHelpers.h"
|
| +#include <gtest/gtest.h>
|
| +
|
| +using namespace blink;
|
| +
|
| +namespace {
|
| +
|
| +class TestManifestLoaderFrameClient : public FrameTestHelpers::TestWebFrameClient {
|
| +public:
|
| + TestManifestLoaderFrameClient()
|
| + : m_succeeded(false)
|
| + , m_failed(false)
|
| + {
|
| + }
|
| +
|
| + ~TestManifestLoaderFrameClient() { }
|
| +
|
| + virtual void didLoadManifest(WebLocalFrame* frame, const WebManifest&) OVERRIDE
|
| + {
|
| + ASSERT(!m_failed && !m_succeeded);
|
| + m_succeeded = true;
|
| + }
|
| +
|
| + virtual void didFailLoadManifest(WebLocalFrame* frame, WebManifestError error) OVERRIDE
|
| + {
|
| + ASSERT(!m_failed && !m_succeeded);
|
| + m_failed = true;
|
| + m_error = error;
|
| + }
|
| +
|
| + bool succeeded() const { return m_succeeded; }
|
| + bool failed() const { return m_failed; }
|
| + WebManifestError error() const { return m_error; }
|
| +
|
| +private:
|
| + bool m_succeeded;
|
| + bool m_failed;
|
| + WebManifestError m_error;
|
| +};
|
| +
|
| +class ManifestLoaderTest : public ::testing::Test {
|
| +protected:
|
| + enum ManifestResponseType {
|
| + NoManifestResponse,
|
| + ManifestResponseSuccess,
|
| + ManifestResponseError,
|
| + };
|
| +
|
| + ManifestLoaderTest()
|
| + : m_baseURL("http://www.test.com/")
|
| + , m_nonBaseURL("http://www.nottest.com/")
|
| + {
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE;
|
| +
|
| + void setupAndLoad(const std::string& filename, const std::string& url, ManifestResponseType);
|
| +
|
| + TestManifestLoaderFrameClient* client()
|
| + {
|
| + return &m_client;
|
| + }
|
| +
|
| +protected:
|
| + std::string m_baseURL;
|
| + std::string m_nonBaseURL;
|
| +
|
| +private:
|
| + void setupSuccessManifestResponse(const std::string& url);
|
| + void setup404ManifestResponse(const std::string& url);
|
| + void loadManifestSynchronously();
|
| +
|
| + LocalFrame* frame()
|
| + {
|
| + return m_webViewHelper.webViewImpl()->mainFrameImpl()->frame();
|
| + }
|
| +
|
| + FrameTestHelpers::WebViewHelper m_webViewHelper;
|
| + TestManifestLoaderFrameClient m_client;
|
| +};
|
| +
|
| +void ManifestLoaderTest::TearDown()
|
| +{
|
| + Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
|
| +}
|
| +
|
| +void ManifestLoaderTest::setupSuccessManifestResponse(const std::string& url)
|
| +{
|
| + URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(url), "dummy_manifest.json", "manifest/", "application/manifest+json");
|
| +}
|
| +
|
| +void ManifestLoaderTest::setup404ManifestResponse(const std::string& strURL)
|
| +{
|
| + KURL url= URLTestHelpers::toKURL(strURL);
|
| +
|
| + WebURLResponse response;
|
| + response.initialize();
|
| + response.setMIMEType("application/manifest+json");
|
| + response.setHTTPStatusCode(404);
|
| + response.setURL(url);
|
| +
|
| + WebURLError error;
|
| + error.reason = 404; // We don't really care but we need a value.
|
| + Platform::current()->unitTestSupport()->registerMockedErrorURL(url, response, error);
|
| +}
|
| +
|
| +void ManifestLoaderTest::loadManifestSynchronously()
|
| +{
|
| + // This call is wrapped in a helper call on purpose because we want to get
|
| + // rid of it. It will make the transition to the new model easier.
|
| + ManifestLoader::loadManifest(PassRefPtr<LocalFrame>(frame()));
|
| + Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
|
| +}
|
| +
|
| +void ManifestLoaderTest::setupAndLoad(const std::string& filename, const std::string& url, ManifestResponseType manifestResponse)
|
| +{
|
| + URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(url), WebString::fromUTF8(filename), "manifest/", "text/html");
|
| + m_webViewHelper.initializeAndLoad(url, false, &m_client);
|
| +
|
| + std::string manifestURL = m_baseURL + "manifest.json";
|
| + if (manifestResponse == ManifestResponseSuccess)
|
| + setupSuccessManifestResponse(manifestURL);
|
| + else if (manifestResponse == ManifestResponseError)
|
| + setup404ManifestResponse(manifestURL);
|
| +
|
| + loadManifestSynchronously();
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, NoLinkManifest)
|
| +{
|
| + setupAndLoad("no-manifest.html", m_baseURL + "index.html", NoManifestResponse);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::NoManifest, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, NoCORSValidURL)
|
| +{
|
| + setupAndLoad("no-cors.html", m_baseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_TRUE(client()->succeeded());
|
| + EXPECT_FALSE(client()->failed());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, NoCORSCrossOriginURL)
|
| +{
|
| + setupAndLoad("no-cors.html", m_nonBaseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_TRUE(client()->succeeded());
|
| + EXPECT_FALSE(client()->failed());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSAnonymousValidURL)
|
| +{
|
| + setupAndLoad("cors-anonymous.html", m_baseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_TRUE(client()->succeeded());
|
| + EXPECT_FALSE(client()->failed());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSDefaultValidURL)
|
| +{
|
| + setupAndLoad("cors-default.html", m_baseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_TRUE(client()->succeeded());
|
| + EXPECT_FALSE(client()->failed());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSUseCredentialsValidURL)
|
| +{
|
| + setupAndLoad("cors-use-credentials.html", m_baseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_TRUE(client()->succeeded());
|
| + EXPECT_FALSE(client()->failed());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSAnonymousCrossOriginURL)
|
| +{
|
| + setupAndLoad("cors-anonymous.html", m_nonBaseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSDefaultCrossOriginURL)
|
| +{
|
| + setupAndLoad("cors-default.html", m_nonBaseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORSUseCredentialsCrossOriginURL)
|
| +{
|
| + setupAndLoad("cors-use-credentials.html", m_nonBaseURL + "index.html", ManifestResponseSuccess);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, NoCORS404URL)
|
| +{
|
| + setupAndLoad("no-cors.html", m_baseURL + "index.html", ManifestResponseError);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORS404URL)
|
| +{
|
| + setupAndLoad("cors-default.html", m_baseURL + "index.html", ManifestResponseError);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +TEST_F(ManifestLoaderTest, CORS404CrossOriginURL)
|
| +{
|
| + setupAndLoad("cors-default.html", m_nonBaseURL + "index.html", ManifestResponseError);
|
| +
|
| + EXPECT_FALSE(client()->succeeded());
|
| + EXPECT_TRUE(client()->failed());
|
| + EXPECT_EQ(WebManifestError::FetchError, client()->error());
|
| +}
|
| +
|
| +} // anonymous namespace
|
|
|