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