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 "base/path_service.h" | |
10 #include "content/public/browser/web_contents.h" | |
11 #include "content/public/test/test_browser_context.h" | |
12 #include "ui/base/ime/text_input_focus_manager.h" | |
13 #include "ui/base/resource/resource_bundle.h" | |
14 #include "ui/base/ui_base_switches.h" | |
15 #include "ui/gl/gl_surface.h" | |
16 #include "ui/views/test/webview_test_helper.h" | |
17 #include "ui/views/test/widget_test.h" | |
18 | |
19 namespace { | |
20 | |
21 class WebViewInteractiveUiTest : public views::test::WidgetTest { | |
22 public: | |
23 virtual void SetUp() OVERRIDE { | |
msw
2014/05/02 18:46:03
nit q: is this SetUp override necessary for this t
Yuki
2014/05/07 05:58:02
It seems we can simplify this code because we don'
| |
24 gfx::GLSurface::InitializeOneOffForTests(); | |
25 base::FilePath pak_dir; | |
26 PathService::Get(base::DIR_MODULE, &pak_dir); | |
27 base::FilePath pak_file; | |
28 pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak")); | |
29 ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); | |
30 WidgetTest::SetUp(); | |
31 } | |
32 | |
33 protected: | |
34 content::BrowserContext* browser_context() { return &browser_context_; } | |
35 | |
36 private: | |
37 content::TestBrowserContext browser_context_; | |
38 views::WebViewTestHelper webview_test_helper_; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(WebViewInteractiveUiTest); | |
41 }; | |
42 | |
43 TEST_F(WebViewInteractiveUiTest, TextInputClientIsUpToDate) { | |
44 // WebViewInteractiveUiTest.TextInputClientIsUpToDate needs | |
45 // kEnableTextInputFocusManager flag to be enabled. | |
46 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | |
47 cmd_line->AppendSwitch(switches::kEnableTextInputFocusManager); | |
48 | |
49 // Create a top level widget and a webview as its content. | |
50 views::Widget* widget = CreateTopLevelFramelessPlatformWidget(); | |
51 views::WebView* webview = new views::WebView(browser_context()); | |
52 widget->SetContentsView(webview); | |
53 widget->Show(); | |
54 webview->RequestFocus(); | |
55 | |
56 ui::TextInputFocusManager* text_input_focus_manager = | |
57 ui::TextInputFocusManager::GetInstance(); | |
58 const ui::TextInputClient* null_text_input_client = NULL; | |
59 EXPECT_EQ(null_text_input_client, webview->GetTextInputClient()); | |
60 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), | |
61 webview->GetTextInputClient()); | |
62 | |
63 // Case 1: Creates a new WebContents. | |
64 webview->GetWebContents(); | |
65 webview->RequestFocus(); | |
66 ui::TextInputClient* client1 = webview->GetTextInputClient(); | |
67 EXPECT_NE(null_text_input_client, client1); | |
68 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client1); | |
69 | |
70 // Case 2: Replaces a WebContents by SetWebContents(). | |
71 content::WebContents::CreateParams params(browser_context()); | |
72 scoped_ptr<content::WebContents> web_contents( | |
73 content::WebContents::Create(params)); | |
74 webview->SetWebContents(web_contents.get()); | |
75 ui::TextInputClient* client2 = webview->GetTextInputClient(); | |
76 EXPECT_NE(null_text_input_client, client2); | |
77 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client2); | |
78 EXPECT_NE(client1, client2); | |
79 | |
80 widget->Close(); | |
81 RunPendingMessages(); | |
82 } | |
83 | |
84 } // namespace | |
OLD | NEW |