OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #define UNIT_TEST // To get the ShadowingAtExitManager. |
| 6 #include "base/at_exit.h" |
| 7 |
5 #include "webkit/plugins/npapi/test/plugin_thread_async_call_test.h" | 8 #include "webkit/plugins/npapi/test/plugin_thread_async_call_test.h" |
6 | 9 |
7 #include "base/at_exit.h" | |
8 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
9 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
10 #include "webkit/plugins/npapi/test/plugin_client.h" | 12 #include "webkit/plugins/npapi/test/plugin_client.h" |
11 | 13 |
12 namespace NPAPIClient { | 14 namespace NPAPIClient { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // There are two plugin instances in this test. The long lived instance is used | 18 // There are two plugin instances in this test. The long lived instance is used |
17 // for reporting errors and signalling test completion. The short lived one is | 19 // for reporting errors and signalling test completion. The short lived one is |
(...skipping 22 matching lines...) Expand all Loading... |
40 g_long_lived_instance->SetError("Async callback invoked after NPP_Destroy"); | 42 g_long_lived_instance->SetError("Async callback invoked after NPP_Destroy"); |
41 } | 43 } |
42 | 44 |
43 void OnCallCompletedHelper(void* data) { | 45 void OnCallCompletedHelper(void* data) { |
44 static_cast<PluginThreadAsyncCallTest*>(data)->OnCallCompleted(); | 46 static_cast<PluginThreadAsyncCallTest*>(data)->OnCallCompleted(); |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 PluginThreadAsyncCallTest::PluginThreadAsyncCallTest( | 50 PluginThreadAsyncCallTest::PluginThreadAsyncCallTest( |
49 NPP id, NPNetscapeFuncs *host_functions) | 51 NPP id, NPNetscapeFuncs *host_functions) |
50 : PluginTest(id, host_functions) { | 52 : PluginTest(id, host_functions), at_exit_manager_(NULL) { |
| 53 } |
| 54 |
| 55 PluginThreadAsyncCallTest::~PluginThreadAsyncCallTest() { |
| 56 delete at_exit_manager_; |
51 } | 57 } |
52 | 58 |
53 NPError PluginThreadAsyncCallTest::New( | 59 NPError PluginThreadAsyncCallTest::New( |
54 uint16 mode, int16 argc, const char* argn[], const char* argv[], | 60 uint16 mode, int16 argc, const char* argn[], const char* argv[], |
55 NPSavedData* saved) { | 61 NPSavedData* saved) { |
56 NPError error = PluginTest::New(mode, argc, argn, argv, saved); | 62 NPError error = PluginTest::New(mode, argc, argn, argv, saved); |
57 if (error != NPERR_NO_ERROR) | 63 if (error != NPERR_NO_ERROR) |
58 return error; | 64 return error; |
59 | 65 |
60 // Determine whether this is the short lived instance. | 66 // Determine whether this is the short lived instance. |
61 for (int i = 0; i < argc; ++i) { | 67 for (int i = 0; i < argc; ++i) { |
62 if (base::strcasecmp(argn[i], "short_lived") == 0) { | 68 if (base::strcasecmp(argn[i], "short_lived") == 0) { |
63 if (base::strcasecmp(argv[i], "true") == 0) { | 69 if (base::strcasecmp(argv[i], "true") == 0) { |
64 g_short_lived_instance = this; | 70 g_short_lived_instance = this; |
65 } else { | 71 } else { |
66 g_long_lived_instance = this; | 72 g_long_lived_instance = this; |
67 } | 73 } |
68 } | 74 } |
69 } | 75 } |
70 | 76 |
71 // Schedule an async call that will succeed. Make sure to call that API from | 77 // Schedule an async call that will succeed. Make sure to call that API from |
72 // a different thread to fully test it. | 78 // a different thread to fully test it. |
73 if (this == g_short_lived_instance) { | 79 if (this == g_short_lived_instance) { |
74 at_exit_manager_.reset(new base::AtExitManager()); | 80 // This is slightly complicated thanks to the Linux shared library build, |
| 81 // which shares more compilation units between the NPAPI plug-in and |
| 82 // the base code. |
| 83 at_exit_manager_ = new base::ShadowingAtExitManager(); |
75 base::Thread random_thread("random_thread"); | 84 base::Thread random_thread("random_thread"); |
76 random_thread.Start(); | 85 random_thread.Start(); |
77 random_thread.message_loop()->PostTask(FROM_HERE, new AsyncCallTask(this)); | 86 random_thread.message_loop()->PostTask(FROM_HERE, new AsyncCallTask(this)); |
78 } | 87 } |
79 | 88 |
80 return NPERR_NO_ERROR; | 89 return NPERR_NO_ERROR; |
81 } | 90 } |
82 | 91 |
83 void PluginThreadAsyncCallTest::AsyncCall() { | 92 void PluginThreadAsyncCallTest::AsyncCall() { |
84 HostFunctions()->pluginthreadasynccall(id(), OnCallSucceededHelper, this); | 93 HostFunctions()->pluginthreadasynccall(id(), OnCallSucceededHelper, this); |
(...skipping 23 matching lines...) Expand all Loading... |
108 } | 117 } |
109 | 118 |
110 return NPERR_NO_ERROR; | 119 return NPERR_NO_ERROR; |
111 } | 120 } |
112 | 121 |
113 void PluginThreadAsyncCallTest::OnCallCompleted() { | 122 void PluginThreadAsyncCallTest::OnCallCompleted() { |
114 SignalTestCompleted(); | 123 SignalTestCompleted(); |
115 } | 124 } |
116 | 125 |
117 } // namespace NPAPIClient | 126 } // namespace NPAPIClient |
OLD | NEW |