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/controls/native/native_view_host.h" |
15 #include "ui/views/test/test_views_delegate.h" | 16 #include "ui/views/test/test_views_delegate.h" |
16 #include "ui/views/test/widget_test.h" | 17 #include "ui/views/test/widget_test.h" |
17 | 18 |
| 19 namespace views { |
| 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 // Provides functionality to create a test WebContents. | 23 // Provides functionality to create a test WebContents. |
21 class WebViewTestViewsDelegate : public views::TestViewsDelegate { | 24 class WebViewTestViewsDelegate : public views::TestViewsDelegate { |
22 public: | 25 public: |
23 WebViewTestViewsDelegate() {} | 26 WebViewTestViewsDelegate() {} |
24 ~WebViewTestViewsDelegate() override {} | 27 ~WebViewTestViewsDelegate() override {} |
25 | 28 |
26 // Overriden from TestViewsDelegate. | 29 // Overriden from TestViewsDelegate. |
27 content::WebContents* CreateWebContents( | 30 content::WebContents* CreateWebContents( |
28 content::BrowserContext* browser_context, | 31 content::BrowserContext* browser_context, |
29 content::SiteInstance* site_instance) override { | 32 content::SiteInstance* site_instance) override { |
30 return content::WebContentsTester::CreateTestWebContents(browser_context, | 33 return content::WebContentsTester::CreateTestWebContents(browser_context, |
31 site_instance); | 34 site_instance); |
32 } | 35 } |
33 | 36 |
34 private: | 37 private: |
35 DISALLOW_COPY_AND_ASSIGN(WebViewTestViewsDelegate); | 38 DISALLOW_COPY_AND_ASSIGN(WebViewTestViewsDelegate); |
36 }; | 39 }; |
37 | 40 |
38 // Provides functionality to test a WebView. | |
39 class WebViewUnitTest : public views::test::WidgetTest { | |
40 public: | |
41 WebViewUnitTest() | |
42 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), | |
43 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | |
44 base::MessageLoop::current()), | |
45 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()) {} | |
46 | |
47 ~WebViewUnitTest() override {} | |
48 | |
49 void SetUp() override { | |
50 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. | |
51 WidgetTest::set_views_delegate(new WebViewTestViewsDelegate); | |
52 browser_context_.reset(new content::TestBrowserContext); | |
53 WidgetTest::SetUp(); | |
54 // Set the test content browser client to avoid pulling in needless | |
55 // dependencies from content. | |
56 SetBrowserClientForTesting(&test_browser_client_); | |
57 } | |
58 | |
59 void TearDown() override { | |
60 browser_context_.reset(NULL); | |
61 // Flush the message loop to execute pending relase tasks as this would | |
62 // upset ASAN and Valgrind. | |
63 RunPendingMessages(); | |
64 WidgetTest::TearDown(); | |
65 } | |
66 | |
67 protected: | |
68 content::BrowserContext* browser_context() { return browser_context_.get(); } | |
69 | |
70 private: | |
71 content::TestBrowserThread ui_thread_; | |
72 content::TestBrowserThread file_blocking_thread_; | |
73 content::TestBrowserThread io_thread_; | |
74 scoped_ptr<content::TestBrowserContext> browser_context_; | |
75 scoped_ptr<WebViewTestViewsDelegate> views_delegate_; | |
76 content::TestContentBrowserClient test_browser_client_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); | |
79 }; | |
80 | |
81 // Provides functionaity to observe events on a WebContents like WasShown/ | 41 // Provides functionaity to observe events on a WebContents like WasShown/ |
82 // WasHidden/WebContentsDestroyed. | 42 // WasHidden/WebContentsDestroyed. |
83 class WebViewTestWebContentsObserver : public content::WebContentsObserver { | 43 class WebViewTestWebContentsObserver : public content::WebContentsObserver { |
84 public: | 44 public: |
85 WebViewTestWebContentsObserver(content::WebContents* web_contents) | 45 WebViewTestWebContentsObserver(content::WebContents* web_contents) |
86 : web_contents_(static_cast<content::WebContentsImpl*>(web_contents)), | 46 : web_contents_(static_cast<content::WebContentsImpl*>(web_contents)), |
87 was_shown_(false), | 47 was_shown_(false), |
88 shown_count_(0), | 48 shown_count_(0), |
89 hidden_count_(0) { | 49 hidden_count_(0) { |
90 content::WebContentsObserver::Observe(web_contents); | 50 content::WebContentsObserver::Observe(web_contents); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 content::WebContentsImpl* web_contents_; | 85 content::WebContentsImpl* web_contents_; |
126 bool was_shown_; | 86 bool was_shown_; |
127 int32 shown_count_; | 87 int32 shown_count_; |
128 int32 hidden_count_; | 88 int32 hidden_count_; |
129 // Set to true if the view containing the webcontents has a valid root window. | 89 // Set to true if the view containing the webcontents has a valid root window. |
130 bool valid_root_while_shown_; | 90 bool valid_root_while_shown_; |
131 | 91 |
132 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsObserver); | 92 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsObserver); |
133 }; | 93 }; |
134 | 94 |
| 95 // Fakes the fullscreen browser state reported to WebContents and WebView. |
| 96 class WebViewTestWebContentsDelegate : public content::WebContentsDelegate { |
| 97 public: |
| 98 WebViewTestWebContentsDelegate() : is_fullscreened_(false) {} |
| 99 ~WebViewTestWebContentsDelegate() override {} |
| 100 |
| 101 void set_is_fullscreened(bool fs) { is_fullscreened_ = fs; } |
| 102 |
| 103 // content::WebContentsDelegate overrides. |
| 104 bool IsFullscreenForTabOrPending( |
| 105 const content::WebContents* ignored) const override { |
| 106 return is_fullscreened_; |
| 107 } |
| 108 |
| 109 private: |
| 110 bool is_fullscreened_; |
| 111 |
| 112 DISALLOW_COPY_AND_ASSIGN(WebViewTestWebContentsDelegate); |
| 113 }; |
| 114 |
| 115 } // namespace |
| 116 |
| 117 // Provides functionality to test a WebView. |
| 118 class WebViewUnitTest : public views::test::WidgetTest { |
| 119 public: |
| 120 WebViewUnitTest() |
| 121 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), |
| 122 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, |
| 123 base::MessageLoop::current()), |
| 124 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), |
| 125 top_level_widget_(nullptr) {} |
| 126 |
| 127 ~WebViewUnitTest() override {} |
| 128 |
| 129 void SetUp() override { |
| 130 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. |
| 131 WidgetTest::set_views_delegate(new WebViewTestViewsDelegate); |
| 132 browser_context_.reset(new content::TestBrowserContext); |
| 133 WidgetTest::SetUp(); |
| 134 // Set the test content browser client to avoid pulling in needless |
| 135 // dependencies from content. |
| 136 SetBrowserClientForTesting(&test_browser_client_); |
| 137 |
| 138 // Create a top level widget and add a child, and give it a WebView as a |
| 139 // child. |
| 140 top_level_widget_ = CreateTopLevelFramelessPlatformWidget(); |
| 141 top_level_widget_->SetBounds(gfx::Rect(0, 10, 100, 100)); |
| 142 View* const contents_view = new View(); |
| 143 top_level_widget_->SetContentsView(contents_view); |
| 144 web_view_ = new WebView(browser_context_.get()); |
| 145 web_view_->SetBoundsRect(gfx::Rect(contents_view->size())); |
| 146 contents_view->AddChildView(web_view_); |
| 147 top_level_widget_->Show(); |
| 148 ASSERT_EQ(gfx::Rect(0, 0, 100, 100), web_view_->bounds()); |
| 149 } |
| 150 |
| 151 void TearDown() override { |
| 152 top_level_widget_->Close(); // Deletes all children and itself. |
| 153 RunPendingMessages(); |
| 154 |
| 155 browser_context_.reset(NULL); |
| 156 // Flush the message loop to execute pending relase tasks as this would |
| 157 // upset ASAN and Valgrind. |
| 158 RunPendingMessages(); |
| 159 WidgetTest::TearDown(); |
| 160 } |
| 161 |
| 162 protected: |
| 163 Widget* top_level_widget() const { return top_level_widget_; } |
| 164 WebView* web_view() const { return web_view_; } |
| 165 NativeViewHost* holder() const { return web_view_->holder_; } |
| 166 |
| 167 scoped_ptr<content::WebContents> CreateWebContents() const { |
| 168 return make_scoped_ptr(content::WebContents::Create( |
| 169 content::WebContents::CreateParams(browser_context_.get()))); |
| 170 } |
| 171 |
| 172 private: |
| 173 content::TestBrowserThread ui_thread_; |
| 174 content::TestBrowserThread file_blocking_thread_; |
| 175 content::TestBrowserThread io_thread_; |
| 176 scoped_ptr<content::TestBrowserContext> browser_context_; |
| 177 scoped_ptr<WebViewTestViewsDelegate> views_delegate_; |
| 178 content::TestContentBrowserClient test_browser_client_; |
| 179 |
| 180 Widget* top_level_widget_; |
| 181 WebView* web_view_; |
| 182 |
| 183 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); |
| 184 }; |
| 185 |
135 // Tests that attaching and detaching a WebContents to a WebView makes the | 186 // Tests that attaching and detaching a WebContents to a WebView makes the |
136 // WebContents visible and hidden respectively. | 187 // WebContents visible and hidden respectively. |
137 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) { | 188 TEST_F(WebViewUnitTest, TestWebViewAttachDetachWebContents) { |
138 // Create a top level widget and a webview as its content. | |
139 views::Widget* parent = CreateTopLevelFramelessPlatformWidget(); | |
140 parent->SetBounds(gfx::Rect(0, 10, 100, 100)); | |
141 | |
142 views::Widget* widget = CreateChildNativeWidgetWithParent(parent); | |
143 widget->SetBounds(gfx::Rect(0, 10, 100, 100)); | |
144 views::WebView* webview = new views::WebView(browser_context()); | |
145 widget->SetContentsView(webview); | |
146 parent->Show(); | |
147 widget->Show(); | |
148 | |
149 // Case 1: Create a new WebContents and set it in the webview via | 189 // Case 1: Create a new WebContents and set it in the webview via |
150 // SetWebContents. This should make the WebContents visible. | 190 // SetWebContents. This should make the WebContents visible. |
151 content::WebContents::CreateParams params(browser_context()); | 191 const scoped_ptr<content::WebContents> web_contents1(CreateWebContents()); |
152 scoped_ptr<content::WebContents> web_contents1( | |
153 content::WebContents::Create(params)); | |
154 WebViewTestWebContentsObserver observer1(web_contents1.get()); | 192 WebViewTestWebContentsObserver observer1(web_contents1.get()); |
155 EXPECT_FALSE(observer1.was_shown()); | 193 EXPECT_FALSE(observer1.was_shown()); |
156 | 194 |
157 webview->SetWebContents(web_contents1.get()); | 195 web_view()->SetWebContents(web_contents1.get()); |
158 EXPECT_TRUE(observer1.was_shown()); | 196 EXPECT_TRUE(observer1.was_shown()); |
159 EXPECT_TRUE(web_contents1->GetNativeView()->IsVisible()); | 197 EXPECT_TRUE(web_contents1->GetNativeView()->IsVisible()); |
160 EXPECT_EQ(observer1.shown_count(), 1); | 198 EXPECT_EQ(observer1.shown_count(), 1); |
161 EXPECT_EQ(observer1.hidden_count(), 0); | 199 EXPECT_EQ(observer1.hidden_count(), 0); |
162 EXPECT_TRUE(observer1.valid_root_while_shown()); | 200 EXPECT_TRUE(observer1.valid_root_while_shown()); |
163 | 201 |
164 // Case 2: Create another WebContents and replace the current WebContents | 202 // Case 2: Create another WebContents and replace the current WebContents |
165 // via SetWebContents(). This should hide the current WebContents and show | 203 // via SetWebContents(). This should hide the current WebContents and show |
166 // the new one. | 204 // the new one. |
167 content::WebContents::CreateParams params2(browser_context()); | 205 const scoped_ptr<content::WebContents> web_contents2(CreateWebContents()); |
168 scoped_ptr<content::WebContents> web_contents2( | |
169 content::WebContents::Create(params2)); | |
170 | |
171 WebViewTestWebContentsObserver observer2(web_contents2.get()); | 206 WebViewTestWebContentsObserver observer2(web_contents2.get()); |
172 EXPECT_FALSE(observer2.was_shown()); | 207 EXPECT_FALSE(observer2.was_shown()); |
173 | 208 |
174 // Setting the new WebContents should hide the existing one. | 209 // Setting the new WebContents should hide the existing one. |
175 webview->SetWebContents(web_contents2.get()); | 210 web_view()->SetWebContents(web_contents2.get()); |
176 EXPECT_FALSE(observer1.was_shown()); | 211 EXPECT_FALSE(observer1.was_shown()); |
177 EXPECT_TRUE(observer2.was_shown()); | 212 EXPECT_TRUE(observer2.was_shown()); |
178 EXPECT_TRUE(observer2.valid_root_while_shown()); | 213 EXPECT_TRUE(observer2.valid_root_while_shown()); |
179 | 214 |
180 // WebContents1 should not get stray show calls when WebContents2 is set. | 215 // WebContents1 should not get stray show calls when WebContents2 is set. |
181 EXPECT_EQ(observer1.shown_count(), 1); | 216 EXPECT_EQ(observer1.shown_count(), 1); |
182 EXPECT_EQ(observer1.hidden_count(), 1); | 217 EXPECT_EQ(observer1.hidden_count(), 1); |
183 EXPECT_EQ(observer2.shown_count(), 1); | 218 EXPECT_EQ(observer2.shown_count(), 1); |
184 EXPECT_EQ(observer2.hidden_count(), 0); | 219 EXPECT_EQ(observer2.hidden_count(), 0); |
185 | 220 |
186 // Case 3: Test that attaching to a hidden webview does not show the web | 221 // Case 3: Test that attaching to a hidden webview does not show the web |
187 // contents. | 222 // contents. |
188 webview->SetVisible(false); | 223 web_view()->SetVisible(false); |
189 EXPECT_EQ(1, observer2.hidden_count()); // Now hidden. | 224 EXPECT_EQ(1, observer2.hidden_count()); // Now hidden. |
190 | 225 |
191 EXPECT_EQ(1, observer1.shown_count()); | 226 EXPECT_EQ(1, observer1.shown_count()); |
192 webview->SetWebContents(web_contents1.get()); | 227 web_view()->SetWebContents(web_contents1.get()); |
193 EXPECT_EQ(1, observer1.shown_count()); | 228 EXPECT_EQ(1, observer1.shown_count()); |
194 | 229 |
195 // Nothing else should change. | 230 // Nothing else should change. |
196 EXPECT_EQ(1, observer1.hidden_count()); | 231 EXPECT_EQ(1, observer1.hidden_count()); |
197 EXPECT_EQ(1, observer2.shown_count()); | 232 EXPECT_EQ(1, observer2.shown_count()); |
198 EXPECT_EQ(1, observer2.hidden_count()); | 233 EXPECT_EQ(1, observer2.hidden_count()); |
199 | 234 |
200 // Case 4: Test that making the webview visible when a window has an invisible | 235 // Case 4: Test that making the webview visible when a window has an invisible |
201 // parent does not make the web contents visible. | 236 // parent does not make the web contents visible. |
202 parent->Hide(); | 237 top_level_widget()->Hide(); |
203 webview->SetVisible(true); | 238 web_view()->SetVisible(true); |
204 // TODO(tapted): The following line is wrong, the shown_count() should still | 239 // TODO(tapted): The following line is wrong, the shown_count() should still |
205 // be 1, until the parent window is made visible on the line after. | 240 // be 1, until the parent window is made visible on the line after. |
206 EXPECT_EQ(2, observer1.shown_count()); | 241 EXPECT_EQ(2, observer1.shown_count()); |
207 parent->Show(); | 242 top_level_widget()->Show(); |
208 EXPECT_EQ(2, observer1.shown_count()); | 243 EXPECT_EQ(2, observer1.shown_count()); |
209 parent->Hide(); | 244 top_level_widget()->Hide(); |
210 EXPECT_EQ(2, observer1.hidden_count()); | 245 EXPECT_EQ(2, observer1.hidden_count()); |
211 | 246 |
212 // Case 5: Test that moving from a hidden parent to a visible parent makes the | 247 // Case 5: Test that moving from a hidden parent to a visible parent makes the |
213 // web contents visible. | 248 // web contents visible. |
214 views::Widget* parent2 = CreateTopLevelFramelessPlatformWidget(); | 249 Widget* parent2 = CreateTopLevelFramelessPlatformWidget(); |
215 parent2->SetBounds(gfx::Rect(0, 10, 100, 100)); | 250 parent2->SetBounds(gfx::Rect(0, 10, 100, 100)); |
216 parent2->Show(); | 251 parent2->Show(); |
217 | |
218 EXPECT_EQ(2, observer1.shown_count()); | 252 EXPECT_EQ(2, observer1.shown_count()); |
219 // Note: that reparenting the windows directly, after the windows have been | 253 // Note: that reparenting the windows directly, after the windows have been |
220 // created, e.g., views::Widget::ReparentNativeView(widget, parent2), is not a | 254 // created, e.g., Widget::ReparentNativeView(widget, parent2), is not a |
221 // supported use case. Instead, move the WebView over. | 255 // supported use case. Instead, move the WebView over. |
222 parent2->SetContentsView(webview); | 256 parent2->SetContentsView(web_view()); |
223 EXPECT_EQ(3, observer1.shown_count()); | 257 EXPECT_EQ(3, observer1.shown_count()); |
224 | |
225 widget->Close(); | |
226 parent->Close(); | |
227 parent2->Close(); | 258 parent2->Close(); |
228 RunPendingMessages(); | |
229 } | 259 } |
230 | 260 |
231 } // namespace | 261 // Tests that the layout of the NativeViewHost within WebView behaves as |
| 262 // expected when embedding a fullscreen widget during WebContents screen |
| 263 // capture. |
| 264 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Layout) { |
| 265 web_view()->SetEmbedFullscreenWidgetMode(true); |
| 266 ASSERT_EQ(1, web_view()->child_count()); |
| 267 |
| 268 const scoped_ptr<content::WebContents> web_contents(CreateWebContents()); |
| 269 WebViewTestWebContentsDelegate delegate; |
| 270 web_contents->SetDelegate(&delegate); |
| 271 web_view()->SetWebContents(web_contents.get()); |
| 272 |
| 273 // Initially, the holder should fill the entire WebView. |
| 274 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); |
| 275 |
| 276 // Simulate a transition into fullscreen mode, but without screen capture |
| 277 // active on the WebContents, the holder should still fill the entire |
| 278 // WebView like before. |
| 279 delegate.set_is_fullscreened(true); |
| 280 static_cast<content::WebContentsObserver*>(web_view())-> |
| 281 DidToggleFullscreenModeForTab(true); |
| 282 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); |
| 283 |
| 284 // ...and transition back out of fullscreen mode. |
| 285 delegate.set_is_fullscreened(false); |
| 286 static_cast<content::WebContentsObserver*>(web_view())-> |
| 287 DidToggleFullscreenModeForTab(false); |
| 288 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); |
| 289 |
| 290 // Now, begin screen capture of the WebContents and then enter fullscreen |
| 291 // mode. This time, the holder should be centered within WebView and |
| 292 // sized to match the capture size. |
| 293 const gfx::Size capture_size(64, 48); |
| 294 web_contents->IncrementCapturerCount(capture_size); |
| 295 delegate.set_is_fullscreened(true); |
| 296 static_cast<content::WebContentsObserver*>(web_view())-> |
| 297 DidToggleFullscreenModeForTab(true); |
| 298 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); |
| 299 |
| 300 // Resize the WebView so that its width is smaller than the capture width. |
| 301 // Expect the holder to be scaled-down, letterboxed style. |
| 302 web_view()->SetBoundsRect(gfx::Rect(0, 0, 32, 32)); |
| 303 EXPECT_EQ(gfx::Rect(0, 4, 32, 24), holder()->bounds()); |
| 304 |
| 305 // Transition back out of fullscreen mode a final time and confirm the bounds |
| 306 // of the holder fill the entire WebView once again. |
| 307 delegate.set_is_fullscreened(false); |
| 308 static_cast<content::WebContentsObserver*>(web_view())-> |
| 309 DidToggleFullscreenModeForTab(false); |
| 310 EXPECT_EQ(gfx::Rect(0, 0, 32, 32), holder()->bounds()); |
| 311 } |
| 312 |
| 313 // Tests that a WebView correctly switches between WebContentses when one of |
| 314 // them is embedding a fullscreen widget during WebContents screen capture. |
| 315 TEST_F(WebViewUnitTest, EmbeddedFullscreenDuringScreenCapture_Switching) { |
| 316 web_view()->SetEmbedFullscreenWidgetMode(true); |
| 317 ASSERT_EQ(1, web_view()->child_count()); |
| 318 const gfx::NativeView unset_native_view = holder()->native_view(); |
| 319 |
| 320 // Create two WebContentses to switch between. |
| 321 const scoped_ptr<content::WebContents> web_contents1(CreateWebContents()); |
| 322 WebViewTestWebContentsDelegate delegate1; |
| 323 web_contents1->SetDelegate(&delegate1); |
| 324 const scoped_ptr<content::WebContents> web_contents2(CreateWebContents()); |
| 325 WebViewTestWebContentsDelegate delegate2; |
| 326 web_contents2->SetDelegate(&delegate2); |
| 327 |
| 328 EXPECT_NE(web_contents1->GetNativeView(), holder()->native_view()); |
| 329 web_view()->SetWebContents(web_contents1.get()); |
| 330 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); |
| 331 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); |
| 332 |
| 333 // Begin screen capture of the WebContents and then enter fullscreen mode. |
| 334 // The native view should not have changed, but the layout of its holder will |
| 335 // have (indicates WebView has responded). |
| 336 const gfx::Size capture_size(64, 48); |
| 337 web_contents1->IncrementCapturerCount(capture_size); |
| 338 delegate1.set_is_fullscreened(true); |
| 339 static_cast<content::WebContentsObserver*>(web_view())-> |
| 340 DidToggleFullscreenModeForTab(true); |
| 341 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); |
| 342 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); |
| 343 |
| 344 // When setting the WebContents to nullptr, the native view should become |
| 345 // unset. |
| 346 web_view()->SetWebContents(nullptr); |
| 347 EXPECT_EQ(unset_native_view, holder()->native_view()); |
| 348 |
| 349 // ...and when setting the WebContents back to the currently-fullscreened |
| 350 // instance, expect the native view and layout to reflect that. |
| 351 web_view()->SetWebContents(web_contents1.get()); |
| 352 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); |
| 353 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); |
| 354 |
| 355 // Now, switch to a different, non-null WebContents instance and check that |
| 356 // the native view has changed and the holder is filling WebView again. |
| 357 web_view()->SetWebContents(web_contents2.get()); |
| 358 EXPECT_EQ(web_contents2->GetNativeView(), holder()->native_view()); |
| 359 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), holder()->bounds()); |
| 360 |
| 361 // Finally, switch back to the first WebContents (still fullscreened). |
| 362 web_view()->SetWebContents(web_contents1.get()); |
| 363 EXPECT_EQ(web_contents1->GetNativeView(), holder()->native_view()); |
| 364 EXPECT_EQ(gfx::Rect(18, 26, 64, 48), holder()->bounds()); |
| 365 } |
| 366 |
| 367 } // namespace views |
OLD | NEW |