summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_talk_private.cc
blob: 4b49ed1c0e97d8e6d74e4021a1a3c81236f4ba5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/tests/test_talk_private.h"

#include <stdio.h>
#include <string.h>
#include <string>

#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/private/ppb_talk_private.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(TalkPrivate);

TestTalkPrivate::TestTalkPrivate(TestingInstance* instance)
    : TestCase(instance),
      talk_private_interface_(NULL) {
}

bool TestTalkPrivate::Init() {
  if (!CheckTestingInterface()) {
    instance_->AppendError("Testing interface not available");
    return false;
  }

  talk_private_interface_ = static_cast<const PPB_Talk_Private*>(
      pp::Module::Get()->GetBrowserInterface(PPB_TALK_PRIVATE_INTERFACE));

#if defined(__native_client__)
  if (talk_private_interface_)
    instance_->AppendError("TalkPrivate interface is supported by NaCl");
#else
  if (!talk_private_interface_)
    instance_->AppendError("TalkPrivate interface not available");
#endif
  return true;
}

void TestTalkPrivate::RunTests(const std::string& filter) {
  RUN_CALLBACK_TEST(TestTalkPrivate, GetPermission, filter);
}

std::string TestTalkPrivate::TestGetPermission() {
  if (!talk_private_interface_) {
    PASS();
  }

  if (!testing_interface_->IsOutOfProcess()) {
    // We only support out-of-process access to this API, so skip in-process
    PASS();
  }

#if defined(USE_ASH)
  // Under Ash, this will prompt the user so the test cannot run in an automated
  // fashion. To manually test under Ash, comment this out.
  PASS();
#endif

  PP_Resource talk_resource = talk_private_interface_->Create(
      instance_->pp_instance());

  TestCompletionCallback callback(instance_->pp_instance(), callback_type());
  callback.WaitForResult(talk_private_interface_->GetPermission(talk_resource,
      callback.GetCallback().pp_completion_callback()));
  CHECK_CALLBACK_BEHAVIOR(callback);

#if defined(USE_ASH)
  // Under Ash, this test will actually prompt the user and return either true
  // or false depending on their choice.
  if (callback.result() != 0 && callback.result() != 1)
    return "Unexpected result";
#else
  // Currently not implemented without Ash, bur always returns false.
  if (callback.result() != 0)
    return "Unexpected non-zero result";
#endif

  PASS();
}