1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)/* Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/**
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This file contains interface functions used for unit testing. Do not use in
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * production code. They are not guaranteed to be available in normal plugin
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * environments so you should not depend on them.
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)label Chrome {
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  M33 = 1.0
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)interface PPB_Testing_Private {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Reads the bitmap data out of the backing store for the given
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * DeviceContext2D and into the given image. If the data was successfully
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * read, it will return PP_TRUE.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * This function should not generally be necessary for normal plugin
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * operation. If you want to update portions of a device, the expectation is
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * that you will either regenerate the data, or maintain a backing store
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * pushing updates to the device from your backing store via PaintImageData.
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Using this function will introduce an extra copy which will make your
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * plugin slower. In some cases, this may be a very expensive operation (it
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * may require slow cross-process transitions or graphics card readbacks).
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Data will be read into the image starting at |top_left| in the device
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * context, and proceeding down and to the right for as many pixels as the
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * image is large. If any part of the image bound would fall outside of the
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * backing store of the device if positioned at |top_left|, this function
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * will fail and return PP_FALSE.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The image format must be of the format
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * PPB_ImageData.GetNativeImageDataFormat() or this function will fail and
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * return PP_FALSE.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * The returned image data will represent the current status of the backing
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * store. This will not include any paint, scroll, or replace operations
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * that have not yet been flushed; these operations are only reflected in
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * the backing store (and hence ReadImageData) until after a Flush()
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * operation has completed.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PP_Bool ReadImageData([in] PP_Resource device_context_2d,
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        [in] PP_Resource image,
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        [in] PP_Point top_left);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Runs a nested message loop. The plugin will be reentered from this call.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * This function is used for unit testing the API. The normal pattern is to
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * issue some asynchronous call that has a callback. Then you call
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * RunMessageLoop which will suspend the plugin and go back to processing
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * messages, giving the asynchronous operation time to complete. In your
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * callback, you save the data and call QuitMessageLoop, which will then
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * pop back up and continue with the test. This avoids having to write a
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * complicated state machine for simple tests for asynchronous APIs.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RunMessageLoop([in] PP_Instance instance);
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Posts a quit message for the outermost nested message loop. Use this to
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * exit and return back to the caller after you call RunMessageLoop.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void QuitMessageLoop([in] PP_Instance instance);
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Returns the number of live objects (resources + strings + objects)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * associated with this plugin instance. Used for detecting leaks. Returns
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * (uint32_t)-1 on failure.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint32_t GetLiveObjectsForInstance([in] PP_Instance instance);
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Returns PP_TRUE if the plugin is running out-of-process, PP_FALSE
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * otherwise.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PP_Bool IsOutOfProcess();
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Passes the input event to the browser, which sends it back to the
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * plugin. The plugin should implement PPP_InputEvent and register for
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * the input event type.
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * This method sends an input event through the browser just as if it had
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * come from the user. If the browser determines that it is an event for the
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * plugin, it will be sent to be handled by the plugin's PPP_InputEvent
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * interface. When generating mouse events, make sure the position is within
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * the plugin's area on the page. When generating a keyboard event, make sure
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * the plugin is focused.
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   *
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Note that the browser may generate extra input events in order to
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * maintain certain invariants, such as always having a "mouse enter" event
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * before any other mouse event. Furthermore, the event the plugin receives
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * after sending a simulated event will be slightly different from the
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * original event. The browser may change the timestamp, add modifiers, and
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * slightly alter the mouse position, due to coordinate transforms it
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * performs.
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SimulateInputEvent([in] PP_Instance instance,
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                          [in] PP_Resource input_event);
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Returns the URL for the document. This is a safe way to retrieve
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * window.location.href.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * If the canonicalized URL is valid, the method will parse the URL
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * and fill in the components structure. This pointer may be NULL
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * to specify that no component information is necessary.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PP_Var GetDocumentURL([in] PP_Instance instance,
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        [out] PP_URLComponents_Dev components);
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  /**
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * Fetches up to |array_size| active PP_Vars in the tracker. Returns the
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * number of vars in the tracker. The active vars are written to |live_vars|
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * contiguously starting at index 0. The vars are not in any particular order.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * If the number of live vars is greater than |array_size|, then an arbitrary
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * subset of |array_size| vars is written to |live_vars|. The reference count
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   * of the returned PP_Vars will *not* be affected by this call.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   */
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  uint32_t GetLiveVars([size_as=array_size] PP_Var[] live_vars,
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       [in] uint32_t array_size);
124c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
125c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  /**
126c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   * Sets the threshold size at which point we switch from transmitting
127c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   * array buffers in IPC messages to using shared memory. This is only used
128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   * for testing purposes where we need to transmit small buffers using shmem
129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   * (in order to have fast tests). Passing a value of 0 resets the threshold
130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   * to its default. The threshold is in bytes.
131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)   */
132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void SetMinimumArrayBufferSizeForShmem([in] PP_Instance instance,
133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                         [in] uint32_t threshold);
1346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  /**
1366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)   * Run the V8 garbage collector for tests.
1376e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)   */
1386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void RunV8GC([in] PP_Instance instance);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
140