| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/test/scoped_task_scheduler.h" |
| 13 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
| 16 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 17 #include "content/public/test/web_contents_tester.h" | 19 #include "content/public/test/web_contents_tester.h" |
| 18 #include "content/test/test_content_browser_client.h" | 20 #include "content/test/test_content_browser_client.h" |
| 19 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 20 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
| 21 #include "ui/views/controls/native/native_view_host.h" | 23 #include "ui/views/controls/native/native_view_host.h" |
| 22 #include "ui/views/test/test_views_delegate.h" | 24 #include "ui/views/test/test_views_delegate.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsDelegate); | 127 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsDelegate); |
| 126 }; | 128 }; |
| 127 | 129 |
| 128 } // namespace | 130 } // namespace |
| 129 | 131 |
| 130 // Provides functionality to test a WebView. | 132 // Provides functionality to test a WebView. |
| 131 class WebViewUnitTest : public views::test::WidgetTest { | 133 class WebViewUnitTest : public views::test::WidgetTest { |
| 132 public: | 134 public: |
| 133 WebViewUnitTest() | 135 WebViewUnitTest() |
| 134 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), | 136 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), |
| 137 scoped_task_scheduler_(base::MessageLoop::current()), |
| 135 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | 138 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, |
| 136 base::MessageLoop::current()), | 139 base::MessageLoop::current()), |
| 137 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), | 140 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), |
| 138 top_level_widget_(nullptr) {} | 141 top_level_widget_(nullptr) {} |
| 139 | 142 |
| 140 ~WebViewUnitTest() override {} | 143 ~WebViewUnitTest() override {} |
| 141 | 144 |
| 142 void SetUp() override { | 145 void SetUp() override { |
| 143 set_views_delegate(base::WrapUnique(new WebViewTestViewsDelegate)); | 146 set_views_delegate(base::WrapUnique(new WebViewTestViewsDelegate)); |
| 144 browser_context_.reset(new content::TestBrowserContext); | 147 browser_context_.reset(new content::TestBrowserContext); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 WebView* web_view() const { return web_view_; } | 179 WebView* web_view() const { return web_view_; } |
| 177 NativeViewHost* holder() const { return web_view_->holder_; } | 180 NativeViewHost* holder() const { return web_view_->holder_; } |
| 178 | 181 |
| 179 std::unique_ptr<content::WebContents> CreateWebContents() const { | 182 std::unique_ptr<content::WebContents> CreateWebContents() const { |
| 180 return base::WrapUnique(content::WebContents::Create( | 183 return base::WrapUnique(content::WebContents::Create( |
| 181 content::WebContents::CreateParams(browser_context_.get()))); | 184 content::WebContents::CreateParams(browser_context_.get()))); |
| 182 } | 185 } |
| 183 | 186 |
| 184 private: | 187 private: |
| 185 content::TestBrowserThread ui_thread_; | 188 content::TestBrowserThread ui_thread_; |
| 189 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
| 186 content::TestBrowserThread file_blocking_thread_; | 190 content::TestBrowserThread file_blocking_thread_; |
| 187 content::TestBrowserThread io_thread_; | 191 content::TestBrowserThread io_thread_; |
| 188 std::unique_ptr<content::TestBrowserContext> browser_context_; | 192 std::unique_ptr<content::TestBrowserContext> browser_context_; |
| 189 content::TestContentBrowserClient test_browser_client_; | 193 content::TestContentBrowserClient test_browser_client_; |
| 190 | 194 |
| 191 Widget* top_level_widget_; | 195 Widget* top_level_widget_; |
| 192 WebView* web_view_; | 196 WebView* web_view_; |
| 193 | 197 |
| 194 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); | 198 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); |
| 195 }; | 199 }; |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 480 |
| 477 // Remove WebView from views hierarchy. NativeView should be detached | 481 // Remove WebView from views hierarchy. NativeView should be detached |
| 478 // from Widget. | 482 // from Widget. |
| 479 contents_view->RemoveChildView(webview.get()); | 483 contents_view->RemoveChildView(webview.get()); |
| 480 // Destroy WebView. NativeView should be detached secondary. | 484 // Destroy WebView. NativeView should be detached secondary. |
| 481 // There should be no crash. | 485 // There should be no crash. |
| 482 webview.reset(); | 486 webview.reset(); |
| 483 } | 487 } |
| 484 | 488 |
| 485 } // namespace views | 489 } // namespace views |
| OLD | NEW |