Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1194)

Unified Diff: ppapi/tests/power_saver_test_plugin.cc

Issue 1088763002: Plugin Power Saver: Add comprehensive browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0260-plugins-overhaul-prerender-tests
Patch Set: update isolate Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/power_saver_test_plugin.cc
diff --git a/ppapi/tests/power_saver_test_plugin.cc b/ppapi/tests/power_saver_test_plugin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..44ccd32c6dac1cd64d434ad5b692b648c0b7f66b
--- /dev/null
+++ b/ppapi/tests/power_saver_test_plugin.cc
@@ -0,0 +1,57 @@
+// Copyright 2015 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 <algorithm>
+
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/cpp/var_dictionary.h"
+#include "ppapi/tests/test_utils.h"
+
+// When compiling natively on Windows, PostMessage can be #define-d to
+// something else.
+#ifdef PostMessage
+#undef PostMessage
+#endif
+
+// This is a simple C++ Pepper plugin that enables Plugin Power Saver tests.
+class PowerSaverTestInstance : public pp::Instance {
+ public:
+ explicit PowerSaverTestInstance(PP_Instance instance)
+ : pp::Instance(instance) {}
+ virtual ~PowerSaverTestInstance() {}
+ virtual void HandleMessage(const pp::Var& message_data);
+};
+
+// When postMessage("isPeripheral") is called on the DOM element associated
+// with this plugin instance, we respond with a Javascript object containing
+// a boolean indicating if the plugin has been marked peripheral.
+void PowerSaverTestInstance::HandleMessage(const pp::Var& message_data) {
+ if (message_data.is_string() && (message_data.AsString() == "isPeripheral")) {
+ pp::VarDictionary message;
+ message.Set(
+ "isPeripheral",
+ pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance()))));
+ PostMessage(message);
+ }
+}
+
+class PowerSaverTestModule : public pp::Module {
+ public:
+ PowerSaverTestModule() : pp::Module() {}
+ virtual ~PowerSaverTestModule() {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new PowerSaverTestInstance(instance);
+ }
+};
+
+namespace pp {
+
+Module* CreateModule() {
+ return new PowerSaverTestModule();
+}
+
+} // namespace pp
« content/public/test/ppapi_test_utils.h ('K') | « ppapi/shared_impl/ppapi_constants.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698