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

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

Issue 173803002: Redesigns the text input focus handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added an unittest and thread checker. Created 6 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 | Annotate | Revision Log
OLDNEW
(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/memory/scoped_ptr.h"
8 #include "content/public/browser/web_contents.h"
9 #include "content/public/test/test_browser_context.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/test/aura_test_helper.h"
13 #include "ui/base/ime/text_input_focus_manager.h"
14 #include "ui/base/ui_base_switches_util.h"
15 #include "ui/compositor/test/context_factories_for_test.h"
16 #include "ui/views/test/webview_test_helper.h"
17 #include "ui/views/widget/widget.h"
18
19 namespace {
20
21 class WebViewTest : public testing::Test {
22 public:
23 WebViewTest()
24 : widget_(NULL), webview_(NULL),
msw 2014/04/18 19:57:57 nit: one initializer per line
Yuki 2014/04/22 09:09:02 After applying your comment, we don't need webview
25 webview_test_helper_(new views::WebViewTestHelper()) {}
26
27 virtual void SetUp() {
28 testing::Test::SetUp();
29
30 ui::InitializeContextFactoryForTests(false);
31
32 aura_test_helper_.reset(
33 new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
34 aura_test_helper_->SetUp();
35
36 InitWebView();
37 }
38
39 virtual void TearDown() {
40 if (widget_)
41 widget_->Close();
42
43 aura_test_helper_->TearDown();
44
45 ui::TerminateContextFactoryForTests();
46
47 testing::Test::TearDown();
48 }
49
50 protected:
51 views::WebView* webview() { return webview_; }
52 content::BrowserContext* browser_context() { return browser_context_.get(); }
53
54 private:
55 void InitWebView() {
56 widget_ = new views::Widget();
57 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
58 params.context = aura_test_helper_->root_window();
59 params.bounds = gfx::Rect(100, 100, 100, 100);
60 widget_->Init(params);
61
62 views::View* container = new views::View();
msw 2014/04/18 19:57:57 nit: is container needed, can you just widget_->Se
Yuki 2014/04/22 09:09:02 Done.
63 widget_->SetContentsView(container);
64
65 browser_context_.reset(new content::TestBrowserContext());
66 webview_ = new views::WebView(browser_context_.get());
67 container->AddChildView(webview_);
68
69 widget_->Activate();
70 widget_->Show();
71 }
72
73 views::Widget* widget_;
74 views::WebView* webview_;
75 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_;
76 scoped_ptr<content::TestBrowserContext> browser_context_;
msw 2014/04/18 19:57:57 nit: drop scoped_ptr for content::TestBrowserConte
Yuki 2014/04/22 09:09:02 Done.
77 scoped_ptr<views::WebViewTestHelper> webview_test_helper_;
msw 2014/04/18 19:57:57 nit: drop scoped_ptr for views::WebViewTestHelper
Yuki 2014/04/22 09:09:02 Done.
78 content::TestBrowserThreadBundle browser_thread_bundle_;
79
80 DISALLOW_COPY_AND_ASSIGN(WebViewTest);
81 };
82
83 TEST_F(WebViewTest, TextInputClientIsUpToDate) {
84 switches::ScopedTextInputFocusManagerForTesting
85 text_input_focus_manager_for_testing;
86
87 webview()->SetEmbedFullscreenWidgetMode(true);
88
89 ui::TextInputFocusManager* const text_input_focus_manager =
msw 2014/04/18 19:57:57 nit: this usage of const is uncommon, is it intend
Yuki 2014/04/22 09:09:02 Removed. It was intentional, but I don't care muc
90 ui::TextInputFocusManager::GetInstance();
91 const ui::TextInputClient* const null_text_input_client = NULL;
msw 2014/04/18 19:57:57 nit: this usage of const is uncommon, is it intend
Yuki 2014/04/22 09:09:02 Done.
92
93 EXPECT_EQ(null_text_input_client, webview()->GetTextInputClient());
94 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(),
95 webview()->GetTextInputClient());
96
97 // Case 1: Creates a new WebContents.
98 webview()->GetWebContents(); // Creates a new WebContents.
msw 2014/04/18 19:57:57 nit: remove comment, it's redundant with the one a
Yuki 2014/04/22 09:09:02 Done.
99 webview()->RequestFocus();
100 ui::TextInputClient* client1 = webview()->GetTextInputClient();
101 EXPECT_NE(null_text_input_client, client1);
102 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client1);
103
104 // Case 2: Replaces a WebContents by SetWebContents().
105 content::WebContents::CreateParams params(browser_context());
106 content::WebContents* web_contents = content::WebContents::Create(params);
msw 2014/04/18 19:57:57 Use a ScopedPtr, WebView doesn't take ownership be
Yuki 2014/04/22 09:09:02 Done.
107 webview()->SetWebContents(web_contents);
108 ui::TextInputClient* client2 = webview()->GetTextInputClient();
109 EXPECT_NE(null_text_input_client, client2);
110 EXPECT_EQ(text_input_focus_manager->GetFocusedTextInputClient(), client2);
111 EXPECT_NE(client1, client2);
112 }
113
114 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698