summaryrefslogtreecommitdiffstats
path: root/extensions/common/test_util.cc
diff options
context:
space:
mode:
authorscheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 20:52:32 +0000
committerscheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-06 20:52:32 +0000
commit98e1617bfcaaffb9aa9e39cd7bd44831f6f5d376 (patch)
tree829c19e53e7535388f9100232803de0ed113d893 /extensions/common/test_util.cc
parente6fc7b45877afd0ca10d139f936af8caf529b3c0 (diff)
downloadchromium_src-98e1617bfcaaffb9aa9e39cd7bd44831f6f5d376.zip
chromium_src-98e1617bfcaaffb9aa9e39cd7bd44831f6f5d376.tar.gz
chromium_src-98e1617bfcaaffb9aa9e39cd7bd44831f6f5d376.tar.bz2
Parse manifest file with app.service_worker.script.
Add parsing logic to load a manifest specifying a service worker script. This is a precursor to registering and using that script. BUG=344917 R=jyasskin@chromium.org Review URL: https://codereview.chromium.org/178253007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/common/test_util.cc')
-rw-r--r--extensions/common/test_util.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/extensions/common/test_util.cc b/extensions/common/test_util.cc
index 4d3164f..05de2c7 100644
--- a/extensions/common/test_util.cc
+++ b/extensions/common/test_util.cc
@@ -4,9 +4,12 @@
#include "extensions/common/test_util.h"
+#include "base/json/json_reader.h"
+#include "base/values.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/value_builder.h"
+#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace test_util {
@@ -27,5 +30,21 @@ scoped_refptr<Extension> CreateExtensionWithID(const std::string& id) {
.Build();
}
+scoped_ptr<base::DictionaryValue> ParseJsonDictionaryWithSingleQuotes(
+ std::string json) {
+ std::replace(json.begin(), json.end(), '\'', '"');
+ std::string error_msg;
+ scoped_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
+ json, base::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg));
+ scoped_ptr<base::DictionaryValue> result_dict;
+ if (result && result->IsType(base::Value::TYPE_DICTIONARY)) {
+ result_dict.reset(static_cast<base::DictionaryValue*>(result.release()));
+ } else {
+ ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
+ result_dict.reset(new base::DictionaryValue());
+ }
+ return result_dict.Pass();
+}
+
} // namespace test_util
} // namespace extensions