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

Unified Diff: ppapi/tests/test_broker.cc

Issue 8400024: Add TestConnectFailure, TestGetHandleFailure and TestConnectAndPipe to PPAPI Broker UI test. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 years, 2 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
« no previous file with comments | « ppapi/tests/test_broker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_broker.cc
diff --git a/ppapi/tests/test_broker.cc b/ppapi/tests/test_broker.cc
index b1d5b028c58cf2adedbc4f45237335461277dfb4..cc59ee098b8906bce9b559d1e3c6c8c56b01bee1 100644
--- a/ppapi/tests/test_broker.cc
+++ b/ppapi/tests/test_broker.cc
@@ -4,13 +4,78 @@
#include "ppapi/tests/test_broker.h"
+#include <cstring>
+#include <fstream>
+
+#include "base/memory/scoped_ptr.h"
#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/trusted/ppp_broker.h"
#include "ppapi/c/trusted/ppb_broker_trusted.h"
-#include "ppapi/cpp/module.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(Broker);
+namespace {
+
+const size_t kTestMessageLength = 30;
ddorwin 2011/10/27 18:19:46 use arraysize() instead?
xhwang 2011/10/27 22:31:57 Done.
+const char kTestMessage[] = "Hello Plugin! This is Broker!";
+const int32_t kTestSandboxSuccess = 0;
ddorwin 2011/10/27 18:19:46 kBrokerIsUnsandboxed I would write a string since
xhwang 2011/10/27 22:31:57 Done.
+const int32_t kTestSandboxFailure = -1;
+
+// Test whether the process is sandboxed or not as expected.
+bool TestSandbox(bool is_sandbox_expected) {
ddorwin 2011/10/27 18:19:46 VerifyIsUnsandboxed Since we're only testing it i
xhwang 2011/10/27 22:31:57 Done.
xhwang 2011/10/27 22:31:57 Done.
+ bool success = true;
+ std::fstream fs;
+
+// FIXME: Add sandbox test for other platforms.
ddorwin 2011/10/27 18:19:46 Move to an #else below and change to "Windows". Ac
xhwang 2011/10/27 22:31:57 Done.
+#if defined(OS_POSIX)
+ const char* const kWriteFile = "/tmp/broker_sandbox_test.txt";
ddorwin 2011/10/27 18:19:46 /tmp/ppapi_... Paths should be the only differenc
xhwang 2011/10/27 22:31:57 Done.
+ fs.open(kWriteFile, std::fstream::out);
+ success &= (fs.fail() == is_sandbox_expected);
+ fs << "ochoococohoho";
+ success &= (fs.fail() == is_sandbox_expected);
+ fs.close();
+
+ const char* const kReadFile = "/var/log/messages";
ddorwin 2011/10/27 18:19:46 messages does not exist on my Mac. kernel.log migh
xhwang 2011/10/27 22:31:57 Done.
+ fs.open(kReadFile, std::fstream::in);
+ success &= (fs.fail() == is_sandbox_expected);
+ char buffer[16] = {0};
+ fs.read(buffer, 8);
+ success &= (fs.fail() == is_sandbox_expected);
+ fs << "this will not work";
ddorwin 2011/10/27 18:19:46 Probably not necessary.
xhwang 2011/10/27 22:31:57 Done.
+ success &= fs.fail();
+ fs.close();
+#endif
+
+ return success;
+}
+
+// Callback in the broker when a new broker connection occurs.
+int32_t OnInstanceConnected(PP_Instance instance, int32_t handle) {
+ // Send test message
+ ::write(handle, kTestMessage, kTestMessageLength);
+
+ // Do sandbox test and send result to plugin over the pipe.
+ const bool kIsChromeSandboxEnabled = false;
+ int32_t test_sandbox_result = TestSandbox(kIsChromeSandboxEnabled) ?
+ kTestSandboxSuccess : kTestSandboxFailure;
+ ::write(handle, &test_sandbox_result, sizeof(test_sandbox_result));
+
+ ::close(handle);
+ return PP_OK;
+}
+
+} // namespace
+
+PP_EXPORT int32_t PPP_InitializeBroker(
+ PP_ConnectInstance_Func* connect_instance_func) {
+ *connect_instance_func = &OnInstanceConnected;
+ return PP_OK;
+}
+
+PP_EXPORT void PPP_ShutdownBroker() {}
+
TestBroker::TestBroker(TestingInstance* instance)
: TestCase(instance),
broker_interface_(NULL) {
@@ -24,6 +89,7 @@ bool TestBroker::Init() {
void TestBroker::RunTest() {
RUN_TEST(Create);
+ RUN_TEST(Connect);
}
std::string TestBroker::TestCreate() {
@@ -44,3 +110,31 @@ std::string TestBroker::TestCreate() {
ddorwin 2011/10/27 18:19:46 There is more testing of Connect and the handle th
xhwang 2011/10/27 22:31:57 ?? Don't get it...
ddorwin 2011/10/27 23:21:23 As discussed.
PASS();
}
+
+std::string TestBroker::TestConnect() {
ddorwin 2011/10/27 18:19:46 ...AndGetHandle
xhwang 2011/10/27 22:31:57 Done.
+ ASSERT_TRUE(broker_interface_);
ddorwin 2011/10/27 18:19:46 I think this is an assumption in all tests, so we
xhwang 2011/10/27 22:31:57 Done.
+ PP_Resource broker = broker_interface_->CreateTrusted(
+ instance_->pp_instance());
+ ASSERT_TRUE(broker);
+
+ TestCompletionCallback cb(instance_->pp_instance());
+
+ ASSERT_EQ(PP_OK_COMPLETIONPENDING, broker_interface_->Connect(
ddorwin 2011/10/27 18:19:46 I'm not sure why the existing test uses ASSERT, bu
xhwang 2011/10/27 22:31:57 EXPECT is no available :-(
+ broker, pp::CompletionCallback(cb).pp_completion_callback()));
+ ASSERT_EQ(PP_OK, cb.WaitForResult());
+
+ int32_t handle = -1;
ddorwin 2011/10/27 18:19:46 Can we use PlatformFileToInt(base::kInvalidPlatfor
xhwang 2011/10/27 22:31:57 Done.
+ ASSERT_EQ(PP_OK, broker_interface_->GetHandle(broker, &handle));
+
+ scoped_array<char> received_msg(new char[kTestMessageLength]);
+ ::read(handle, received_msg.get(), kTestMessageLength);
+ ASSERT_EQ(0, ::strcmp(received_msg.get(), kTestMessage));
ddorwin 2011/10/27 18:19:46 EXPECT_STREQ
+
+ int32_t test_sandbox_result = kTestSandboxFailure;
+ ::read(handle, &test_sandbox_result, sizeof(test_sandbox_result));
+ ASSERT_EQ(kTestSandboxSuccess, test_sandbox_result);
+
+ ASSERT_EQ(0, ::close(handle));
+
+ PASS();
+}
« no previous file with comments | « ppapi/tests/test_broker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698