| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 6 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 7 #include "chrome/browser/search_engines/template_url_service_factory.h" | 7 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 8 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
| 9 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 9 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 10 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 10 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 11 #include "chrome/browser/ui/toolbar/test_toolbar_model.h" | 11 #include "chrome/browser/ui/toolbar/test_toolbar_model.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using base::ASCIIToUTF16; | 15 using base::ASCIIToUTF16; |
| 16 using base::UTF8ToUTF16; | 16 using base::UTF8ToUTF16; |
| 17 using content::WebContents; | 17 using content::WebContents; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 class TestingOmniboxView : public OmniboxView { | 21 class TestingOmniboxView : public OmniboxView { |
| 22 public: | 22 public: |
| 23 explicit TestingOmniboxView(OmniboxEditController* controller) | 23 explicit TestingOmniboxView(OmniboxEditController* controller) |
| 24 : OmniboxView(NULL, controller, NULL) {} | 24 : OmniboxView(NULL, controller, NULL) {} |
| 25 | 25 |
| 26 // OmniboxView: | 26 // OmniboxView: |
| 27 virtual void SaveStateToTab(WebContents* tab) OVERRIDE {} | 27 virtual void SaveStateToTab(WebContents* tab) override {} |
| 28 virtual void OnTabChanged(const WebContents* web_contents) OVERRIDE {} | 28 virtual void OnTabChanged(const WebContents* web_contents) override {} |
| 29 virtual void Update() OVERRIDE {} | 29 virtual void Update() override {} |
| 30 virtual void UpdatePlaceholderText() OVERRIDE {} | 30 virtual void UpdatePlaceholderText() override {} |
| 31 virtual void OpenMatch(const AutocompleteMatch& match, | 31 virtual void OpenMatch(const AutocompleteMatch& match, |
| 32 WindowOpenDisposition disposition, | 32 WindowOpenDisposition disposition, |
| 33 const GURL& alternate_nav_url, | 33 const GURL& alternate_nav_url, |
| 34 const base::string16& pasted_text, | 34 const base::string16& pasted_text, |
| 35 size_t selected_line) OVERRIDE {} | 35 size_t selected_line) override {} |
| 36 virtual base::string16 GetText() const OVERRIDE { return text_; } | 36 virtual base::string16 GetText() const override { return text_; } |
| 37 virtual void SetUserText(const base::string16& text, | 37 virtual void SetUserText(const base::string16& text, |
| 38 const base::string16& display_text, | 38 const base::string16& display_text, |
| 39 bool update_popup) OVERRIDE { | 39 bool update_popup) override { |
| 40 text_ = display_text; | 40 text_ = display_text; |
| 41 } | 41 } |
| 42 virtual void SetWindowTextAndCaretPos(const base::string16& text, | 42 virtual void SetWindowTextAndCaretPos(const base::string16& text, |
| 43 size_t caret_pos, | 43 size_t caret_pos, |
| 44 bool update_popup, | 44 bool update_popup, |
| 45 bool notify_text_changed) OVERRIDE { | 45 bool notify_text_changed) override { |
| 46 text_ = text; | 46 text_ = text; |
| 47 } | 47 } |
| 48 virtual void SetForcedQuery() OVERRIDE {} | 48 virtual void SetForcedQuery() override {} |
| 49 virtual bool IsSelectAll() const OVERRIDE { return false; } | 49 virtual bool IsSelectAll() const override { return false; } |
| 50 virtual bool DeleteAtEndPressed() OVERRIDE { return false; } | 50 virtual bool DeleteAtEndPressed() override { return false; } |
| 51 virtual void GetSelectionBounds(size_t* start, size_t* end) const OVERRIDE {} | 51 virtual void GetSelectionBounds(size_t* start, size_t* end) const override {} |
| 52 virtual void SelectAll(bool reversed) OVERRIDE {} | 52 virtual void SelectAll(bool reversed) override {} |
| 53 virtual void RevertAll() OVERRIDE {} | 53 virtual void RevertAll() override {} |
| 54 virtual void UpdatePopup() OVERRIDE {} | 54 virtual void UpdatePopup() override {} |
| 55 virtual void SetFocus() OVERRIDE {} | 55 virtual void SetFocus() override {} |
| 56 virtual void ApplyCaretVisibility() OVERRIDE {} | 56 virtual void ApplyCaretVisibility() override {} |
| 57 virtual void OnTemporaryTextMaybeChanged( | 57 virtual void OnTemporaryTextMaybeChanged( |
| 58 const base::string16& display_text, | 58 const base::string16& display_text, |
| 59 bool save_original_selection, | 59 bool save_original_selection, |
| 60 bool notify_text_changed) OVERRIDE { | 60 bool notify_text_changed) override { |
| 61 text_ = display_text; | 61 text_ = display_text; |
| 62 } | 62 } |
| 63 virtual bool OnInlineAutocompleteTextMaybeChanged( | 63 virtual bool OnInlineAutocompleteTextMaybeChanged( |
| 64 const base::string16& display_text, size_t user_text_length) OVERRIDE { | 64 const base::string16& display_text, size_t user_text_length) override { |
| 65 const bool text_changed = text_ != display_text; | 65 const bool text_changed = text_ != display_text; |
| 66 text_ = display_text; | 66 text_ = display_text; |
| 67 inline_autocomplete_text_ = display_text.substr(user_text_length); | 67 inline_autocomplete_text_ = display_text.substr(user_text_length); |
| 68 return text_changed; | 68 return text_changed; |
| 69 } | 69 } |
| 70 virtual void OnInlineAutocompleteTextCleared() OVERRIDE { | 70 virtual void OnInlineAutocompleteTextCleared() override { |
| 71 inline_autocomplete_text_.clear(); | 71 inline_autocomplete_text_.clear(); |
| 72 } | 72 } |
| 73 virtual void OnRevertTemporaryText() OVERRIDE {} | 73 virtual void OnRevertTemporaryText() override {} |
| 74 virtual void OnBeforePossibleChange() OVERRIDE {} | 74 virtual void OnBeforePossibleChange() override {} |
| 75 virtual bool OnAfterPossibleChange() OVERRIDE { return false; } | 75 virtual bool OnAfterPossibleChange() override { return false; } |
| 76 virtual gfx::NativeView GetNativeView() const OVERRIDE { return NULL; } | 76 virtual gfx::NativeView GetNativeView() const override { return NULL; } |
| 77 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE { | 77 virtual gfx::NativeView GetRelativeWindowForPopup() const override { |
| 78 return NULL; | 78 return NULL; |
| 79 } | 79 } |
| 80 virtual void SetGrayTextAutocompletion( | 80 virtual void SetGrayTextAutocompletion( |
| 81 const base::string16& input) OVERRIDE {} | 81 const base::string16& input) override {} |
| 82 virtual base::string16 GetGrayTextAutocompletion() const OVERRIDE { | 82 virtual base::string16 GetGrayTextAutocompletion() const override { |
| 83 return base::string16(); | 83 return base::string16(); |
| 84 } | 84 } |
| 85 virtual int GetTextWidth() const OVERRIDE { return 0; } | 85 virtual int GetTextWidth() const override { return 0; } |
| 86 virtual int GetWidth() const OVERRIDE { return 0; } | 86 virtual int GetWidth() const override { return 0; } |
| 87 virtual bool IsImeComposing() const OVERRIDE { return false; } | 87 virtual bool IsImeComposing() const override { return false; } |
| 88 virtual int GetOmniboxTextLength() const OVERRIDE { return 0; } | 88 virtual int GetOmniboxTextLength() const override { return 0; } |
| 89 virtual void EmphasizeURLComponents() OVERRIDE { } | 89 virtual void EmphasizeURLComponents() override { } |
| 90 | 90 |
| 91 const base::string16& inline_autocomplete_text() const { | 91 const base::string16& inline_autocomplete_text() const { |
| 92 return inline_autocomplete_text_; | 92 return inline_autocomplete_text_; |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 base::string16 text_; | 96 base::string16 text_; |
| 97 base::string16 inline_autocomplete_text_; | 97 base::string16 inline_autocomplete_text_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); | 99 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxView); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 class TestingOmniboxEditController : public OmniboxEditController { | 102 class TestingOmniboxEditController : public OmniboxEditController { |
| 103 public: | 103 public: |
| 104 explicit TestingOmniboxEditController(ToolbarModel* toolbar_model) | 104 explicit TestingOmniboxEditController(ToolbarModel* toolbar_model) |
| 105 : OmniboxEditController(NULL), | 105 : OmniboxEditController(NULL), |
| 106 toolbar_model_(toolbar_model) { | 106 toolbar_model_(toolbar_model) { |
| 107 } | 107 } |
| 108 | 108 |
| 109 protected: | 109 protected: |
| 110 // OmniboxEditController: | 110 // OmniboxEditController: |
| 111 virtual void Update(const content::WebContents* contents) OVERRIDE {} | 111 virtual void Update(const content::WebContents* contents) override {} |
| 112 virtual void OnChanged() OVERRIDE {} | 112 virtual void OnChanged() override {} |
| 113 virtual void OnSetFocus() OVERRIDE {} | 113 virtual void OnSetFocus() override {} |
| 114 virtual void ShowURL() OVERRIDE {} | 114 virtual void ShowURL() override {} |
| 115 virtual void HideURL() OVERRIDE {} | 115 virtual void HideURL() override {} |
| 116 virtual void EndOriginChipAnimations(bool cancel_fade) OVERRIDE {} | 116 virtual void EndOriginChipAnimations(bool cancel_fade) override {} |
| 117 virtual InstantController* GetInstant() OVERRIDE { return NULL; } | 117 virtual InstantController* GetInstant() override { return NULL; } |
| 118 virtual WebContents* GetWebContents() OVERRIDE { return NULL; } | 118 virtual WebContents* GetWebContents() override { return NULL; } |
| 119 virtual ToolbarModel* GetToolbarModel() OVERRIDE { return toolbar_model_; } | 119 virtual ToolbarModel* GetToolbarModel() override { return toolbar_model_; } |
| 120 virtual const ToolbarModel* GetToolbarModel() const OVERRIDE { | 120 virtual const ToolbarModel* GetToolbarModel() const override { |
| 121 return toolbar_model_; | 121 return toolbar_model_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 ToolbarModel* toolbar_model_; | 125 ToolbarModel* toolbar_model_; |
| 126 | 126 |
| 127 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); | 127 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxEditController); |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace | 130 } // namespace |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 model.SetUserText(UTF8ToUTF16("he")); | 256 model.SetUserText(UTF8ToUTF16("he")); |
| 257 model.OnPopupDataChanged(UTF8ToUTF16("llo"), NULL, base::string16(), false); | 257 model.OnPopupDataChanged(UTF8ToUTF16("llo"), NULL, base::string16(), false); |
| 258 EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText()); | 258 EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText()); |
| 259 EXPECT_EQ(UTF8ToUTF16("llo"), view.inline_autocomplete_text()); | 259 EXPECT_EQ(UTF8ToUTF16("llo"), view.inline_autocomplete_text()); |
| 260 | 260 |
| 261 model.AcceptTemporaryTextAsUserText(); | 261 model.AcceptTemporaryTextAsUserText(); |
| 262 EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText()); | 262 EXPECT_EQ(UTF8ToUTF16("hello"), view.GetText()); |
| 263 EXPECT_EQ(base::string16(), view.inline_autocomplete_text()); | 263 EXPECT_EQ(base::string16(), view.inline_autocomplete_text()); |
| 264 } | 264 } |
| OLD | NEW |