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.
5 #include "ppapi/tests/test_console.h"
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"
13 REGISTER_TEST_CASE(Console
);
15 TestConsole::TestConsole(TestingInstance
* instance
)
17 console_interface_(NULL
) {
20 bool TestConsole::Init() {
21 console_interface_
= static_cast<const PPB_Console
*>(
22 pp::Module::Get()->GetBrowserInterface(PPB_CONSOLE_INTERFACE
));
23 return !!console_interface_
;
26 void TestConsole::RunTests(const std::string
& filter
) {
27 RUN_TEST(Smoke
, filter
);
32 void TestConsoleSub(const PPB_Console
* console_interface_
,
37 console_interface_
->Log(instance
, PP_LOGLEVEL_ERROR
,
39 console_interface_
->LogWithSource(instance
, PP_LOGLEVEL_LOG
,
40 source
.pp_var(), message
.pp_var());
43 } // anonymous namespace
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
49 pp::Var
source(std::string("somewhere"));
50 const PPB_Console
* interface
= console_interface_
;
51 PP_Instance pp_instance
= instance()->pp_instance();
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());