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

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

Issue 1868363002: Replace scoped_ptr with std::unique_ptr in //ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scopedptrcc
Patch Set: scopedptrui: rebase-make_scoped_ptr Created 4 years, 8 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
« no previous file with comments | « ui/views/controls/webview/webview.cc ('k') | ui/views/corewm/cursor_height_provider_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
10
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/ptr_util.h"
11 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_observer.h" 14 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/test/test_browser_context.h" 15 #include "content/public/test/test_browser_context.h"
14 #include "content/public/test/test_browser_thread.h" 16 #include "content/public/test/test_browser_thread.h"
15 #include "content/public/test/web_contents_tester.h" 17 #include "content/public/test/web_contents_tester.h"
16 #include "content/test/test_content_browser_client.h" 18 #include "content/test/test_content_browser_client.h"
17 #include "ui/events/event.h" 19 #include "ui/events/event.h"
18 #include "ui/events/event_utils.h" 20 #include "ui/events/event_utils.h"
19 #include "ui/views/controls/native/native_view_host.h" 21 #include "ui/views/controls/native/native_view_host.h"
20 #include "ui/views/test/test_views_delegate.h" 22 #include "ui/views/test/test_views_delegate.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 WebViewUnitTest() 133 WebViewUnitTest()
132 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), 134 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()),
133 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, 135 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING,
134 base::MessageLoop::current()), 136 base::MessageLoop::current()),
135 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), 137 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()),
136 top_level_widget_(nullptr) {} 138 top_level_widget_(nullptr) {}
137 139
138 ~WebViewUnitTest() override {} 140 ~WebViewUnitTest() override {}
139 141
140 void SetUp() override { 142 void SetUp() override {
141 set_views_delegate(make_scoped_ptr(new WebViewTestViewsDelegate)); 143 set_views_delegate(base::WrapUnique(new WebViewTestViewsDelegate));
142 browser_context_.reset(new content::TestBrowserContext); 144 browser_context_.reset(new content::TestBrowserContext);
143 WidgetTest::SetUp(); 145 WidgetTest::SetUp();
144 // Set the test content browser client to avoid pulling in needless 146 // Set the test content browser client to avoid pulling in needless
145 // dependencies from content. 147 // dependencies from content.
146 SetBrowserClientForTesting(&test_browser_client_); 148 SetBrowserClientForTesting(&test_browser_client_);
147 149
148 // Create a top level widget and add a child, and give it a WebView as a 150 // Create a top level widget and add a child, and give it a WebView as a
149 // child. 151 // child.
150 top_level_widget_ = CreateTopLevelFramelessPlatformWidget(); 152 top_level_widget_ = CreateTopLevelFramelessPlatformWidget();
151 top_level_widget_->SetBounds(gfx::Rect(0, 10, 100, 100)); 153 top_level_widget_->SetBounds(gfx::Rect(0, 10, 100, 100));
(...skipping 15 matching lines...) Expand all
167 // upset ASAN and Valgrind. 169 // upset ASAN and Valgrind.
168 RunPendingMessages(); 170 RunPendingMessages();
169 WidgetTest::TearDown(); 171 WidgetTest::TearDown();
170 } 172 }
171 173
172 protected: 174 protected:
173 Widget* top_level_widget() const { return top_level_widget_; } 175 Widget* top_level_widget() const { return top_level_widget_; }
174 WebView* web_view() const { return web_view_; } 176 WebView* web_view() const { return web_view_; }
175 NativeViewHost* holder() const { return web_view_->holder_; } 177 NativeViewHost* holder() const { return web_view_->holder_; }
176 178
177 scoped_ptr<content::WebContents> CreateWebContents() const { 179 std::unique_ptr<content::WebContents> CreateWebContents() const {
178 return make_scoped_ptr(content::WebContents::Create( 180 return base::WrapUnique(content::WebContents::Create(
179 content::WebContents::CreateParams(browser_context_.get()))); 181 content::WebContents::CreateParams(browser_context_.get())));
180 } 182 }
181 183
182 private: 184 private:
183 content::TestBrowserThread ui_thread_; 185 content::TestBrowserThread ui_thread_;
184 content::TestBrowserThread file_blocking_thread_; 186 content::TestBrowserThread file_blocking_thread_;
185 content::TestBrowserThread io_thread_; 187 content::TestBrowserThread io_thread_;
186 scoped_ptr<content::TestBrowserContext> browser_context_; 188 std::unique_ptr<content::TestBrowserContext> browser_context_;
187 content::TestContentBrowserClient test_browser_client_; 189 content::TestContentBrowserClient test_browser_client_;
188 190
189 Widget* top_level_widget_; 191 Widget* top_level_widget_;
190 WebView* web_view_; 192 WebView* web_view_;
191 193
192 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); 194 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest);
193 }; 195 };
194 196
195 // Tests that attaching and detaching a WebContents to a WebView makes the 197 // Tests that attaching and detaching a WebContents to a WebView makes the
196 // WebContents visible and hidden respectively. 198 // WebContents visible and hidden respectively.
197 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) { 199 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) {
198 // Case 1: Create a new WebContents and set it in the webview via 200 // Case 1: Create a new WebContents and set it in the webview via
199 // SetWebContents. This should make the WebContents visible. 201 // SetWebContents. This should make the WebContents visible.
200 const scoped_ptr<content::WebContents> web_contents1(CreateWebContents()); 202 const std::unique_ptr<content::WebContents> web_contents1(
203 CreateWebContents());
201 WebViewTestWebContentsObserver observer1(web_contents1.get()); 204 WebViewTestWebContentsObserver observer1(web_contents1.get());
202 EXPECT_FALSE(observer1.was_shown()); 205 EXPECT_FALSE(observer1.was_shown());
203 206
204 web_view()->SetWebContents(web_contents1.get()); 207 web_view()->SetWebContents(web_contents1.get());
205 EXPECT_TRUE(observer1.was_shown()); 208 EXPECT_TRUE(observer1.was_shown());
206 #if defined(USE_AURA) 209 #if defined(USE_AURA)
207 EXPECT_TRUE(web_contents1->GetNativeView()->IsVisible()); 210 EXPECT_TRUE(web_contents1->GetNativeView()->IsVisible());
208 #endif 211 #endif
209 EXPECT_EQ(observer1.shown_count(), 1); 212 EXPECT_EQ(observer1.shown_count(), 1);
210 EXPECT_EQ(observer1.hidden_count(), 0); 213 EXPECT_EQ(observer1.hidden_count(), 0);
211 EXPECT_TRUE(observer1.valid_root_while_shown()); 214 EXPECT_TRUE(observer1.valid_root_while_shown());
212 215
213 // Case 2: Create another WebContents and replace the current WebContents 216 // Case 2: Create another WebContents and replace the current WebContents
214 // via SetWebContents(). This should hide the current WebContents and show 217 // via SetWebContents(). This should hide the current WebContents and show
215 // the new one. 218 // the new one.
216 const scoped_ptr<content::WebContents> web_contents2(CreateWebContents()); 219 const std::unique_ptr<content::WebContents> web_contents2(
220 CreateWebContents());
217 WebViewTestWebContentsObserver observer2(web_contents2.get()); 221 WebViewTestWebContentsObserver observer2(web_contents2.get());
218 EXPECT_FALSE(observer2.was_shown()); 222 EXPECT_FALSE(observer2.was_shown());
219 223
220 // Setting the new WebContents should hide the existing one. 224 // Setting the new WebContents should hide the existing one.
221 web_view()->SetWebContents(web_contents2.get()); 225 web_view()->SetWebContents(web_contents2.get());
222 EXPECT_FALSE(observer1.was_shown()); 226 EXPECT_FALSE(observer1.was_shown());
223 EXPECT_TRUE(observer2.was_shown()); 227 EXPECT_TRUE(observer2.was_shown());
224 EXPECT_TRUE(observer2.valid_root_while_shown()); 228 EXPECT_TRUE(observer2.valid_root_while_shown());
225 229
226 // WebContents1 should not get stray show calls when WebContents2 is set. 230 // WebContents1 should not get stray show calls when WebContents2 is set.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 parent2->Close(); 285 parent2->Close();
282 } 286 }
283 287
284 // Tests that the layout of the NativeViewHost within WebView behaves as 288 // Tests that the layout of the NativeViewHost within WebView behaves as
285 // expected when embedding a fullscreen widget during WebContents screen 289 // expected when embedding a fullscreen widget during WebContents screen
286 // capture. 290 // capture.
287 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Layout) { 291 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Layout) {
288 web_view()->SetEmbedFullscreenWidgetMode(true); 292 web_view()->SetEmbedFullscreenWidgetMode(true);
289 ASSERT_EQ(1, web_view()->child_count()); 293 ASSERT_EQ(1, web_view()->child_count());
290 294
291 const scoped_ptr<content::WebContents> web_contents(CreateWebContents()); 295 const std::unique_ptr<content::WebContents> web_contents(CreateWebContents());
292 WebViewTestWebContentsDelegate delegate; 296 WebViewTestWebContentsDelegate delegate;
293 web_contents->SetDelegate(&delegate); 297 web_contents->SetDelegate(&delegate);
294 web_view()->SetWebContents(web_contents.get()); 298 web_view()->SetWebContents(web_contents.get());
295 299
296 // Initially, the holder should fill the entire WebView. 300 // Initially, the holder should fill the entire WebView.
297 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 301 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
298 302
299 // Simulate a transition into fullscreen mode, but without screen capture 303 // Simulate a transition into fullscreen mode, but without screen capture
300 // active on the WebContents, the holder should still fill the entire 304 // active on the WebContents, the holder should still fill the entire
301 // WebView like before. 305 // WebView like before.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 } 338 }
335 339
336 // Tests that a WebView correctly switches between WebContentses when one of 340 // Tests that a WebView correctly switches between WebContentses when one of
337 // them is embedding a fullscreen widget during WebContents screen capture. 341 // them is embedding a fullscreen widget during WebContents screen capture.
338 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) { 342 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) {
339 web_view()->SetEmbedFullscreenWidgetMode(true); 343 web_view()->SetEmbedFullscreenWidgetMode(true);
340 ASSERT_EQ(1, web_view()->child_count()); 344 ASSERT_EQ(1, web_view()->child_count());
341 const gfx::NativeView unset_native_view = holder()->native_view(); 345 const gfx::NativeView unset_native_view = holder()->native_view();
342 346
343 // Create two WebContentses to switch between. 347 // Create two WebContentses to switch between.
344 const scoped_ptr<content::WebContents> web_contents1(CreateWebContents()); 348 const std::unique_ptr<content::WebContents> web_contents1(
349 CreateWebContents());
345 WebViewTestWebContentsDelegate delegate1; 350 WebViewTestWebContentsDelegate delegate1;
346 web_contents1->SetDelegate(&delegate1); 351 web_contents1->SetDelegate(&delegate1);
347 const scoped_ptr<content::WebContents> web_contents2(CreateWebContents()); 352 const std::unique_ptr<content::WebContents> web_contents2(
353 CreateWebContents());
348 WebViewTestWebContentsDelegate delegate2; 354 WebViewTestWebContentsDelegate delegate2;
349 web_contents2->SetDelegate(&delegate2); 355 web_contents2->SetDelegate(&delegate2);
350 356
351 EXPECT_NE(web_contents1->GetNativeView(), holder()->native_view()); 357 EXPECT_NE(web_contents1->GetNativeView(), holder()->native_view());
352 web_view()->SetWebContents(web_contents1.get()); 358 web_view()->SetWebContents(web_contents1.get());
353 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); 359 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view());
354 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); 360 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds());
355 361
356 // Begin screen capture of the WebContents and then enter fullscreen mode. 362 // Begin screen capture of the WebContents and then enter fullscreen mode.
357 // The native view should not have changed, but the layout of its holder will 363 // The native view should not have changed, but the layout of its holder will
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // For this test, add another View that can take focus away from WebView. 400 // For this test, add another View that can take focus away from WebView.
395 web_view()->SetBoundsRect(gfx::Rect(0, 0, 100, 90)); 401 web_view()->SetBoundsRect(gfx::Rect(0, 0, 100, 90));
396 views::View* const something_to_focus = new views::View(); 402 views::View* const something_to_focus = new views::View();
397 something_to_focus->SetBoundsRect(gfx::Rect(0, 90, 100, 10)); 403 something_to_focus->SetBoundsRect(gfx::Rect(0, 90, 100, 10));
398 something_to_focus->SetFocusable(true); 404 something_to_focus->SetFocusable(true);
399 top_level_widget()->GetContentsView()->AddChildView(something_to_focus); 405 top_level_widget()->GetContentsView()->AddChildView(something_to_focus);
400 406
401 web_view()->SetEmbedFullscreenWidgetMode(true); 407 web_view()->SetEmbedFullscreenWidgetMode(true);
402 ASSERT_EQ(1, web_view()->child_count()); 408 ASSERT_EQ(1, web_view()->child_count());
403 409
404 const scoped_ptr<content::WebContents> web_contents(CreateWebContents()); 410 const std::unique_ptr<content::WebContents> web_contents(CreateWebContents());
405 WebViewTestWebContentsDelegate delegate; 411 WebViewTestWebContentsDelegate delegate;
406 web_contents->SetDelegate(&delegate); 412 web_contents->SetDelegate(&delegate);
407 web_view()->SetWebContents(web_contents.get()); 413 web_view()->SetWebContents(web_contents.get());
408 414
409 // Begin screen capture of the WebContents and then enter fullscreen mode. 415 // Begin screen capture of the WebContents and then enter fullscreen mode.
410 // The holder should be centered within WebView and sized to match the capture 416 // The holder should be centered within WebView and sized to match the capture
411 // size. 417 // size.
412 const gfx::Size capture_size(64, 48); 418 const gfx::Size capture_size(64, 48);
413 web_contents->IncrementCapturerCount(capture_size); 419 web_contents->IncrementCapturerCount(capture_size);
414 delegate.set_is_fullscreened(true); 420 delegate.set_is_fullscreened(true);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 475
470 // Remove WebView from views hierarchy. NativeView should be detached 476 // Remove WebView from views hierarchy. NativeView should be detached
471 // from Widget. 477 // from Widget.
472 contents_view->RemoveChildView(webview.get()); 478 contents_view->RemoveChildView(webview.get());
473 // Destroy WebView. NativeView should be detached secondary. 479 // Destroy WebView. NativeView should be detached secondary.
474 // There should be no crash. 480 // There should be no crash.
475 webview.reset(); 481 webview.reset();
476 } 482 }
477 483
478 } // namespace views 484 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/webview/webview.cc ('k') | ui/views/corewm/cursor_height_provider_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698