summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_query_policy.cc
blob: 87fba20e2a936b5369b9e0ef4f23f3f0dc18bdb8 (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
// Copyright (c) 2011 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_query_policy.h"

#include "ppapi/c/dev/ppb_query_policy_dev.h"
#include "ppapi/c/dev/ppp_policy_update_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(QueryPolicy);

namespace {

// Since this is a unittest, we don't care about a global string.
std::string g_received_policy;

void PolicyUpdated(PP_Instance instance, PP_Var pp_policy_json) {
  g_received_policy = pp::Var(pp::Var::DontManage(), pp_policy_json).AsString();
  GetTestingInterface()->QuitMessageLoop(instance);
}

static PPP_PolicyUpdate_Dev policy_updated_interface = {
  &PolicyUpdated,
};

}  // namespace

bool TestQueryPolicy::Init() {
  query_policy_interface_ = static_cast<PPB_QueryPolicy_Dev const*>(
      pp::Module::Get()->GetBrowserInterface(PPB_QUERYPOLICY_DEV_INTERFACE));
  pp::Module::Get()->AddPluginInterface(PPP_POLICYUPDATE_DEV_INTERFACE,
                                        &policy_updated_interface);

  return query_policy_interface_ && InitTestingInterface();
}

void TestQueryPolicy::RunTest() {
  RUN_TEST(SubscribeToPolicyUpdates);
}

std::string TestQueryPolicy::TestSubscribeToPolicyUpdates() {
  query_policy_interface_->SubscribeToPolicyUpdates(
      instance_->pp_instance());

  // Wait for a response on PPP_PolicyUpdate_Dev.
  GetTestingInterface()->RunMessageLoop(instance_->pp_instance());

  ASSERT_FALSE(g_received_policy.empty());

  PASS();
}