Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: Source/web/tests/ManifestLoaderTest.cpp

Issue 295063002: [NotLanded] Implement the fetching algorithm of the Web Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/WebLocalFrameImpl.cpp ('k') | Source/web/tests/data/manifest/cors-anonymous.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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
5 #include "config.h"
6 #include "core/loader/ManifestLoader.h"
7
8 #include "core/testing/URLTestHelpers.h"
9 #include "public/platform/Platform.h"
10 #include "public/platform/WebURLResponse.h"
11 #include "public/platform/WebUnitTestSupport.h"
12 #include "web/WebLocalFrameImpl.h"
13 #include "web/tests/FrameTestHelpers.h"
14 #include <gtest/gtest.h>
15
16 using namespace blink;
17
18 namespace {
19
20 class TestManifestLoaderFrameClient : public FrameTestHelpers::TestWebFrameClien t {
21 public:
22 TestManifestLoaderFrameClient()
23 : m_succeeded(false)
24 , m_failed(false)
25 {
26 }
27
28 ~TestManifestLoaderFrameClient() { }
29
30 virtual void didLoadManifest(WebLocalFrame* frame, const WebManifest&) OVERR IDE
31 {
32 ASSERT(!m_failed && !m_succeeded);
33 m_succeeded = true;
34 }
35
36 virtual void didFailLoadManifest(WebLocalFrame* frame, WebManifestError erro r) OVERRIDE
37 {
38 ASSERT(!m_failed && !m_succeeded);
39 m_failed = true;
40 m_error = error;
41 }
42
43 bool succeeded() const { return m_succeeded; }
44 bool failed() const { return m_failed; }
45 WebManifestError error() const { return m_error; }
46
47 private:
48 bool m_succeeded;
49 bool m_failed;
50 WebManifestError m_error;
51 };
52
53 class ManifestLoaderTest : public ::testing::Test {
54 protected:
55 enum ManifestResponseType {
56 NoManifestResponse,
57 ManifestResponseSuccess,
58 ManifestResponseError,
59 };
60
61 ManifestLoaderTest()
62 : m_baseURL("http://www.test.com/")
63 , m_nonBaseURL("http://www.nottest.com/")
64 {
65 }
66
67 virtual void TearDown() OVERRIDE;
68
69 void setupAndLoad(const std::string& filename, const std::string& url, Manif estResponseType);
70
71 TestManifestLoaderFrameClient* client()
72 {
73 return &m_client;
74 }
75
76 protected:
77 std::string m_baseURL;
78 std::string m_nonBaseURL;
79
80 private:
81 void setupSuccessManifestResponse(const std::string& url);
82 void setup404ManifestResponse(const std::string& url);
83 void loadManifestSynchronously();
84
85 LocalFrame* frame()
86 {
87 return m_webViewHelper.webViewImpl()->mainFrameImpl()->frame();
88 }
89
90 FrameTestHelpers::WebViewHelper m_webViewHelper;
91 TestManifestLoaderFrameClient m_client;
92 };
93
94 void ManifestLoaderTest::TearDown()
95 {
96 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
97 }
98
99 void ManifestLoaderTest::setupSuccessManifestResponse(const std::string& url)
100 {
101 URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(url), "dummy_ma nifest.json", "manifest/", "application/manifest+json");
102 }
103
104 void ManifestLoaderTest::setup404ManifestResponse(const std::string& strURL)
105 {
106 KURL url= URLTestHelpers::toKURL(strURL);
107
108 WebURLResponse response;
109 response.initialize();
110 response.setMIMEType("application/manifest+json");
111 response.setHTTPStatusCode(404);
112 response.setURL(url);
113
114 WebURLError error;
115 error.reason = 404; // We don't really care but we need a value.
116 Platform::current()->unitTestSupport()->registerMockedErrorURL(url, response , error);
117 }
118
119 void ManifestLoaderTest::loadManifestSynchronously()
120 {
121 // This call is wrapped in a helper call on purpose because we want to get
122 // rid of it. It will make the transition to the new model easier.
123 ManifestLoader::loadManifest(PassRefPtr<LocalFrame>(frame()));
124 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
125 }
126
127 void ManifestLoaderTest::setupAndLoad(const std::string& filename, const std::st ring& url, ManifestResponseType manifestResponse)
128 {
129 URLTestHelpers::registerMockedURLLoad(URLTestHelpers::toKURL(url), WebString ::fromUTF8(filename), "manifest/", "text/html");
130 m_webViewHelper.initializeAndLoad(url, false, &m_client);
131
132 std::string manifestURL = m_baseURL + "manifest.json";
133 if (manifestResponse == ManifestResponseSuccess)
134 setupSuccessManifestResponse(manifestURL);
135 else if (manifestResponse == ManifestResponseError)
136 setup404ManifestResponse(manifestURL);
137
138 loadManifestSynchronously();
139 }
140
141 TEST_F(ManifestLoaderTest, NoLinkManifest)
142 {
143 setupAndLoad("no-manifest.html", m_baseURL + "index.html", NoManifestRespons e);
144
145 EXPECT_FALSE(client()->succeeded());
146 EXPECT_TRUE(client()->failed());
147 EXPECT_EQ(WebManifestError::NoManifest, client()->error());
148 }
149
150 TEST_F(ManifestLoaderTest, NoCORSValidURL)
151 {
152 setupAndLoad("no-cors.html", m_baseURL + "index.html", ManifestResponseSucce ss);
153
154 EXPECT_TRUE(client()->succeeded());
155 EXPECT_FALSE(client()->failed());
156 }
157
158 TEST_F(ManifestLoaderTest, NoCORSCrossOriginURL)
159 {
160 setupAndLoad("no-cors.html", m_nonBaseURL + "index.html", ManifestResponseSu ccess);
161
162 EXPECT_TRUE(client()->succeeded());
163 EXPECT_FALSE(client()->failed());
164 }
165
166 TEST_F(ManifestLoaderTest, CORSAnonymousValidURL)
167 {
168 setupAndLoad("cors-anonymous.html", m_baseURL + "index.html", ManifestRespon seSuccess);
169
170 EXPECT_TRUE(client()->succeeded());
171 EXPECT_FALSE(client()->failed());
172 }
173
174 TEST_F(ManifestLoaderTest, CORSDefaultValidURL)
175 {
176 setupAndLoad("cors-default.html", m_baseURL + "index.html", ManifestResponse Success);
177
178 EXPECT_TRUE(client()->succeeded());
179 EXPECT_FALSE(client()->failed());
180 }
181
182 TEST_F(ManifestLoaderTest, CORSUseCredentialsValidURL)
183 {
184 setupAndLoad("cors-use-credentials.html", m_baseURL + "index.html", Manifest ResponseSuccess);
185
186 EXPECT_TRUE(client()->succeeded());
187 EXPECT_FALSE(client()->failed());
188 }
189
190 TEST_F(ManifestLoaderTest, CORSAnonymousCrossOriginURL)
191 {
192 setupAndLoad("cors-anonymous.html", m_nonBaseURL + "index.html", ManifestRes ponseSuccess);
193
194 EXPECT_FALSE(client()->succeeded());
195 EXPECT_TRUE(client()->failed());
196 EXPECT_EQ(WebManifestError::FetchError, client()->error());
197 }
198
199 TEST_F(ManifestLoaderTest, CORSDefaultCrossOriginURL)
200 {
201 setupAndLoad("cors-default.html", m_nonBaseURL + "index.html", ManifestRespo nseSuccess);
202
203 EXPECT_FALSE(client()->succeeded());
204 EXPECT_TRUE(client()->failed());
205 EXPECT_EQ(WebManifestError::FetchError, client()->error());
206 }
207
208 TEST_F(ManifestLoaderTest, CORSUseCredentialsCrossOriginURL)
209 {
210 setupAndLoad("cors-use-credentials.html", m_nonBaseURL + "index.html", Manif estResponseSuccess);
211
212 EXPECT_FALSE(client()->succeeded());
213 EXPECT_TRUE(client()->failed());
214 EXPECT_EQ(WebManifestError::FetchError, client()->error());
215 }
216
217 TEST_F(ManifestLoaderTest, NoCORS404URL)
218 {
219 setupAndLoad("no-cors.html", m_baseURL + "index.html", ManifestResponseError );
220
221 EXPECT_FALSE(client()->succeeded());
222 EXPECT_TRUE(client()->failed());
223 EXPECT_EQ(WebManifestError::FetchError, client()->error());
224 }
225
226 TEST_F(ManifestLoaderTest, CORS404URL)
227 {
228 setupAndLoad("cors-default.html", m_baseURL + "index.html", ManifestResponse Error);
229
230 EXPECT_FALSE(client()->succeeded());
231 EXPECT_TRUE(client()->failed());
232 EXPECT_EQ(WebManifestError::FetchError, client()->error());
233 }
234
235 TEST_F(ManifestLoaderTest, CORS404CrossOriginURL)
236 {
237 setupAndLoad("cors-default.html", m_nonBaseURL + "index.html", ManifestRespo nseError);
238
239 EXPECT_FALSE(client()->succeeded());
240 EXPECT_TRUE(client()->failed());
241 EXPECT_EQ(WebManifestError::FetchError, client()->error());
242 }
243
244 } // anonymous namespace
OLDNEW
« no previous file with comments | « Source/web/WebLocalFrameImpl.cpp ('k') | Source/web/tests/data/manifest/cors-anonymous.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698