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

Unified Diff: mojo/apps/js/test/js_to_cpp_unittest.cc

Issue 292243002: Add mojo bindings backpointer tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove stray "explicit" keywords. Created 6 years, 7 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 | « mojo/apps/js/test/js_to_cpp.mojom ('k') | mojo/apps/js/test/js_to_cpp_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/apps/js/test/js_to_cpp_unittest.cc
diff --git a/mojo/apps/js/test/js_to_cpp_unittest.cc b/mojo/apps/js/test/js_to_cpp_unittest.cc
index 64259df156faaf7c2b00c4229412aa2edda00162..5e2cc73b3b606297e5a6531254becea8ddc0bfbc 100644
--- a/mojo/apps/js/test/js_to_cpp_unittest.cc
+++ b/mojo/apps/js/test/js_to_cpp_unittest.cc
@@ -126,12 +126,6 @@ void CheckSampleEchoArgs(const js_to_cpp::EchoArgs& arg) {
CheckDataPipe(arg.data_handle().get().value());
}
-js_to_cpp::EchoArgsList BuildSampleEchoArgsList() {
- js_to_cpp::EchoArgsList::Builder builder;
- builder.set_item(BuildSampleEchoArgs());
- return builder.Finish();
-}
-
void CheckSampleEchoArgsList(const js_to_cpp::EchoArgsList& list) {
if (list.is_null())
return;
@@ -154,6 +148,22 @@ void CheckCorruptedStringArray(const mojo::Array<mojo::String>& string_array) {
CheckCorruptedString(string_array[i]);
}
+void CheckCorruptedEchoArgs(const js_to_cpp::EchoArgs& arg) {
+ if (arg.is_null())
+ return;
+ CheckCorruptedString(arg.name());
+ CheckCorruptedStringArray(arg.string_array());
+ if (arg.data_handle().is_valid())
+ CheckDataPipe(arg.data_handle().get().value());
+}
+
+void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsList& list) {
+ if (list.is_null())
+ return;
+ CheckCorruptedEchoArgs(list.item());
+ CheckCorruptedEchoArgsList(list.next());
+}
+
// Base Provider implementation class. It's expected that tests subclass and
// override the appropriate Provider functions. When test is done quit the
// run_loop().
@@ -186,10 +196,14 @@ class CppSideConnection : public js_to_cpp::CppSide {
NOTREACHED();
}
- virtual void BitFlipResponse(const js_to_cpp::EchoArgs& arg1) OVERRIDE {
+ virtual void BitFlipResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
NOTREACHED();
}
+ virtual void BackPointerResponse(
+ const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ NOTREACHED();
+ }
protected:
base::RunLoop* run_loop_;
js_to_cpp::JsSide* js_side_;
@@ -201,7 +215,7 @@ class CppSideConnection : public js_to_cpp::CppSide {
// Trivial test to verify a message sent from JS is received.
class PingCppSideConnection : public CppSideConnection {
public:
- explicit PingCppSideConnection() : got_message_(false) {}
+ PingCppSideConnection() : got_message_(false) {}
virtual ~PingCppSideConnection() {}
// js_to_cpp::CppSide:
@@ -226,7 +240,7 @@ class PingCppSideConnection : public CppSideConnection {
// Test that parameters are passed with correct values.
class EchoCppSideConnection : public CppSideConnection {
public:
- explicit EchoCppSideConnection() :
+ EchoCppSideConnection() :
message_count_(0),
termination_seen_(false) {
}
@@ -235,7 +249,7 @@ class EchoCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
AllocationScope scope;
- js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgsList());
+ js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
}
virtual void EchoResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
@@ -259,7 +273,7 @@ class EchoCppSideConnection : public CppSideConnection {
}
private:
- static const int kExpectedMessageCount = 100;
+ static const int kExpectedMessageCount = 10;
int message_count_;
bool termination_seen_;
DISALLOW_COPY_AND_ASSIGN(EchoCppSideConnection);
@@ -268,7 +282,7 @@ class EchoCppSideConnection : public CppSideConnection {
// Test that corrupted messages don't wreak havoc.
class BitFlipCppSideConnection : public CppSideConnection {
public:
- explicit BitFlipCppSideConnection() : termination_seen_(false) {}
+ BitFlipCppSideConnection() : termination_seen_(false) {}
virtual ~BitFlipCppSideConnection() {}
// js_to_cpp::CppSide:
@@ -277,13 +291,8 @@ class BitFlipCppSideConnection : public CppSideConnection {
js_side_->BitFlip(BuildSampleEchoArgs());
}
- virtual void BitFlipResponse(const js_to_cpp::EchoArgs& arg) OVERRIDE {
- if (arg.is_null())
- return;
- CheckCorruptedString(arg.name());
- CheckCorruptedStringArray(arg.string_array());
- if (arg.data_handle().is_valid())
- CheckDataPipe(arg.data_handle().get().value());
+ virtual void BitFlipResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ CheckCorruptedEchoArgsList(list);
}
virtual void TestFinished() OVERRIDE {
@@ -300,6 +309,37 @@ class BitFlipCppSideConnection : public CppSideConnection {
DISALLOW_COPY_AND_ASSIGN(BitFlipCppSideConnection);
};
+// Test that severely random messages don't wreak havoc.
+class BackPointerCppSideConnection : public CppSideConnection {
+ public:
+ BackPointerCppSideConnection() : termination_seen_(false) {}
+ virtual ~BackPointerCppSideConnection() {}
+
+ // js_to_cpp::CppSide:
+ virtual void StartTest() OVERRIDE {
+ AllocationScope scope;
+ js_side_->BackPointer(BuildSampleEchoArgs());
+ }
+
+ virtual void BackPointerResponse(
+ const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ CheckCorruptedEchoArgsList(list);
+ }
+
+ virtual void TestFinished() OVERRIDE {
+ termination_seen_ = true;
+ run_loop()->Quit();
+ }
+
+ bool DidSucceed() {
+ return termination_seen_;
+ }
+
+ private:
+ bool termination_seen_;
+ DISALLOW_COPY_AND_ASSIGN(BackPointerCppSideConnection);
+};
+
} // namespace
class JsToCppTest : public testing::Test {
@@ -363,5 +403,15 @@ TEST_F(JsToCppTest, DISABLED_BitFlip) {
EXPECT_TRUE(cpp_side_connection.DidSucceed());
}
+// TODO(tsepez): Disabled due to http://crbug.com/366797.
+TEST_F(JsToCppTest, DISABLED_BackPointer) {
+ if (IsRunningOnIsolatedBot())
+ return;
+
+ BackPointerCppSideConnection cpp_side_connection;
+ RunTest("mojo/apps/js/test/js_to_cpp_unittest", &cpp_side_connection);
+ EXPECT_TRUE(cpp_side_connection.DidSucceed());
+}
+
} // namespace js
} // namespace mojo
« no previous file with comments | « mojo/apps/js/test/js_to_cpp.mojom ('k') | mojo/apps/js/test/js_to_cpp_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698