Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2012 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_console.h"
      6 
      7 #include "ppapi/cpp/module.h"
      8 #include "ppapi/cpp/var_array.h"
      9 #include "ppapi/cpp/var_array_buffer.h"
     10 #include "ppapi/cpp/var_dictionary.h"
     11 #include "ppapi/tests/testing_instance.h"
     12 
     13 REGISTER_TEST_CASE(Console);
     14 
     15 TestConsole::TestConsole(TestingInstance* instance)
     16     : TestCase(instance),
     17       console_interface_(NULL) {
     18 }
     19 
     20 bool TestConsole::Init() {
     21   console_interface_ = static_cast<const PPB_Console*>(
     22       pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
     23   return !!console_interface_;
     24 }
     25 
     26 void TestConsole::RunTests(const std::string& filter) {
     27   RUN_TEST(Smoke, filter);
     28 }
     29 
     30 namespace {
     31 
     32 void TestConsoleSub(const PPB_Console* console_interface_,
     33                     PP_Instance instance,
     34                     pp::Var source,
     35                     pp::Var message) {
     36 
     37   console_interface_->Log(instance, PP_LOGLEVEL_ERROR,
     38                           message.pp_var());
     39   console_interface_->LogWithSource(instance, PP_LOGLEVEL_LOG,
     40                                     source.pp_var(), message.pp_var());
     41 }
     42 
     43 } // anonymous namespace
     44 
     45 std::string TestConsole::TestSmoke() {
     46   // This test does not verify the log message actually reaches the console, but
     47   // it does test that the interface exists and that it can be called without
     48   // crashing.
     49   pp::Var source(std::string("somewhere"));
     50   const PPB_Console* interface = console_interface_;
     51   PP_Instance pp_instance = instance()->pp_instance();
     52 
     53   TestConsoleSub(interface, pp_instance, source, pp::Var());
     54   TestConsoleSub(interface, pp_instance, source, pp::Var(pp::Var::Null()));
     55   TestConsoleSub(interface, pp_instance, source, pp::Var(false));
     56   TestConsoleSub(interface, pp_instance, source, pp::Var(12345678));
     57   TestConsoleSub(interface, pp_instance, source, pp::Var(-0.0));
     58   TestConsoleSub(interface, pp_instance, source, pp::Var("Hello World!"));
     59   TestConsoleSub(interface, pp_instance, source, pp::VarArray());
     60   TestConsoleSub(interface, pp_instance, source, pp::VarArrayBuffer());
     61   TestConsoleSub(interface, pp_instance, source, pp::VarDictionary());
     62   PASS();
     63 }
     64