Commit 81286531 authored by sigbjornf's avatar sigbjornf Committed by Commit bot

More regular Platform implementations in unit tests.

R=haraken,jbroman
BUG=

Review URL: https://codereview.chromium.org/1456873003

Cr-Commit-Position: refs/heads/master@{#361019}
parent 20c2d44f
......@@ -26,7 +26,7 @@
#define CompositorAnimationsTestHelper_h
#include "core/animation/CompositorAnimations.h"
#include "public/platform/Platform.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/WebCompositorAnimationPlayer.h"
#include "public/platform/WebCompositorAnimationTimeline.h"
#include "public/platform/WebCompositorSupport.h"
......@@ -152,31 +152,13 @@ public:
};
private:
class PlatformProxy : public Platform {
class PlatformProxy : public TestingPlatformSupport {
public:
PlatformProxy(WebCompositorSupportMock** compositor) : m_platform(Platform::current()), m_compositor(compositor) { }
~PlatformProxy()
{
blink::Platform::initialize(m_platform);
}
virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length) { ASSERT_NOT_REACHED(); }
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
{
static const unsigned char tracingIsDisabled = 0;
return &tracingIsDisabled;
}
WebThread* currentThread() override
{
return m_platform->currentThread();
}
explicit PlatformProxy(WebCompositorSupportMock** compositor) : m_compositor(compositor) { }
private:
blink::Platform* m_platform; // Not owned.
WebCompositorSupportMock** m_compositor;
WebCompositorSupport* compositorSupport() override { return *m_compositor; }
WebCompositorSupportMock** m_compositor;
};
WebCompositorSupportMock* m_mockCompositor;
......
......@@ -10,6 +10,7 @@
#include "core/dom/ScriptLoader.h"
#include "platform/heap/Handle.h"
#include "platform/scheduler/CancellableTaskFactory.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "public/platform/WebViewScheduler.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -95,7 +96,7 @@ public:
Deque<OwnPtr<WebTaskRunner::Task>>* m_tasks; // NOT OWNED
};
class MockPlatform : public Platform, public WebScheduler {
class MockPlatform : public TestingPlatformSupport, public WebScheduler {
public:
MockPlatform()
: m_mockWebThread(this)
......@@ -103,17 +104,6 @@ public:
{
}
void cryptographicallyRandomValues(unsigned char* buffer, size_t length) override
{
RELEASE_ASSERT_NOT_REACHED();
}
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
{
static const unsigned char tracingIsDisabled = 0;
return &tracingIsDisabled;
}
WebThread* currentThread() override { return &m_mockWebThread; }
void runSingleTask()
......@@ -163,16 +153,14 @@ private:
class ScriptRunnerTest : public testing::Test {
public:
void SetUp() override
ScriptRunnerTest()
: m_document(Document::create())
, m_element(m_document->createElement("foo", ASSERT_NO_EXCEPTION))
{
m_document = Document::create();
m_element = m_document->createElement("foo", ASSERT_NO_EXCEPTION);
m_oldPlatform = Platform::current();
// Force Platform::initialize to create a new one pointing at MockPlatform.
Platform::initialize(&m_platform);
}
void SetUp() override
{
// We have to create ScriptRunner after initializing platform, because we need
// Platform::current()->currentThread()->scheduler()->loadingTaskRunner()
// to be initialized before creating ScriptRunner to save it in constructor.
......@@ -182,15 +170,13 @@ public:
void TearDown() override
{
m_scriptRunner.release();
Platform::initialize(m_oldPlatform);
}
RefPtrWillBePersistent<Document> m_document;
RefPtrWillBePersistent<Element> m_element;
MockPlatform m_platform;
OwnPtrWillBePersistent<ScriptRunner> m_scriptRunner;
WTF::Vector<int> m_order;
MockPlatform m_platform;
Platform* m_oldPlatform; // NOT OWNED
};
TEST_F(ScriptRunnerTest, QueueSingleScript_Async)
......
......@@ -38,6 +38,7 @@
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourcePtr.h"
#include "platform/network/ResourceRequest.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/OwnPtr.h"
......@@ -55,8 +56,6 @@ const double kOriginalRequestDateAsDouble = 233433000.;
const char kOneDayBeforeOriginalRequest[] = "Wed, 24 May 1977 18:30:00 GMT";
const char kOneDayAfterOriginalRequest[] = "Fri, 26 May 1977 18:30:00 GMT";
const unsigned char kAConstUnsignedCharZero = 0;
class MockFetchContext : public FetchContext {
public:
static MockFetchContext* create()
......@@ -120,25 +119,15 @@ protected:
private:
// A simple platform that mocks out the clock, for cache freshness testing.
class ProxyPlatform : public blink::Platform {
class ProxyPlatform : public TestingPlatformSupport {
public:
ProxyPlatform() : m_platform(blink::Platform::current()), m_elapsedSeconds(0.) { }
~ProxyPlatform()
{
blink::Platform::initialize(m_platform);
}
ProxyPlatform() : m_elapsedSeconds(0.) { }
void advanceClock(double seconds)
{
m_elapsedSeconds += seconds;
}
WebThread* currentThread() override
{
return m_platform->currentThread();
}
private:
// From blink::Platform:
double currentTimeSeconds() override
......@@ -146,24 +135,11 @@ private:
return kOriginalRequestDateAsDouble + m_elapsedSeconds;
}
// These blink::Platform methods must be overriden to make a usable object.
virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
{
RELEASE_ASSERT_NOT_REACHED();
}
virtual const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName)
{
return &kAConstUnsignedCharZero;
}
blink::Platform* m_platform; // Not owned.
double m_elapsedSeconds;
};
virtual void SetUp()
{
blink::Platform::initialize(&m_proxyPlatform);
// Save the global memory cache to restore it upon teardown.
m_globalMemoryCache = replaceMemoryCacheForTesting(MemoryCache::create());
......
......@@ -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
......@@ -31,7 +31,7 @@
#include "config.h"
#include "platform/PurgeableVector.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/WebDiscardableMemory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/Vector.h"
......
......@@ -31,7 +31,7 @@
#include "config.h"
#include "platform/SharedBuffer.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/WebDiscardableMemory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/RefPtr.h"
......
......@@ -5,6 +5,7 @@
#include "config.h"
#include "platform/Timer.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "public/platform/WebScheduler.h"
#include "public/platform/WebThread.h"
......@@ -236,7 +237,7 @@ private:
OwnPtr<MockWebScheduler> m_webScheduler;
};
class TimerTestPlatform : public Platform {
class TimerTestPlatform : public TestingPlatformSupport {
public:
TimerTestPlatform()
: m_webThread(adoptPtr(new FakeWebThread())) { }
......@@ -247,17 +248,6 @@ public:
return m_webThread.get();
}
void cryptographicallyRandomValues(unsigned char*, size_t) override
{
ASSERT_NOT_REACHED();
}
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
{
static const unsigned char enabled[] = {0};
return enabled;
}
void runUntilIdle()
{
mockScheduler()->runUntilIdle();
......@@ -296,9 +286,6 @@ class TimerTest : public testing::Test {
public:
void SetUp() override
{
m_platform = adoptPtr(new TimerTestPlatform());
m_oldPlatform = Platform::current();
Platform::initialize(m_platform.get());
WTF::setMonotonicallyIncreasingTimeFunction(currentTime);
m_runTimes.clear();
......@@ -306,11 +293,6 @@ public:
m_startTime = gCurrentTimeSecs;
}
void TearDown() override
{
Platform::initialize(m_oldPlatform);
}
void countingTask(Timer<TimerTest>*)
{
m_runTimes.append(monotonicallyIncreasingTime());
......@@ -328,27 +310,27 @@ public:
void runUntilIdle()
{
m_platform->runUntilIdle();
m_platform.runUntilIdle();
}
void runPendingTasks()
{
m_platform->runPendingTasks();
m_platform.runPendingTasks();
}
void runUntilIdleOrDeadlinePassed(double deadline)
{
m_platform->runUntilIdleOrDeadlinePassed(deadline);
m_platform.runUntilIdleOrDeadlinePassed(deadline);
}
bool hasOneTimerTask() const
{
return m_platform->hasOneTimerTask();
return m_platform.hasOneTimerTask();
}
double nextTimerTaskDelaySecs() const
{
return m_platform->nextTimerTaskDelaySecs();
return m_platform.nextTimerTaskDelaySecs();
}
protected:
......@@ -357,8 +339,7 @@ protected:
WTF::Vector<double> m_nextFireTimes;
private:
OwnPtr<TimerTestPlatform> m_platform;
Platform* m_oldPlatform;
TimerTestPlatform m_platform;
};
TEST_F(TimerTest, StartOneShot_Zero)
......
......@@ -973,8 +973,6 @@
'PODRedBlackTreeTest.cpp',
'PurgeableVectorTest.cpp',
'SharedBufferTest.cpp',
'TestingPlatformSupport.cpp',
'TestingPlatformSupport.h',
'TimerTest.cpp',
'TracedValueTest.cpp',
'UUIDTest.cpp',
......@@ -1078,6 +1076,8 @@
'testing/GeometryPrinters.h',
'testing/PaintPrinters.cpp',
'testing/PaintPrinters.h',
'testing/TestingPlatformSupport.cpp',
'testing/TestingPlatformSupport.h',
'testing/TransformPrinters.cpp',
'testing/TransformPrinters.h',
],
......
......@@ -128,6 +128,8 @@
'sources': [
'<@(platform_test_support_files)',
],
# Disable c4267 warnings until we fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267 ],
},
],
'conditions': [
......
......@@ -7,19 +7,16 @@
#include "platform/fonts/FontDescription.h"
#include "platform/fonts/SimpleFontData.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
class EmptyPlatform : public Platform {
class EmptyPlatform : public TestingPlatformSupport {
public:
EmptyPlatform() {}
~EmptyPlatform() override {}
void cryptographicallyRandomValues(unsigned char* buffer, size_t length) override
{
RELEASE_ASSERT_NOT_REACHED();
}
};
TEST(FontCache, getLastResortFallbackFont)
......@@ -27,9 +24,7 @@ TEST(FontCache, getLastResortFallbackFont)
FontCache* fontCache = FontCache::fontCache();
ASSERT_TRUE(fontCache);
Platform* oldPlatform = Platform::current();
OwnPtr<EmptyPlatform> platform = adoptPtr(new EmptyPlatform);
Platform::initialize(platform.get());
EmptyPlatform platform;
FontDescription fontDescription;
fontDescription.setGenericFamily(FontDescription::StandardFamily);
......@@ -39,8 +34,6 @@ TEST(FontCache, getLastResortFallbackFont)
fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
fontData = fontCache->getLastResortFallbackFont(fontDescription, Retain);
EXPECT_TRUE(fontData);
Platform::initialize(oldPlatform);
}
} // namespace blink
......@@ -9,6 +9,7 @@
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/ImageBufferClient.h"
#include "platform/graphics/UnacceleratedImageBufferSurface.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "public/platform/WebTaskRunner.h"
#include "public/platform/WebThread.h"
......@@ -236,24 +237,13 @@ namespace {
// for the current thread. The Mock thread is capable of queuing a single non-delayed task
// and registering a single task observer. The run loop exits immediately after running
// the single task.
class AutoInstallCurrentThreadPlatformMock {
public:
AutoInstallCurrentThreadPlatformMock()
{
m_oldPlatform = Platform::current();
Platform::initialize(&m_mockPlatform);
}
~AutoInstallCurrentThreadPlatformMock()
{
Platform::initialize(m_oldPlatform);
}
void enterRunLoop()
{
m_mockPlatform.enterRunLoop();
}
class CurrentThreadPlatformMock : public TestingPlatformSupport {
public:
CurrentThreadPlatformMock() { }
WebThread* currentThread() override { return &m_currentThread; }
void enterRunLoop() { m_currentThread.enterRunLoop(); }
private:
class MockWebTaskRunner : public WebTaskRunner {
public:
......@@ -335,22 +325,7 @@ private:
TaskObserver* m_taskObserver;
};
class CurrentThreadPlatformMock : public Platform {
public:
CurrentThreadPlatformMock() { }
virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t length)
{
RELEASE_ASSERT_NOT_REACHED();
}
WebThread* currentThread() override { return &m_currentThread; }
void enterRunLoop() { m_currentThread.enterRunLoop(); }
private:
CurrentThreadMock m_currentThread;
};
CurrentThreadPlatformMock m_mockPlatform;
Platform* m_oldPlatform;
CurrentThreadMock m_currentThread;
};
} // anonymous namespace
......@@ -366,7 +341,7 @@ class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task {
#define CALL_TEST_TASK_WRAPPER(TEST_METHOD) \
{ \
AutoInstallCurrentThreadPlatformMock ctpm; \
CurrentThreadPlatformMock ctpm; \
Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new TestWrapperTask_ ## TEST_METHOD(this)); \
ctpm.enterRunLoop(); \
}
......
......@@ -5,7 +5,7 @@
#include "config.h"
#include "platform/scroll/ScrollableArea.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "public/platform/WebScheduler.h"
#include "public/platform/WebThread.h"
......@@ -86,7 +86,7 @@ public:
// We need just enough scaffolding for the Timer constructor to not segfault.
class FakePlatform : public TestingPlatformSupport {
public:
FakePlatform() : TestingPlatformSupport(TestingPlatformSupport::Config()) { }
FakePlatform() { }
~FakePlatform() override { }
WebThread* currentThread() override
......
......@@ -31,8 +31,8 @@
#include "config.h"
#include "platform/EventTracer.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/heap/Heap.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "wtf/CryptographicallyRandomNumber.h"
#include "wtf/MainThread.h"
#include "wtf/Partitions.h"
......
......@@ -30,7 +30,7 @@
#include "config.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/testing/TestingPlatformSupport.h"
namespace blink {
......@@ -69,6 +69,11 @@ WebMemoryAllocatorDump* TestingDiscardableMemory::createMemoryAllocatorDump(cons
return nullptr;
}
TestingPlatformSupport::TestingPlatformSupport()
: TestingPlatformSupport(TestingPlatformSupport::Config())
{
}
TestingPlatformSupport::TestingPlatformSupport(const Config& config)
: m_config(config)
, m_oldPlatform(Platform::current())
......@@ -107,4 +112,9 @@ WebCompositorSupport* TestingPlatformSupport::compositorSupport()
return m_config.compositorSupport;
}
WebThread* TestingPlatformSupport::currentThread()
{
return m_oldPlatform ? m_oldPlatform->currentThread() : nullptr;
}
} // namespace blink
......@@ -31,12 +31,16 @@
#ifndef TestingPlatformSupport_h
#define TestingPlatformSupport_h
#include "platform/PlatformExport.h"
#include "public/platform/Platform.h"
#include "public/platform/WebDiscardableMemory.h"
#include "wtf/Vector.h"
namespace blink {
class WebCompositorSupport;
class WebThread;
class TestingDiscardableMemory : public WebDiscardableMemory {
public:
explicit TestingDiscardableMemory(size_t);
......@@ -64,6 +68,7 @@ public:
WebCompositorSupport* compositorSupport;
};
TestingPlatformSupport();
explicit TestingPlatformSupport(const Config&);
~TestingPlatformSupport() override;
......@@ -74,8 +79,9 @@ public:
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override;
WebString defaultLocale() override;
WebCompositorSupport* compositorSupport() override;
WebThread* currentThread() override;
private:
protected:
const Config m_config;
Platform* const m_oldPlatform;
};
......
......@@ -27,7 +27,7 @@
#include "platform/text/LocaleMac.h"
#include "platform/DateComponents.h"
#include "platform/TestingPlatformSupport.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/DateMath.h"
......@@ -39,8 +39,6 @@ namespace blink {
class LocalePlatformSupport : public TestingPlatformSupport {
public:
LocalePlatformSupport() : TestingPlatformSupport(TestingPlatformSupport::Config()) { }
WebString queryLocalizedString(WebLocalizedString::Name /*name*/) override
{
return WebString::fromUTF8("Week $2, $1");
......
......@@ -31,6 +31,7 @@
#include "config.h"
#include "platform/weborigin/OriginAccessEntry.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
......@@ -55,43 +56,19 @@ private:
size_t m_length;
};
class OriginAccessEntryTestPlatform : public blink::Platform {
class OriginAccessEntryTestPlatform : public TestingPlatformSupport {
public:
OriginAccessEntryTestPlatform()
: m_oldPlatform(Platform::current())
{
Platform::initialize(this);
}
~OriginAccessEntryTestPlatform()
{
Platform::initialize(m_oldPlatform);
}
blink::WebPublicSuffixList* publicSuffixList() override
{
return &m_suffixList;
}
// Stub for pure virtual method.
void cryptographicallyRandomValues(unsigned char*, size_t) override
{
RELEASE_ASSERT_NOT_REACHED();
}
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
{
static const unsigned char tracingIsDisabled = 0;
return &tracingIsDisabled;
}
void setPublicSuffix(const blink::WebString& suffix)
{
m_suffixList.setPublicSuffix(suffix);
}
private:
blink::Platform* m_oldPlatform;
OriginAccessEntryTestSuffixList m_suffixList;
};
......@@ -313,4 +290,3 @@ TEST(OriginAccessEntryTest, IPAddressMatchingTest)
}
} // namespace blink
......@@ -111,6 +111,7 @@ test("webkit_unit_tests") {
"//testing/gmock",
"//testing/gtest",
"//third_party/WebKit/Source/platform:test_support",
"//third_party/WebKit/Source/wtf",
"//third_party/WebKit/Source/wtf:test_support",
"//third_party/libwebp",
"//third_party/zlib",
......
......@@ -25,6 +25,7 @@ http://crbug.com/398235#c103 and http://crbug.com/258324#c5
#include "platform/SharedBuffer.h"
#include "platform/image-decoders/ImageDecoder.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "public/platform/Platform.h"
#include "public/web/WebKit.h"
#include "wtf/OwnPtr.h"
......@@ -360,18 +361,8 @@ int main(int argc, char* argv[])
// Create a web platform without V8.
class WebPlatform : public blink::Platform {
class WebPlatform : public TestingPlatformSupport {
public:
const unsigned char* getTraceCategoryEnabledFlag(const char*) override
{
return reinterpret_cast<const unsigned char *>("nope-none-nada");
}
void cryptographicallyRandomValues(unsigned char*, size_t) override
{
RELEASE_ASSERT_NOT_REACHED();
}
void screenColorProfile(WebVector<char>* profile) override
{
getScreenColorProfile(profile); // Returns a whacked color profile.
......
......@@ -14,6 +14,7 @@
#include "core/html/HTMLElement.h"
#include "core/layout/TextAutosizer.h"
#include "core/page/Page.h"
#include "platform/testing/TestingPlatformSupport.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/web/WebDocument.h"
......@@ -29,7 +30,15 @@ namespace blink {
class TextFinderTest : public ::testing::Test {
protected:
void SetUp() override;
TextFinderTest()
{
m_webViewHelper.initialize();
WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrameImpl();
frameImpl.viewImpl()->resize(WebSize(640, 480));
frameImpl.viewImpl()->updateAllLifecyclePhases();
m_document = PassRefPtrWillBeRawPtr<Document>(frameImpl.document());
m_textFinder = &frameImpl.ensureTextFinder();
}
Document& document() const;
TextFinder& textFinder() const;
......@@ -42,16 +51,6 @@ private:
RawPtrWillBePersistent<TextFinder> m_textFinder;
};
void TextFinderTest::SetUp()
{
m_webViewHelper.initialize();
WebLocalFrameImpl& frameImpl = *m_webViewHelper.webViewImpl()->mainFrameImpl();
frameImpl.viewImpl()->resize(WebSize(640, 480));
frameImpl.viewImpl()->updateAllLifecyclePhases();
m_document = PassRefPtrWillBeRawPtr<Document>(frameImpl.document());
m_textFinder = &frameImpl.ensureTextFinder();
}
Document& TextFinderTest::document() const
{
return *m_document;
......@@ -398,41 +397,19 @@ TEST_F(TextFinderTest, SequentialMatches)
class TextFinderFakeTimerTest : public TextFinderTest {
protected:
void SetUp() override;
void TearDown() override;
// A simple platform that mocks out the clock.
class TimeProxyPlatform : public Platform {
class TimeProxyPlatform : public TestingPlatformSupport {
public:
TimeProxyPlatform()
: m_timeCounter(0.)
, m_fallbackPlatform(0)
{ }
void install()
: m_timeCounter(m_oldPlatform->currentTimeSeconds())
{
// Check that the proxy wasn't installed yet.
ASSERT_NE(Platform::current(), this);
m_fallbackPlatform = Platform::current();
m_timeCounter = m_fallbackPlatform->currentTimeSeconds();
Platform::initialize(this);
ASSERT_EQ(Platform::current(), this);
}
void remove()
{
// Check that the proxy was installed.
ASSERT_EQ(Platform::current(), this);
Platform::initialize(m_fallbackPlatform);
ASSERT_EQ(Platform::current(), m_fallbackPlatform);
m_fallbackPlatform = 0;
}
private:
Platform& ensureFallback()
{
ASSERT(m_fallbackPlatform);
return *m_fallbackPlatform;
ASSERT(m_oldPlatform);
return *m_oldPlatform;
}
// From blink::Platform:
......@@ -441,47 +418,22 @@ protected:
return ++m_timeCounter;
}
// These blink::Platform methods must be overriden to make a usable object.
void cryptographicallyRandomValues(unsigned char* buffer, size_t length) override
{
ensureFallback().cryptographicallyRandomValues(buffer, length);
}
const unsigned char* getTraceCategoryEnabledFlag(const char* categoryName) override
{
return ensureFallback().getTraceCategoryEnabledFlag(categoryName);
}
// These two methods allow timers to work correctly.
double monotonicallyIncreasingTimeSeconds() override
{
return ensureFallback().monotonicallyIncreasingTimeSeconds();
}
WebThread* currentThread() override { return ensureFallback().currentThread(); }
WebUnitTestSupport* unitTestSupport() override { return ensureFallback().unitTestSupport(); }
WebString defaultLocale() override { return ensureFallback().defaultLocale(); }
WebCompositorSupport* compositorSupport() override { return ensureFallback().compositorSupport(); }
double m_timeCounter;
Platform* m_fallbackPlatform;
};
TimeProxyPlatform m_proxyTimePlatform;
};
void TextFinderFakeTimerTest::SetUp()
{
TextFinderTest::SetUp();
m_proxyTimePlatform.install();
}
void TextFinderFakeTimerTest::TearDown()
{
m_proxyTimePlatform.remove();
TextFinderTest::TearDown();
}
TEST_F(TextFinderFakeTimerTest, ScopeWithTimeouts)
{
// Make a long string.
......
......@@ -49,6 +49,7 @@
'../../public/blink.gyp:blink',
'../config.gyp:unittest_config',
'../platform/blink_platform_tests.gyp:blink_platform_test_support',
'../wtf/wtf.gyp:wtf',
'../wtf/wtf_tests.gyp:wtf_unittest_helpers',
'web.gyp:blink_web_test_support',
'<(DEPTH)/base/base.gyp:base',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment