summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authorscheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 17:46:55 +0000
committerscheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 17:46:55 +0000
commitb6cd72093b5281cda2599e0c697c81da67097353 (patch)
treee5703bfdcb3d7d5539275be8f64452d2561e2255 /ppapi/tests
parent0aaef48415ba1c5bef604db93abba6ca4915d6e9 (diff)
downloadchromium_src-b6cd72093b5281cda2599e0c697c81da67097353.zip
chromium_src-b6cd72093b5281cda2599e0c697c81da67097353.tar.gz
chromium_src-b6cd72093b5281cda2599e0c697c81da67097353.tar.bz2
Test Keeping NaCl plugins used in app background pages alive when active.
(Re-landing with fixes from https://codereview.chromium.org/112663007/ ) Activity in Native Client plugins results in IPC messages sent to the BrowserPpapiHostImpl and routed to call extensions::ProcessManager::KeepaliveImpulse. Testing patch, builds on implementation: https://codereview.chromium.org/61063003/ Design doc: https://docs.google.com/a/chromium.org/document/d/1mI0lS1rfAf-BAGLmWAEcWy37Xq9dOvgfMx8OqeUMXts/edit# BUG=298339 No change to mseaborn owned file since last LGTM: R=yzshen@chromium.org TBR=mseaborn@chromium.org Review URL: https://codereview.chromium.org/125353006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243326 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/extensions/background_keepalive/background.cc63
-rw-r--r--ppapi/tests/extensions/background_keepalive/background.js41
-rw-r--r--ppapi/tests/extensions/background_keepalive/manifest.json11
-rw-r--r--ppapi/tests/extensions/extensions.gyp19
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',
+ ],
+ },
+ },
],
}