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/public/browser/web_contents.h" | 8 #include "content/public/browser/web_contents.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" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), | 123 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()), |
124 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, | 124 file_blocking_thread_(content::BrowserThread::FILE_USER_BLOCKING, |
125 base::MessageLoop::current()), | 125 base::MessageLoop::current()), |
126 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), | 126 io_thread_(content::BrowserThread::IO, base::MessageLoop::current()), |
127 top_level_widget_(nullptr) {} | 127 top_level_widget_(nullptr) {} |
128 | 128 |
129 ~WebViewUnitTest() override {} | 129 ~WebViewUnitTest() override {} |
130 | 130 |
131 void SetUp() override { | 131 void SetUp() override { |
132 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. | 132 // The ViewsDelegate is deleted when the ViewsTestBase class is torn down. |
133 WidgetTest::set_views_delegate(new WebViewTestViewsDelegate); | 133 scoped_ptr<views::TestViewsDelegate> views_delegate( |
134 new WebViewTestViewsDelegate); | |
135 set_views_delegate(views_delegate.Pass()); | |
sadrul
2015/06/08 03:27:43
You can also do:
set_views_delegate(make_scoped_
mohsen
2015/06/08 19:27:34
Done.
| |
134 browser_context_.reset(new content::TestBrowserContext); | 136 browser_context_.reset(new content::TestBrowserContext); |
135 WidgetTest::SetUp(); | 137 WidgetTest::SetUp(); |
136 // Set the test content browser client to avoid pulling in needless | 138 // Set the test content browser client to avoid pulling in needless |
137 // dependencies from content. | 139 // dependencies from content. |
138 SetBrowserClientForTesting(&test_browser_client_); | 140 SetBrowserClientForTesting(&test_browser_client_); |
139 | 141 |
140 // Create a top level widget and add a child, and give it a WebView as a | 142 // Create a top level widget and add a child, and give it a WebView as a |
141 // child. | 143 // child. |
142 top_level_widget_ = CreateTopLevelFramelessPlatformWidget(); | 144 top_level_widget_ = CreateTopLevelFramelessPlatformWidget(); |
143 top_level_widget_->SetBounds(gfx::Rect(0, 10, 100, 100)); | 145 top_level_widget_->SetBounds(gfx::Rect(0, 10, 100, 100)); |
(...skipping 25 matching lines...) Expand all Loading... | |
169 scoped_ptr<content::WebContents> CreateWebContents() const { | 171 scoped_ptr<content::WebContents> CreateWebContents() const { |
170 return make_scoped_ptr(content::WebContents::Create( | 172 return make_scoped_ptr(content::WebContents::Create( |
171 content::WebContents::CreateParams(browser_context_.get()))); | 173 content::WebContents::CreateParams(browser_context_.get()))); |
172 } | 174 } |
173 | 175 |
174 private: | 176 private: |
175 content::TestBrowserThread ui_thread_; | 177 content::TestBrowserThread ui_thread_; |
176 content::TestBrowserThread file_blocking_thread_; | 178 content::TestBrowserThread file_blocking_thread_; |
177 content::TestBrowserThread io_thread_; | 179 content::TestBrowserThread io_thread_; |
178 scoped_ptr<content::TestBrowserContext> browser_context_; | 180 scoped_ptr<content::TestBrowserContext> browser_context_; |
179 scoped_ptr<WebViewTestViewsDelegate> views_delegate_; | |
180 content::TestContentBrowserClient test_browser_client_; | 181 content::TestContentBrowserClient test_browser_client_; |
181 | 182 |
182 Widget* top_level_widget_; | 183 Widget* top_level_widget_; |
183 WebView* web_view_; | 184 WebView* web_view_; |
184 | 185 |
185 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); | 186 DISALLOW_COPY_AND_ASSIGN(WebViewUnitTest); |
186 }; | 187 }; |
187 | 188 |
188 // Tests that attaching and detaching a WebContents to a WebView makes the | 189 // Tests that attaching and detaching a WebContents to a WebView makes the |
189 // WebContents visible and hidden respectively. | 190 // WebContents visible and hidden respectively. |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 gfx::Point(), // Immaterial. | 431 gfx::Point(), // Immaterial. |
431 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 432 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
432 EXPECT_FALSE(static_cast<views::View*>(web_view())-> | 433 EXPECT_FALSE(static_cast<views::View*>(web_view())-> |
433 OnMousePressed(click_inside_holder)); | 434 OnMousePressed(click_inside_holder)); |
434 EXPECT_FALSE(web_view()->HasFocus()); | 435 EXPECT_FALSE(web_view()->HasFocus()); |
435 EXPECT_FALSE(holder()->HasFocus()); | 436 EXPECT_FALSE(holder()->HasFocus()); |
436 EXPECT_TRUE(something_to_focus->HasFocus()); | 437 EXPECT_TRUE(something_to_focus->HasFocus()); |
437 } | 438 } |
438 | 439 |
439 } // namespace views | 440 } // namespace views |
OLD | NEW |