Chromium Code Reviews| 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 #include "public/platform/FilePathConversion.h" | 37 #include "public/platform/FilePathConversion.h" |
| 38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
| 39 #include "public/platform/WebString.h" | 39 #include "public/platform/WebString.h" |
| 40 #include "public/platform/WebThread.h" | 40 #include "public/platform/WebThread.h" |
| 41 #include "public/platform/WebTraceLocation.h" | 41 #include "public/platform/WebTraceLocation.h" |
| 42 #include "wtf/text/StringUTF8Adaptor.h" | 42 #include "wtf/text/StringUTF8Adaptor.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 namespace testing { | 45 namespace testing { |
| 46 | 46 |
| 47 namespace { | |
| 48 | |
| 49 base::FilePath blinkRootFilePath() { | |
| 50 base::FilePath path; | |
| 51 base::PathService::Get(base::DIR_SOURCE_ROOT, &path); | |
| 52 return base::MakeAbsoluteFilePath( | |
| 53 path.Append(FILE_PATH_LITERAL("third_party/WebKit"))); | |
| 54 } | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 47 void runPendingTasks() { | 58 void runPendingTasks() { |
| 48 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | 59 Platform::current()->currentThread()->getWebTaskRunner()->postTask( |
| 49 BLINK_FROM_HERE, WTF::bind(&exitRunLoop)); | 60 BLINK_FROM_HERE, WTF::bind(&exitRunLoop)); |
| 50 | 61 |
| 51 // We forbid GC in the tasks. Otherwise the registered GCTaskObserver tries | 62 // We forbid GC in the tasks. Otherwise the registered GCTaskObserver tries |
| 52 // to run GC with NoHeapPointerOnStack. | 63 // to run GC with NoHeapPointerOnStack. |
| 53 ThreadState::current()->enterGCForbiddenScope(); | 64 ThreadState::current()->enterGCForbiddenScope(); |
| 54 enterRunLoop(); | 65 enterRunLoop(); |
| 55 ThreadState::current()->leaveGCForbiddenScope(); | 66 ThreadState::current()->leaveGCForbiddenScope(); |
| 56 } | 67 } |
| 57 | 68 |
| 58 void runDelayedTasks(double delayMs) { | 69 void runDelayedTasks(double delayMs) { |
| 59 Platform::current()->currentThread()->getWebTaskRunner()->postDelayedTask( | 70 Platform::current()->currentThread()->getWebTaskRunner()->postDelayedTask( |
| 60 BLINK_FROM_HERE, WTF::bind(&exitRunLoop), delayMs); | 71 BLINK_FROM_HERE, WTF::bind(&exitRunLoop), delayMs); |
| 61 enterRunLoop(); | 72 enterRunLoop(); |
| 62 } | 73 } |
| 63 | 74 |
| 64 String blinkRootDir() { | |
| 65 base::FilePath path; | |
| 66 base::PathService::Get(base::DIR_SOURCE_ROOT, &path); | |
| 67 path = path.Append(FILE_PATH_LITERAL("third_party/WebKit")); | |
| 68 path = base::MakeAbsoluteFilePath(path); | |
| 69 return String::fromUTF8(path.MaybeAsASCII().c_str()); | |
| 70 } | |
| 71 | |
| 72 PassRefPtr<SharedBuffer> readFromFile(const String& path) { | |
| 73 base::FilePath filePath = blink::WebStringToFilePath(path); | |
| 74 std::string buffer; | |
| 75 base::ReadFileToString(filePath, &buffer); | |
| 76 return SharedBuffer::create(buffer.data(), buffer.size()); | |
| 77 } | |
| 78 | |
| 79 void enterRunLoop() { | 75 void enterRunLoop() { |
| 80 base::RunLoop().Run(); | 76 base::RunLoop().Run(); |
| 81 } | 77 } |
| 82 | 78 |
| 83 void exitRunLoop() { | 79 void exitRunLoop() { |
| 84 base::MessageLoop::current()->QuitWhenIdle(); | 80 base::MessageLoop::current()->QuitWhenIdle(); |
| 85 } | 81 } |
| 86 | 82 |
| 87 void yieldCurrentThread() { | 83 void yieldCurrentThread() { |
| 88 base::PlatformThread::YieldCurrentThread(); | 84 base::PlatformThread::YieldCurrentThread(); |
| 89 } | 85 } |
| 90 | 86 |
| 87 String blinkRootDir() { | |
| 88 base::FilePath path = blinkRootFilePath(); | |
| 89 return String::fromUTF8(path.AsUTF8Unsafe().c_str()); | |
|
kinuko
2017/01/26 09:32:41
FilePathToWebString(path)
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
| 90 } | |
| 91 | |
| 92 String webTestDataPath(const std::string& relativePath) { | |
| 93 base::FilePath path = blinkRootFilePath() | |
| 94 .Append(FILE_PATH_LITERAL("Source/web/tests/data")) | |
| 95 .Append(relativePath); | |
| 96 return String::fromUTF8(path.AsUTF8Unsafe().c_str()); | |
|
kinuko
2017/01/26 09:32:41
ditto
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
| 97 } | |
| 98 | |
| 99 String platformTestDataPath(const std::string& relativePath) { | |
| 100 base::FilePath path = | |
| 101 blinkRootFilePath() | |
| 102 .Append(FILE_PATH_LITERAL("Source/platform/testing/data")) | |
| 103 .Append(relativePath); | |
| 104 return String::fromUTF8(path.AsUTF8Unsafe().c_str()); | |
|
kinuko
2017/01/26 09:32:41
ditto
Takashi Toyoshima
2017/01/26 10:57:57
Done.
| |
| 105 } | |
| 106 | |
| 107 PassRefPtr<SharedBuffer> readFromFile(const String& path) { | |
| 108 base::FilePath filePath = blink::WebStringToFilePath(path); | |
| 109 std::string buffer; | |
| 110 base::ReadFileToString(filePath, &buffer); | |
| 111 return SharedBuffer::create(buffer.data(), buffer.size()); | |
| 112 } | |
| 113 | |
| 91 } // namespace testing | 114 } // namespace testing |
| 92 } // namespace blink | 115 } // namespace blink |
| OLD | NEW |