Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / pepper / pepper_gamepad_host_unittest.cc
index 43ff117..b5787e1 100644 (file)
@@ -22,14 +22,11 @@ namespace content {
 
 namespace {
 
-class PepperGamepadHostTest
-    : public testing::Test,
-      public BrowserPpapiHostTest {
+class PepperGamepadHostTest : public testing::Test,
+                              public BrowserPpapiHostTest {
  public:
-  PepperGamepadHostTest() {
-  }
-  virtual ~PepperGamepadHostTest() {
-  }
+  PepperGamepadHostTest() {}
+  ~PepperGamepadHostTest() override {}
 
   void ConstructService(const blink::WebGamepads& test_data) {
     service_.reset(new GamepadServiceTestConstructor(test_data));
@@ -55,7 +52,7 @@ inline ptrdiff_t AddressDiff(const void* a, const void* b) {
 TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) {
   // Hardware buffer.
   COMPILE_ASSERT(sizeof(ppapi::ContentGamepadHardwareBuffer) ==
-                 sizeof(GamepadHardwareBuffer),
+                     sizeof(GamepadHardwareBuffer),
                  gamepad_hardware_buffers_must_match);
   ppapi::ContentGamepadHardwareBuffer ppapi_buf;
   GamepadHardwareBuffer content_buf;
@@ -67,8 +64,7 @@ TEST_F(PepperGamepadHostTest, ValidateHardwareBuffersMatch) {
 
 TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) {
   // Gamepads.
-  COMPILE_ASSERT(sizeof(ppapi::WebKitGamepads) ==
-                 sizeof(blink::WebGamepads),
+  COMPILE_ASSERT(sizeof(ppapi::WebKitGamepads) == sizeof(blink::WebGamepads),
                  gamepads_data_must_match);
   ppapi::WebKitGamepads ppapi_gamepads;
   blink::WebGamepads web_gamepads;
@@ -88,8 +84,7 @@ TEST_F(PepperGamepadHostTest, ValidateGamepadsMatch) {
 
 TEST_F(PepperGamepadHostTest, ValidateGamepadMatch) {
   // Gamepad.
-  COMPILE_ASSERT(sizeof(ppapi::WebKitGamepad) ==
-                 sizeof(blink::WebGamepad),
+  COMPILE_ASSERT(sizeof(ppapi::WebKitGamepad) == sizeof(blink::WebGamepad),
                  gamepad_data_must_match);
   ppapi::WebKitGamepad ppapi_gamepad;
   blink::WebGamepad web_gamepad;
@@ -135,39 +130,29 @@ TEST_F(PepperGamepadHostTest, WaitForReply) {
 
   PP_Instance pp_instance = 12345;
   PP_Resource pp_resource = 67890;
-  PepperGamepadHost gamepad_host(gamepad_service(), GetBrowserPpapiHost(),
-                                 pp_instance, pp_resource);
+  PepperGamepadHost gamepad_host(
+      gamepad_service(), GetBrowserPpapiHost(), pp_instance, pp_resource);
 
   // Synthesize a request for gamepad data.
   ppapi::host::HostMessageContext context(
       ppapi::proxy::ResourceMessageCallParams(pp_resource, 1));
   EXPECT_EQ(PP_OK_COMPLETIONPENDING,
             gamepad_host.OnResourceMessageReceived(
-                PpapiHostMsg_Gamepad_RequestMemory(),
-                &context));
+                PpapiHostMsg_Gamepad_RequestMemory(), &context));
 
-  // Wait for the gamepad background thread to read twice to make sure we
-  // don't get a message yet (see below for why).
   MockGamepadDataFetcher* fetcher = service_->data_fetcher();
-  fetcher->WaitForDataRead();
-  fetcher->WaitForDataRead();
+  fetcher->WaitForDataReadAndCallbacksIssued();
 
   // It should not have sent the callback message.
   service_->message_loop().RunUntilIdle();
   EXPECT_EQ(0u, sink().message_count());
 
   // Set a button down and wait for it to be read twice.
-  //
-  // We wait for two reads before calling RunAllPending because the provider
-  // will read the data on the background thread (setting the event) and *then*
-  // will issue the callback on our thread. Waiting for it to read twice
-  // ensures that it was able to issue callbacks for the first read (if it
-  // issued one) before we try to check for it.
   blink::WebGamepads button_down_data = default_data;
-  button_down_data.items[0].buttons[0] = 1.f;
+  button_down_data.items[0].buttons[0].value = 1.f;
+  button_down_data.items[0].buttons[0].pressed = true;
   fetcher->SetTestData(button_down_data);
-  fetcher->WaitForDataRead();
-  fetcher->WaitForDataRead();
+  fetcher->WaitForDataReadAndCallbacksIssued();
 
   // It should have sent a callback.
   service_->message_loop().RunUntilIdle();
@@ -190,15 +175,16 @@ TEST_F(PepperGamepadHostTest, WaitForReply) {
   EXPECT_EQ(button_down_data.items[0].buttonsLength,
             buffer->buffer.items[0].buttons_length);
   for (size_t i = 0; i < ppapi::WebKitGamepad::kButtonsLengthCap; i++) {
-    EXPECT_EQ(button_down_data.items[0].buttons[i],
-              buffer->buffer.items[0].buttons[i]);
+    EXPECT_EQ(button_down_data.items[0].buttons[i].value,
+              buffer->buffer.items[0].buttons[i].value);
+    EXPECT_EQ(button_down_data.items[0].buttons[i].pressed,
+              buffer->buffer.items[0].buttons[i].pressed);
   }
 
   // Duplicate requests should be denied.
   EXPECT_EQ(PP_ERROR_FAILED,
             gamepad_host.OnResourceMessageReceived(
-                PpapiHostMsg_Gamepad_RequestMemory(),
-                &context));
+                PpapiHostMsg_Gamepad_RequestMemory(), &context));
 }
 
 }  // namespace content