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_talk_private.h"
      6 
      7 #include <stdio.h>
      8 #include <string.h>
      9 #include <string>
     10 
     11 #include "ppapi/c/pp_errors.h"
     12 #include "ppapi/c/private/ppb_talk_private.h"
     13 #include "ppapi/cpp/instance.h"
     14 #include "ppapi/cpp/module.h"
     15 #include "ppapi/tests/test_utils.h"
     16 #include "ppapi/tests/testing_instance.h"
     17 
     18 REGISTER_TEST_CASE(TalkPrivate);
     19 
     20 TestTalkPrivate::TestTalkPrivate(TestingInstance* instance)
     21     : TestCase(instance),
     22       talk_private_interface_1(NULL) {
     23 }
     24 
     25 bool TestTalkPrivate::Init() {
     26   if (!CheckTestingInterface()) {
     27     instance_->AppendError("Testing interface not available");
     28     return false;
     29   }
     30 
     31   talk_private_interface_1 = static_cast<const PPB_Talk_Private_1_0*>(
     32       pp::Module::Get()->GetBrowserInterface(PPB_TALK_PRIVATE_INTERFACE_1_0));
     33 
     34 #if defined(__native_client__)
     35   if (talk_private_interface_1)
     36     instance_->AppendError("TalkPrivate interface is supported by NaCl");
     37 #else
     38   if (!talk_private_interface_1)
     39     instance_->AppendError("TalkPrivate interface not available");
     40 #endif
     41   return true;
     42 }
     43 
     44 void TestTalkPrivate::RunTests(const std::string& filter) {
     45   RUN_CALLBACK_TEST(TestTalkPrivate, GetPermission, filter);
     46 }
     47 
     48 std::string TestTalkPrivate::TestGetPermission() {
     49   if (!talk_private_interface_1) {
     50     PASS();
     51   }
     52 
     53   if (!testing_interface_->IsOutOfProcess()) {
     54     // We only support out-of-process access to this API, so skip in-process
     55     PASS();
     56   }
     57 
     58 #if defined(USE_ASH)
     59   // Under Ash, this will prompt the user so the test cannot run in an automated
     60   // fashion. To manually test under Ash, comment this out.
     61   PASS();
     62 #endif
     63 
     64   PP_Resource talk_resource = talk_private_interface_1->Create(
     65       instance_->pp_instance());
     66 
     67   TestCompletionCallback callback(instance_->pp_instance(), callback_type());
     68   callback.WaitForResult(talk_private_interface_1->GetPermission(talk_resource,
     69       callback.GetCallback().pp_completion_callback()));
     70   CHECK_CALLBACK_BEHAVIOR(callback);
     71 
     72 #if defined(USE_ASH)
     73   // Under Ash, this test will actually prompt the user and return either true
     74   // or false depending on their choice.
     75   if (callback.result() != 0 && callback.result() != 1)
     76     return "Unexpected result";
     77 #else
     78   // Currently not implemented without Ash, bur always returns false.
     79   if (callback.result() != 0)
     80     return "Unexpected non-zero result";
     81 #endif
     82 
     83   PASS();
     84 }
     85