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

Side by Side Diff: ui/views/controls/webview/webview_unittest.cc

Issue 2867663007: Use ScopedTaskEnvironment instead of MessageLoopForUI in ViewsTestBase. (Closed)
Patch Set: self-review Created 3 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 unified diff | Download patch
OLDNEW
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"
15 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/test/test_browser_context.h" 15 #include "content/public/test/test_browser_context.h"
18 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "content/public/test/web_contents_tester.h" 17 #include "content/public/test/web_contents_tester.h"
20 #include "content/test/test_content_browser_client.h" 18 #include "content/test/test_content_browser_client.h"
21 #include "ui/events/event.h" 19 #include "ui/events/event.h"
22 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
23 #include "ui/views/controls/native/native_view_host.h" 21 #include "ui/views/controls/native/native_view_host.h"
24 #include "ui/views/test/test_views_delegate.h" 22 #include "ui/views/test/test_views_delegate.h"
25 #include "ui/views/test/widget_test.h" 23 #include "ui/views/test/widget_test.h"
26 24
27 #if defined(USE_AURA) 25 #if defined(USE_AURA)
28 #include "ui/aura/window.h" 26 #include "ui/aura/window.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 bool is_fullscreened_; 123 bool is_fullscreened_;
126 124
127 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsDelegate); 125 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsDelegate);
128 }; 126 };
129 127
130 } // namespace 128 } // namespace
131 129
132 // Provides functionality to test a WebView. 130 // Provides functionality to test a WebView.
133 class WebViewUnitTest : public views::test::WidgetTest { 131 class WebViewUnitTest : public views::test::WidgetTest {
134 public: 132 public:
135 WebViewUnitTest() 133 WebViewUnitTest() = default;
136 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()),
137 scoped_task_scheduler_(base::MessageLoop::current()),
138 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING,
139 base::MessageLoop::current()),
140 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()),
141 top_level_widget_(nullptr) {}
142 134
143 ~WebViewUnitTest() override {} 135 ~WebViewUnitTest() override {}
144 136
145 void SetUp() override { 137 void SetUp() override {
146 set_views_delegate(base::WrapUnique(new WebViewTestViewsDelegate)); 138 set_views_delegate(base::WrapUnique(new WebViewTestViewsDelegate));
147 browser_context_.reset(new content::TestBrowserContext); 139 browser_context_.reset(new content::TestBrowserContext);
148 WidgetTest::SetUp(); 140 WidgetTest::SetUp();
149 // Set the test content browser client to avoid pulling in needless 141 // Set the test content browser client to avoid pulling in needless
150 // dependencies from content. 142 // dependencies from content.
151 SetBrowserClientForTesting(&test_browser_client_); 143 SetBrowserClientForTesting(&test_browser_client_);
(...skipping 26 matching lines...) Expand all
178 Widget* top_level_widget() const { return top_level_widget_; } 170 Widget* top_level_widget() const { return top_level_widget_; }
179 WebView* web_view() const { return web_view_; } 171 WebView* web_view() const { return web_view_; }
180 NativeViewHost* holder() const { return web_view_->holder_; } 172 NativeViewHost* holder() const { return web_view_->holder_; }
181 173
182 std::unique_ptr<content::WebContents> CreateWebContents() const { 174 std::unique_ptr<content::WebContents> CreateWebContents() const {
183 return base::WrapUnique(content::WebContents::Create( 175 return base::WrapUnique(content::WebContents::Create(
184 content::WebContents::CreateParams(browser_context_.get()))); 176 content::WebContents::CreateParams(browser_context_.get())));
185 } 177 }
186 178
187 private: 179 private:
188 content::TestBrowserThread ui_thread_; 180 content::TestBrowserThreadBundle test_browser_thread_bundle_;
189 base::test::ScopedTaskScheduler scoped_task_scheduler_;
190 content::TestBrowserThread file_blocking_thread_;
191 content::TestBrowserThread io_thread_;
192 std::unique_ptr<content::TestBrowserContext> browser_context_; 181 std::unique_ptr<content::TestBrowserContext> browser_context_;
193 content::TestContentBrowserClient test_browser_client_; 182 content::TestContentBrowserClient test_browser_client_;
194 183
195 Widget* top_level_widget_; 184 Widget* top_level_widget_ = nullptr;
196 WebView* web_view_; 185 WebView* web_view_ = nullptr;
197 186
198 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); 187 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest);
199 }; 188 };
200 189
201 // Tests that attaching and detaching a WebContents to a WebView makes the 190 // Tests that attaching and detaching a WebContents to a WebView makes the
202 // WebContents visible and hidden respectively. 191 // WebContents visible and hidden respectively.
203 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) { 192 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) {
204 // Case 1: Create a new WebContents and set it in the webview via 193 // Case 1: Create a new WebContents and set it in the webview via
205 // SetWebContents. This should make the WebContents visible. 194 // SetWebContents. This should make the WebContents visible.
206 const std::unique_ptr<content::WebContents> web_contents1( 195 const std::unique_ptr<content::WebContents> web_contents1(
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 469
481 // Remove WebView from views hierarchy. NativeView should be detached 470 // Remove WebView from views hierarchy. NativeView should be detached
482 // from Widget. 471 // from Widget.
483 contents_view->RemoveChildView(webview.get()); 472 contents_view->RemoveChildView(webview.get());
484 // Destroy WebView. NativeView should be detached secondary. 473 // Destroy WebView. NativeView should be detached secondary.
485 // There should be no crash. 474 // There should be no crash.
486 webview.reset(); 475 webview.reset();
487 } 476 }
488 477
489 } // namespace views 478 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/toolbar_action_view_unittest.cc ('k') | ui/views/test/views_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698