Index: Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.cpp |
diff --git a/Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.cpp b/Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..50882605ce9cc6bf408a1ca9758fb19130e0e110 |
--- /dev/null |
+++ b/Tools/DumpRenderTree/chromium/TestRunner/src/MockWebCrypto.cpp |
@@ -0,0 +1,114 @@ |
+/* |
+ * Copyright (C) 2013 Google 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: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * 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. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT |
+ * OWNER OR 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 "MockWebCrypto.h" |
+ |
+#include "base/sha1.h" |
abarth-chromium
2013/07/23 06:22:07
You're not allowed to depend directly on base from
eroman
2013/07/23 06:53:41
I saw that DumpRenderTree already depended on "bas
|
+#include "public/platform/WebArrayBuffer.h" |
+#include "public/platform/WebCryptoAlgorithm.h" |
+#include <string> |
+#include <string.h> |
+ |
+using namespace WebKit; |
+ |
+namespace WebTestRunner { |
+ |
+namespace { |
+ |
+class MockCryptoOperation : public WebKit::WebCryptoOperation { |
+public: |
+ MockCryptoOperation(const WebKit::WebCryptoAlgorithm& algorithm, WebKit::WebCryptoOperationResult* result) : m_algorithm(algorithm), m_result(result) { } |
+ |
+ virtual void process(const unsigned char* bytes, size_t size) OVERRIDE |
+ { |
+ // Don't buffer too much data. |
+ if (m_data.size() + size > 100) |
+ m_result->completeWithError(); |
+ |
+ if (size) |
+ m_data.append(reinterpret_cast<const char*>(bytes), size); |
+ } |
+ |
+ virtual void abort() OVERRIDE |
+ { |
+ delete this; |
+ } |
+ |
+ virtual void finish() OVERRIDE |
+ { |
+ if (m_algorithm.id() == WebKit::WebCryptoAlgorithmIdSha1) { |
+ WebKit::WebArrayBuffer hash = WebKit::WebArrayBuffer::create(base::kSHA1Length, 1); |
+ base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(m_data.data()), m_data.size(), static_cast<unsigned char*>(hash.data())); |
+ m_result->completeWithArrayBuffer(hash); |
+ } else { |
+ m_result->completeWithError(); |
+ } |
+ delete this; |
+ } |
+ |
+protected: |
+ WebKit::WebCryptoAlgorithm m_algorithm; |
+ WebKit::WebCryptoOperationResult* m_result; |
+ std::string m_data; |
+}; |
+ |
+} // namespace |
+ |
+MockWebCrypto* MockWebCrypto::get() |
+{ |
+ static MockWebCrypto crypto; |
+ return &crypto; |
+} |
+ |
+void MockWebCrypto::digest(const WebKit::WebCryptoAlgorithm& algorithm, WebKit::WebCryptoOperationResult* result) |
+{ |
+ result->initializationSucceded(new MockCryptoOperation(algorithm, result)); |
+} |
+ |
+void MockWebCrypto::importKey(WebKit::WebCryptoKeyFormat, const unsigned char* keyData, size_t keyDataSize, const WebKit::WebCryptoAlgorithm& algorithm, bool extractable, WebKit::WebCryptoKeyUsageMask usages, WebKit::WebCryptoKeyOperationResult* result) |
+{ |
+ std::string keyDataString(reinterpret_cast<const char*>(keyData), keyDataSize); |
+ |
+ WebKit::WebCryptoKeyType type; |
+ if (keyDataString == "reject") { |
+ result->completeWithError(); |
+ } else if (keyDataString == "throw") { |
+ result->initializationFailed(); |
+ } else { |
+ if (keyDataString == "public") { |
+ type = WebKit::WebCryptoKeyTypePublic; |
+ } else if (keyDataString == "private") { |
+ type = WebKit::WebCryptoKeyTypePrivate; |
+ } |
+ result->completeWithKey(WebKit::WebCryptoKey::create(0, type, extractable, algorithm, usages)); |
+ } |
+} |
+ |
+} // namespace WebTestRunner |