| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/macros.h" | |
| 6 #include "base/memory/ptr_util.h" | |
| 7 #include "blimp/engine/browser/font_data_fetcher.h" | |
| 8 #include "blimp/engine/mojo/font_fetcher_mojo_impl.h" | |
| 9 #include "mojo/public/cpp/system/buffer.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 namespace engine { | |
| 14 namespace { | |
| 15 | |
| 16 const char kFakeHash[] = "fake hash"; | |
| 17 const char kTestString[] = "Hello world"; | |
| 18 | |
| 19 class FakeFontDataFetcher : public FontDataFetcher { | |
| 20 public: | |
| 21 FakeFontDataFetcher() {} | |
| 22 | |
| 23 void FetchFontStream(const std::string& font_hash, | |
| 24 const FontResponseCallback& callback) const override { | |
| 25 // Return an empty stream if font_hash is empty, otherwise return a SkStream | |
| 26 // which contains kTestString. | |
| 27 if (font_hash.empty()) { | |
| 28 callback.Run(base::MakeUnique<SkMemoryStream>()); | |
| 29 } else { | |
| 30 callback.Run(base::MakeUnique<SkMemoryStream>( | |
| 31 kTestString, arraysize(kTestString) - 1)); | |
| 32 } | |
| 33 } | |
| 34 }; | |
| 35 | |
| 36 void VerifyEmptyDataWrite(mojo::ScopedSharedBufferHandle handle, | |
| 37 uint32_t size) { | |
| 38 ASSERT_FALSE(handle.is_valid()); | |
| 39 EXPECT_EQ(size, (uint32_t)0); | |
| 40 } | |
| 41 | |
| 42 void VerifyDataWriteCorrectly(mojo::ScopedSharedBufferHandle handle, | |
| 43 uint32_t size) { | |
| 44 ASSERT_TRUE(handle.is_valid()); | |
| 45 | |
| 46 mojo::ScopedSharedBufferMapping mapping = handle->Map(size); | |
| 47 ASSERT_TRUE(mapping); | |
| 48 | |
| 49 std::string contents(static_cast<const char*>(mapping.get()), size); | |
| 50 EXPECT_EQ(kTestString, contents); | |
| 51 } | |
| 52 | |
| 53 class FontFetcherMojoImplUnittest : public testing::Test { | |
| 54 public: | |
| 55 FontFetcherMojoImplUnittest() | |
| 56 : font_fetcher_mojo_impl_(new FakeFontDataFetcher()) {} | |
| 57 ~FontFetcherMojoImplUnittest() override {} | |
| 58 | |
| 59 protected: | |
| 60 base::MessageLoop message_loop_; | |
| 61 FontFetcherMojoImpl font_fetcher_mojo_impl_; | |
| 62 }; | |
| 63 | |
| 64 TEST_F(FontFetcherMojoImplUnittest, VerifyWriteToDataPipe) { | |
| 65 mojom::FontFetcherPtr mojo_ptr; | |
| 66 font_fetcher_mojo_impl_.BindRequest(MakeRequest(&mojo_ptr)); | |
| 67 | |
| 68 // Expect that dummy font data is written correctly to a Mojo DataPipe. | |
| 69 mojo_ptr->GetFontStream(kFakeHash, base::Bind(&VerifyDataWriteCorrectly)); | |
| 70 | |
| 71 // Expect empty handle if the font stream is empty. | |
| 72 mojo_ptr->GetFontStream("", base::Bind(&VerifyEmptyDataWrite)); | |
| 73 } | |
| 74 | |
| 75 } // namespace | |
| 76 } // namespace engine | |
| 77 } // namespace blimp | |
| OLD | NEW |