| /* |
| * Copyright (C) 2016 Apple Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
| * are met: |
| * 1. Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * 2. Redistributions in binary form must reproduce the above copyright |
| * notice, this list of conditions and the following disclaimer in the |
| * documentation and/or other materials provided with the distribution. |
| * |
| * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| * THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "config.h" |
| #include "TestOptions.h" |
| |
| #include <Foundation/Foundation.h> |
| #include <fstream> |
| #include <string> |
| |
| static bool parseBooleanTestHeaderValue(const std::string& value) |
| { |
| if (value == "true") |
| return true; |
| if (value == "false") |
| return false; |
| |
| NSLog(@"Found unexpected value '%s' for boolean option. Expected 'true' or 'false'.", value.c_str()); |
| return false; |
| } |
| |
| TestOptions::TestOptions(NSURL *testURL, const TestCommand& command) |
| { |
| std::string path = command.absolutePath; |
| if (path.empty() && [testURL isFileURL]) |
| path = [testURL fileSystemRepresentation]; |
| else |
| path = command.pathOrURL; |
| |
| if (path.empty()) |
| return; |
| |
| std::string options; |
| std::ifstream testFile(path.data()); |
| if (!testFile.good()) |
| return; |
| getline(testFile, options); |
| std::string beginString("webkit-test-runner [ "); |
| std::string endString(" ]"); |
| size_t beginLocation = options.find(beginString); |
| if (beginLocation == std::string::npos) |
| return; |
| size_t endLocation = options.find(endString, beginLocation); |
| if (endLocation == std::string::npos) { |
| NSLog(@"Could not find end of test header in %s", path.c_str()); |
| return; |
| } |
| std::string pairString = options.substr(beginLocation + beginString.size(), endLocation - (beginLocation + beginString.size())); |
| size_t pairStart = 0; |
| while (pairStart < pairString.size()) { |
| size_t pairEnd = pairString.find(" ", pairStart); |
| if (pairEnd == std::string::npos) |
| pairEnd = pairString.size(); |
| size_t equalsLocation = pairString.find("=", pairStart); |
| if (equalsLocation == std::string::npos) { |
| NSLog(@"Malformed option in test header (could not find '=' character) in %s", path.c_str()); |
| break; |
| } |
| auto key = pairString.substr(pairStart, equalsLocation - pairStart); |
| auto value = pairString.substr(equalsLocation + 1, pairEnd - (equalsLocation + 1)); |
| if (key == "enableIntersectionObserver") |
| this->enableIntersectionObserver = parseBooleanTestHeaderValue(value); |
| else if (key == "enableModernMediaControls") |
| this->enableModernMediaControls = parseBooleanTestHeaderValue(value); |
| else if (key == "enablePointerLock") |
| this->enablePointerLock = parseBooleanTestHeaderValue(value); |
| pairStart = pairEnd + 1; |
| } |
| } |