summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/testing_instance.cc
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 16:23:36 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-08 16:23:36 +0000
commit368ca47678e6c2208bd1849e5c8ad6f954ff0989 (patch)
treef308afb5e2e1f77906b8bd5b0479903ac9c7f42b /ppapi/tests/testing_instance.cc
parent7b084b0f357f6a8a2cd4b58a56af234e7af063f5 (diff)
downloadchromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.zip
chromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.tar.gz
chromium_src-368ca47678e6c2208bd1849e5c8ad6f954ff0989.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91859 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/testing_instance.cc')
-rw-r--r--ppapi/tests/testing_instance.cc37
1 files changed, 20 insertions, 17 deletions
diff --git a/ppapi/tests/testing_instance.cc b/ppapi/tests/testing_instance.cc
index 87022bb..138ef16 100644
--- a/ppapi/tests/testing_instance.cc
+++ b/ppapi/tests/testing_instance.cc
@@ -17,7 +17,11 @@ 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) {
@@ -36,8 +40,9 @@ 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++) {
@@ -57,12 +62,14 @@ 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::Var(this, NULL);
+ return pp::VarPrivate();
}
+#endif
void TestingInstance::HandleMessage(const pp::Var& message_data) {
current_case_->HandleMessage(message_data);
@@ -109,10 +116,7 @@ void TestingInstance::ExecuteTests(int32_t unused) {
SetCookie("STARTUP_COOKIE", "STARTED");
// Clear the console.
- // This does: window.document.getElementById("console").innerHTML = "";
- pp::Var window = GetWindowObject();
- window.GetProperty("document").
- Call("getElementById", "console").SetProperty("innerHTML", "");
+ PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole"));
if (!errors_.empty()) {
// Catch initialization errors and output the current error string to
@@ -131,8 +135,7 @@ 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_);
-
- window.Call("DidExecuteTests");
+ PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests"));
}
TestCase* TestingInstance::CaseForTestName(const char* name) {
@@ -168,6 +171,7 @@ void TestingInstance::LogAvailableTests() {
}
html.append("</dl>");
html.append("<button onclick='RunAll()'>Run All Tests</button>");
+
LogHTML(html);
}
@@ -180,19 +184,18 @@ void TestingInstance::LogError(const std::string& text) {
}
void TestingInstance::LogHTML(const std::string& html) {
- // 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);
+ std::string message("TESTING_MESSAGE:LogHTML:");
+ message.append(html);
+ PostMessage(pp::Var(message));
}
void TestingInstance::SetCookie(const std::string& name,
const std::string& value) {
- // window.document.cookie = "<name>=<value>; path=/"
- std::string cookie_string = name + "=" + value + "; path=/";
- pp::Var document = GetWindowObject().GetProperty("document");
- document.SetProperty("cookie", cookie_string);
+ std::string message("TESTING_MESSAGE:SetCookie:");
+ message.append(name);
+ message.append("=");
+ message.append(value);
+ PostMessage(pp::Var(message));
}
class Module : public pp::Module {