Use Persistent::Reset.
[chromium-blink-merge.git] / ppapi / native_client / tests / ppapi_browser / ppp_instance / ppapi_ppp_instance.cc
blobf77d58bcb4261332e4b0ec76bee1c1667e36aa1b
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string.h>
7 #include <vector>
9 #include "native_client/src/include/nacl_macros.h"
10 #include "native_client/src/shared/platform/nacl_check.h"
11 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
12 #include "native_client/tests/ppapi_test_lib/test_interface.h"
14 #include "ppapi/c/pp_bool.h"
15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/c/pp_input_event.h"
17 #include "ppapi/c/ppb_view.h"
18 #include "ppapi/c/ppp_instance.h"
20 namespace {
22 PP_Bool DidCreate(PP_Instance instance,
23 uint32_t argc,
24 const char* argn[],
25 const char* argv[]) {
26 printf("--- PPP_Instance::DidCreate\n");
27 PP_Bool status = DidCreateDefault(instance, argc, argn, argv);
28 // TEST_PASSED has no effect from this function.
29 // But as long as the plugin loads and tests are run, we know this succeeded.
30 // See ppapi_browser/bad for failing DidCreate.
31 return status;
34 // This should never be called.
35 void DidDestroy(PP_Instance instance) {
36 printf("--- PPP_Instance::DidDestroy\n");
37 CHECK(instance == pp_instance());
38 NACL_NOTREACHED();
41 void DidChangeView(PP_Instance instance, PP_Resource view) {
42 printf("--- PPP_Instance::DidChangeView\n");
43 EXPECT(instance == pp_instance());
45 PP_Rect clip;
46 PPBView()->GetClipRect(view, &clip);
47 EXPECT(clip.point.x == 0 && clip.point.y == 0);
49 // These are based on embed dimensions.
50 PP_Rect position;
51 PPBView()->GetRect(view, &position);
52 EXPECT(position.size.width == 15 && clip.size.width == 15);
53 EXPECT(position.size.height == 20 && clip.size.height == 20);
55 TEST_PASSED;
58 void DidChangeFocus(PP_Instance instance,
59 PP_Bool has_focus) {
60 printf("--- PPP_Instance::DidChangeFocus has_focus=%d\n", has_focus);
61 // There should be no focus on load, so this will trigger when we gain it
62 // and then release it and so on.
63 static bool expected_has_focus = true;
64 EXPECT(instance == pp_instance());
65 EXPECT(has_focus == expected_has_focus);
66 expected_has_focus = !expected_has_focus;
68 TEST_PASSED;
71 PP_Bool HandleDocumentLoad(PP_Instance instance,
72 PP_Resource url_loader) {
73 // Only called for full-frame plugins. For coverage see:
74 // tests/ppapi_browser/extension_mime_handler/
75 NACL_NOTREACHED();
76 return PP_FALSE;
79 const PPP_Instance ppp_instance_interface = {
80 DidCreate,
81 DidDestroy,
82 DidChangeView,
83 DidChangeFocus,
84 HandleDocumentLoad
87 } // namespace
90 void SetupTests() {
91 // Each PPP_Instance function called by the browser acts as a test.
94 void SetupPluginInterfaces() {
95 RegisterPluginInterface(PPP_INSTANCE_INTERFACE, &ppp_instance_interface);