OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/controls/webview/webview.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/test_browser_context.h" |
| 11 #include "ui/base/ime/text_input_focus_manager.h" |
| 12 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/gl/gl_surface.h" |
| 14 #include "ui/views/test/webview_test_helper.h" |
| 15 #include "ui/views/test/widget_test.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 class WebViewInteractiveUiTest : public views::test::WidgetTest { |
| 20 public: |
| 21 WebViewInteractiveUiTest() {} |
| 22 |
| 23 virtual void SetUp() OVERRIDE { |
| 24 gfx::GLSurface::InitializeOneOffForTests(); |
| 25 WidgetTest::SetUp(); |
| 26 } |
| 27 |
| 28 protected: |
| 29 content::BrowserContext* browser_context() { return &browser_context_; } |
| 30 |
| 31 private: |
| 32 content::TestBrowserContext browser_context_; |
| 33 views::WebViewTestHelper webview_test_helper_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(WebViewInteractiveUiTest); |
| 36 }; |
| 37 |
| 38 TEST_F(WebViewInteractiveUiTest, TextInputClientIsUpToDate) { |
| 39 // WebViewInteractiveUiTest.TextInputClientIsUpToDate needs |
| 40 // kEnableTextInputFocusManager flag to be enabled. |
| 41 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 42 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); |
| 43 |
| 44 // Create a top level widget and a webview as its content. |
| 45 views::Widget* widget = CreateTopLevelFramelessPlatformWidget(); |
| 46 views::WebView* webview = new views::WebView(browser_context()); |
| 47 widget->SetContentsView(webview); |
| 48 widget->Show(); |
| 49 webview->RequestFocus(); |
| 50 |
| 51 ui::TextInputFocusManager* text_input_focus_manager = |
| 52 ui::TextInputFocusManager::GetInstance(); |
| 53 const ui::TextInputClient* null_text_input_client = NULL; |
| 54 EXPECT_EQ(null_text_input_client, webview->GetTextInputClient()); |
| 55 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), |
| 56 webview->GetTextInputClient()); |
| 57 |
| 58 // Case 1: Creates a new WebContents. |
| 59 webview->GetWebContents(); |
| 60 webview->RequestFocus(); |
| 61 ui::TextInputClient* client1 = webview->GetTextInputClient(); |
| 62 EXPECT_NE(null_text_input_client, client1); |
| 63 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client1); |
| 64 |
| 65 // Case 2: Replaces a WebContents by SetWebContents(). |
| 66 content::WebContents::CreateParams params(browser_context()); |
| 67 scoped_ptr<content::WebContents> web_contents( |
| 68 content::WebContents::Create(params)); |
| 69 webview->SetWebContents(web_contents.get()); |
| 70 ui::TextInputClient* client2 = webview->GetTextInputClient(); |
| 71 EXPECT_NE(null_text_input_client, client2); |
| 72 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client2); |
| 73 EXPECT_NE(client1, client2); |
| 74 |
| 75 widget->Close(); |
| 76 RunPendingMessages(); |
| 77 } |
| 78 |
| 79 } // namespace |
OLD | NEW |