summaryrefslogtreecommitdiffstats
path: root/ppapi/tests
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 17:06:43 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 17:06:43 +0000
commit4c85f66d40d3b1b25e6f30ad90888dc29eb90ee8 (patch)
treeefafdd70c921591168a8cc34dff990f83c147916 /ppapi/tests
parentad301eb035b5610de22356cadaac3a3826ca3abe (diff)
downloadchromium_src-4c85f66d40d3b1b25e6f30ad90888dc29eb90ee8.zip
chromium_src-4c85f66d40d3b1b25e6f30ad90888dc29eb90ee8.tar.gz
chromium_src-4c85f66d40d3b1b25e6f30ad90888dc29eb90ee8.tar.bz2
Revert 91859 - Porting ppapi_tests framework to postMessage.
Some tests still rely on scripting, so we changed to using InstancePrivate (since scripting will disappear from Instance soon). Also use conditional compilation so that if compiled as untrusted with NaCl, the tests use Instance instead of InstancePrivate. This means that tests which rely on scripting aren't runnable in NaCl. I also added a gyp option: pepper_scripting. The default is that scripting is on in this CL, but it will make it easy to turn it off in local builds. Soon we'll switch the default to no scripting, and soon after we can remove the option entirely. BUG=82606 TEST=these tests Review URL: http://codereview.chromium.org/7312008 TBR=dmichael@chromium.org Review URL: http://codereview.chromium.org/7329024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91866 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r--ppapi/tests/test_case.cc13
-rw-r--r--ppapi/tests/test_case.h15
-rw-r--r--ppapi/tests/test_case.html66
-rw-r--r--ppapi/tests/test_post_message.cc11
-rw-r--r--ppapi/tests/test_url_util.cc2
-rw-r--r--ppapi/tests/test_var_deprecated.cc7
-rw-r--r--ppapi/tests/test_var_deprecated.h6
-rw-r--r--ppapi/tests/testing_instance.cc37
-rw-r--r--ppapi/tests/testing_instance.h25
9 files changed, 36 insertions, 146 deletions
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc
index 15f24f0..1d91ef5 100644
--- a/ppapi/tests/test_case.cc
+++ b/ppapi/tests/test_case.cc
@@ -35,24 +35,20 @@ std::string TestCase::MakeFailureMessage(const char* file,
return output.str();
}
-#if !(defined __native_client__)
-pp::VarPrivate TestCase::GetTestObject() {
+pp::Var TestCase::GetTestObject() {
if (test_object_.is_undefined()) {
pp::deprecated::ScriptableObject* so = CreateTestObject();
if (so)
- test_object_ = pp::VarPrivate(instance_, so); // Takes ownership.
+ test_object_ = pp::Var(instance_, so); // Takes ownership.
}
return test_object_;
}
-#endif
void TestCase::HandleMessage(const pp::Var& message_data) {}
-#if !(defined __native_client__)
pp::deprecated::ScriptableObject* TestCase::CreateTestObject() {
return NULL;
}
-#endif
bool TestCase::InitTestingInterface() {
testing_interface_ = GetTestingInterface();
@@ -69,7 +65,10 @@ bool TestCase::InitTestingInterface() {
}
bool TestCase::EnsureRunningOverHTTP() {
- if (instance_->protocol() != "http:") {
+ pp::Var window = instance_->GetWindowObject();
+ pp::Var location = window.GetProperty("location");
+ pp::Var protocol = location.GetProperty("protocol");
+ if (!protocol.is_string() || protocol.AsString() != "http:") {
instance_->AppendError("This test needs to be run over HTTP.");
return false;
}
diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h
index 0a3cdc6..5ec4435 100644
--- a/ppapi/tests/test_case.h
+++ b/ppapi/tests/test_case.h
@@ -11,12 +11,7 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/cpp/dev/scrollbar_dev.h"
-
-#if (defined __native_client__)
#include "ppapi/cpp/var.h"
-#else
-#include "ppapi/cpp/private/var_private.h"
-#endif
struct PPB_Testing_Dev;
class TestingInstance;
@@ -43,11 +38,9 @@ class TestCase {
static std::string MakeFailureMessage(const char* file, int line,
const char* cmd);
-#if !(defined __native_client__)
// Returns the scriptable test object for the current test, if any.
// Internally, this uses CreateTestObject which each test overrides.
- pp::VarPrivate GetTestObject();
-#endif
+ pp::Var GetTestObject();
// A function that is invoked whenever HandleMessage is called on the
// associated TestingInstance. Default implementation does nothing. TestCases
@@ -56,7 +49,6 @@ class TestCase {
virtual void HandleMessage(const pp::Var& message_data);
protected:
-#if !(defined __native_client__)
// Overridden by each test to supply a ScriptableObject corresponding to the
// test. There can only be one object created for all test in a given class
// so be sure your object is designed to be re-used.
@@ -64,7 +56,6 @@ class TestCase {
// This object should be created on the heap. Ownership will be passed to the
// caller. Return NULL if there is no supported test object (the default).
virtual pp::deprecated::ScriptableObject* CreateTestObject();
-#endif
// Initializes the testing interface.
bool InitTestingInterface();
@@ -82,10 +73,8 @@ class TestCase {
bool force_async_;
private:
-#if !(defined __native_client__)
// Holds the test object, if any was retrieved from CreateTestObject.
- pp::VarPrivate test_object_;
-#endif
+ pp::Var test_object_;
};
// This class is an implementation detail.
diff --git a/ppapi/tests/test_case.html b/ppapi/tests/test_case.html
index 1d395fe..89bf1b6 100644
--- a/ppapi/tests/test_case.html
+++ b/ppapi/tests/test_case.html
@@ -66,67 +66,6 @@ function ExtractSearchParameter(name) {
return "";
}
-// Parses the message, looking for strings of the form:
-// TESTING_MESSAGE:<message_type>:<message_contents>
-//
-// If the message_data is not a string or does not match the above format, then
-// undefined is returned.
-//
-// Otherwise, returns an array containing 2 items. The 0th element is the
-// message_type, one of:
-// - ClearContents
-// - DidExecuteTests
-// - LogHTML
-// - SetCookie
-// The second item is the verbatim message_contents.
-function ParseTestingMessage(message_data) {
- if (typeof(message_data)!='string')
- return undefined;
- var testing_message_prefix = "TESTING_MESSAGE";
- var delim_str = ":";
- var delim1 = message_data.indexOf(delim_str);
- if (message_data.substring(0, delim1) !== testing_message_prefix)
- return undefined;
- var delim2 = message_data.indexOf(delim_str, delim1 + 1);
- if (delim2 == -1)
- delim2 = message_data.length;
- var message_type = message_data.substring(delim1 + 1, delim2);
- var message_contents = message_data.substring(delim2 + 1);
- return [message_type, message_contents];
-}
-
-function ClearConsole() {
- window.document.getElementById("console").innerHTML = "";
-}
-
-function LogHTML(html) {
- window.document.getElementById("console").innerHTML += html;
-}
-
-function SetCookie(key_value_string) {
- window.document.cookie = key_value_string + "; path=/";
-}
-
-function IsTestingMessage(message_data) {
- return (ParseTestingMessage(message_data) != undefined);
-}
-
-function handleTestingMessage(message_event) {
- var type_contents_tuple = ParseTestingMessage(message_event.data);
- if (type_contents_tuple) {
- var type = type_contents_tuple[0];
- var contents = type_contents_tuple[1];
- if (type === "ClearConsole")
- ClearConsole();
- else if (type === "DidExecuteTests")
- DidExecuteTests();
- else if (type === "LogHTML")
- LogHTML(contents);
- else if (type === "SetCookie")
- SetCookie(contents);
- }
-}
-
onload = function() {
var testcase = ExtractSearchParameter("testcase");
var mode = ExtractSearchParameter("mode");
@@ -152,10 +91,7 @@ onload = function() {
if (obj) {
obj.setAttribute("id", "plugin");
obj.setAttribute("testcase", testcase);
- obj.setAttribute("protocol", window.location.protocol);
- var container = document.getElementById("container");
- container.appendChild(obj);
- container.addEventListener("message", handleTestingMessage, true);
+ document.getElementById("container").appendChild(obj);
}
}
</script>
diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc
index ea29882..a97ba42 100644
--- a/ppapi/tests/test_post_message.cc
+++ b/ppapi/tests/test_post_message.cc
@@ -44,18 +44,11 @@ void TestPostMessage::HandleMessage(const pp::Var& message_data) {
bool TestPostMessage::AddEchoingListener(const std::string& expression) {
std::string js_code;
- // Note the following code is dependent on some features of test_case.html.
- // E.g., it is assumed that the DOM element where the plugin is embedded has
- // an id of 'plugin', and there is a function 'IsTestingMessage' that allows
- // us to ignore the messages that are intended for use by the testing
- // framework itself.
js_code += "var plugin = document.getElementById('plugin');"
"var message_handler = function(message_event) {"
- " if (!IsTestingMessage(message_event.data)) {"
- " plugin.postMessage(";
+ " plugin.postMessage(";
js_code += expression;
- js_code += " );"
- " }"
+ js_code += " );"
"};"
"plugin.addEventListener('message', message_handler);"
// Maintain an array of all event listeners, attached to the
diff --git a/ppapi/tests/test_url_util.cc b/ppapi/tests/test_url_util.cc
index dc6cb47..964060d 100644
--- a/ppapi/tests/test_url_util.cc
+++ b/ppapi/tests/test_url_util.cc
@@ -121,7 +121,7 @@ std::string TestURLUtil::TestDocumentCanAccessDocument() {
std::string TestURLUtil::TestGetDocumentURL() {
pp::Var url = util_->GetDocumentURL(*instance_);
ASSERT_TRUE(url.is_string());
- pp::VarPrivate window = instance_->GetWindowObject();
+ pp::Var window = instance_->GetWindowObject();
pp::Var href = window.GetProperty("location").GetProperty("href");
ASSERT_TRUE(href.is_string());
// In the test framework, they should be the same.
diff --git a/ppapi/tests/test_var_deprecated.cc b/ppapi/tests/test_var_deprecated.cc
index 07ccf91..34309ee 100644
--- a/ppapi/tests/test_var_deprecated.cc
+++ b/ppapi/tests/test_var_deprecated.cc
@@ -57,7 +57,7 @@ pp::Var VarScriptableObject::Call(const pp::Var& method_name,
if (args.size() != 1)
*exception = pp::Var("Bad argument to SetValue(<value>)");
else
- test_var_deprecated_->set_var_from_page(pp::VarPrivate(args[0]));
+ test_var_deprecated_->set_var_from_page(args[0]);
}
return pp::Var();
@@ -297,7 +297,7 @@ std::string TestVarDeprecated::TestHasPropertyAndMethod() {
uint32_t before_objects = testing_interface_->GetLiveObjectsForInstance(
instance_->pp_instance());
{
- pp::VarPrivate window = instance_->GetWindowObject();
+ pp::Var window = instance_->GetWindowObject();
ASSERT_TRUE(window.is_object());
// Regular property.
@@ -330,7 +330,7 @@ std::string TestVarDeprecated::TestHasPropertyAndMethod() {
// Try to use something not an object.
exception = pp::Var();
- pp::VarPrivate string_object("asdf");
+ pp::Var string_object("asdf");
ASSERT_FALSE(string_object.HasProperty("find", &exception));
ASSERT_FALSE(exception.is_undefined());
exception = pp::Var();
@@ -397,4 +397,3 @@ std::string TestVarDeprecated::TestPassReference() {
PASS();
}
-
diff --git a/ppapi/tests/test_var_deprecated.h b/ppapi/tests/test_var_deprecated.h
index 8e64ece..faed7be 100644
--- a/ppapi/tests/test_var_deprecated.h
+++ b/ppapi/tests/test_var_deprecated.h
@@ -7,7 +7,7 @@
#include <string>
-#include "ppapi/cpp/private/var_private.h"
+#include "ppapi/cpp/var.h"
#include "ppapi/tests/test_case.h"
struct PPB_Var_Deprecated;
@@ -20,7 +20,7 @@ class TestVarDeprecated : public TestCase {
virtual bool Init();
virtual void RunTest();
- void set_var_from_page(const pp::VarPrivate& v) { var_from_page_ = v; }
+ void set_var_from_page(const pp::Var& v) { var_from_page_ = v; }
protected:
// Test case protected overrides.
@@ -41,7 +41,7 @@ class TestVarDeprecated : public TestCase {
const PPB_Var_Deprecated* var_interface_;
// Saves the var from when a value is set on the test from the page.
- pp::VarPrivate var_from_page_;
+ pp::Var var_from_page_;
};
#endif // PPAPI_TEST_TEST_VAR_DEPRECATED_H_
diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc
index 138ef16..87022bb 100644
--- a/ppapi/tests/testing_instance.cc
+++ b/ppapi/tests/testing_instance.cc
@@ -17,11 +17,7 @@ TestCaseFactory* TestCaseFactory::head_ = NULL;
// Returns a new heap-allocated test case for the given test, or NULL on
// failure.
TestingInstance::TestingInstance(PP_Instance instance)
-#if (defined __native_client__)
: pp::Instance(instance),
-#else
- : pp::InstancePrivate(instance),
-#endif
current_case_(NULL),
executed_tests_(false),
nacl_mode_(false) {
@@ -40,9 +36,8 @@ bool TestingInstance::Init(uint32_t argc,
if (std::strcmp(argn[i], "mode") == 0) {
if (std::strcmp(argv[i], "nacl") == 0)
nacl_mode_ = true;
+ break;
}
- else if (std::strcmp(argn[i], "protocol") == 0)
- protocol_ = argv[i];
}
// Create the proper test case from the argument.
for (uint32_t i = 0; i < argc; i++) {
@@ -62,14 +57,12 @@ bool TestingInstance::Init(uint32_t argc,
return true;
}
-#if !(defined __native_client__)
pp::Var TestingInstance::GetInstanceObject() {
if (current_case_)
return current_case_->GetTestObject();
- return pp::VarPrivate();
+ return pp::Var(this, NULL);
}
-#endif
void TestingInstance::HandleMessage(const pp::Var& message_data) {
current_case_->HandleMessage(message_data);
@@ -116,7 +109,10 @@ void TestingInstance::ExecuteTests(int32_t unused) {
SetCookie("STARTUP_COOKIE", "STARTED");
// Clear the console.
- PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole"));
+ // This does: window.document.getElementById("console").innerHTML = "";
+ pp::Var window = GetWindowObject();
+ window.GetProperty("document").
+ Call("getElementById", "console").SetProperty("innerHTML", "");
if (!errors_.empty()) {
// Catch initialization errors and output the current error string to
@@ -135,7 +131,8 @@ void TestingInstance::ExecuteTests(int32_t unused) {
// Declare we're done by setting a cookie to either "PASS" or the errors.
SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_);
- PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests"));
+
+ window.Call("DidExecuteTests");
}
TestCase* TestingInstance::CaseForTestName(const char* name) {
@@ -171,7 +168,6 @@ void TestingInstance::LogAvailableTests() {
}
html.append("</dl>");
html.append("<button onclick='RunAll()'>Run All Tests</button>");
-
LogHTML(html);
}
@@ -184,18 +180,19 @@ void TestingInstance::LogError(const std::string& text) {
}
void TestingInstance::LogHTML(const std::string& html) {
- std::string message("TESTING_MESSAGE:LogHTML:");
- message.append(html);
- PostMessage(pp::Var(message));
+ // This does: window.document.getElementById("console").innerHTML += html
+ pp::Var console = GetWindowObject().GetProperty("document").
+ Call("getElementById", "console");
+ pp::Var inner_html = console.GetProperty("innerHTML");
+ console.SetProperty("innerHTML", inner_html.AsString() + html);
}
void TestingInstance::SetCookie(const std::string& name,
const std::string& value) {
- std::string message("TESTING_MESSAGE:SetCookie:");
- message.append(name);
- message.append("=");
- message.append(value);
- PostMessage(pp::Var(message));
+ // window.document.cookie = "<name>=<value>; path=/"
+ std::string cookie_string = name + "=" + value + "; path=/";
+ pp::Var document = GetWindowObject().GetProperty("document");
+ document.SetProperty("cookie", cookie_string);
}
class Module : public pp::Module {
diff --git a/ppapi/tests/testing_instance.h b/ppapi/tests/testing_instance.h
index 9f42409..2201e13 100644
--- a/ppapi/tests/testing_instance.h
+++ b/ppapi/tests/testing_instance.h
@@ -8,23 +8,11 @@
#include <string>
#include "ppapi/cpp/completion_callback.h"
-
-#if defined(__native_client__)
#include "ppapi/cpp/instance.h"
-#else
-#include "ppapi/cpp/private/instance_private.h"
-#endif
class TestCase;
-// In trusted builds, we use InstancePrivate and allow tests that use
-// synchronous scripting. NaCl does not support synchronous scripting.
-class TestingInstance : public
-#if defined(__native_client__)
-pp::Instance {
-#else
-pp::InstancePrivate {
-#endif
+class TestingInstance : public pp::Instance {
public:
explicit TestingInstance(PP_Instance instance);
virtual ~TestingInstance();
@@ -32,10 +20,7 @@ pp::InstancePrivate {
// 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);
-
-#if !(defined __native_client__)
virtual pp::Var GetInstanceObject();
-#endif
// Outputs the information from one test run, using the format
// <test_name> [PASS|FAIL <error_message>]
@@ -61,10 +46,6 @@ pp::InstancePrivate {
// TestClass object that's associated with this instance.
virtual void HandleMessage(const pp::Var& message_data);
- const std::string& protocol() {
- return protocol_;
- }
-
private:
void ExecuteTests(int32_t unused);
@@ -97,10 +78,6 @@ pp::InstancePrivate {
// True if running in Native Client.
bool nacl_mode_;
-
- // String representing the protocol. Used for detecting whether we're running
- // with http.
- std::string protocol_;
};
#endif // PPAPI_TESTS_TESTING_INSTANCE_H_