| Index: content/renderer/manifest/manifest_parser_unittest.cc
|
| diff --git a/content/renderer/manifest/manifest_parser_unittest.cc b/content/renderer/manifest/manifest_parser_unittest.cc
|
| index 362177eb0511119d4c3efd1fc8ea92dcce9f4254..ee54103076ea4fd321d3688b517eb08a658a7b07 100644
|
| --- a/content/renderer/manifest/manifest_parser_unittest.cc
|
| +++ b/content/renderer/manifest/manifest_parser_unittest.cc
|
| @@ -2,26 +2,32 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/renderer/manifest/manifest_parser.h"
|
| +#include "content/public/renderer/manifest_parser.h"
|
|
|
| #include "base/strings/string_util.h"
|
| #include "content/public/common/manifest.h"
|
| +#include "content/public/renderer/content_renderer_client.h"
|
| +#include "content/test/test_content_client.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace content {
|
|
|
| class ManifestParserTest : public testing::Test {
|
| protected:
|
| - ManifestParserTest() {}
|
| + ManifestParserTest() {
|
| + SetContentClient(&test_content_client_);
|
| + SetRendererClientForTesting(&test_content_renderer_client_);
|
| + }
|
| +
|
| ~ManifestParserTest() override {}
|
|
|
| Manifest ParseManifestWithURLs(const base::StringPiece& data,
|
| const GURL& document_url,
|
| const GURL& manifest_url) {
|
| - ManifestParser parser(data, document_url, manifest_url);
|
| - parser.Parse();
|
| - errors_ = parser.errors();
|
| - return parser.manifest();
|
| + scoped_ptr<ManifestParser> parser = ManifestParser::Get();
|
| + parser->Parse(data, document_url, manifest_url);
|
| + errors_ = parser->errors();
|
| + return parser->manifest();
|
| }
|
|
|
| Manifest ParseManifest(const base::StringPiece& data) {
|
| @@ -43,6 +49,9 @@ class ManifestParserTest : public testing::Test {
|
| private:
|
| std::vector<std::string> errors_;
|
|
|
| + TestContentClient test_content_client_;
|
| + ContentRendererClient test_content_renderer_client_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(ManifestParserTest);
|
| };
|
|
|
| @@ -53,14 +62,14 @@ const GURL ManifestParserTest::default_manifest_url(
|
|
|
| TEST_F(ManifestParserTest, CrashTest) {
|
| // Passing temporary variables should not crash.
|
| - ManifestParser parser("{\"start_url\": \"/\"}",
|
| - GURL("http://example.com"),
|
| - GURL("http://example.com"));
|
| - parser.Parse();
|
| + scoped_ptr<ManifestParser> parser = ManifestParser::Get();
|
| + parser->Parse("{\"start_url\": \"/\"}",
|
| + GURL("http://example.com"),
|
| + GURL("http://example.com"));
|
|
|
| // .Parse() should have been call without crashing and succeeded.
|
| - EXPECT_EQ(0u, parser.errors().size());
|
| - EXPECT_FALSE(parser.manifest().IsEmpty());
|
| + EXPECT_EQ(0u, parser->errors().size());
|
| + EXPECT_FALSE(parser->manifest().IsEmpty());
|
| }
|
|
|
| TEST_F(ManifestParserTest, EmptyStringNull) {
|
| @@ -78,8 +87,6 @@ TEST_F(ManifestParserTest, EmptyStringNull) {
|
| ASSERT_TRUE(manifest.start_url.is_empty());
|
| ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
|
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
|
| - ASSERT_TRUE(manifest.gcm_sender_id.is_null());
|
| - ASSERT_FALSE(manifest.gcm_user_visible_only);
|
| }
|
|
|
| TEST_F(ManifestParserTest, ValidNoContentParses) {
|
| @@ -95,16 +102,14 @@ TEST_F(ManifestParserTest, ValidNoContentParses) {
|
| ASSERT_TRUE(manifest.start_url.is_empty());
|
| ASSERT_EQ(manifest.display, Manifest::DISPLAY_MODE_UNSPECIFIED);
|
| ASSERT_EQ(manifest.orientation, blink::WebScreenOrientationLockDefault);
|
| - ASSERT_TRUE(manifest.gcm_sender_id.is_null());
|
| - ASSERT_FALSE(manifest.gcm_user_visible_only);
|
| }
|
|
|
| TEST_F(ManifestParserTest, MultipleErrorsReporting) {
|
| Manifest manifest = ParseManifest("{ \"name\": 42, \"short_name\": 4,"
|
| "\"orientation\": {}, \"display\": \"foo\", \"start_url\": null,"
|
| - "\"icons\": {}, \"gcm_user_visible_only\": 42 }");
|
| + "\"icons\": {} }");
|
|
|
| - EXPECT_EQ(7u, GetErrorCount());
|
| + EXPECT_EQ(6u, GetErrorCount());
|
|
|
| EXPECT_EQ("Manifest parsing error: property 'name' ignored,"
|
| " type string expected.",
|
| @@ -123,9 +128,6 @@ TEST_F(ManifestParserTest, MultipleErrorsReporting) {
|
| EXPECT_EQ("Manifest parsing error: property 'icons' ignored, "
|
| "type array expected.",
|
| errors()[5]);
|
| - EXPECT_EQ("Manifest parsing error: property 'gcm_user_visible_only' ignored, "
|
| - "type boolean expected.",
|
| - errors()[6]);
|
| }
|
|
|
| TEST_F(ManifestParserTest, NameParseRules) {
|
| @@ -797,84 +799,4 @@ TEST_F(ManifestParserTest, IconSizesParseRules) {
|
| }
|
| }
|
|
|
| -TEST_F(ManifestParserTest, GCMSenderIDParseRules) {
|
| - // Smoke test.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }");
|
| - EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo"));
|
| - EXPECT_EQ(0u, GetErrorCount());
|
| - }
|
| -
|
| - // Trim whitespaces.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }");
|
| - EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo"));
|
| - EXPECT_EQ(0u, GetErrorCount());
|
| - }
|
| -
|
| - // Don't parse if the property isn't a string.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }");
|
| - EXPECT_TRUE(manifest.gcm_sender_id.is_null());
|
| - EXPECT_EQ(1u, GetErrorCount());
|
| - EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored,"
|
| - " type string expected.",
|
| - errors()[0]);
|
| - }
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
|
| - EXPECT_TRUE(manifest.gcm_sender_id.is_null());
|
| - EXPECT_EQ(1u, GetErrorCount());
|
| - EXPECT_EQ("Manifest parsing error: property 'gcm_sender_id' ignored,"
|
| - " type string expected.",
|
| - errors()[0]);
|
| - }
|
| -}
|
| -
|
| -TEST_F(ManifestParserTest, GCMUserVisibleOnlyParseRules) {
|
| - // Smoke test.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": true }");
|
| - EXPECT_TRUE(manifest.gcm_user_visible_only);
|
| - EXPECT_EQ(0u, GetErrorCount());
|
| - }
|
| -
|
| - // Don't parse if the property isn't a boolean.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": {} }");
|
| - EXPECT_FALSE(manifest.gcm_user_visible_only);
|
| - EXPECT_EQ(1u, GetErrorCount());
|
| - EXPECT_EQ(
|
| - "Manifest parsing error: property 'gcm_user_visible_only' ignored,"
|
| - " type boolean expected.",
|
| - errors()[0]);
|
| - }
|
| - {
|
| - Manifest manifest = ParseManifest(
|
| - "{ \"gcm_user_visible_only\": \"true\" }");
|
| - EXPECT_FALSE(manifest.gcm_user_visible_only);
|
| - EXPECT_EQ(1u, GetErrorCount());
|
| - EXPECT_EQ(
|
| - "Manifest parsing error: property 'gcm_user_visible_only' ignored,"
|
| - " type boolean expected.",
|
| - errors()[0]);
|
| - }
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": 1 }");
|
| - EXPECT_FALSE(manifest.gcm_user_visible_only);
|
| - EXPECT_EQ(1u, GetErrorCount());
|
| - EXPECT_EQ(
|
| - "Manifest parsing error: property 'gcm_user_visible_only' ignored,"
|
| - " type boolean expected.",
|
| - errors()[0]);
|
| - }
|
| -
|
| - // "False" should set the boolean false without throwing errors.
|
| - {
|
| - Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }");
|
| - EXPECT_FALSE(manifest.gcm_user_visible_only);
|
| - EXPECT_EQ(0u, GetErrorCount());
|
| - }
|
| -}
|
| -
|
| } // namespace content
|
|
|