summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_flash_message_loop.cc
blob: e5b7fe8f8f29cf7f99841db761863cdd57fb001f (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
// 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_flash_message_loop.h"

#include "ppapi/c/pp_macros.h"
#include "ppapi/cpp/core.h"
#include "ppapi/cpp/logging.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/private/flash_message_loop.h"
#include "ppapi/tests/testing_instance.h"

REGISTER_TEST_CASE(FlashMessageLoop);

TestFlashMessageLoop::TestFlashMessageLoop(TestingInstance* instance)
    : TestCase(instance),
      message_loop_(NULL),
      PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
}

TestFlashMessageLoop::~TestFlashMessageLoop() {
  PP_DCHECK(!message_loop_);
}

void TestFlashMessageLoop::RunTests(const std::string& filter) {
  RUN_TEST(Basics, filter);
  RUN_TEST(RunWithoutQuit, filter);
}

std::string TestFlashMessageLoop::TestBasics() {
  message_loop_ = new pp::flash::MessageLoop(instance_);

  pp::CompletionCallback callback = callback_factory_.NewCallback(
      &TestFlashMessageLoop::QuitMessageLoopTask);
  pp::Module::Get()->core()->CallOnMainThread(0, callback);
  int32_t result = message_loop_->Run();

  ASSERT_TRUE(message_loop_);
  delete message_loop_;
  message_loop_ = NULL;

  ASSERT_EQ(result, PP_OK);
  PASS();
}

std::string TestFlashMessageLoop::TestRunWithoutQuit() {
  message_loop_ = new pp::flash::MessageLoop(instance_);

  pp::CompletionCallback callback = callback_factory_.NewCallback(
      &TestFlashMessageLoop::DestroyMessageLoopResourceTask);
  pp::Module::Get()->core()->CallOnMainThread(0, callback);
  int32_t result = message_loop_->Run();

  if (message_loop_) {
    delete message_loop_;
    message_loop_ = NULL;
    ASSERT_TRUE(false);
  }

  ASSERT_EQ(result, PP_ERROR_ABORTED);
  PASS();
}

void TestFlashMessageLoop::QuitMessageLoopTask(int32_t unused) {
  if (message_loop_)
    message_loop_->Quit();
  else
    PP_NOTREACHED();
}

void TestFlashMessageLoop::DestroyMessageLoopResourceTask(int32_t unused) {
  if (message_loop_) {
    delete message_loop_;
    message_loop_ = NULL;
  } else {
    PP_NOTREACHED();
  }
}