diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 83b1d7a66b37..2959af1f5a46 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -13,7 +13,6 @@ #include "mozilla/FloatingPoint.h" #include "mozilla/Assertions.h" #include "mozilla/Preferences.h" -#include "mozilla/unused.h" #include "AccessCheck.h" #include "jsfriendapi.h" @@ -47,7 +46,6 @@ #include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "WorkerPrivate.h" #include "nsDOMClassInfo.h" -#include "ipc/ErrorIPCUtils.h" namespace mozilla { namespace dom { @@ -151,31 +149,6 @@ ErrorResult::ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber, mMessage = message; } -void -ErrorResult::SerializeMessage(IPC::Message* aMsg) const -{ - using namespace IPC; - MOZ_ASSERT(mMessage); - WriteParam(aMsg, mMessage->mArgs); - WriteParam(aMsg, mMessage->mErrorNumber); -} - -bool -ErrorResult::DeserializeMessage(const IPC::Message* aMsg, void** aIter) -{ - using namespace IPC; - nsAutoPtr readMessage(new Message()); - if (!ReadParam(aMsg, aIter, &readMessage->mArgs) || - !ReadParam(aMsg, aIter, &readMessage->mErrorNumber)) { - return false; - } - if (mMessage) { - delete mMessage; - } - mMessage = readMessage.forget(); - return true; -} - void ErrorResult::ThrowTypeError(const dom::ErrNum errorNumber, ...) { @@ -328,37 +301,6 @@ ErrorResult::ReportNotEnoughArgsError(JSContext* cx, ThrowErrorMessage(cx, dom::MSG_MISSING_ARGUMENTS, errorMessage.get()); } -ErrorResult& -ErrorResult::operator=(ErrorResult&& aRHS) -{ -#ifdef DEBUG - mMightHaveUnreportedJSException = aRHS.mMightHaveUnreportedJSException; - aRHS.mMightHaveUnreportedJSException = false; -#endif - if (aRHS.IsErrorWithMessage()) { - mMessage = aRHS.mMessage; - aRHS.mMessage = nullptr; - } else if (aRHS.IsJSException()) { - JSContext* cx = nsContentUtils::GetDefaultJSContextForThread(); - MOZ_ASSERT(cx); - mJSException.setUndefined(); - if (!js::AddRawValueRoot(cx, &mJSException, "ErrorResult::mJSException")) { - MOZ_CRASH("Could not root mJSException, we're about to OOM"); - } - mJSException = aRHS.mJSException; - aRHS.mJSException.setUndefined(); - js::RemoveRawValueRoot(cx, &aRHS.mJSException); - } else { - // Null out the union on both sides for hygiene purposes. - mMessage = aRHS.mMessage = nullptr; - } - // Note: It's important to do this last, since this affects the condition - // checks above! - mResult = aRHS.mResult; - aRHS.mResult = NS_OK; - return *this; -} - namespace dom { bool diff --git a/dom/bindings/ErrorIPCUtils.h b/dom/bindings/ErrorIPCUtils.h deleted file mode 100644 index c929949bc4b0..000000000000 --- a/dom/bindings/ErrorIPCUtils.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ -/* vim: set ts=2 sw=2 et tw=79: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "ipc/IPCMessageUtils.h" -#include "mozilla/ErrorResult.h" -#include "mozilla/Assertions.h" -#include "mozilla/Move.h" - -#ifndef IPC_ErrorIPCUtils_h -#define IPC_ErrorIPCUtils_h - -namespace IPC { - -template<> -struct ParamTraits : - public ContiguousEnumSerializer {}; - -template<> -struct ParamTraits -{ - typedef mozilla::ErrorResult paramType; - - static void Write(Message* aMsg, const paramType& aParam) - { - // It should be the case that mMightHaveUnreportedJSException can only be - // true when we're expecting a JS exception. We cannot send such messages - // over the IPC channel since there is no sane way of transferring the JS - // value over to the other side. Callers should never do that. - MOZ_ASSERT_IF(aParam.IsJSException(), aParam.mMightHaveUnreportedJSException); - if (aParam.IsJSException() -#ifdef DEBUG - || aParam.mMightHaveUnreportedJSException -#endif - ) { - MOZ_CRASH("Cannot encode an ErrorResult representing a Javascript exception"); - } - - WriteParam(aMsg, aParam.mResult); - WriteParam(aMsg, aParam.IsErrorWithMessage()); - if (aParam.IsErrorWithMessage()) { - aParam.SerializeMessage(aMsg); - } - } - - static bool Read(const Message* aMsg, void** aIter, paramType* aResult) - { - paramType readValue; - if (!ReadParam(aMsg, aIter, &readValue.mResult)) { - return false; - } - bool hasMessage = false; - if (!ReadParam(aMsg, aIter, &hasMessage)) { - return false; - } - if (hasMessage && !readValue.DeserializeMessage(aMsg, aIter)) { - return false; - } - *aResult = Move(readValue); - return true; - } -}; - -} - -#endif diff --git a/dom/bindings/ErrorResult.h b/dom/bindings/ErrorResult.h index 9beb59a96893..64f977762b7a 100644 --- a/dom/bindings/ErrorResult.h +++ b/dom/bindings/ErrorResult.h @@ -17,12 +17,6 @@ #include "nscore.h" #include "nsStringGlue.h" #include "mozilla/Assertions.h" -#include "mozilla/Move.h" - -namespace IPC { -class Message; -template struct ParamTraits; -} namespace mozilla { @@ -62,12 +56,6 @@ public: } #endif - ErrorResult(ErrorResult&& aRHS) - { - *this = Move(aRHS); - } - ErrorResult& operator=(ErrorResult&& aRHS); - void Throw(nsresult rv) { MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success"); MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()"); @@ -173,10 +161,6 @@ private: JS::Value mJSException; // valid when IsJSException() }; - friend struct IPC::ParamTraits; - void SerializeMessage(IPC::Message* aMsg) const; - bool DeserializeMessage(const IPC::Message* aMsg, void** aIter); - #ifdef DEBUG // Used to keep track of codepaths that might throw JS exceptions, // for assertion purposes. @@ -186,7 +170,6 @@ private: // Not to be implemented, to make sure people always pass this by // reference, not by value. ErrorResult(const ErrorResult&) = delete; - void operator=(const ErrorResult&) = delete; void ThrowErrorWithMessage(va_list ap, const dom::ErrNum errorNumber, nsresult errorType); }; diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index 2b38a24bf14f..2c828efa1026 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -73,5 +73,4 @@ MSG_DEF(MSG_INVALID_RESPONSE_STATUSCODE_ERROR, 0, JSEXN_RANGEERR, "Invalid respo MSG_DEF(MSG_INVALID_REDIRECT_STATUSCODE_ERROR, 0, JSEXN_RANGEERR, "Invalid redirect status code.") MSG_DEF(MSG_INVALID_URL_SCHEME, 2, JSEXN_TYPEERR, "{0} URL {1} must be either http:// or https://.") MSG_DEF(MSG_RESPONSE_URL_IS_NULL, 0, JSEXN_TYPEERR, "Cannot set Response.finalURL when Response.url is null.") -MSG_DEF(MSG_RESPONSE_HAS_VARY_STAR, 0, JSEXN_TYPEERR, "Invalid Response object with a 'Vary: *' header.") MSG_DEF(MSG_BAD_FORMDATA, 0, JSEXN_TYPEERR, "Could not parse content as FormData.") diff --git a/dom/bindings/moz.build b/dom/bindings/moz.build index 25f2ffb8359b..747fec2a7ee3 100644 --- a/dom/bindings/moz.build +++ b/dom/bindings/moz.build @@ -6,10 +6,6 @@ TEST_DIRS += ['test'] -EXPORTS.ipc += [ - 'ErrorIPCUtils.h', -] - EXPORTS.mozilla += [ 'ErrorResult.h', ] diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index c01770515217..c0ba120ac996 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -452,16 +452,12 @@ Cache::RecvMatchAllResponse(RequestId aRequestId, nsresult aRv, } void -Cache::RecvAddAllResponse(RequestId aRequestId, - const mozilla::ErrorResult& aError) +Cache::RecvAddAllResponse(RequestId aRequestId, nsresult aRv) { nsRefPtr promise = RemoveRequestPromise(aRequestId); - if (aError.Failed()) { - // TODO: Remove this const_cast (bug 1152078). - // It is safe for now since this ErrorResult is handed off to us by IPDL - // and is thrown into the trash afterwards. - promise->MaybeReject(const_cast(aError)); + if (NS_FAILED(aRv)) { + promise->MaybeReject(aRv); return; } diff --git a/dom/cache/Cache.h b/dom/cache/Cache.h index ceae13efafa3..93a77f2d8109 100644 --- a/dom/cache/Cache.h +++ b/dom/cache/Cache.h @@ -81,8 +81,7 @@ public: const PCacheResponseOrVoid& aResponse); void RecvMatchAllResponse(RequestId aRequestId, nsresult aRv, const nsTArray& aResponses); - void RecvAddAllResponse(RequestId aRequestId, - const mozilla::ErrorResult& aError); + void RecvAddAllResponse(RequestId aRequestId, nsresult aRv); void RecvPutResponse(RequestId aRequestId, nsresult aRv); void RecvDeleteResponse(RequestId aRequestId, nsresult aRv, diff --git a/dom/cache/CacheChild.cpp b/dom/cache/CacheChild.cpp index 4facd1ebb77b..4adf3b71aece 100644 --- a/dom/cache/CacheChild.cpp +++ b/dom/cache/CacheChild.cpp @@ -146,13 +146,12 @@ CacheChild::RecvMatchAllResponse(const RequestId& requestId, const nsresult& aRv } bool -CacheChild::RecvAddAllResponse(const RequestId& requestId, - const mozilla::ErrorResult& aError) +CacheChild::RecvAddAllResponse(const RequestId& requestId, const nsresult& aRv) { NS_ASSERT_OWNINGTHREAD(CacheChild); nsRefPtr listener = mListener; if (listener) { - listener->RecvAddAllResponse(requestId, aError); + listener->RecvAddAllResponse(requestId, aRv); } return true; } diff --git a/dom/cache/CacheChild.h b/dom/cache/CacheChild.h index 58ca8ffb1297..d01f6f7352ba 100644 --- a/dom/cache/CacheChild.h +++ b/dom/cache/CacheChild.h @@ -55,7 +55,7 @@ private: nsTArray&& responses) override; virtual bool RecvAddAllResponse(const RequestId& requestId, - const mozilla::ErrorResult& aError) override; + const nsresult& aRv) override; virtual bool RecvPutResponse(const RequestId& aRequestId, const nsresult& aRv) override; diff --git a/dom/cache/CacheParent.cpp b/dom/cache/CacheParent.cpp index c79da5d651e4..e98119447f62 100644 --- a/dom/cache/CacheParent.cpp +++ b/dom/cache/CacheParent.cpp @@ -23,7 +23,6 @@ namespace mozilla { namespace dom { namespace cache { -using mozilla::dom::ErrNum; using mozilla::ipc::FileDescriptorSetParent; using mozilla::ipc::PFileDescriptorSetParent; @@ -122,10 +121,7 @@ CacheParent::RecvAddAll(const RequestId& aRequestId, aRequests, requestStreams, getter_AddRefs(fetchPut)); if (NS_WARN_IF(NS_FAILED(rv))) { - MOZ_ASSERT(rv != NS_ERROR_TYPE_ERR); - ErrorResult error; - error.Throw(rv); - if (!SendAddAllResponse(aRequestId, error)) { + if (!SendAddAllResponse(aRequestId, rv)) { // child process is gone, warn and allow actor to clean up normally NS_WARNING("Cache failed to send AddAll response."); } @@ -260,7 +256,7 @@ CacheParent::OnCacheKeys(RequestId aRequestId, nsresult aRv, } void -CacheParent::OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, const ErrorResult& aRv) +CacheParent::OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv) { aFetchPut->ClearListener(); mFetchPutList.RemoveElement(aFetchPut); diff --git a/dom/cache/CacheParent.h b/dom/cache/CacheParent.h index 2aa757de6987..57d3ba5d9223 100644 --- a/dom/cache/CacheParent.h +++ b/dom/cache/CacheParent.h @@ -70,7 +70,7 @@ private: // FetchPut::Listener methods virtual void OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, - const mozilla::ErrorResult& aRv) override; + nsresult aRv) override; already_AddRefed DeserializeCacheStream(const PCacheReadStreamOrVoid& aStreamOrVoid); diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index 2a8447896160..6c4f70b86e79 100644 --- a/dom/cache/DBSchema.cpp +++ b/dom/cache/DBSchema.cpp @@ -944,9 +944,9 @@ DBSchema::MatchByVaryHeader(mozIStorageConnection* aConn, for (; token; token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer)) { nsDependentCString header(token); - MOZ_ASSERT(!header.EqualsLiteral("*"), - "We should have already caught this in " - "TypeUtils::ToPCacheResponseWithoutBody()"); + if (header.EqualsLiteral("*")) { + continue; + } ErrorResult errorResult; nsAutoCString queryValue; diff --git a/dom/cache/FetchPut.cpp b/dom/cache/FetchPut.cpp index 3d41cf8e45d3..ef3248c78bcc 100644 --- a/dom/cache/FetchPut.cpp +++ b/dom/cache/FetchPut.cpp @@ -136,6 +136,7 @@ FetchPut::FetchPut(Listener* aListener, Manager* aManager, , mInitiatingThread(NS_GetCurrentThread()) , mStateList(aRequests.Length()) , mPendingCount(0) + , mResult(NS_OK) { MOZ_ASSERT(mListener); MOZ_ASSERT(mManager); @@ -156,7 +157,6 @@ FetchPut::~FetchPut() MOZ_ASSERT(!mListener); mManager->RemoveListener(this); mManager->ReleaseCacheId(mCacheId); - mResult.ClearMessage(); // This may contain a TypeError. } nsresult @@ -249,7 +249,7 @@ FetchPut::FetchComplete(FetchObserver* aObserver, { MOZ_ASSERT(NS_IsMainThread()); - if (aInternalResponse->IsError() && !mResult.Failed()) { + if (aInternalResponse->IsError() && NS_SUCCEEDED(mResult)) { MaybeSetError(NS_ERROR_FAILURE); } @@ -259,10 +259,10 @@ FetchPut::FetchComplete(FetchObserver* aObserver, ToPCacheResponseWithoutBody(mStateList[i].mPCacheResponse, *aInternalResponse, rv); if (rv.Failed()) { - mResult = Move(rv); - } else { - aInternalResponse->GetBody(getter_AddRefs(mStateList[i].mResponseStream)); + MaybeSetError(rv.ErrorCode()); + return; } + aInternalResponse->GetBody(getter_AddRefs(mStateList[i].mResponseStream)); mStateList[i].mFetchObserver = nullptr; MOZ_ASSERT(mPendingCount > 0); mPendingCount -= 1; @@ -291,7 +291,7 @@ FetchPut::DoPutOnWorkerThread() { MOZ_ASSERT(mInitiatingThread == NS_GetCurrentThread()); - if (mResult.Failed()) { + if (NS_FAILED(mResult)) { MaybeNotifyListener(); return; } @@ -377,9 +377,9 @@ FetchPut::MatchInPutList(const PCacheRequest& aRequest, for (; token; token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer)) { nsDependentCString header(token); - MOZ_ASSERT(!header.EqualsLiteral("*"), - "We should have already caught this in " - "TypeUtils::ToPCacheResponseWithoutBody()"); + if (header.EqualsLiteral("*")) { + continue; + } ErrorResult headerRv; nsAutoCString value; @@ -428,10 +428,10 @@ FetchPut::OnCachePutAll(RequestId aRequestId, nsresult aRv) void FetchPut::MaybeSetError(nsresult aRv) { - if (mResult.Failed() || NS_SUCCEEDED(aRv)) { + if (NS_FAILED(mResult) || NS_SUCCEEDED(aRv)) { return; } - mResult.Throw(aRv); + mResult = aRv; } void @@ -442,7 +442,6 @@ FetchPut::MaybeNotifyListener() return; } mListener->OnFetchPut(this, mRequestId, mResult); - mResult.ClearMessage(); // This may contain a TypeError. } nsIGlobalObject* diff --git a/dom/cache/FetchPut.h b/dom/cache/FetchPut.h index 4c1bad371d94..1efad6f6de27 100644 --- a/dom/cache/FetchPut.h +++ b/dom/cache/FetchPut.h @@ -9,7 +9,6 @@ #include "mozilla/AlreadyAddRefed.h" #include "mozilla/Attributes.h" -#include "mozilla/ErrorResult.h" #include "mozilla/dom/cache/Manager.h" #include "mozilla/dom/cache/PCacheTypes.h" #include "mozilla/dom/cache/Types.h" @@ -40,7 +39,7 @@ public: { public: virtual void - OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, const ErrorResult& aRv) = 0; + OnFetchPut(FetchPut* aFetchPut, RequestId aRequestId, nsresult aRv) = 0; }; static nsresult @@ -105,7 +104,7 @@ private: nsCOMPtr mInitiatingThread; nsTArray mStateList; uint32_t mPendingCount; - ErrorResult mResult; + nsresult mResult; nsCOMPtr mRunnable; public: diff --git a/dom/cache/PCache.ipdl b/dom/cache/PCache.ipdl index b10eb9bc4cbe..2ad5bf421e46 100644 --- a/dom/cache/PCache.ipdl +++ b/dom/cache/PCache.ipdl @@ -11,7 +11,6 @@ include protocol PBlob; // FIXME: bug 792908 include protocol PCacheStreamControl; using mozilla::dom::cache::RequestId from "mozilla/dom/cache/Types.h"; -using mozilla::ErrorResult from "ipc/ErrorIPCUtils.h"; include "mozilla/dom/cache/IPCUtils.h"; namespace mozilla { @@ -36,7 +35,7 @@ parent: child: MatchResponse(RequestId requestId, nsresult aRv, PCacheResponseOrVoid aResponse); MatchAllResponse(RequestId requestId, nsresult aRv, PCacheResponse[] responses); - AddAllResponse(RequestId requestId, ErrorResult aRv); + AddAllResponse(RequestId requestId, nsresult aRv); PutResponse(RequestId requestId, nsresult aRv); DeleteResponse(RequestId requestId, nsresult aRv, bool success); KeysResponse(RequestId requestId, nsresult aRv, PCacheRequest[] requests); diff --git a/dom/cache/TypeUtils.cpp b/dom/cache/TypeUtils.cpp index 9fd31ffcb1cf..d9fa6ff0c41b 100644 --- a/dom/cache/TypeUtils.cpp +++ b/dom/cache/TypeUtils.cpp @@ -26,8 +26,6 @@ #include "nsStreamUtils.h" #include "nsString.h" #include "nsURLParsers.h" -#include "nsCRT.h" -#include "nsHttp.h" namespace { @@ -106,29 +104,6 @@ ProcessURL(nsAString& aUrl, bool* aSchemeValidOut, *aUrlWithoutQueryOut = Substring(aUrl, 0, queryPos - 1); } -static bool -HasVaryStar(mozilla::dom::InternalHeaders* aHeaders) -{ - nsAutoTArray varyHeaders; - ErrorResult rv; - aHeaders->GetAll(NS_LITERAL_CSTRING("vary"), varyHeaders, rv); - MOZ_ALWAYS_TRUE(!rv.Failed()); - - for (uint32_t i = 0; i < varyHeaders.Length(); ++i) { - nsAutoCString varyValue(varyHeaders[i]); - char* rawBuffer = varyValue.BeginWriting(); - char* token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer); - for (; token; - token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer)) { - nsDependentCString header(token); - if (header.EqualsLiteral("*")) { - return true; - } - } - } - return false; -} - void SerializeNormalStream(nsIInputStream* aStream, PCacheReadStream& aReadStreamOut) { @@ -291,10 +266,6 @@ TypeUtils::ToPCacheResponseWithoutBody(PCacheResponse& aOut, aOut.statusText() = aIn.GetStatusText(); nsRefPtr headers = aIn.UnfilteredHeaders(); MOZ_ASSERT(headers); - if (HasVaryStar(headers)) { - aRv.ThrowTypeError(MSG_RESPONSE_HAS_VARY_STAR); - return; - } headers->GetPHeaders(aOut.headers()); aOut.headersGuard() = headers->Guard(); aOut.securityInfo() = aIn.GetSecurityInfo(); @@ -310,9 +281,6 @@ TypeUtils::ToPCacheResponse(PCacheResponse& aOut, Response& aIn, ErrorResult& aR nsRefPtr ir = aIn.GetInternalResponse(); ToPCacheResponseWithoutBody(aOut, *ir, aRv); - if (NS_WARN_IF(aRv.Failed())) { - return; - } nsCOMPtr stream; aIn.GetBody(getter_AddRefs(stream)); diff --git a/dom/cache/test/mochitest/test_cache_match_vary.js b/dom/cache/test/mochitest/test_cache_match_vary.js index 9bb948b6a548..82f8c31738a2 100644 --- a/dom/cache/test/mochitest/test_cache_match_vary.js +++ b/dom/cache/test/mochitest/test_cache_match_vary.js @@ -107,59 +107,15 @@ function testBasicKeys() { } function testStar() { - function ensurePromiseRejected(promise) { - return promise - .then(function() { - ok(false, "Promise should be rejected"); - }, function(err) { - is(err.name, "TypeError", "Attempting to store a Response with a Vary:* header must fail"); - }); - } var test; - return new Promise(function(resolve, reject) { - var cache; - caches.open(name).then(function(c) { - cache = c; - Promise.all([ - ensurePromiseRejected( - cache.add(new Request(requestURL + "1", {headers: {"WhatToVary": "*"}}))), - ensurePromiseRejected( - cache.addAll([ - new Request(requestURL + "2", {headers: {"WhatToVary": "*"}}), - requestURL + "3", - ])), - ensurePromiseRejected( - fetch(new Request(requestURL + "4", {headers: {"WhatToVary": "*"}})) - .then(function(response) { - return cache.put(requestURL + "4", response); - })), - ensurePromiseRejected( - cache.add(new Request(requestURL + "5", {headers: {"WhatToVary": "*,User-Agent"}}))), - ensurePromiseRejected( - cache.addAll([ - new Request(requestURL + "6", {headers: {"WhatToVary": "*,User-Agent"}}), - requestURL + "7", - ])), - ensurePromiseRejected( - fetch(new Request(requestURL + "8", {headers: {"WhatToVary": "*,User-Agent"}})) - .then(function(response) { - return cache.put(requestURL + "8", response); - })), - ensurePromiseRejected( - cache.add(new Request(requestURL + "9", {headers: {"WhatToVary": "User-Agent,*"}}))), - ensurePromiseRejected( - cache.addAll([ - new Request(requestURL + "10", {headers: {"WhatToVary": "User-Agent,*"}}), - requestURL + "10", - ])), - ensurePromiseRejected( - fetch(new Request(requestURL + "11", {headers: {"WhatToVary": "User-Agent,*"}})) - .then(function(response) { - return cache.put(requestURL + "11", response); - })), - ]).then(reject, resolve); + return setupTest({"WhatToVary": "*", "Cookie": "foo=bar"}) + .then(function(t) { + test = t; + // Ensure that searching with a different Cookie header with Vary:* succeeds. + return test.cache.match(new Request(requestURL, {headers: {"Cookie": "bar=baz"}})); + }).then(function(r) { + return checkResponse(r, test.response, test.responseText); }); - }); } function testMatch() { @@ -178,6 +134,23 @@ function testMatch() { }); } +function testStarAndAnotherHeader() { + var test; + return setupTest({"WhatToVary": "*,User-Agent"}) + .then(function(t) { + test = t; + // Ensure that searching with a different User-Agent header fails. + return test.cache.match(new Request(requestURL, {headers: {"User-Agent": "MyUA"}})); + }).then(function(r) { + is(typeof r, "undefined", "Searching for a request with a non-matching User-Agent header should not succeed"); + // Ensure that searching with a different User-Agent header but with ignoreVary succeeds. + return test.cache.match(new Request(requestURL, {headers: {"User-Agent": "MyUA"}}), + {ignoreVary: true}); + }).then(function(r) { + return checkResponse(r, test.response, test.responseText); + }); +} + function testInvalidHeaderName() { var test; return setupTest({"WhatToVary": "Foo/Bar, User-Agent"}) @@ -312,8 +285,6 @@ function testMultipleCacheEntries() { function step(testPromise) { return testPromise.then(function() { caches.delete(name); - }, function() { - caches.delete(name); }); } @@ -323,6 +294,8 @@ step(testBasics()).then(function() { return step(testStar()); }).then(function() { return step(testMatch()); +}).then(function() { + return step(testStarAndAnotherHeader()); }).then(function() { return step(testInvalidHeaderName()); }).then(function() {