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

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

Issue 1464953003: Revert of More regular Platform implementations in unit tests (reland.) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 3a100eff18a1c878eb1a8b4ae457651054ad015d..143d942f8ec200326e010b54a69bc78d5eb246ee 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
@@ -8,7 +8,6 @@
#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"
@@ -18,9 +17,9 @@
namespace {
-class MockPlatform final : public TestingPlatformSupport {
+class MockPlatform final : public Platform {
public:
- MockPlatform() { }
+ MockPlatform() : m_oldPlatform(Platform::current()) { }
~MockPlatform() override { }
// From blink::Platform:
@@ -34,8 +33,43 @@
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()
@@ -59,19 +93,19 @@
TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform)
{
- MockPlatform mock;
+ AutoInstallMockPlatform mock;
OwnPtr<ResourceResponse> response(createTestResourceResponse());
createTestResourceAndSetCachedMetadata(response.get());
- EXPECT_EQ(1u, mock.cachedURLs().size());
+ EXPECT_EQ(1u, mock.platform()->cachedURLs().size());
}
TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedViaServiceWorker)
{
- MockPlatform mock;
+ AutoInstallMockPlatform mock;
OwnPtr<ResourceResponse> response(createTestResourceResponse());
response->setWasFetchedViaServiceWorker(true);
createTestResourceAndSetCachedMetadata(response.get());
- EXPECT_EQ(0u, mock.cachedURLs().size());
+ EXPECT_EQ(0u, mock.platform()->cachedURLs().size());
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698