| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/tests/test_utils.h" | 5 #include "ppapi/tests/test_utils.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #if defined(_MSC_VER) | 9 #if defined(_MSC_VER) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #else | 11 #else |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
| 16 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/var.h" | 17 #include "ppapi/cpp/var.h" |
| 18 | 18 |
| 19 namespace { |
| 20 |
| 21 bool IsBigEndian() { |
| 22 union { |
| 23 uint32_t integer32; |
| 24 uint8_t integer8[4]; |
| 25 } data = { 0x01020304 }; |
| 26 |
| 27 return data.integer8[0] == 1; |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 19 const int kActionTimeoutMs = 10000; | 32 const int kActionTimeoutMs = 10000; |
| 20 | 33 |
| 21 const PPB_Testing_Dev* GetTestingInterface() { | 34 const PPB_Testing_Dev* GetTestingInterface() { |
| 22 static const PPB_Testing_Dev* g_testing_interface = | 35 static const PPB_Testing_Dev* g_testing_interface = |
| 23 static_cast<const PPB_Testing_Dev*>( | 36 static_cast<const PPB_Testing_Dev*>( |
| 24 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); | 37 pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); |
| 25 return g_testing_interface; | 38 return g_testing_interface; |
| 26 } | 39 } |
| 27 | 40 |
| 28 std::string ReportError(const char* method, int32_t error) { | 41 std::string ReportError(const char* method, int32_t error) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return false; | 77 return false; |
| 65 | 78 |
| 66 int i = atoi(url.substr(components.port.begin, components.port.len).c_str()); | 79 int i = atoi(url.substr(components.port.begin, components.port.len).c_str()); |
| 67 if (i < 0 || i > 65535) | 80 if (i < 0 || i > 65535) |
| 68 return false; | 81 return false; |
| 69 *port = static_cast<uint16_t>(i); | 82 *port = static_cast<uint16_t>(i); |
| 70 | 83 |
| 71 return true; | 84 return true; |
| 72 } | 85 } |
| 73 | 86 |
| 87 uint16_t ConvertFromNetEndian16(uint16_t x) { |
| 88 if (IsBigEndian()) |
| 89 return x; |
| 90 else |
| 91 return (x << 8) | (x >> 8); |
| 92 } |
| 93 |
| 94 uint16_t ConvertToNetEndian16(uint16_t x) { |
| 95 if (IsBigEndian()) |
| 96 return x; |
| 97 else |
| 98 return (x << 8) | (x >> 8); |
| 99 } |
| 100 |
| 74 void NestedEvent::Wait() { | 101 void NestedEvent::Wait() { |
| 75 PP_DCHECK(pp::Module::Get()->core()->IsMainThread()); | 102 PP_DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 76 // Don't allow nesting more than once; it doesn't work with the code as-is, | 103 // Don't allow nesting more than once; it doesn't work with the code as-is, |
| 77 // and probably is a bad idea most of the time anyway. | 104 // and probably is a bad idea most of the time anyway. |
| 78 PP_DCHECK(!waiting_); | 105 PP_DCHECK(!waiting_); |
| 79 if (signalled_) | 106 if (signalled_) |
| 80 return; | 107 return; |
| 81 waiting_ = true; | 108 waiting_ = true; |
| 82 while (!signalled_) | 109 while (!signalled_) |
| 83 GetTestingInterface()->RunMessageLoop(instance_); | 110 GetTestingInterface()->RunMessageLoop(instance_); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); | 288 pp::MessageLoop loop(pp::MessageLoop::GetCurrent()); |
| 262 // If we don't have a message loop, we're probably running in process, where | 289 // If we don't have a message loop, we're probably running in process, where |
| 263 // PPB_MessageLoop is not supported. Just use the Testing message loop. | 290 // PPB_MessageLoop is not supported. Just use the Testing message loop. |
| 264 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) { | 291 if (loop.is_null() || loop == pp::MessageLoop::GetForMainThread()) { |
| 265 GetTestingInterface()->QuitMessageLoop(instance_); | 292 GetTestingInterface()->QuitMessageLoop(instance_); |
| 266 } else { | 293 } else { |
| 267 const bool should_quit = false; | 294 const bool should_quit = false; |
| 268 loop.PostQuit(should_quit); | 295 loop.PostQuit(should_quit); |
| 269 } | 296 } |
| 270 } | 297 } |
| OLD | NEW |