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 "content/renderer/pepper/ppapi_unittest.h" | 5 #include "content/renderer/pepper/ppapi_unittest.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "content/renderer/pepper/gfx_conversion.h" | 8 #include "content/renderer/pepper/gfx_conversion.h" |
9 #include "content/renderer/pepper/host_globals.h" | 9 #include "content/renderer/pepper/host_globals.h" |
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
11 #include "content/renderer/pepper/plugin_module.h" | 11 #include "content/renderer/pepper/plugin_module.h" |
| 12 #include "content/renderer/pepper/unittest_instance_util.h" |
12 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/c/pp_var.h" | 14 #include "ppapi/c/pp_var.h" |
14 #include "ppapi/c/ppp_instance.h" | 15 #include "ppapi/c/ppp_instance.h" |
15 #include "ppapi/shared_impl/ppapi_globals.h" | 16 #include "ppapi/shared_impl/ppapi_globals.h" |
16 #include "ppapi/shared_impl/ppapi_permissions.h" | 17 #include "ppapi/shared_impl/ppapi_permissions.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | |
21 | |
22 PpapiUnittest* current_unittest = NULL; | |
23 | |
24 const void* MockGetInterface(const char* interface_name) { | |
25 return current_unittest->GetMockInterface(interface_name); | |
26 } | |
27 | |
28 int MockInitializeModule(PP_Module, PPB_GetInterface) { | |
29 return PP_OK; | |
30 } | |
31 | |
32 // PPP_Instance implementation ------------------------------------------------ | |
33 | |
34 PP_Bool Instance_DidCreate(PP_Instance pp_instance, | |
35 uint32_t argc, | |
36 const char* argn[], | |
37 const char* argv[]) { | |
38 return PP_TRUE; | |
39 } | |
40 | |
41 void Instance_DidDestroy(PP_Instance instance) { | |
42 } | |
43 | |
44 void Instance_DidChangeView(PP_Instance pp_instance, PP_Resource view) { | |
45 } | |
46 | |
47 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) { | |
48 } | |
49 | |
50 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance, | |
51 PP_Resource pp_url_loader) { | |
52 return PP_FALSE; | |
53 } | |
54 | |
55 static PPP_Instance mock_instance_interface = { | |
56 &Instance_DidCreate, | |
57 &Instance_DidDestroy, | |
58 &Instance_DidChangeView, | |
59 &Instance_DidChangeFocus, | |
60 &Instance_HandleDocumentLoad | |
61 }; | |
62 | |
63 } // namespace | |
64 | |
65 // PpapiUnittest -------------------------------------------------------------- | |
66 | |
67 PpapiUnittest::PpapiUnittest() { | 21 PpapiUnittest::PpapiUnittest() { |
68 DCHECK(!current_unittest); | |
69 current_unittest = this; | |
70 } | 22 } |
71 | 23 |
72 PpapiUnittest::~PpapiUnittest() { | 24 PpapiUnittest::~PpapiUnittest() { |
73 DCHECK(current_unittest == this); | |
74 current_unittest = NULL; | |
75 } | 25 } |
76 | 26 |
77 void PpapiUnittest::SetUp() { | 27 void PpapiUnittest::SetUp() { |
78 message_loop_.reset(new base::MessageLoop()); | 28 message_loop_.reset(new base::MessageLoop()); |
79 | 29 |
80 // Initialize the mock module. | 30 ASSERT_TRUE(instance_util_.SetUp()); |
81 module_ = new PluginModule("Mock plugin", base::FilePath(), | |
82 ::ppapi::PpapiPermissions()); | |
83 ::ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); | |
84 PepperPluginInfo::EntryPoints entry_points; | |
85 entry_points.get_interface = &MockGetInterface; | |
86 entry_points.initialize_module = &MockInitializeModule; | |
87 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); | |
88 | |
89 // Initialize the mock instance. | |
90 instance_ = PepperPluginInstanceImpl::Create( | |
91 NULL, NULL, module(), NULL, GURL()); | |
92 } | 31 } |
93 | 32 |
94 void PpapiUnittest::TearDown() { | 33 void PpapiUnittest::TearDown() { |
95 instance_ = NULL; | |
96 module_ = NULL; | |
97 message_loop_.reset(); | 34 message_loop_.reset(); |
98 PluginModule::ResetHostGlobalsForTest(); | |
99 } | |
100 | 35 |
101 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { | 36 instance_util_.TearDown(); |
102 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) | |
103 return &mock_instance_interface; | |
104 return NULL; | |
105 } | |
106 | |
107 void PpapiUnittest::ShutdownModule() { | |
108 DCHECK(instance_->HasOneRef()); | |
109 instance_ = NULL; | |
110 DCHECK(module_->HasOneRef()); | |
111 module_ = NULL; | |
112 } | |
113 | |
114 void PpapiUnittest::SetViewSize(int width, int height) const { | |
115 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); | |
116 instance_->view_data_.clip_rect = instance_->view_data_.rect; | |
117 } | 37 } |
118 | 38 |
119 } // namespace content | 39 } // namespace content |
OLD | NEW |