| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ui/views/controls/webview/webview.h" | 5 #include "ui/views/controls/webview/webview.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 9 #include "content/public/browser/web_contents_observer.h" | 9 #include "content/public/browser/web_contents_observer.h" |
| 10 #include "content/public/test/test_browser_context.h" | 10 #include "content/public/test/test_browser_context.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "content/public/test/web_contents_tester.h" | 12 #include "content/public/test/web_contents_tester.h" |
| 13 #include "content/test/test_content_browser_client.h" | 13 #include "content/test/test_content_browser_client.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/views/test/test_views_delegate.h" | 15 #include "ui/views/test/test_views_delegate.h" |
| 16 #include "ui/views/test/widget_test.h" | 16 #include "ui/views/test/widget_test.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Provides functionality to create a test WebContents. | 20 // Provides functionality to create a test WebContents. |
| 21 class WebViewTestViewsDelegate : public views::TestViewsDelegate { | 21 class WebViewTestViewsDelegate : public views::TestViewsDelegate { |
| 22 public: | 22 public: |
| 23 WebViewTestViewsDelegate() {} | 23 WebViewTestViewsDelegate() {} |
| 24 virtual ~WebViewTestViewsDelegate() {} | 24 virtual ~WebViewTestViewsDelegate() {} |
| 25 | 25 |
| 26 // Overriden from TestViewsDelegate. | 26 // Overriden from TestViewsDelegate. |
| 27 virtual content::WebContents* CreateWebContents( | 27 virtual content::WebContents* CreateWebContents( |
| 28 content::BrowserContext* browser_context, | 28 content::BrowserContext* browser_context, |
| 29 content::SiteInstance* site_instance) OVERRIDE { | 29 content::SiteInstance* site_instance) override { |
| 30 return content::WebContentsTester::CreateTestWebContents(browser_context, | 30 return content::WebContentsTester::CreateTestWebContents(browser_context, |
| 31 site_instance); | 31 site_instance); |
| 32 } | 32 } |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 DISALLOW_COPY_AND_ASSIGN(WebViewTestViewsDelegate); | 35 DISALLOW_COPY_AND_ASSIGN(WebViewTestViewsDelegate); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Provides functionality to test a WebView. | 38 // Provides functionality to test a WebView. |
| 39 class WebViewUnitTest : public views::test::WidgetTest { | 39 class WebViewUnitTest : public views::test::WidgetTest { |
| 40 public: | 40 public: |
| 41 WebViewUnitTest() | 41 WebViewUnitTest() |
| 42 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), | 42 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), |
| 43 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | 43 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, |
| 44 base::MessageLoop::current()), | 44 base::MessageLoop::current()), |
| 45 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()) {} | 45 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()) {} |
| 46 | 46 |
| 47 virtual ~WebViewUnitTest() {} | 47 virtual ~WebViewUnitTest() {} |
| 48 | 48 |
| 49 virtual void SetUp() OVERRIDE { | 49 virtual void SetUp() override { |
| 50 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. | 50 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. |
| 51 WidgetTest::set_views_delegate(new WebViewTestViewsDelegate); | 51 WidgetTest::set_views_delegate(new WebViewTestViewsDelegate); |
| 52 browser_context_.reset(new content::TestBrowserContext); | 52 browser_context_.reset(new content::TestBrowserContext); |
| 53 WidgetTest::SetUp(); | 53 WidgetTest::SetUp(); |
| 54 // Set the test content browser client to avoid pulling in needless | 54 // Set the test content browser client to avoid pulling in needless |
| 55 // dependencies from content. | 55 // dependencies from content. |
| 56 SetBrowserClientForTesting(&test_browser_client_); | 56 SetBrowserClientForTesting(&test_browser_client_); |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void TearDown() OVERRIDE { | 59 virtual void TearDown() override { |
| 60 browser_context_.reset(NULL); | 60 browser_context_.reset(NULL); |
| 61 // Flush the message loop to execute pending relase tasks as this would | 61 // Flush the message loop to execute pending relase tasks as this would |
| 62 // upset ASAN and Valgrind. | 62 // upset ASAN and Valgrind. |
| 63 RunPendingMessages(); | 63 RunPendingMessages(); |
| 64 WidgetTest::TearDown(); | 64 WidgetTest::TearDown(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 protected: | 67 protected: |
| 68 content::BrowserContext* browser_context() { return browser_context_.get(); } | 68 content::BrowserContext* browser_context() { return browser_context_.get(); } |
| 69 | 69 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 88 shown_count_(0), | 88 shown_count_(0), |
| 89 hidden_count_(0) { | 89 hidden_count_(0) { |
| 90 content::WebContentsObserver::Observe(web_contents); | 90 content::WebContentsObserver::Observe(web_contents); |
| 91 } | 91 } |
| 92 | 92 |
| 93 virtual ~WebViewTestWebContentsObserver() { | 93 virtual ~WebViewTestWebContentsObserver() { |
| 94 if (web_contents_) | 94 if (web_contents_) |
| 95 content::WebContentsObserver::Observe(NULL); | 95 content::WebContentsObserver::Observe(NULL); |
| 96 } | 96 } |
| 97 | 97 |
| 98 virtual void WebContentsDestroyed() OVERRIDE { | 98 virtual void WebContentsDestroyed() override { |
| 99 DCHECK(web_contents_); | 99 DCHECK(web_contents_); |
| 100 content::WebContentsObserver::Observe(NULL); | 100 content::WebContentsObserver::Observe(NULL); |
| 101 web_contents_ = NULL; | 101 web_contents_ = NULL; |
| 102 } | 102 } |
| 103 | 103 |
| 104 virtual void WasShown() OVERRIDE { | 104 virtual void WasShown() override { |
| 105 valid_root_while_shown_ = | 105 valid_root_while_shown_ = |
| 106 web_contents()->GetNativeView()->GetRootWindow() != NULL; | 106 web_contents()->GetNativeView()->GetRootWindow() != NULL; |
| 107 was_shown_ = true; | 107 was_shown_ = true; |
| 108 ++shown_count_; | 108 ++shown_count_; |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual void WasHidden() OVERRIDE { | 111 virtual void WasHidden() override { |
| 112 was_shown_ = false; | 112 was_shown_ = false; |
| 113 ++hidden_count_; | 113 ++hidden_count_; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool was_shown() const { return was_shown_; } | 116 bool was_shown() const { return was_shown_; } |
| 117 | 117 |
| 118 int shown_count() const { return shown_count_; } | 118 int shown_count() const { return shown_count_; } |
| 119 | 119 |
| 120 int hidden_count() const { return hidden_count_; } | 120 int hidden_count() const { return hidden_count_; } |
| 121 | 121 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 EXPECT_EQ(observer1.shown_count(), 1); | 177 EXPECT_EQ(observer1.shown_count(), 1); |
| 178 EXPECT_EQ(observer1.hidden_count(), 1); | 178 EXPECT_EQ(observer1.hidden_count(), 1); |
| 179 EXPECT_EQ(observer2.shown_count(), 1); | 179 EXPECT_EQ(observer2.shown_count(), 1); |
| 180 EXPECT_EQ(observer2.hidden_count(), 0); | 180 EXPECT_EQ(observer2.hidden_count(), 0); |
| 181 | 181 |
| 182 widget->Close(); | 182 widget->Close(); |
| 183 RunPendingMessages(); | 183 RunPendingMessages(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 } // namespace | 186 } // namespace |
| OLD | NEW |