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

Side by Side Diff: mojo/edk/js/tests/js_to_cpp_tests.cc

Issue 709603002: Move mojo/apps/js tests et al to mojo/edk/js/test,tests (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: chromium environment for JS tests Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "gin/array_buffer.h" 12 #include "gin/array_buffer.h"
13 #include "gin/public/isolate_holder.h" 13 #include "gin/public/isolate_holder.h"
14 #include "mojo/apps/js/mojo_runner_delegate.h" 14 #include "mojo/edk/js/mojo_runner_delegate.h"
15 #include "mojo/apps/js/test/js_to_cpp.mojom.h" 15 #include "mojo/edk/js/tests/js_to_cpp.mojom.h"
16 #include "mojo/common/common_type_converters.h"
17 #include "mojo/edk/test/test_utils.h" 16 #include "mojo/edk/test/test_utils.h"
18 #include "mojo/public/cpp/system/core.h" 17 #include "mojo/public/cpp/system/core.h"
19 #include "mojo/public/cpp/system/macros.h" 18 #include "mojo/public/cpp/system/macros.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 namespace mojo { 21 namespace mojo {
23 namespace js { 22 namespace js {
24 23
25 // Global value updated by some checks to prevent compilers from optimizing 24 // Global value updated by some checks to prevent compilers from optimizing
26 // reads out of existence. 25 // reads out of existence.
(...skipping 19 matching lines...) Expand all
46 const double kExpectedDoubleVal = 3.14159265358979323846; 45 const double kExpectedDoubleVal = 3.14159265358979323846;
47 const double kExpectedDoubleInf = std::numeric_limits<double>::infinity(); 46 const double kExpectedDoubleInf = std::numeric_limits<double>::infinity();
48 const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN(); 47 const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN();
49 const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal); 48 const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal);
50 const float kExpectedFloatInf = std::numeric_limits<float>::infinity(); 49 const float kExpectedFloatInf = std::numeric_limits<float>::infinity();
51 const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN(); 50 const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN();
52 51
53 // NaN has the property that it is not equal to itself. 52 // NaN has the property that it is not equal to itself.
54 #define EXPECT_NAN(x) EXPECT_NE(x, x) 53 #define EXPECT_NAN(x) EXPECT_NE(x, x)
55 54
56 bool IsRunningOnIsolatedBot() {
57 // TODO(yzshen): Remove this check once isolated tests are supported on the
58 // Chromium waterfall. (http://crbug.com/351214)
59 const base::FilePath test_file_path(
60 test::GetFilePathForJSResource(
61 "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom"));
62 if (!base::PathExists(test_file_path)) {
63 LOG(WARNING) << "Mojom binding files don't exist. Skipping the test.";
64 return true;
65 }
66 return false;
67 }
68
69 void CheckDataPipe(MojoHandle data_pipe_handle) { 55 void CheckDataPipe(MojoHandle data_pipe_handle) {
70 unsigned char buffer[100]; 56 unsigned char buffer[100];
71 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer)); 57 uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
72 MojoResult result = MojoReadData( 58 MojoResult result = MojoReadData(
73 data_pipe_handle, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE); 59 data_pipe_handle, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE);
74 EXPECT_EQ(MOJO_RESULT_OK, result); 60 EXPECT_EQ(MOJO_RESULT_OK, result);
75 EXPECT_EQ(64u, buffer_size); 61 EXPECT_EQ(64u, buffer_size);
76 for (int i = 0; i < 64; ++i) { 62 for (int i = 0; i < 64; ++i) {
77 EXPECT_EQ(i, buffer[i]); 63 EXPECT_EQ(i, buffer[i]);
78 } 64 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 MakeProxy<js_to_cpp::JsSide>(pipe.handle0.Pass()); 368 MakeProxy<js_to_cpp::JsSide>(pipe.handle0.Pass());
383 js_side.set_client(cpp_side); 369 js_side.set_client(cpp_side);
384 370
385 js_side.internal_state()->router_for_testing()->EnableTestingMode(); 371 js_side.internal_state()->router_for_testing()->EnableTestingMode();
386 372
387 cpp_side->set_js_side(js_side.get()); 373 cpp_side->set_js_side(js_side.get());
388 374
389 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, 375 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
390 gin::ArrayBufferAllocator::SharedInstance()); 376 gin::ArrayBufferAllocator::SharedInstance());
391 gin::IsolateHolder instance; 377 gin::IsolateHolder instance;
392 apps::MojoRunnerDelegate delegate; 378 MojoRunnerDelegate delegate;
393 gin::ShellRunner runner(&delegate, instance.isolate()); 379 gin::ShellRunner runner(&delegate, instance.isolate());
394 delegate.Start(&runner, pipe.handle1.release().value(), test); 380 delegate.Start(&runner, pipe.handle1.release().value(), test);
395 381
396 run_loop_.Run(); 382 run_loop_.Run();
397 } 383 }
398 384
399 private: 385 private:
400 base::ShadowingAtExitManager at_exit_; 386 base::ShadowingAtExitManager at_exit_;
401 base::MessageLoop loop; 387 base::MessageLoop loop;
402 base::RunLoop run_loop_; 388 base::RunLoop run_loop_;
403 389
404 DISALLOW_COPY_AND_ASSIGN(JsToCppTest); 390 DISALLOW_COPY_AND_ASSIGN(JsToCppTest);
405 }; 391 };
406 392
407 TEST_F(JsToCppTest, Ping) { 393 TEST_F(JsToCppTest, Ping) {
408 if (IsRunningOnIsolatedBot())
409 return;
410
411 PingCppSideConnection cpp_side_connection; 394 PingCppSideConnection cpp_side_connection;
412 RunTest("mojo/apps/js/test/js_to_cpp_unittest", &cpp_side_connection); 395 RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
413 EXPECT_TRUE(cpp_side_connection.DidSucceed()); 396 EXPECT_TRUE(cpp_side_connection.DidSucceed());
414 } 397 }
415 398
416 TEST_F(JsToCppTest, Echo) { 399 TEST_F(JsToCppTest, Echo) {
417 if (IsRunningOnIsolatedBot())
418 return;
419
420 EchoCppSideConnection cpp_side_connection; 400 EchoCppSideConnection cpp_side_connection;
421 RunTest("mojo/apps/js/test/js_to_cpp_unittest", &cpp_side_connection); 401 RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
422 EXPECT_TRUE(cpp_side_connection.DidSucceed()); 402 EXPECT_TRUE(cpp_side_connection.DidSucceed());
423 } 403 }
424 404
425 TEST_F(JsToCppTest, BitFlip) { 405 TEST_F(JsToCppTest, BitFlip) {
426 if (IsRunningOnIsolatedBot())
427 return;
428
429 BitFlipCppSideConnection cpp_side_connection; 406 BitFlipCppSideConnection cpp_side_connection;
430 RunTest("mojo/apps/js/test/js_to_cpp_unittest", &cpp_side_connection); 407 RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
431 EXPECT_TRUE(cpp_side_connection.DidSucceed()); 408 EXPECT_TRUE(cpp_side_connection.DidSucceed());
432 } 409 }
433 410
434 TEST_F(JsToCppTest, BackPointer) { 411 TEST_F(JsToCppTest, BackPointer) {
435 if (IsRunningOnIsolatedBot())
436 return;
437
438 BackPointerCppSideConnection cpp_side_connection; 412 BackPointerCppSideConnection cpp_side_connection;
439 RunTest("mojo/apps/js/test/js_to_cpp_unittest", &cpp_side_connection); 413 RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
440 EXPECT_TRUE(cpp_side_connection.DidSucceed()); 414 EXPECT_TRUE(cpp_side_connection.DidSucceed());
441 } 415 }
442 416
443 } // namespace js 417 } // namespace js
444 } // namespace mojo 418 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698