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

Unified Diff: third_party/WebKit/Source/core/fetch/ResourceTest.cpp

Issue 1456873003: More regular Platform implementations in unit tests (reland.) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: have GN disable c4267 also Created 5 years, 1 month 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: third_party/WebKit/Source/core/fetch/ResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
index 143d942f8ec200326e010b54a69bc78d5eb246ee..3a100eff18a1c878eb1a8b4ae457651054ad015d 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
@@ -8,6 +8,7 @@
#include "core/fetch/ResourcePtr.h"
#include "platform/network/ResourceRequest.h"
#include "platform/network/ResourceResponse.h"
+#include "platform/testing/TestingPlatformSupport.h"
#include "platform/testing/URLTestHelpers.h"
#include "public/platform/Platform.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,9 +18,9 @@ namespace blink {
namespace {
-class MockPlatform final : public Platform {
+class MockPlatform final : public TestingPlatformSupport {
public:
- MockPlatform() : m_oldPlatform(Platform::current()) { }
+ MockPlatform() { }
~MockPlatform() override { }
// From blink::Platform:
@@ -33,45 +34,10 @@ public:
return m_cachedURLs;
}
- WebThread* currentThread() override
- {
- return m_oldPlatform->currentThread();
- }
-
- // These blink::Platform methods must be overriden to make a usable object.
- void cryptographicallyRandomValues(unsigned char* buffer, size_t length) override
- {
- ASSERT_NOT_REACHED();
- }
-
- const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
- {
- static const unsigned char tracingIsDisabled = 0;
- return &tracingIsDisabled;
- }
-
private:
- Platform* m_oldPlatform; // Not owned.
Vector<WebURL> m_cachedURLs;
};
-class AutoInstallMockPlatform {
-public:
- AutoInstallMockPlatform()
- {
- m_oldPlatform = Platform::current();
- Platform::initialize(&m_mockPlatform);
- }
- ~AutoInstallMockPlatform()
- {
- Platform::initialize(m_oldPlatform);
- }
- MockPlatform* platform() { return &m_mockPlatform; }
-private:
- MockPlatform m_mockPlatform;
- Platform* m_oldPlatform;
-};
-
PassOwnPtr<ResourceResponse> createTestResourceResponse()
{
OwnPtr<ResourceResponse> response = adoptPtr(new ResourceResponse);
@@ -93,19 +59,19 @@ void createTestResourceAndSetCachedMetadata(const ResourceResponse* response)
TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform)
{
- AutoInstallMockPlatform mock;
+ MockPlatform mock;
OwnPtr<ResourceResponse> response(createTestResourceResponse());
createTestResourceAndSetCachedMetadata(response.get());
- EXPECT_EQ(1u, mock.platform()->cachedURLs().size());
+ EXPECT_EQ(1u, mock.cachedURLs().size());
}
TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedViaServiceWorker)
{
- AutoInstallMockPlatform mock;
+ MockPlatform mock;
OwnPtr<ResourceResponse> response(createTestResourceResponse());
response->setWasFetchedViaServiceWorker(true);
createTestResourceAndSetCachedMetadata(response.get());
- EXPECT_EQ(0u, mock.platform()->cachedURLs().size());
+ EXPECT_EQ(0u, mock.cachedURLs().size());
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/fetch/CachingCorrectnessTest.cpp ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698