| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "core/fetch/RawResource.h" | 34 #include "core/fetch/RawResource.h" |
| 35 #include "platform/network/ResourceRequest.h" | 35 #include "platform/network/ResourceRequest.h" |
| 36 #include "platform/testing/UnitTestHelpers.h" | 36 #include "platform/testing/UnitTestHelpers.h" |
| 37 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class MemoryCacheTest : public ::testing::Test { | 42 class MemoryCacheTest : public ::testing::Test { |
| 43 public: | 43 public: |
| 44 class FakeDecodedResource : public Resource { | 44 class FakeDecodedResource final : public Resource { |
| 45 public: | 45 public: |
| 46 static FakeDecodedResource* create(const ResourceRequest& request, Type
type) | 46 static FakeDecodedResource* create(const ResourceRequest& request, Type
type) |
| 47 { | 47 { |
| 48 return new FakeDecodedResource(request, type, ResourceLoaderOptions(
)); | 48 return new FakeDecodedResource(request, type, ResourceLoaderOptions(
)); |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual void appendData(const char* data, size_t len) | 51 virtual void appendData(const char* data, size_t len) |
| 52 { | 52 { |
| 53 Resource::appendData(data, len); | 53 Resource::appendData(data, len); |
| 54 setDecodedSize(this->size()); | 54 setDecodedSize(this->size()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 protected: | 57 private: |
| 58 FakeDecodedResource(const ResourceRequest& request, Type type, const Res
ourceLoaderOptions& options) | 58 FakeDecodedResource(const ResourceRequest& request, Type type, const Res
ourceLoaderOptions& options) |
| 59 : Resource(request, type, options) | 59 : Resource(request, type, options) |
| 60 { | 60 { |
| 61 } | 61 } |
| 62 | 62 |
| 63 void destroyDecodedDataIfPossible() override | 63 void destroyDecodedDataIfPossible() override |
| 64 { | 64 { |
| 65 setDecodedSize(0); | 65 setDecodedSize(0); |
| 66 } | 66 } |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class FakeResource : public Resource { | 69 class FakeResource final : public Resource { |
| 70 public: | 70 public: |
| 71 static FakeResource* create(const ResourceRequest& request, Type type) | 71 static FakeResource* create(const ResourceRequest& request, Type type) |
| 72 { | 72 { |
| 73 return new FakeResource(request, type, ResourceLoaderOptions()); | 73 return new FakeResource(request, type, ResourceLoaderOptions()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void fakeEncodedSize(size_t size) | 76 void fakeEncodedSize(size_t size) |
| 77 { | 77 { |
| 78 setEncodedSize(size); | 78 setEncodedSize(size); |
| 79 } | 79 } |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 419 |
| 420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url)
; | 420 HeapVector<Member<Resource>> resources = memoryCache()->resourcesForURL(url)
; |
| 421 EXPECT_EQ(2u, resources.size()); | 421 EXPECT_EQ(2u, resources.size()); |
| 422 | 422 |
| 423 memoryCache()->evictResources(); | 423 memoryCache()->evictResources(); |
| 424 EXPECT_FALSE(memoryCache()->contains(resource1)); | 424 EXPECT_FALSE(memoryCache()->contains(resource1)); |
| 425 EXPECT_FALSE(memoryCache()->contains(resource3)); | 425 EXPECT_FALSE(memoryCache()->contains(resource3)); |
| 426 } | 426 } |
| 427 | 427 |
| 428 } // namespace blink | 428 } // namespace blink |
| OLD | NEW |