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

Unified Diff: chrome/browser/android/vr_shell/gltf_parser_unittest.cc

Issue 2774653002: Support for parsing external file references in a glTF resource. (Closed)
Patch Set: Scoping Clean call. Created 3 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/gltf_parser_unittest.cc
diff --git a/chrome/browser/android/vr_shell/gltf_parser_unittest.cc b/chrome/browser/android/vr_shell/gltf_parser_unittest.cc
index ff30ce2bbde61ea112db687f0d5c58d2947d4fec..0af89cf2b9804e8fc9341113eeb408478ae74a4a 100644
--- a/chrome/browser/android/vr_shell/gltf_parser_unittest.cc
+++ b/chrome/browser/android/vr_shell/gltf_parser_unittest.cc
@@ -17,12 +17,21 @@
namespace vr_shell {
-TEST(GltfParser, Parse) {
- test::RegisterPathProvider();
- base::FilePath gltf_path;
- PathService::Get(test::DIR_TEST_DATA, &gltf_path);
- gltf_path = gltf_path.Append("sample_inline.gltf");
+class GltfParserTest : public testing::Test {
+ protected:
+ void SetUp() override {
+ test::RegisterPathProvider();
+ PathService::Get(test::DIR_TEST_DATA, &data_dir_);
+ }
+ base::FilePath data_dir_;
+
+ std::unique_ptr<base::DictionaryValue> Deserialize(
+ const base::FilePath& gltf_path);
+};
+
+std::unique_ptr<base::DictionaryValue> GltfParserTest::Deserialize(
+ const base::FilePath& gltf_path) {
int error_code;
std::string error_msg;
JSONFileValueDeserializer json_deserializer(gltf_path);
@@ -30,8 +39,14 @@ TEST(GltfParser, Parse) {
EXPECT_NE(nullptr, asset_value);
base::DictionaryValue* asset;
EXPECT_TRUE(asset_value->GetAsDictionary(&asset));
+ asset_value.release();
+ return std::unique_ptr<base::DictionaryValue>(asset);
+}
+TEST_F(GltfParserTest, Parse) {
+ auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
GltfParser parser;
+
auto gltf_model = parser.Parse(*asset);
EXPECT_TRUE(gltf_model);
@@ -92,4 +107,50 @@ TEST(GltfParser, Parse) {
EXPECT_EQ(scene, gltf_model->GetMainScene());
}
+TEST_F(GltfParserTest, ParseUnknownBuffer) {
+ auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
+ GltfParser parser;
+
+ // Parsing succeeds.
+ EXPECT_NE(nullptr, parser.Parse(*asset));
+
+ // Parsing fails when a referenced buffer is removed.
+ std::unique_ptr<base::Value> value;
+ asset->Remove("buffers.dummyBuffer", &value);
+ EXPECT_EQ(nullptr, parser.Parse(*asset));
+
+ // Parsing fails when the buffer reinserted with a different ID.
+ asset->Set("buffers.anotherDummyBuffer", std::move(value));
+ EXPECT_EQ(nullptr, parser.Parse(*asset));
+}
+
+TEST_F(GltfParserTest, ParseMissingRequired) {
+ auto asset = Deserialize(data_dir_.Append("sample_inline.gltf"));
+ GltfParser parser;
+
+ std::unique_ptr<base::Value> value;
+ asset->Remove("buffers.dummyBuffer.uri", &value);
+ EXPECT_EQ(nullptr, parser.Parse(*asset));
+}
+
+TEST_F(GltfParserTest, ParseExternal) {
+ auto gltf_path = data_dir_.Append("sample_external.gltf");
+ GltfParser parser;
+
+ auto gltf_model = parser.Parse(gltf_path);
+ EXPECT_NE(nullptr, gltf_model);
+ const gltf::Buffer* buffer = gltf_model->GetBuffer(0);
+ EXPECT_NE(nullptr, buffer);
+ EXPECT_EQ("HELLO WORLD!", *buffer);
+ EXPECT_EQ(12u, buffer->length());
+}
+
+TEST_F(GltfParserTest, ParseExternalNoPath) {
+ auto asset = Deserialize(data_dir_.Append("sample_external.gltf"));
+ GltfParser parser;
+
+ // Parsing fails when no path is provided.
+ EXPECT_EQ(nullptr, parser.Parse(*asset));
+}
+
} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/gltf_parser.cc ('k') | chrome/browser/android/vr_shell/test/data/sample.bin » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698