1// Copyright (c) 2011 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "ppapi/tests/test_crypto.h" 6 7#include "ppapi/c/dev/ppb_crypto_dev.h" 8#include "ppapi/cpp/module.h" 9#include "ppapi/tests/testing_instance.h" 10 11REGISTER_TEST_CASE(Crypto); 12 13TestCrypto::TestCrypto(TestingInstance* instance) 14 : TestCase(instance), 15 crypto_interface_(NULL) { 16} 17 18bool TestCrypto::Init() { 19 crypto_interface_ = static_cast<const PPB_Crypto_Dev*>( 20 pp::Module::Get()->GetBrowserInterface(PPB_CRYPTO_DEV_INTERFACE)); 21 return !!crypto_interface_; 22} 23 24void TestCrypto::RunTests(const std::string& filter) { 25 RUN_TEST(GetRandomBytes, filter); 26} 27 28std::string TestCrypto::TestGetRandomBytes() { 29 const int kBufSize = 16; 30 char buf[kBufSize] = {0}; 31 32 crypto_interface_->GetRandomBytes(buf, kBufSize); 33 34 // Verify that the interface wrote "something" to the buffer. 35 bool found_nonzero = false; 36 for (int i = 0; i < kBufSize; i++) { 37 if (buf[i]) { 38 found_nonzero = true; 39 break; 40 } 41 } 42 ASSERT_TRUE(found_nonzero); 43 44 PASS(); 45} 46