summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/webview/webview_unittest.cc
diff options
context:
space:
mode:
authornhiroki <nhiroki@chromium.org>2014-09-15 23:25:04 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-16 06:26:17 +0000
commite467a7139b660a5fddc72012cdc6628de9fa9f25 (patch)
tree386e606986c6dd2d9f6acffdb18d93cb738916a9 /ui/views/controls/webview/webview_unittest.cc
parent326fdba9410033d6d49d4d36ee44818e6a6e8a80 (diff)
downloadchromium_src-e467a7139b660a5fddc72012cdc6628de9fa9f25.zip
chromium_src-e467a7139b660a5fddc72012cdc6628de9fa9f25.tar.gz
chromium_src-e467a7139b660a5fddc72012cdc6628de9fa9f25.tar.bz2
Revert of When we switch tabs in chrome, the tab being switched away from gets hidden/shown/hidden. (patchset #14 id:260001 of https://codereview.chromium.org/564553002/)
Reason for revert: This seems to cause memory leaks in WebViewUnitTest.TestWebViewAttachDetachWebContents on Linux(ASan/LSan) and ChromiumOS(ASan/LSan) http://build.chromium.org/p/chromium.memory/builders/Linux%20ASan%20LSan%20Tests%20%282%29/builds/7468 Original issue's description: > When we switch tabs in chrome, the tab being switched away from gets hidden/shown/hidden. > > This occurs in the NativeViewHostAura::NativeViewDetaching code path where we first remove the > clipping window which is the intermediate parent of the web contents view. The clipping window > is hidden which causes the RWHVA::Hide function to get called which initiates the hiding sequence. > Then the web contents view is reparented to the main view which is still visible. Now the RWHVA::Show > function is called which initiates the show sequence. Eventually the main view is hidden, which then > initiates the hide sequence. > > Addressed this with the following changes. > 1. WebView::AttachWebContents and WebView::DetachWebContents > now show and hide the webcontents native view. The > WebContents is shown and hidden as before in > WebContentsNativeViewAura::OnWindowVisibilityChanged. > > 2. Removed the WebContentsNativeViewAura::OnWindowParentChanged function. > This function was present to show and hide the webcontents if the window was visible. > This should not be needed with the change in #1 above. > > 3. Added a new file webview_unittest.cc. This contains the unittest WebViewUnitTest.TestWebViewAttachDetachWebContents > This is run as part of unit_tests.exe. > > BUG=412989 > R=sky > > Committed: https://crrev.com/99941773a742f62892fc9aad1a1ebfb7cc967164 > Cr-Commit-Position: refs/heads/master@{#294962} TBR=sky@chromium.org,ananta@chromium.org NOTREECHECKS=true NOTRY=true BUG=412989 Review URL: https://codereview.chromium.org/577533003 Cr-Commit-Position: refs/heads/master@{#295020}
Diffstat (limited to 'ui/views/controls/webview/webview_unittest.cc')
-rw-r--r--ui/views/controls/webview/webview_unittest.cc163
1 files changed, 0 insertions, 163 deletions
diff --git a/ui/views/controls/webview/webview_unittest.cc b/ui/views/controls/webview/webview_unittest.cc
deleted file mode 100644
index 245370f..0000000
--- a/ui/views/controls/webview/webview_unittest.cc
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright 2014 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 "ui/views/controls/webview/webview.h"
-
-#include "base/memory/scoped_ptr.h"
-#include "content/browser/web_contents/web_contents_impl.h"
-#include "content/public/browser/web_contents_observer.h"
-#include "content/public/test/test_browser_context.h"
-#include "content/public/test/test_browser_thread.h"
-#include "content/public/test/web_contents_tester.h"
-#include "content/test/test_content_browser_client.h"
-#include "ui/aura/window.h"
-#include "ui/views/test/test_views_delegate.h"
-#include "ui/views/test/widget_test.h"
-
-namespace {
-
-// Provides functionality to create a test WebContents.
-class WebViewTestViewsDelegate : public views::TestViewsDelegate {
- public:
- WebViewTestViewsDelegate() {}
- virtual ~WebViewTestViewsDelegate() {}
-
- // Overriden from TestViewsDelegate.
- virtual content::WebContents* CreateWebContents(
- content::BrowserContext* browser_context,
- content::SiteInstance* site_instance) OVERRIDE {
- return content::WebContentsTester::CreateTestWebContents(browser_context,
- site_instance);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WebViewTestViewsDelegate);
-};
-
-// Provides functionality to test a WebView.
-class WebViewUnitTest : public views::test::WidgetTest {
- public:
- WebViewUnitTest()
- : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()) {}
-
- virtual ~WebViewUnitTest() {}
-
- virtual void SetUp() OVERRIDE {
- // The ViewsDelegate is deleted when the ViewsTestBase class is torn down.
- WidgetTest::set_views_delegate(new WebViewTestViewsDelegate);
- WidgetTest::SetUp();
- // Set the test content browser client to avoid pulling in needless
- // dependencies from content.
- SetBrowserClientForTesting(&test_browser_client_);
- }
-
- protected:
- content::BrowserContext* browser_context() { return &browser_context_; }
-
- private:
- content::TestBrowserThread ui_thread_;
- content::TestBrowserContext browser_context_;
- scoped_ptr<WebViewTestViewsDelegate> views_delegate_;
- content::TestContentBrowserClient test_browser_client_;
-
- DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest);
-};
-
-// Provides functionaity to observe events on a WebContents like WasShown/
-// WasHidden/WebContentsDestroyed.
-class WebViewTestWebContentsObserver : public content::WebContentsObserver {
- public:
- WebViewTestWebContentsObserver(content::WebContents* web_contents)
- : web_contents_(static_cast<content::WebContentsImpl*>(web_contents)),
- was_shown_(false),
- shown_count_(0),
- hidden_count_(0) {
- content::WebContentsObserver::Observe(web_contents);
- }
-
- virtual ~WebViewTestWebContentsObserver() {
- if (web_contents_)
- content::WebContentsObserver::Observe(NULL);
- }
-
- virtual void WebContentsDestroyed() OVERRIDE {
- DCHECK(web_contents_);
- content::WebContentsObserver::Observe(NULL);
- web_contents_ = NULL;
- }
-
- virtual void WasShown() OVERRIDE {
- was_shown_ = true;
- ++shown_count_;
- }
-
- virtual void WasHidden() OVERRIDE {
- was_shown_ = false;
- ++hidden_count_;
- }
-
- bool was_shown() const { return was_shown_; }
-
- int shown_count() const { return shown_count_; }
-
- int hidden_count() const { return hidden_count_; }
-
- private:
- content::WebContentsImpl* web_contents_;
- bool was_shown_;
- int32 shown_count_;
- int32 hidden_count_;
-
- DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsObserver);
-};
-
-// Tests that attaching and detaching a WebContents to a WebView makes the
-// WebContents visible and hidden respectively.
-TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) {
- // Create a top level widget and a webview as its content.
- views::Widget* widget = CreateTopLevelFramelessPlatformWidget();
- widget->SetBounds(gfx::Rect(0, 10, 100, 100));
- views::WebView* webview = new views::WebView(browser_context());
- widget->SetContentsView(webview);
- widget->Show();
-
- // Case 1: Create a new WebContents and set it in the webview via
- // SetWebContents. This should make the WebContents visible.
- content::WebContents::CreateParams params(browser_context());
- scoped_ptr<content::WebContents> web_contents1(
- content::WebContents::Create(params));
- WebViewTestWebContentsObserver observer1(web_contents1.get());
- EXPECT_FALSE(observer1.was_shown());
-
- webview->SetWebContents(web_contents1.get());
- EXPECT_TRUE(observer1.was_shown());
- EXPECT_TRUE(web_contents1->GetNativeView()->IsVisible());
- EXPECT_EQ(observer1.shown_count(), 1);
- EXPECT_EQ(observer1.hidden_count(), 0);
-
- // Case 2: Create another WebContents and replace the current WebContents
- // via SetWebContents(). This should hide the current WebContents and show
- // the new one.
- content::WebContents::CreateParams params2(browser_context());
- scoped_ptr<content::WebContents> web_contents2(
- content::WebContents::Create(params2));
- WebViewTestWebContentsObserver observer2(web_contents2.get());
- EXPECT_FALSE(observer2.was_shown());
-
- // Setting the new WebContents should hide the existing one.
- webview->SetWebContents(web_contents2.get());
- EXPECT_FALSE(observer1.was_shown());
- EXPECT_TRUE(observer2.was_shown());
-
- // WebContents1 should not get stray show calls when WebContents2 is set.
- EXPECT_EQ(observer1.shown_count(), 1);
- EXPECT_EQ(observer1.hidden_count(), 1);
- EXPECT_EQ(observer2.shown_count(), 1);
- EXPECT_EQ(observer2.hidden_count(), 0);
-
- widget->Close();
- RunPendingMessages();
-}
-
-} // namespace