OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 "chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.h" | |
6 | |
7 #include <gtk/gtk.h> | |
8 | |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/autocomplete/autocomplete_match.h" | |
11 #include "chrome/browser/ui/browser.h" | |
12 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | |
13 #include "chrome/test/base/testing_profile.h" | |
14 #include "content/public/test/test_browser_thread.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/platform_test.h" | |
17 #include "ui/base/gtk/gtk_hig_constants.h" | |
18 #include "ui/gfx/image/image.h" | |
19 | |
20 namespace { | |
21 class OmniboxEditControllerMock : public OmniboxEditController { | |
22 public: | |
23 OmniboxEditControllerMock() : OmniboxEditController(NULL) {} | |
24 virtual ~OmniboxEditControllerMock() {} | |
25 | |
26 MOCK_METHOD1(Update, void(const content::WebContents* contents)); | |
27 MOCK_METHOD0(OnChanged, void()); | |
28 MOCK_METHOD0(OnSetFocus, void()); | |
29 MOCK_METHOD0(ShowURL, void()); | |
30 MOCK_METHOD0(GetInstant, InstantController*()); | |
31 MOCK_METHOD0(GetWebContents, content::WebContents*()); | |
32 MOCK_METHOD0(GetToolbarModel, ToolbarModel*()); | |
33 MOCK_CONST_METHOD0(GetToolbarModel, ToolbarModel*()); | |
34 MOCK_METHOD0(HideURL, void()); | |
35 }; | |
36 } // namespace | |
37 | |
38 class OmniboxViewGtkTest : public PlatformTest { | |
39 public: | |
40 OmniboxViewGtkTest() : file_thread_(content::BrowserThread::UI) {} | |
41 | |
42 virtual void SetUp() { | |
43 PlatformTest::SetUp(); | |
44 profile_.reset(new TestingProfile); | |
45 window_ = gtk_window_new(GTK_WINDOW_POPUP); | |
46 controller_.reset(new OmniboxEditControllerMock); | |
47 view_.reset(new OmniboxViewGtk(controller_.get(), NULL, profile_.get(), | |
48 NULL, false, window_)); | |
49 view_->Init(); | |
50 text_buffer_ = view_->text_buffer_; | |
51 } | |
52 | |
53 virtual void TearDown() { | |
54 gtk_widget_destroy(window_); | |
55 PlatformTest::TearDown(); | |
56 } | |
57 | |
58 void SetPasteClipboardRequested(bool b) { | |
59 view_->paste_clipboard_requested_ = b; | |
60 } | |
61 | |
62 scoped_ptr<OmniboxEditControllerMock> controller_; | |
63 scoped_ptr<TestingProfile> profile_; | |
64 GtkTextBuffer* text_buffer_; | |
65 scoped_ptr<OmniboxViewGtk> view_; | |
66 GtkWidget* window_; | |
67 content::TestBrowserThread file_thread_; | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(OmniboxViewGtkTest); | |
71 }; | |
72 | |
73 TEST_F(OmniboxViewGtkTest, InsertText) { | |
74 GtkTextIter i; | |
75 const char input[] = " hello, world "; | |
76 const std::string expected = input; | |
77 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); | |
78 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); | |
79 ASSERT_EQ(expected, base::UTF16ToUTF8(view_->GetText())); | |
80 } | |
81 | |
82 TEST_F(OmniboxViewGtkTest, PasteText) { | |
83 GtkTextIter i; | |
84 const char input[] = " hello, world "; | |
85 const std::string expected = "hello, world"; | |
86 SetPasteClipboardRequested(true); | |
87 view_->OnBeforePossibleChange(); | |
88 gtk_text_buffer_get_iter_at_offset(text_buffer_, &i, 0); | |
89 gtk_text_buffer_insert(text_buffer_, &i, input, strlen(input)); | |
90 | |
91 ASSERT_EQ(expected, base::UTF16ToUTF8(view_->GetText())); | |
92 } | |
OLD | NEW |