Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / tests / WebHelperPluginTest.cpp
blobc6ed4545ebb20b32a13508055330c4302c1d7ce3
1 // Copyright 2014 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 "config.h"
6 #include "public/web/WebHelperPlugin.h"
8 #include "platform/testing/UnitTestHelpers.h"
9 #include "public/web/WebFrameClient.h"
10 #include "public/web/WebLocalFrame.h"
11 #include "web/tests/FakeWebPlugin.h"
12 #include "web/tests/FrameTestHelpers.h"
13 #include <gtest/gtest.h>
15 namespace blink {
17 namespace {
19 class FakePlaceholderWebPlugin : public FakeWebPlugin {
20 public:
21 FakePlaceholderWebPlugin(WebFrame* frame, const WebPluginParams& params)
22 : FakeWebPlugin(frame, params)
25 ~FakePlaceholderWebPlugin() override {}
27 bool isPlaceholder() override { return true; }
30 class WebHelperPluginFrameClient : public FrameTestHelpers::TestWebFrameClient {
31 public:
32 WebHelperPluginFrameClient() : m_createPlaceholder(false) {}
33 ~WebHelperPluginFrameClient() override {}
35 WebPlugin* createPlugin(WebLocalFrame* frame, const WebPluginParams& params) override
37 return m_createPlaceholder ? new FakePlaceholderWebPlugin(frame, params) : new FakeWebPlugin(frame, params);
40 void setCreatePlaceholder(bool createPlaceholder) { m_createPlaceholder = createPlaceholder; }
42 private:
43 bool m_createPlaceholder;
46 class WebHelperPluginTest : public ::testing::Test {
47 protected:
48 void SetUp() override
50 m_helper.initializeAndLoad("about:blank", false, &m_frameClient);
54 void destroyHelperPlugin()
56 m_plugin.clear();
57 // WebHelperPlugin is destroyed by a task posted to the message loop.
58 testing::runPendingTasks();
61 FrameTestHelpers::WebViewHelper m_helper;
62 WebHelperPluginFrameClient m_frameClient;
63 OwnPtr<WebHelperPlugin> m_plugin;
66 TEST_F(WebHelperPluginTest, CreateAndDestroyAfterWebViewDestruction)
68 m_plugin = adoptPtr(WebHelperPlugin::create("hello", m_helper.webView()->mainFrame()->toWebLocalFrame()));
69 EXPECT_TRUE(m_plugin);
70 EXPECT_TRUE(m_plugin->getPlugin());
72 m_helper.reset();
73 destroyHelperPlugin();
76 TEST_F(WebHelperPluginTest, CreateAndDestroyBeforeWebViewDestruction)
78 m_plugin = adoptPtr(WebHelperPlugin::create("hello", m_helper.webView()->mainFrame()->toWebLocalFrame()));
79 EXPECT_TRUE(m_plugin);
80 EXPECT_TRUE(m_plugin->getPlugin());
82 destroyHelperPlugin();
83 m_helper.reset();
86 TEST_F(WebHelperPluginTest, CreateFailsWithPlaceholder)
88 m_frameClient.setCreatePlaceholder(true);
90 m_plugin = adoptPtr(WebHelperPlugin::create("hello", m_helper.webView()->mainFrame()->toWebLocalFrame()));
91 EXPECT_EQ(0, m_plugin.get());
94 } // namespace
96 } // namespace