diff options
Diffstat (limited to 'ppapi/tests')
4 files changed, 134 insertions, 0 deletions
diff --git a/ppapi/tests/extensions/background_keepalive/background.cc b/ppapi/tests/extensions/background_keepalive/background.cc new file mode 100644 index 0000000..f4b3b7a --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/background.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2013 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 <cstdio> +#include <string> + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/message_loop.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/var.h" +#include "ppapi/utility/completion_callback_factory.h" + +class Instance : public pp::Instance { + public: + explicit Instance(PP_Instance instance) : + pp::Instance(instance), + callback_factory_(this), + delay_milliseconds_(10), + active_(true) { + DoSomething(PP_OK); + } + virtual ~Instance() {} + + virtual void HandleMessage(const pp::Var& message_var) { + std::string message_string = message_var.AsString(); + if (message_string == "be idle") { + active_ = false; + } else { + PostMessage("Unhandled control message."); + } + } + + void DoSomething(int32_t result) { + if (active_) { + pp::MessageLoop loop = pp::MessageLoop::GetCurrent(); + pp::CompletionCallback c = callback_factory_.NewCallback( + &Instance::DoSomething); + loop.PostWork(c, delay_milliseconds_); + } + } + + pp::CompletionCallbackFactory<Instance> callback_factory_; + int delay_milliseconds_; + bool active_; +}; + +class Module : public pp::Module { + public: + Module() : pp::Module() {} + virtual ~Module() {} + + virtual pp::Instance* CreateInstance(PP_Instance instance) { + return new Instance(instance); + } +}; + +namespace pp { +Module* CreateModule() { + return new ::Module(); +} +} // namespace pp + diff --git a/ppapi/tests/extensions/background_keepalive/background.js b/ppapi/tests/extensions/background_keepalive/background.js new file mode 100644 index 0000000..cd649c1 --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/background.js @@ -0,0 +1,41 @@ +// Copyright (c) 2013 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. + +var NaClModulesExpected = 0; +var NaClModulesLoaded = 0; + +// Indicate load success. +function moduleDidLoad() { + NaClModulesLoaded++; + if (NaClModulesLoaded == NaClModulesExpected) + chrome.test.sendMessage("nacl_modules_loaded", handleChromeTestMessage); +} + +var handleChromeTestMessage = function (message) { + NaClModules = document.querySelectorAll('embed'); + for (var i = 0; i < NaClModules.length; i++) { + NaClModules[i].postMessage(message); + } +} + +function handleNaclMessage(message_event) { + console.log("handleNaclMessage: " + message_event.data); +} + +function createNaClEmbed() { + NaClModulesExpected++; + + var listener = document.createElement("div"); + listener.addEventListener("load", moduleDidLoad, true); + listener.addEventListener("message", handleNaclMessage, true); + listener.innerHTML = '<embed' + + ' src="ppapi_tests_extensions_background_keepalive.nmf"' + + ' type="application/x-nacl" />'; + document.body.appendChild(listener); +} + +// Create 2 embeds to verify that we can handle more than one. +createNaClEmbed(); +createNaClEmbed(); + diff --git a/ppapi/tests/extensions/background_keepalive/manifest.json b/ppapi/tests/extensions/background_keepalive/manifest.json new file mode 100644 index 0000000..28fb912 --- /dev/null +++ b/ppapi/tests/extensions/background_keepalive/manifest.json @@ -0,0 +1,11 @@ +{ + "manifest_version": 2, + "name": "background_nacl", + "version": "0", + "description": "Tests keeping background page with NaCl alive when active.", + "app": { + "background": { + "scripts": ["background.js"] + } + } +} diff --git a/ppapi/tests/extensions/extensions.gyp b/ppapi/tests/extensions/extensions.gyp index d063b83f4..70af268 100644 --- a/ppapi/tests/extensions/extensions.gyp +++ b/ppapi/tests/extensions/extensions.gyp @@ -29,5 +29,24 @@ ], }, }, + { + 'target_name': 'ppapi_tests_extensions_background_keepalive', + 'type': 'none', + 'variables': { + 'nexe_target': 'ppapi_tests_extensions_background_keepalive', + # Only newlib build is used in tests, no need to build others. + 'build_newlib': 1, + 'build_glibc': 0, + 'build_pnacl_newlib': 0, + 'nexe_destination_dir': 'test_data/ppapi/tests/extensions/background_keepalive', + 'sources': [ + 'background_keepalive/background.cc', + ], + 'test_files': [ + 'background_keepalive/background.js', + 'background_keepalive/manifest.json', + ], + }, + }, ], } |