
Note, I did something differently from other per-instance interfaces. While the C interface has 'PPB_Messaging' and 'PPP_Messaging' separate from the Instance interfaces, I stuck the per-instance messaging in to pp::Instance. It seems more intuitive to me, and doesn't have the drawbacks of having too many functions in the C layer instance interfaces. Happy to back off of that position, but it's worth a shot. Overview: From JavaScript, you can invoke 'postMessage' on the embedded module. That results in a call to 'PPP_Messaging::HandleMessage'. From Native Code, you can invoke 'PPB_Messaging::PostMessage', which results in a call to an 'onmessage' function on the DOM element for the module instance in the JavaScript code (if one has been registered). Please see the included example or the examples in the comments of PPB_Messaging and PPP_Messaging. Restrictions: - This implementation is synchronous. A later CL will make it asynchronous. - This implementation supports only intrinsic values and strings (all types that PP_Var supports except for objects). Object & array support will come later. - This implementation only allows for 1 channel per instance. You can not expose other 'channels' or 'ports'. Future CLs will add support for MessagePorts. BUG=None TEST=test_post_message.h/.cc (This CL replaces http://codereview.chromium.org/6538028/ ) Review URL: http://codereview.chromium.org/6716005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79178 0039d316-1c4b-4281-b951-d872f2087c98
84 lines
2.7 KiB
C++
84 lines
2.7 KiB
C++
// Copyright (c) 2010 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.
|
|
|
|
#ifndef PPAPI_TESTS_TESTING_INSTANCE_H_
|
|
#define PPAPI_TESTS_TESTING_INSTANCE_H_
|
|
|
|
#include <string>
|
|
|
|
#include "ppapi/cpp/completion_callback.h"
|
|
#include "ppapi/cpp/instance.h"
|
|
|
|
class TestCase;
|
|
|
|
class TestingInstance : public pp::Instance {
|
|
public:
|
|
explicit TestingInstance(PP_Instance instance);
|
|
|
|
// pp::Instance override.
|
|
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]);
|
|
virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip);
|
|
virtual pp::Var GetInstanceObject();
|
|
|
|
// Outputs the information from one test run, using the format
|
|
// <test_name> [PASS|FAIL <error_message>]
|
|
// If error_message is empty, we say the test passed and emit PASS. If
|
|
// error_message is nonempty, the test failed with that message as the error
|
|
// string.
|
|
//
|
|
// Intended usage:
|
|
// LogTest("Foo", FooTest());
|
|
//
|
|
// Where FooTest is defined as:
|
|
// std::string FooTest() {
|
|
// if (something_horrible_happened)
|
|
// return "Something horrible happened";
|
|
// return "";
|
|
// }
|
|
void LogTest(const std::string& test_name, const std::string& error_message);
|
|
|
|
// Appends an error message to the log.
|
|
void AppendError(const std::string& message);
|
|
|
|
// Passes the message_data through to the HandleMessage method on the
|
|
// TestClass object that's associated with this instance.
|
|
virtual void HandleMessage(const pp::Var& message_data);
|
|
|
|
private:
|
|
void ExecuteTests(int32_t unused);
|
|
|
|
// Creates a new TestCase for the give test name, or NULL if there is no such
|
|
// test. Ownership is passed to the caller.
|
|
TestCase* CaseForTestName(const char* name);
|
|
|
|
// Appends a list of available tests to the console in the document.
|
|
void LogAvailableTests();
|
|
|
|
// Appends the given error test to the console in the document.
|
|
void LogError(const std::string& text);
|
|
|
|
// Appends the given HTML string to the console in the document.
|
|
void LogHTML(const std::string& html);
|
|
|
|
// Sets the given cookie in the current document.
|
|
void SetCookie(const std::string& name, const std::string& value);
|
|
|
|
pp::CompletionCallbackFactory<TestingInstance> callback_factory_;
|
|
|
|
// Owning pointer to the current test case. Valid after Init has been called.
|
|
TestCase* current_case_;
|
|
|
|
// Set once the tests are run so we know not to re-run when the view is sized.
|
|
bool executed_tests_;
|
|
|
|
// Collects all errors to send the the browser. Empty indicates no error yet.
|
|
std::string errors_;
|
|
|
|
// True if running in Native Client.
|
|
bool nacl_mode_;
|
|
};
|
|
|
|
#endif // PPAPI_TESTS_TESTING_INSTANCE_H_
|
|
|