1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/quota/ArtificialFailure.h"
9 #include "mozilla/Result.h"
10 #include "mozilla/StaticPrefs_dom.h"
12 namespace mozilla::dom::quota
{
14 Result
<Ok
, nsresult
> ArtificialFailure(
15 nsIQuotaArtificialFailure::Category aCategory
) {
16 MOZ_ASSERT(aCategory
!= 0 && ((aCategory
& (aCategory
- 1)) == 0));
18 if ((StaticPrefs::dom_quotaManager_artificialFailure_categories() &
23 uint32_t probability
=
24 StaticPrefs::dom_quotaManager_artificialFailure_probability();
25 if (probability
== 0) {
29 uint32_t randomValue
= std::rand() % 100;
30 if (randomValue
>= probability
) {
35 StaticPrefs::dom_quotaManager_artificialFailure_errorCode();
37 nsresult rv
= static_cast<nsresult
>(errorCode
);
41 } // namespace mozilla::dom::quota