Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: content/renderer/pepper/pepper_webplugin_impl_browsertest.cc

Issue 1141793002: Reland: Fix WebViewPlugin::scheduleAnimation crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: filepath windows issue Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/pepper/pepper_webplugin_impl_browsertest.cc
diff --git a/content/renderer/pepper/pepper_webplugin_impl_browsertest.cc b/content/renderer/pepper/pepper_webplugin_impl_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21b28990202dbd6c6c3453e29fe280a1dcede6e3
--- /dev/null
+++ b/content/renderer/pepper/pepper_webplugin_impl_browsertest.cc
@@ -0,0 +1,197 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/common/content_client.h"
+#include "content/public/common/content_constants.h"
+#include "content/public/common/pepper_plugin_info.h"
+#include "content/public/renderer/content_renderer_client.h"
+#include "content/public/test/render_view_test.h"
+#include "content/renderer/pepper/pepper_webplugin_impl.h"
+#include "content/renderer/pepper/plugin_instance_throttler_impl.h"
+#include "content/renderer/pepper/plugin_module.h"
+#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
+#include "content/renderer/render_frame_impl.h"
+#include "content/test/test_content_client.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/c/ppb_graphics_2d.h"
+#include "ppapi/c/ppb_image_data.h"
+#include "ppapi/c/ppb_instance.h"
+#include "ppapi/c/ppp_instance.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
+
+namespace content {
+namespace {
+
+class PepperWebPluginImplBrowserTest
+ : public RenderViewTest,
+ public PluginInstanceThrottler::Observer {
+ public:
+ PepperWebPluginImplBrowserTest()
+ : throttler_(nullptr),
+ throttle_engaged_(false),
+ pp_module_(0),
+ pp_instance_(0),
+ graphics2d_(0) {}
+
+ void SetUp() override {
+ current_test_ = this;
+ RenderViewTest::SetUp();
+ }
+ void TearDown() override {
+ RenderViewTest::TearDown();
+ current_test_ = nullptr;
+ }
+ ContentClient* CreateContentClient() override {
+ return new MockContentClient;
+ }
+ ContentRendererClient* CreateContentRendererClient() override {
+ return new MockContentRendererClient;
+ }
+
+ // PluginInstanceThrottler::Observer implementation
+ void OnThrottleStateChange() override {
+ if (throttler_->IsThrottled())
+ throttle_engaged_ = true;
+ }
+
+ protected:
+ // PPP implementation
+ static const void* GetInterface(const char* name) {
+ static PPP_Instance ppp_instance = {
+ &PepperWebPluginImplBrowserTest::DidCreate,
+ &PepperWebPluginImplBrowserTest::DidDestroy,
+ &PepperWebPluginImplBrowserTest::DidChangeView,
+ &PepperWebPluginImplBrowserTest::DidChangeFocus,
+ &PepperWebPluginImplBrowserTest::HandleDocumentLoad};
+ if (!strcmp(name, PPP_INSTANCE_INTERFACE))
+ return &ppp_instance;
+ return nullptr;
+ }
+ static int InitializeModule(PP_Module module,
+ PPB_GetInterface get_interface) {
+ EXPECT_EQ(0, current_test_->pp_module_);
+ current_test_->pp_module_ = module;
+ ppb_core_ = static_cast<const PPB_Core*>(get_interface(PPB_CORE_INTERFACE));
+ ppb_graphics2d_ = static_cast<const PPB_Graphics2D*>(
+ get_interface(PPB_GRAPHICS_2D_INTERFACE));
+ ppb_image_data_ = static_cast<const PPB_ImageData*>(
+ get_interface(PPB_IMAGEDATA_INTERFACE));
+ ppb_instance_ =
+ static_cast<const PPB_Instance*>(get_interface(PPB_INSTANCE_INTERFACE));
+ return PP_OK;
+ }
+ static void ShutdownModule() {
+ EXPECT_NE(0, current_test_->pp_module_);
+ current_test_->pp_module_ = 0;
+ }
+
+ static void DummyCallback(void*, int32_t) {}
raymes 2015/05/18 04:39:06 nit: newline below
+ void PaintSomething() {
+ PP_Size size = {2, 1};
+ PP_Resource image = ppb_image_data_->Create(
+ pp_instance_, ppb_image_data_->GetNativeImageDataFormat(), &size,
+ PP_TRUE);
+ int32_t* pixels = static_cast<int32_t*>(ppb_image_data_->Map(image));
+ pixels[0] = 0xff000000;
+ pixels[1] = 0xffffffff;
+ ppb_image_data_->Unmap(image);
+ ppb_graphics2d_->ReplaceContents(graphics2d_, image);
+ PP_CompletionCallback callback = {
+ &PepperWebPluginImplBrowserTest::DummyCallback, nullptr, 0};
+ ppb_graphics2d_->Flush(graphics2d_, callback);
+ ppb_core_->ReleaseResource(image);
+ }
+
+ // PPP_Instance implementation
+ static PP_Bool DidCreate(PP_Instance instance,
+ uint32_t,
+ const char* [],
+ const char* []) {
+ EXPECT_EQ(0, current_test_->pp_instance_);
+ current_test_->pp_instance_ = instance;
+ PP_Size size = {2, 1};
+ current_test_->graphics2d_ =
+ ppb_graphics2d_->Create(instance, &size, PP_TRUE);
+ ppb_instance_->BindGraphics(instance, current_test_->graphics2d_);
+ return PP_TRUE;
+ }
+ static void DidDestroy(PP_Instance instance) {
+ EXPECT_NE(0, current_test_->pp_instance_);
+ current_test_->PaintSomething();
+ ppb_core_->ReleaseResource(current_test_->graphics2d_);
+ current_test_->pp_instance_ = 0;
+ }
+ static void DidChangeView(PP_Instance, PP_Resource) {}
+ static void DidChangeFocus(PP_Instance, PP_Bool) {}
+ static PP_Bool HandleDocumentLoad(PP_Instance, PP_Resource) {
+ return PP_FALSE;
+ }
+
+ static PepperPluginInfo GetPluginInfo() {
+ PepperPluginInfo info;
+ info.is_internal = true;
+ info.path = base::FilePath(FILE_PATH_LITERAL("internal-always-throttle"));
+ info.name = kAlwaysThrottleTestPluginName;
+ info.mime_types.push_back(
+ WebPluginMimeType("test/always-throttle", "", ""));
+ info.internal_entry_points.get_interface =
+ &PepperWebPluginImplBrowserTest::GetInterface;
+ info.internal_entry_points.initialize_module =
+ &PepperWebPluginImplBrowserTest::InitializeModule;
+ info.internal_entry_points.shutdown_module =
+ &PepperWebPluginImplBrowserTest::ShutdownModule;
+ return info;
+ }
+
+ class MockContentClient : public TestContentClient {
+ public:
+ void AddPepperPlugins(std::vector<PepperPluginInfo>* plugins) override {
+ plugins->push_back(GetPluginInfo());
+ }
+ };
+ class MockContentRendererClient : public ContentRendererClient {
+ public:
+ bool OverrideCreatePlugin(RenderFrame* render_frame,
+ blink::WebLocalFrame* frame,
+ const blink::WebPluginParams& params,
+ blink::WebPlugin** plugin) override {
+ current_test_->throttler_ = new PluginInstanceThrottlerImpl;
+ current_test_->throttler_->AddObserver(current_test_);
+ *plugin = render_frame->CreatePlugin(frame,
+ GetPluginInfo().ToWebPluginInfo(), params,
+ make_scoped_ptr(current_test_->throttler_));
+ return *plugin;
+ }
+ };
+
+ PluginInstanceThrottlerImpl* throttler_;
+ bool throttle_engaged_;
+ PP_Module pp_module_;
+ PP_Instance pp_instance_;
+ PP_Resource graphics2d_;
+ static PepperWebPluginImplBrowserTest* current_test_;
+ static const PPB_Core* ppb_core_;
+ static const PPB_Graphics2D* ppb_graphics2d_;
+ static const PPB_ImageData* ppb_image_data_;
+ static const PPB_Instance* ppb_instance_;
+};
+PepperWebPluginImplBrowserTest* PepperWebPluginImplBrowserTest::current_test_;
+const PPB_Core* PepperWebPluginImplBrowserTest::ppb_core_;
+const PPB_Graphics2D* PepperWebPluginImplBrowserTest::ppb_graphics2d_;
+const PPB_ImageData* PepperWebPluginImplBrowserTest::ppb_image_data_;
+const PPB_Instance* PepperWebPluginImplBrowserTest::ppb_instance_;
+
+TEST_F(PepperWebPluginImplBrowserTest, NotEngageThrottleDuringDestroy) {
raymes 2015/05/18 04:39:06 nit: perhaps add a comment saying what this does w
+ LoadHTML("<!DOCTYPE html><object type='test/always-throttle'></object>");
+ EXPECT_NE(0, pp_instance_);
+ LoadHTML("");
+ EXPECT_EQ(0, pp_instance_);
+ EXPECT_FALSE(throttle_engaged_);
+}
+
+} // unnamed namespace
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698