Commit bc2335ab authored by kinuko's avatar kinuko Committed by Commit bot

Platform WebUnitTestSupport onion soup: remove more indirect methods

Removing following three indirect methods which can be directly
implemented within blink platform:
- readFromFile
- enterRunLoop
- exitRunLoop

BUG=571332
TBR=danakj

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

Cr-Commit-Position: refs/heads/master@{#368473}
parent 09aac57c
......@@ -360,16 +360,6 @@ blink::WebThread* TestBlinkWebUnitTestSupport::currentThread() {
return BlinkPlatformImpl::currentThread();
}
void TestBlinkWebUnitTestSupport::enterRunLoop() {
DCHECK(base::MessageLoop::current());
DCHECK(!base::MessageLoop::current()->is_running());
base::MessageLoop::current()->Run();
}
void TestBlinkWebUnitTestSupport::exitRunLoop() {
base::MessageLoop::current()->QuitWhenIdle();
}
void TestBlinkWebUnitTestSupport::getPluginList(
bool refresh, blink::WebPluginListBuilder* builder) {
builder->addPlugin("pdf", "pdf", "pdf-files");
......
......@@ -87,8 +87,6 @@ class TestBlinkWebUnitTestSupport : public blink::WebUnitTestSupport,
blink::WebLayerTreeView* createLayerTreeViewForTesting() override;
blink::WebData readFromFile(const blink::WebString& path) override;
blink::WebThread* currentThread() override;
void enterRunLoop() override;
void exitRunLoop() override;
void getPluginList(bool refresh,
blink::WebPluginListBuilder* builder) override;
......
......@@ -9,8 +9,6 @@
#include "platform/graphics/paint/TransformPaintPropertyNode.h"
#include "platform/testing/UnitTestHelpers.h"
#include "platform/text/TextStream.h"
#include "public/platform/Platform.h"
#include "public/platform/WebUnitTestSupport.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/HashMap.h"
#include "wtf/Vector.h"
......@@ -28,8 +26,8 @@ public:
String fullPath = testing::blinkRootDir();
fullPath.append("/Source/core/paint/test_data/");
fullPath.append(fileName);
WebData inputBuffer = Platform::current()->unitTestSupport()->readFromFile(fullPath);
setBodyInnerHTML(String(inputBuffer.data(), inputBuffer.size()));
RefPtr<SharedBuffer> inputBuffer = testing::readFromFile(fullPath);
setBodyInnerHTML(String(inputBuffer->data(), inputBuffer->size()));
}
private:
......
......@@ -33,8 +33,7 @@
#include "platform/fonts/FontCustomPlatformData.h"
#include "platform/fonts/FontSelector.h"
#include "public/platform/Platform.h"
#include "public/platform/WebUnitTestSupport.h"
#include "platform/testing/UnitTestHelpers.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/text/AtomicString.h"
......@@ -45,10 +44,7 @@ class TestFontSelector : public FontSelector {
public:
static PassRefPtrWillBeRawPtr<TestFontSelector> create(const String& path)
{
WebUnitTestSupport* unitTestSupport = Platform::current()->
unitTestSupport();
RefPtr<SharedBuffer> fontBuffer = static_cast<PassRefPtr<SharedBuffer>>(
unitTestSupport->readFromFile(path));
RefPtr<SharedBuffer> fontBuffer = testing::readFromFile(path);
String otsParseMessage;
return adoptRefWillBeNoop(new TestFontSelector(FontCustomPlatformData::create(
fontBuffer.get(), otsParseMessage)));
......
......@@ -34,8 +34,6 @@
#include "platform/graphics/DeferredImageDecoder.h"
#include "platform/graphics/ImageObserver.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebUnitTestSupport.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
......@@ -66,7 +64,7 @@ public:
{
String filePath = testing::blinkRootDir();
filePath.append(fileName);
return Platform::current()->unitTestSupport()->readFromFile(filePath);
return testing::readFromFile(filePath);
}
// Accessors to BitmapImage's protected methods.
......
......@@ -8,8 +8,6 @@
#include "platform/image-decoders/ImageDecoder.h"
#include "platform/image-decoders/ImageFrame.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebUnitTestSupport.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "wtf/OwnPtr.h"
#include "wtf/StringHasher.h"
......@@ -20,7 +18,7 @@ PassRefPtr<SharedBuffer> readFile(const char* fileName)
{
String filePath = testing::blinkRootDir();
filePath.append(fileName);
return Platform::current()->unitTestSupport()->readFromFile(filePath);
return testing::readFromFile(filePath);
}
PassRefPtr<SharedBuffer> readFile(const char* dir, const char* fileName)
......@@ -31,7 +29,7 @@ PassRefPtr<SharedBuffer> readFile(const char* dir, const char* fileName)
filePath.append("/");
filePath.append(fileName);
return Platform::current()->unitTestSupport()->readFromFile(filePath);
return testing::readFromFile(filePath);
}
unsigned hashBitmap(const SkBitmap& bitmap)
......
......@@ -3,4 +3,5 @@ include_rules = [
# directories and files instead of writing 'base/'.
"+base/files",
"+base/path_service.h",
"+base/message_loop",
]
......@@ -27,12 +27,15 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "platform/SharedBuffer.h"
#include "public/platform/Platform.h"
#include "public/platform/WebTaskRunner.h"
#include "public/platform/WebThread.h"
#include "public/platform/WebTraceLocation.h"
#include "public/platform/WebUnitTestSupport.h"
#include "wtf/text/StringUTF8Adaptor.h"
namespace blink {
namespace testing {
......@@ -41,14 +44,14 @@ class QuitTask : public WebTaskRunner::Task {
public:
virtual void run()
{
Platform::current()->unitTestSupport()->exitRunLoop();
exitRunLoop();
}
};
void runPendingTasks()
{
Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new QuitTask);
Platform::current()->unitTestSupport()->enterRunLoop();
enterRunLoop();
}
String blinkRootDir()
......@@ -60,5 +63,25 @@ String blinkRootDir()
return String::fromUTF8(path.MaybeAsASCII().c_str());
}
PassRefPtr<SharedBuffer> readFromFile(const String& path)
{
StringUTF8Adaptor utf8(path);
base::FilePath file_path = base::FilePath::FromUTF8Unsafe(
std::string(utf8.data(), utf8.length()));
std::string buffer;
base::ReadFileToString(file_path, &buffer);
return SharedBuffer::create(buffer.data(), buffer.size());
}
void enterRunLoop()
{
base::MessageLoop::current()->Run();
}
void exitRunLoop()
{
base::MessageLoop::current()->QuitWhenIdle();
}
}
}
......@@ -26,15 +26,24 @@
#ifndef UnitTestHelpers_h
#define UnitTestHelpers_h
#include "wtf/PassRefPtr.h"
#include "wtf/text/WTFString.h"
namespace blink {
class SharedBuffer;
namespace testing {
void runPendingTasks();
String blinkRootDir();
PassRefPtr<SharedBuffer> readFromFile(const String& path);
void enterRunLoop();
void exitRunLoop();
} // namespace testing
} // namespace blink
......
......@@ -85,7 +85,7 @@ public:
if (m_client->isLoading())
Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ServeAsyncRequestsTask(m_client));
else
Platform::current()->unitTestSupport()->exitRunLoop();
testing::exitRunLoop();
}
private:
......@@ -95,7 +95,7 @@ private:
void pumpPendingRequests(WebFrame* frame)
{
Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_HERE, new ServeAsyncRequestsTask(testClientForFrame(frame)));
Platform::current()->unitTestSupport()->enterRunLoop();
testing::enterRunLoop();
}
class LoadTask : public WebTaskRunner::Task {
......
......@@ -167,7 +167,7 @@ private:
PassRefPtr<SharedBuffer> readFile(const char* fileName)
{
String filePath = m_filePath + fileName;
return Platform::current()->unitTestSupport()->readFromFile(filePath);
return testing::readFromFile(filePath);
}
String m_filePath;
......
......@@ -32,10 +32,8 @@
#include "platform/SharedBuffer.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebData.h"
#include "public/platform/WebSize.h"
#include "public/platform/WebUnitTestSupport.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
......@@ -46,7 +44,7 @@ static PassRefPtr<SharedBuffer> readFile(const char* fileName)
filePath.append("/Source/web/tests/data/");
filePath.append(fileName);
return Platform::current()->unitTestSupport()->readFromFile(filePath);
return testing::readFromFile(filePath);
}
TEST(WebImageTest, PNGImage)
......
......@@ -61,9 +61,6 @@ public:
virtual WebLayerTreeView* createLayerTreeViewForTesting() { return nullptr; }
virtual WebData readFromFile(const WebString& path) { return WebData(); }
virtual void enterRunLoop() { }
virtual void exitRunLoop() { }
};
}
......
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