Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: content/renderer/manifest/manifest_parser_unittest.cc

Issue 803063003: Fix crash when passing temporary variable as document/manifest URL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/manifest/manifest_parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/manifest/manifest_parser.h" 5 #include "content/renderer/manifest/manifest_parser.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "content/public/common/manifest.h" 8 #include "content/public/common/manifest.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 std::vector<std::string> errors_; 44 std::vector<std::string> errors_;
45 45
46 DISALLOW_COPY_AND_ASSIGN(ManifestParserTest); 46 DISALLOW_COPY_AND_ASSIGN(ManifestParserTest);
47 }; 47 };
48 48
49 const GURL ManifestParserTest::default_document_url( 49 const GURL ManifestParserTest::default_document_url(
50 "http://foo.com/index.html"); 50 "http://foo.com/index.html");
51 const GURL ManifestParserTest::default_manifest_url( 51 const GURL ManifestParserTest::default_manifest_url(
52 "http://foo.com/manifest.json"); 52 "http://foo.com/manifest.json");
53 53
54 TEST_F(ManifestParserTest, CrashTest) {
55 // Passing temporary variables should not crash.
56 ManifestParser parser("{\"start_url\": \"/\"}",
57 GURL("http://example.com"),
58 GURL("http://example.com"));
59 parser.Parse();
60
61 // .Parse() should have been call without crashing and succeeded.
62 EXPECT_EQ(0u, parser.errors().size());
63 EXPECT_FALSE(parser.manifest().IsEmpty());
64 }
65
54 TEST_F(ManifestParserTest, EmptyStringNull) { 66 TEST_F(ManifestParserTest, EmptyStringNull) {
55 Manifest manifest = ParseManifest(""); 67 Manifest manifest = ParseManifest("");
56 68
57 // This Manifest is not a valid JSON object, it's a parsing error. 69 // This Manifest is not a valid JSON object, it's a parsing error.
58 EXPECT_EQ(1u, GetErrorCount()); 70 EXPECT_EQ(1u, GetErrorCount());
59 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.", 71 EXPECT_EQ("Manifest parsing error: Line: 1, column: 1, Unexpected token.",
60 errors()[0]); 72 errors()[0]);
61 73
62 // A parsing error is equivalent to an empty manifest. 74 // A parsing error is equivalent to an empty manifest.
63 ASSERT_TRUE(manifest.IsEmpty()); 75 ASSERT_TRUE(manifest.IsEmpty());
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 871
860 // "False" should set the boolean false without throwing errors. 872 // "False" should set the boolean false without throwing errors.
861 { 873 {
862 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }"); 874 Manifest manifest = ParseManifest("{ \"gcm_user_visible_only\": false }");
863 EXPECT_FALSE(manifest.gcm_user_visible_only); 875 EXPECT_FALSE(manifest.gcm_user_visible_only);
864 EXPECT_EQ(0u, GetErrorCount()); 876 EXPECT_EQ(0u, GetErrorCount());
865 } 877 }
866 } 878 }
867 879
868 } // namespace content 880 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698