Chromium Code Reviews| 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..1ca25dc20368cfa679ae6a72acab871fb0321d47 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_; |
| @@ -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); |
| @@ -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: |
| + explicit BackPointerCppSideConnection() : termination_seen_(false) {} |
|
viettrungluu
2014/05/20 18:10:24
nit: no need for "explicit"
|
| + 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 |