| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/serviceworkers/Cache.h" | 6 #include "modules/serviceworkers/Cache.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptFunction.h" | 9 #include "bindings/core/v8/ScriptFunction.h" |
| 10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 m_lastErrorWebCacheMethodCalled.clear(); | 46 m_lastErrorWebCacheMethodCalled.clear(); |
| 47 return old; | 47 return old; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // These methods do not take ownership of their parameter. They provide an o
ptional sample object to check parameters against. | 50 // These methods do not take ownership of their parameter. They provide an o
ptional sample object to check parameters against. |
| 51 void setExpectedUrl(const String* expectedUrl) { m_expectedUrl = expectedUrl
; } | 51 void setExpectedUrl(const String* expectedUrl) { m_expectedUrl = expectedUrl
; } |
| 52 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { m_expe
ctedQueryParams = expectedQueryParams; } | 52 void setExpectedQueryParams(const QueryParams* expectedQueryParams) { m_expe
ctedQueryParams = expectedQueryParams; } |
| 53 void setExpectedBatchOperations(const WebVector<BatchOperation>* expectedBat
chOperations) { m_expectedBatchOperations = expectedBatchOperations; } | 53 void setExpectedBatchOperations(const WebVector<BatchOperation>* expectedBat
chOperations) { m_expectedBatchOperations = expectedBatchOperations; } |
| 54 | 54 |
| 55 // From WebServiceWorkerCache: | 55 // From WebServiceWorkerCache: |
| 56 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | 56 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) override |
| 57 { | 57 { |
| 58 m_lastErrorWebCacheMethodCalled = "dispatchMatch"; | 58 m_lastErrorWebCacheMethodCalled = "dispatchMatch"; |
| 59 checkUrlIfProvided(webRequest.url()); | 59 checkUrlIfProvided(webRequest.url()); |
| 60 checkQueryParamsIfProvided(queryParams); | 60 checkQueryParamsIfProvided(queryParams); |
| 61 | 61 |
| 62 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 62 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 63 WebServiceWorkerCacheError error = m_error; | 63 WebServiceWorkerCacheError error = m_error; |
| 64 return callbacks->onError(&error); | 64 return callbacks->onError(&error); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const
WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | 67 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const
WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) override |
| 68 { | 68 { |
| 69 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll"; | 69 m_lastErrorWebCacheMethodCalled = "dispatchMatchAll"; |
| 70 checkUrlIfProvided(webRequest.url()); | 70 checkUrlIfProvided(webRequest.url()); |
| 71 checkQueryParamsIfProvided(queryParams); | 71 checkQueryParamsIfProvided(queryParams); |
| 72 | 72 |
| 73 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 73 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 74 WebServiceWorkerCacheError error = m_error; | 74 WebServiceWorkerCacheError error = m_error; |
| 75 return callbacks->onError(&error); | 75 return callbacks->onError(&error); |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE | 78 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) override |
| 79 { | 79 { |
| 80 m_lastErrorWebCacheMethodCalled = "dispatchKeys"; | 80 m_lastErrorWebCacheMethodCalled = "dispatchKeys"; |
| 81 if (webRequest) { | 81 if (webRequest) { |
| 82 checkUrlIfProvided(webRequest->url()); | 82 checkUrlIfProvided(webRequest->url()); |
| 83 checkQueryParamsIfProvided(queryParams); | 83 checkQueryParamsIfProvided(queryParams); |
| 84 } | 84 } |
| 85 | 85 |
| 86 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 86 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 87 WebServiceWorkerCacheError error = m_error; | 87 WebServiceWorkerCacheError error = m_error; |
| 88 return callbacks->onError(&error); | 88 return callbacks->onError(&error); |
| 89 } | 89 } |
| 90 | 90 |
| 91 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) OVERRIDE | 91 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) override |
| 92 { | 92 { |
| 93 m_lastErrorWebCacheMethodCalled = "dispatchBatch"; | 93 m_lastErrorWebCacheMethodCalled = "dispatchBatch"; |
| 94 checkBatchOperationsIfProvided(batchOperations); | 94 checkBatchOperationsIfProvided(batchOperations); |
| 95 | 95 |
| 96 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 96 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 97 WebServiceWorkerCacheError error = m_error; | 97 WebServiceWorkerCacheError error = m_error; |
| 98 return callbacks->onError(&error); | 98 return callbacks->onError(&error); |
| 99 } | 99 } |
| 100 | 100 |
| 101 protected: | 101 protected: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 private: | 202 private: |
| 203 // A ScriptFunction that creates a test failure if it is ever called. | 203 // A ScriptFunction that creates a test failure if it is ever called. |
| 204 class UnreachableFunction : public ScriptFunction { | 204 class UnreachableFunction : public ScriptFunction { |
| 205 public: | 205 public: |
| 206 static v8::Handle<v8::Function> create(ScriptState* scriptState) | 206 static v8::Handle<v8::Function> create(ScriptState* scriptState) |
| 207 { | 207 { |
| 208 UnreachableFunction* self = new UnreachableFunction(scriptState); | 208 UnreachableFunction* self = new UnreachableFunction(scriptState); |
| 209 return self->bindToV8Function(); | 209 return self->bindToV8Function(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 virtual ScriptValue call(ScriptValue value) OVERRIDE | 212 virtual ScriptValue call(ScriptValue value) override |
| 213 { | 213 { |
| 214 ADD_FAILURE() << "Unexpected call to a null ScriptFunction."; | 214 ADD_FAILURE() << "Unexpected call to a null ScriptFunction."; |
| 215 return value; | 215 return value; |
| 216 } | 216 } |
| 217 private: | 217 private: |
| 218 UnreachableFunction(ScriptState* scriptState) : ScriptFunction(scriptSta
te) { } | 218 UnreachableFunction(ScriptState* scriptState) : ScriptFunction(scriptSta
te) { } |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 // A ScriptFunction that saves its parameter; used by tests to assert on cor
rect | 221 // A ScriptFunction that saves its parameter; used by tests to assert on cor
rect |
| 222 // values being passed. | 222 // values being passed. |
| 223 class TestFunction : public ScriptFunction { | 223 class TestFunction : public ScriptFunction { |
| 224 public: | 224 public: |
| 225 static v8::Handle<v8::Function> create(ScriptState* scriptState, ScriptV
alue* outValue) | 225 static v8::Handle<v8::Function> create(ScriptState* scriptState, ScriptV
alue* outValue) |
| 226 { | 226 { |
| 227 TestFunction* self = new TestFunction(scriptState, outValue); | 227 TestFunction* self = new TestFunction(scriptState, outValue); |
| 228 return self->bindToV8Function(); | 228 return self->bindToV8Function(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 virtual ScriptValue call(ScriptValue value) OVERRIDE | 231 virtual ScriptValue call(ScriptValue value) override |
| 232 { | 232 { |
| 233 ASSERT(!value.isEmpty()); | 233 ASSERT(!value.isEmpty()); |
| 234 *m_value = value; | 234 *m_value = value; |
| 235 return value; | 235 return value; |
| 236 } | 236 } |
| 237 | 237 |
| 238 private: | 238 private: |
| 239 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu
nction(scriptState), m_value(outValue) { } | 239 TestFunction(ScriptState* scriptState, ScriptValue* outValue) : ScriptFu
nction(scriptState), m_value(outValue) { } |
| 240 | 240 |
| 241 ScriptValue* m_value; | 241 ScriptValue* m_value; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 // From ::testing::Test: | 244 // From ::testing::Test: |
| 245 virtual void SetUp() OVERRIDE | 245 virtual void SetUp() override |
| 246 { | 246 { |
| 247 EXPECT_FALSE(m_scriptScope); | 247 EXPECT_FALSE(m_scriptScope); |
| 248 m_scriptScope = adoptPtr(new ScriptState::Scope(scriptState())); | 248 m_scriptScope = adoptPtr(new ScriptState::Scope(scriptState())); |
| 249 } | 249 } |
| 250 | 250 |
| 251 virtual void TearDown() OVERRIDE | 251 virtual void TearDown() override |
| 252 { | 252 { |
| 253 m_scriptScope = 0; | 253 m_scriptScope = 0; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Lifetime is that of the text fixture. | 256 // Lifetime is that of the text fixture. |
| 257 OwnPtr<DummyPageHolder> m_page; | 257 OwnPtr<DummyPageHolder> m_page; |
| 258 | 258 |
| 259 // Lifetime is per test instance. | 259 // Lifetime is per test instance. |
| 260 OwnPtr<ScriptState::Scope> m_scriptScope; | 260 OwnPtr<ScriptState::Scope> m_scriptScope; |
| 261 }; | 261 }; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 | 400 |
| 401 // FIXME: test add & addAll. | 401 // FIXME: test add & addAll. |
| 402 } | 402 } |
| 403 | 403 |
| 404 class MatchTestCache : public NotImplementedErrorCache { | 404 class MatchTestCache : public NotImplementedErrorCache { |
| 405 public: | 405 public: |
| 406 MatchTestCache(WebServiceWorkerResponse& response) | 406 MatchTestCache(WebServiceWorkerResponse& response) |
| 407 : m_response(response) { } | 407 : m_response(response) { } |
| 408 | 408 |
| 409 // From WebServiceWorkerCache: | 409 // From WebServiceWorkerCache: |
| 410 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | 410 virtual void dispatchMatch(CacheMatchCallbacks* callbacks, const WebServiceW
orkerRequest& webRequest, const QueryParams& queryParams) override |
| 411 { | 411 { |
| 412 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 412 OwnPtr<CacheMatchCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 413 return callbacks->onSuccess(&m_response); | 413 return callbacks->onSuccess(&m_response); |
| 414 } | 414 } |
| 415 | 415 |
| 416 private: | 416 private: |
| 417 WebServiceWorkerResponse& m_response; | 417 WebServiceWorkerResponse& m_response; |
| 418 }; | 418 }; |
| 419 | 419 |
| 420 TEST_F(ServiceWorkerCacheTest, MatchResponseTest) | 420 TEST_F(ServiceWorkerCacheTest, MatchResponseTest) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 434 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); | 434 Response* response = V8Response::toImplWithTypeCheck(isolate(), scriptValue.
v8Value()); |
| 435 ASSERT_TRUE(response); | 435 ASSERT_TRUE(response); |
| 436 EXPECT_EQ(responseUrl, response->url()); | 436 EXPECT_EQ(responseUrl, response->url()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 class KeysTestCache : public NotImplementedErrorCache { | 439 class KeysTestCache : public NotImplementedErrorCache { |
| 440 public: | 440 public: |
| 441 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) | 441 KeysTestCache(WebVector<WebServiceWorkerRequest>& requests) |
| 442 : m_requests(requests) { } | 442 : m_requests(requests) { } |
| 443 | 443 |
| 444 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) OVERRIDE | 444 virtual void dispatchKeys(CacheWithRequestsCallbacks* callbacks, const WebSe
rviceWorkerRequest* webRequest, const QueryParams& queryParams) override |
| 445 { | 445 { |
| 446 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 446 OwnPtr<CacheWithRequestsCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 447 return callbacks->onSuccess(&m_requests); | 447 return callbacks->onSuccess(&m_requests); |
| 448 } | 448 } |
| 449 | 449 |
| 450 private: | 450 private: |
| 451 WebVector<WebServiceWorkerRequest>& m_requests; | 451 WebVector<WebServiceWorkerRequest>& m_requests; |
| 452 }; | 452 }; |
| 453 | 453 |
| 454 TEST_F(ServiceWorkerCacheTest, KeysResponseTest) | 454 TEST_F(ServiceWorkerCacheTest, KeysResponseTest) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 478 if (request) | 478 if (request) |
| 479 EXPECT_EQ(expectedUrls[i], request->url()); | 479 EXPECT_EQ(expectedUrls[i], request->url()); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { | 483 class MatchAllAndBatchTestCache : public NotImplementedErrorCache { |
| 484 public: | 484 public: |
| 485 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) | 485 MatchAllAndBatchTestCache(WebVector<WebServiceWorkerResponse>& responses) |
| 486 : m_responses(responses) { } | 486 : m_responses(responses) { } |
| 487 | 487 |
| 488 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const
WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) OVERRIDE | 488 virtual void dispatchMatchAll(CacheWithResponsesCallbacks* callbacks, const
WebServiceWorkerRequest& webRequest, const QueryParams& queryParams) override |
| 489 { | 489 { |
| 490 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 490 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 491 return callbacks->onSuccess(&m_responses); | 491 return callbacks->onSuccess(&m_responses); |
| 492 } | 492 } |
| 493 | 493 |
| 494 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) OVERRIDE | 494 virtual void dispatchBatch(CacheWithResponsesCallbacks* callbacks, const Web
Vector<BatchOperation>& batchOperations) override |
| 495 { | 495 { |
| 496 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); | 496 OwnPtr<CacheWithResponsesCallbacks> ownedCallbacks(adoptPtr(callbacks)); |
| 497 return callbacks->onSuccess(&m_responses); | 497 return callbacks->onSuccess(&m_responses); |
| 498 } | 498 } |
| 499 | 499 |
| 500 private: | 500 private: |
| 501 WebVector<WebServiceWorkerResponse>& m_responses; | 501 WebVector<WebServiceWorkerResponse>& m_responses; |
| 502 }; | 502 }; |
| 503 | 503 |
| 504 TEST_F(ServiceWorkerCacheTest, MatchAllAndBatchResponseTest) | 504 TEST_F(ServiceWorkerCacheTest, MatchAllAndBatchResponseTest) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 533 } | 533 } |
| 534 | 534 |
| 535 result = cache->deleteFunction(scriptState(), "http://some.url/", *options); | 535 result = cache->deleteFunction(scriptState(), "http://some.url/", *options); |
| 536 scriptValue = getResolveValue(result); | 536 scriptValue = getResolveValue(result); |
| 537 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); | 537 EXPECT_TRUE(scriptValue.v8Value()->IsBoolean()); |
| 538 EXPECT_EQ(true, scriptValue.v8Value()->BooleanValue()); | 538 EXPECT_EQ(true, scriptValue.v8Value()->BooleanValue()); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace | 541 } // namespace |
| 542 } // namespace blink | 542 } // namespace blink |
| OLD | NEW |